[tbb-commits] [tor-browser/tor-browser-45.1.0esr-6.0-1] Bug 18995: Regression test to ensure CacheStorage is disabled in private browsing

gk at torproject.org gk at torproject.org
Wed May 11 20:23:51 UTC 2016


commit cea5f1efcd9590885127a0763432143aca01524c
Author: Arthur Edelstein <arthuredelstein at gmail.com>
Date:   Tue May 10 16:51:08 2016 -0700

    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(+)

diff --git a/tbb-tests/browser.ini b/tbb-tests/browser.ini
index f481660..9b6c47b 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 0000000..1f1801b
--- /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 <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);
+});
diff --git a/tbb-tests/bug18995.html b/tbb-tests/bug18995.html
new file mode 100644
index 0000000..445a26ab
--- /dev/null
+++ b/tbb-tests/bug18995.html
@@ -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>
diff --git a/tbb-tests/worker_bug_18995.html b/tbb-tests/worker_bug_18995.html
new file mode 100644
index 0000000..d9be95c
--- /dev/null
+++ b/tbb-tests/worker_bug_18995.html
@@ -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>
diff --git a/tbb-tests/worker_bug_18995.js b/tbb-tests/worker_bug_18995.js
new file mode 100644
index 0000000..11641e1
--- /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());
+});



More information about the tbb-commits mailing list