Bug 1173467 P4 Add a test to validate Cache in private browsing window. r=ehsan
authorBen Kelly <ben@wanderview.com>
Fri, 26 Jun 2015 17:42:56 -0700
changeset 281234 30cefdf8d020e2badcffdeed6649b9df0adfeeb0
parent 281233 af075443ab21d097aa88eae96b3522647f23a869
child 281235 d4c34d7fb112dbfd548a9c371021980abd14ac96
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1173467
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1173467 P4 Add a test to validate Cache in private browsing window. r=ehsan
dom/cache/moz.build
dom/cache/test/mochitest/browser.ini
dom/cache/test/mochitest/browser_cache_pb_window.js
--- a/dom/cache/moz.build
+++ b/dom/cache/moz.build
@@ -95,8 +95,12 @@ FINAL_LIBRARY = 'xul'
 
 MOCHITEST_MANIFESTS += [
     'test/mochitest/mochitest.ini',
 ]
 
 MOCHITEST_CHROME_MANIFESTS += [
     'test/mochitest/chrome.ini',
 ]
+
+BROWSER_CHROME_MANIFESTS += [
+    'test/mochitest/browser.ini',
+]
new file mode 100644
--- /dev/null
+++ b/dom/cache/test/mochitest/browser.ini
@@ -0,0 +1,1 @@
+[browser_cache_pb_window.js]
new file mode 100644
--- /dev/null
+++ b/dom/cache/test/mochitest/browser_cache_pb_window.js
@@ -0,0 +1,82 @@
+var name = 'pb-window-cache';
+
+function testMatch(win) {
+  return new Promise(function(resolve, reject) {
+    win.caches.match('http://foo.com').then(function(response) {
+      ok(false, 'caches.match() should not return success');
+      reject();
+    }).catch(function(err) {
+      is('SecurityError', err.name, 'caches.match() should throw SecurityError');
+      resolve();
+    });
+  });
+}
+
+function testHas(win) {
+  return new Promise(function(resolve, reject) {
+    win.caches.has(name).then(function(result) {
+      ok(false, 'caches.has() should not return success');
+      reject();
+    }).catch(function(err) {
+      is('SecurityError', err.name, 'caches.has() should throw SecurityError');
+      resolve();
+    });
+  });
+}
+
+function testOpen(win) {
+  return new Promise(function(resolve, reject) {
+    win.caches.open(name).then(function(c) {
+      ok(false, 'caches.open() should not return success');
+      reject();
+    }).catch(function(err) {
+      is('SecurityError', err.name, 'caches.open() should throw SecurityError');
+      resolve();
+    });
+  });
+}
+
+function testDelete(win) {
+  return new Promise(function(resolve, reject) {
+    win.caches.delete(name).then(function(result) {
+      ok(false, 'caches.delete() should not return success');
+      reject();
+    }).catch(function(err) {
+      is('SecurityError', err.name, 'caches.delete() should throw SecurityError');
+      resolve();
+    });
+  });
+}
+
+function testKeys(win) {
+  return new Promise(function(resolve, reject) {
+    win.caches.keys().then(function(names) {
+      ok(false, 'caches.keys() should not return success');
+      reject();
+    }).catch(function(err) {
+      is('SecurityError', err.name, 'caches.keys() should throw SecurityError');
+      resolve();
+    });
+  });
+}
+
+function test() {
+  waitForExplicitFinish();
+  SpecialPowers.pushPrefEnv({'set': [['browser.privatebrowing.autostart', true],
+                                     ['dom.caches.enabled', true]]},
+                            function() {
+    var privateWin = OpenBrowserWindow({private: true});
+    privateWin.addEventListener('load', function() {
+      Promise.all([
+        testMatch(privateWin),
+        testHas(privateWin),
+        testOpen(privateWin),
+        testDelete(privateWin),
+        testKeys(privateWin)
+      ]).then(function() {
+        privateWin.close();
+        finish();
+      });
+    });
+  });
+}