From b2409204a324f9ff15d65b732f4bd76e32b290fa Mon Sep 17 00:00:00 2001 From: Tomislav Jovanovic Date: Sat, 7 Apr 2018 02:38:51 +0200 Subject: [PATCH] Bug 1441336 - Test addon permissions for PerformanceTiming properties r=kmag MozReview-Commit-ID: LlySv9AinVC --HG-- extra : rebase_source : a0030887988152361ade306391c453ebaeb064a6 --- .../test_ext_contentscript_perf_observers.js | 67 +++++++++++++++++++ .../test/xpcshell/xpcshell-remote.ini | 3 + 2 files changed, 70 insertions(+) create mode 100644 toolkit/components/extensions/test/xpcshell/test_ext_contentscript_perf_observers.js diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_perf_observers.js b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_perf_observers.js new file mode 100644 index 000000000000..6bc2fd115db8 --- /dev/null +++ b/toolkit/components/extensions/test/xpcshell/test_ext_contentscript_perf_observers.js @@ -0,0 +1,67 @@ +"use strict"; + +const server = createHttpServer({hosts: ["a.example.com", "b.example.com", "c.example.com"]}); +server.registerDirectory("/data/", do_get_file("data")); + +add_task(async function test_perf_observers_cors() { + const extension = ExtensionTestUtils.loadExtension({ + manifest: { + permissions: [ + "http://b.example.com/", + ], + content_scripts: [{ + matches: ["http://a.example.com/file_sample.html"], + js: ["cs.js"], + }], + }, + files: { + "cs.js"() { + let obs = new window.PerformanceObserver(list => { + list.getEntries().forEach(e => { + browser.test.sendMessage("observed", { + url: e.name, + time: e.connectEnd, + size: e.encodedBodySize, + }); + }); + }); + obs.observe({entryTypes: ["resource"]}); + + let b = document.createElement("link"); + b.rel = "stylesheet"; + + // Simulate page including a cross-origin resource from b.example.com. + b.wrappedJSObject.href = "http://b.example.com/file_download.txt"; + document.head.appendChild(b); + + let c = document.createElement("link"); + c.rel = "stylesheet"; + + // Simulate page including a cross-origin resource from c.example.com. + c.wrappedJSObject.href = "http://c.example.com/file_download.txt"; + document.head.appendChild(c); + }, + }, + }); + + let page = await ExtensionTestUtils.loadContentPage("http://a.example.com/file_sample.html"); + await extension.startup(); + + let b = await extension.awaitMessage("observed"); + let c = await extension.awaitMessage("observed"); + + if (b.url.startsWith("http://c.")) { + [c, b] = [b, c]; + } + + ok(b.url.startsWith("http://b."), "Observed resource from b.example.com"); + ok(b.time > 0, "connectionEnd available from b.example.com"); + equal(b.size, 428, "encodedBodySize available from b.example.com"); + + ok(c.url.startsWith("http://c."), "Observed resource from c.example.com"); + equal(c.time, 0, "connectionEnd == 0 from c.example.com"); + equal(c.size, 0, "encodedBodySize == 0 from c.example.com"); + + await extension.unload(); + await page.close(); +}); diff --git a/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini b/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini index 31cec2a7e1c0..116e3ea1b81d 100644 --- a/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini +++ b/toolkit/components/extensions/test/xpcshell/xpcshell-remote.ini @@ -11,3 +11,6 @@ tags = webextensions remote-webextensions [include:xpcshell-common.ini] [include:xpcshell-content.ini] + +[test_ext_contentscript_perf_observers.js] +# Inexplicably, PerformanceObserver used in the test doesn't fire in non-e10s mode.