Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Bug 18995: Regression test to ensure CacheStorage is disabled in priv…
…ate browsing
- Loading branch information
Showing
with
120 additions
and 0 deletions.
- +5 −0 tbb-tests/browser.ini
- +50 −0 tbb-tests/browser_tor_bug18995.js
- +31 −0 tbb-tests/bug18995.html
- +26 −0 tbb-tests/worker_bug_18995.html
- +8 −0 tbb-tests/worker_bug_18995.js
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -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 <div id="result"/> 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 <div> | ||
| 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); | ||
| }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -0,0 +1,31 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>Bug 18995 test</title> | ||
| </head> | ||
| <body> | ||
| <div id="result"></div> | ||
| <script type="application/javascript"> | ||
| let resultDiv = document.getElementById("result"); | ||
| // Wait for a signal from chrome to start. | ||
| resultDiv.addEventListener("ready", function () { | ||
| let resultEvent = new Event("result"); | ||
| // Test caches.open(...) | ||
| caches.open("test1").then(function (value) { | ||
| // We are not supposed to succeed, but if we do, | ||
| // post the result to resultDiv. | ||
| resultDiv.innerHTML = value.toString(); | ||
| // Notify chrome that the result is available. | ||
| resultDiv.dispatchEvent(resultEvent); | ||
| }, function (reason) { | ||
| // We should arrive here to fail. Post the result | ||
| // to resultDiv. | ||
| resultDiv.innerHTML = reason.toString(); | ||
| // Notify chrome that the result is available. | ||
| resultDiv.dispatchEvent(resultEvent); | ||
| }); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -0,0 +1,26 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>Bug 18995 test</title> | ||
| </head> | ||
| <body> | ||
| <div id="result"></div> | ||
| <script type="application/javascript"> | ||
| let resultDiv = document.getElementById("result"); | ||
| // Wait for a signal from chrome to start. | ||
| resultDiv.addEventListener("ready", function() { | ||
| // Run the test worker. | ||
| let worker = new Worker("worker_bug_18995.js"); | ||
| // Wait for a message from the worker, which should contain | ||
| // the result or the error from the caches.open(...) call. | ||
| worker.addEventListener("message", function (msg) { | ||
| // Put the result in our resultDiv. | ||
| resultDiv.innerHTML = msg.data; | ||
| // Notify chrome that the result is ready. | ||
| resultDiv.dispatchEvent(new Event("result")); | ||
| }); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| @@ -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()); | ||
| }); |