From addf35abaeb312454252477003a775f39d987b8a Mon Sep 17 00:00:00 2001 From: Arthur Edelstein Date: Tue, 10 May 2016 16:51:08 -0700 Subject: [PATCH] Bug 18995: Regression test to ensure CacheStorage is disabled in private browsing --- tbb-tests/browser.ini | 5 ++++ tbb-tests/browser_tor_bug18995.js | 50 +++++++++++++++++++++++++++++++ tbb-tests/bug18995.html | 31 +++++++++++++++++++ tbb-tests/worker_bug_18995.html | 26 ++++++++++++++++ tbb-tests/worker_bug_18995.js | 8 +++++ 5 files changed, 120 insertions(+) create mode 100644 tbb-tests/browser_tor_bug18995.js create mode 100644 tbb-tests/bug18995.html create mode 100644 tbb-tests/worker_bug_18995.html create mode 100644 tbb-tests/worker_bug_18995.js diff --git a/tbb-tests/browser.ini b/tbb-tests/browser.ini index f481660f14170..9b6c47b1c8199 100644 --- a/tbb-tests/browser.ini +++ b/tbb-tests/browser.ini @@ -1,5 +1,10 @@ [DEFAULT] +support-files = + bug18995.html + worker_bug_18995.js + worker_bug_18995.html +[browser_tor_bug18995.js] [browser_tor_bug2950.js] [browser_tor_omnibox.js] [browser_tor_TB4.js] diff --git a/tbb-tests/browser_tor_bug18995.js b/tbb-tests/browser_tor_bug18995.js new file mode 100644 index 0000000000000..1f1801b0a3975 --- /dev/null +++ b/tbb-tests/browser_tor_bug18995.js @@ -0,0 +1,50 @@ +// __browser_tor_bug18995.js__. +// In this test, we open a private browsing window, and load pages +// that test whether we can call `caches.open("test")` + +// Helper function. +// Returns a promise that is fulfilled when the first event of eventype +// arrives from the target. +let listen = function (target, eventType, useCapture) { + return new Promise(function (resolve, reject) { + let listenFunction = function (event) { + target.removeEventListener(eventType, listenFunction, useCapture); + resolve(event); + }; + target.addEventListener(eventType, listenFunction, useCapture); + }); +}; + +// The main test +add_task(function* () { + // First open the private browsing window + let privateWin = yield BrowserTestUtils.openNewBrowserWindow({private: true}); + let privateBrowser = privateWin.gBrowser.selectedBrowser; + + // We have two pages: (1) access CacheStorage in content page + // (2) access CacheStorage in worker + let testURIs = ["http://mochi.test:8888/browser/tbb-tests/bug18995.html", + "http://mochi.test:8888/browser/tbb-tests/worker_bug_18995.html"]; + for (let testURI of testURIs) { + // Load the test page + privateBrowser.loadURI(testURI); + // Wait for it too fully load + yield BrowserTestUtils.browserLoaded(privateBrowser); + // Get the
in the content page + let resultDiv = privateBrowser.contentDocument.getElementById("result"); + // Send an event to the content page indicating we are ready to receive. + resultDiv.dispatchEvent(new Event("ready")); + // Wait for a signal from the content page that a result is ready. + yield listen(resultDiv, "result", false); + // Read the result from the result
+ let resultValue = resultDiv.innerHTML; + // Print out the result + info("received: " + resultValue); + // If we are in PBM, then the promise returned by caches.open(...) + // is supposed to arrive at a rejection with a SecurityError. + ok(resultValue.contains("SecurityError"), + "CacheStorage should fail in private browsing mode"); + } + // Close the browser window because we are done testing. + yield BrowserTestUtils.closeWindow(privateWin); +}); diff --git a/tbb-tests/bug18995.html b/tbb-tests/bug18995.html new file mode 100644 index 0000000000000..445a26abac12f --- /dev/null +++ b/tbb-tests/bug18995.html @@ -0,0 +1,31 @@ + + + + + Bug 18995 test + + +
+ + + diff --git a/tbb-tests/worker_bug_18995.html b/tbb-tests/worker_bug_18995.html new file mode 100644 index 0000000000000..d9be95c112d6d --- /dev/null +++ b/tbb-tests/worker_bug_18995.html @@ -0,0 +1,26 @@ + + + + + Bug 18995 test + + +
+ + + diff --git a/tbb-tests/worker_bug_18995.js b/tbb-tests/worker_bug_18995.js new file mode 100644 index 0000000000000..11641e1ad3e70 --- /dev/null +++ b/tbb-tests/worker_bug_18995.js @@ -0,0 +1,8 @@ +// Attempt to open a cache +caches.open("test2").then(function (value) { + // This is not supposed to happen. + self.postMessage(value.toString()); +}, function (reason) { + // We are supposed to fail. + self.postMessage(reason.toString()); +}); -- GitLab