2015-07-30 18:56:12 +03:00
|
|
|
//Used by JSHint:
|
2016-06-14 04:40:00 +03:00
|
|
|
/*global Cu, BrowserTestUtils, ok, add_task, gBrowser */
|
2015-07-30 18:56:12 +03:00
|
|
|
"use strict";
|
2016-06-14 04:40:00 +03:00
|
|
|
const { ManifestFinder } = Cu.import("resource://gre/modules/ManifestFinder.jsm", {});
|
|
|
|
const defaultURL = new URL("http://example.org/browser/dom/manifest/test/resource.sjs");
|
|
|
|
defaultURL.searchParams.set("Content-Type", "text/html; charset=utf-8");
|
2015-07-30 18:56:12 +03:00
|
|
|
|
|
|
|
const tests = [{
|
2016-06-14 04:40:00 +03:00
|
|
|
body: `
|
|
|
|
<link rel="manifesto" href='${defaultURL}?body={"name":"fail"}'>
|
|
|
|
<link rel="foo bar manifest bar test" href='${defaultURL}?body={"name":"value"}'>
|
|
|
|
<link rel="manifest" href='${defaultURL}?body={"name":"fail"}'>
|
|
|
|
`,
|
2015-07-30 18:56:12 +03:00
|
|
|
run(result) {
|
2016-06-14 04:40:00 +03:00
|
|
|
ok(result, "Document has a web manifest.");
|
2015-07-30 18:56:12 +03:00
|
|
|
},
|
|
|
|
}, {
|
2016-06-14 04:40:00 +03:00
|
|
|
body: `
|
|
|
|
<link rel="amanifista" href='${defaultURL}?body={"name":"fail"}'>
|
|
|
|
<link rel="foo bar manifesto bar test" href='${defaultURL}?body={"name":"pass-1"}'>
|
|
|
|
<link rel="manifesto" href='${defaultURL}?body={"name":"fail"}'>`,
|
2015-07-30 18:56:12 +03:00
|
|
|
run(result) {
|
2016-06-14 04:40:00 +03:00
|
|
|
ok(!result, "Document does not have a web manifest.");
|
2015-07-30 18:56:12 +03:00
|
|
|
},
|
|
|
|
}, {
|
2016-06-14 04:40:00 +03:00
|
|
|
body: `
|
|
|
|
<link rel="manifest" href="">
|
|
|
|
<link rel="manifest" href='${defaultURL}?body={"name":"fail"}'>`,
|
2015-07-30 18:56:12 +03:00
|
|
|
run(result) {
|
2016-06-14 04:40:00 +03:00
|
|
|
ok(!result, "Manifest link is has empty href.");
|
2015-07-30 18:56:12 +03:00
|
|
|
},
|
|
|
|
}, {
|
2016-06-14 04:40:00 +03:00
|
|
|
body: `
|
|
|
|
<link rel="manifest">
|
|
|
|
<link rel="manifest" href='${defaultURL}?body={"name":"fail"}'>`,
|
2015-07-30 18:56:12 +03:00
|
|
|
run(result) {
|
2016-06-14 04:40:00 +03:00
|
|
|
ok(!result, "Manifest link is missing.");
|
2015-07-30 18:56:12 +03:00
|
|
|
},
|
|
|
|
}];
|
|
|
|
|
2016-06-14 04:40:00 +03:00
|
|
|
function makeTestURL({ body }) {
|
|
|
|
const url = new URL(defaultURL);
|
|
|
|
url.searchParams.set("body", encodeURIComponent(body));
|
|
|
|
return url.href;
|
|
|
|
}
|
|
|
|
|
2015-07-30 18:56:12 +03:00
|
|
|
/**
|
|
|
|
* Test basic API error conditions
|
|
|
|
*/
|
2016-06-14 04:40:00 +03:00
|
|
|
add_task(function*() {
|
|
|
|
const expected = "Invalid types should throw a TypeError.";
|
2015-07-30 18:56:12 +03:00
|
|
|
for (let invalidValue of [undefined, null, 1, {}, "test"]) {
|
|
|
|
try {
|
|
|
|
yield ManifestFinder.contentManifestLink(invalidValue);
|
|
|
|
ok(false, expected);
|
|
|
|
} catch (e) {
|
|
|
|
is(e.name, "TypeError", expected);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
yield ManifestFinder.browserManifestLink(invalidValue);
|
|
|
|
ok(false, expected);
|
|
|
|
} catch (e) {
|
|
|
|
is(e.name, "TypeError", expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-14 04:40:00 +03:00
|
|
|
add_task(function*() {
|
|
|
|
const runningTests = tests
|
|
|
|
.map(
|
|
|
|
test => ({
|
|
|
|
gBrowser,
|
|
|
|
test,
|
|
|
|
url: makeTestURL(test),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.map(
|
|
|
|
tabOptions => BrowserTestUtils.withNewTab(tabOptions, function*(browser) {
|
|
|
|
const result = yield ManifestFinder.browserHasManifestLink(browser);
|
|
|
|
tabOptions.test.run(result);
|
|
|
|
})
|
2015-07-30 18:56:12 +03:00
|
|
|
);
|
2016-06-14 04:40:00 +03:00
|
|
|
yield Promise.all(runningTests);
|
2015-07-30 18:56:12 +03:00
|
|
|
});
|