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";
|
2018-01-30 08:17:48 +03:00
|
|
|
const { ManifestFinder } = Cu.import("resource://gre/modules/ManifestFinder.jsm", {});
|
2016-06-14 04:40:00 +03:00
|
|
|
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
|
|
|
|
*/
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function() {
|
2016-06-14 04:40:00 +03:00
|
|
|
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 {
|
2017-06-22 13:51:42 +03:00
|
|
|
await ManifestFinder.contentManifestLink(invalidValue);
|
2015-07-30 18:56:12 +03:00
|
|
|
ok(false, expected);
|
|
|
|
} catch (e) {
|
|
|
|
is(e.name, "TypeError", expected);
|
|
|
|
}
|
|
|
|
try {
|
2017-06-22 13:51:42 +03:00
|
|
|
await ManifestFinder.browserManifestLink(invalidValue);
|
2015-07-30 18:56:12 +03:00
|
|
|
ok(false, expected);
|
|
|
|
} catch (e) {
|
|
|
|
is(e.name, "TypeError", expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-22 13:51:42 +03:00
|
|
|
add_task(async function() {
|
2016-06-14 04:40:00 +03:00
|
|
|
const runningTests = tests
|
|
|
|
.map(
|
|
|
|
test => ({
|
|
|
|
gBrowser,
|
|
|
|
test,
|
|
|
|
url: makeTestURL(test),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.map(
|
2017-06-22 13:51:42 +03:00
|
|
|
tabOptions => BrowserTestUtils.withNewTab(tabOptions, async function(browser) {
|
|
|
|
const result = await ManifestFinder.browserHasManifestLink(browser);
|
2016-06-14 04:40:00 +03:00
|
|
|
tabOptions.test.run(result);
|
|
|
|
})
|
2015-07-30 18:56:12 +03:00
|
|
|
);
|
2017-06-22 13:51:42 +03:00
|
|
|
await Promise.all(runningTests);
|
2015-07-30 18:56:12 +03:00
|
|
|
});
|