//Used by JSHint: /*global Cu, BrowserTestUtils, ok, add_task, gBrowser */ "use strict"; 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"); const tests = [{ body: ` `, run(result) { ok(result, "Document has a web manifest."); }, }, { body: ` `, run(result) { ok(!result, "Document does not have a web manifest."); }, }, { body: ` `, run(result) { ok(!result, "Manifest link is has empty href."); }, }, { body: ` `, run(result) { ok(!result, "Manifest link is missing."); }, }]; function makeTestURL({ body }) { const url = new URL(defaultURL); url.searchParams.set("body", encodeURIComponent(body)); return url.href; } /** * Test basic API error conditions */ add_task(function*() { const expected = "Invalid types should throw a TypeError."; 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); } } }); 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); }) ); yield Promise.all(runningTests); });