Bug 880621 - Create a test that checks about:cache after private browsing. r=ehsan
authorManuela Muntean <manuela.muntean@softvision.ro>
Tue, 16 Jul 2013 10:16:58 +0300
changeset 138691 269b7a2b7310625157cc4503775fde110096b526
parent 138690 8421bc7505851157457c4986d31a3e1edbf67de3
child 138692 5a4b367aae64db4e6cdaabcf87d4b6c301bb5f3c
push id24964
push userryanvm@gmail.com
push dateTue, 16 Jul 2013 20:04:09 +0000
treeherderautoland@fd10ead17ace [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs880621
milestone25.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 880621 - Create a test that checks about:cache after private browsing. r=ehsan
browser/components/privatebrowsing/test/browser/Makefile.in
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js
--- a/browser/components/privatebrowsing/test/browser/Makefile.in
+++ b/browser/components/privatebrowsing/test/browser/Makefile.in
@@ -9,16 +9,17 @@ VPATH		= @srcdir@
 relativesrcdir  = @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_BROWSER_FILES =  \
 		head.js \
                 browser_privatebrowsing_aboutHomeButtonAfterWindowClose.js \
                 browser_privatebrowsing_aboutSessionRestore.js \
+                browser_privatebrowsing_cache.js \
 		browser_privatebrowsing_certexceptionsui.js \
 		browser_privatebrowsing_concurrent.js \
 		browser_privatebrowsing_concurrent_page.html \
 		browser_privatebrowsing_cookieacceptdialog.js \
 		browser_privatebrowsing_cookieacceptdialog.html \
 		browser_privatebrowsing_crh.js \
 		browser_privatebrowsing_downloadLastDir.js \
 		browser_privatebrowsing_downloadLastDir_c.js \
new file mode 100644
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js
@@ -0,0 +1,121 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Check about:cache after private browsing
+// This test covers MozTrap test 6047
+// bug 880621
+
+let tmp = {};
+
+Cc["@mozilla.org/moz/jssubscript-loader;1"]
+  .getService(Ci.mozIJSSubScriptLoader)
+  .loadSubScript("chrome://browser/content/sanitize.js", tmp);
+
+let Sanitizer = tmp.Sanitizer;
+
+function test() {
+
+  waitForExplicitFinish();
+
+  sanitizeCache();
+
+  let nrEntriesR1 = get_device_entry_count("disk");
+  is (nrEntriesR1, 0, "Disk cache reports 0KB and has no entries");
+
+  get_cache_for_private_window();
+}
+
+function cleanup() {
+  let prefs = Services.prefs.getBranch("privacy.cpd.");
+
+  prefs.clearUserPref("history");
+  prefs.clearUserPref("downloads");
+  prefs.clearUserPref("cache");
+  prefs.clearUserPref("cookies");
+  prefs.clearUserPref("formdata");
+  prefs.clearUserPref("offlineApps");
+  prefs.clearUserPref("passwords");
+  prefs.clearUserPref("sessions");
+  prefs.clearUserPref("siteSettings");
+}
+
+function sanitizeCache() {
+
+  let s = new Sanitizer();
+  s.ignoreTimespan = false;
+  s.prefDomain = "privacy.cpd.";
+
+  let prefs = gPrefService.getBranch(s.prefDomain);
+  prefs.setBoolPref("history", false);
+  prefs.setBoolPref("downloads", false);
+  prefs.setBoolPref("cache", true);
+  prefs.setBoolPref("cookies", false);
+  prefs.setBoolPref("formdata", false);
+  prefs.setBoolPref("offlineApps", false);
+  prefs.setBoolPref("passwords", false);
+  prefs.setBoolPref("sessions", false);
+  prefs.setBoolPref("siteSettings", false);
+
+  s.sanitize();
+}
+
+function get_cache_service() {
+  return Components.classes["@mozilla.org/network/cache-service;1"]
+                   .getService(Components.interfaces.nsICacheService);
+}
+
+function get_device_entry_count(device) {
+  var cs = get_cache_service();
+  var entry_count = -1;
+
+  var visitor = {
+    visitDevice: function (deviceID, deviceInfo) {
+      if (device == deviceID) {
+        entry_count = deviceInfo.entryCount;
+      }
+      return false;
+    },
+    visitEntry: function (deviceID, entryInfo) {
+      do_throw("nsICacheVisitor.visitEntry should not be called " +
+               "when checking the availability of devices");
+    }
+  };
+
+  cs.visitEntries(visitor);
+  return entry_count;
+}
+
+function get_cache_for_private_window () {
+  let win = OpenBrowserWindow({private: true});
+  win.addEventListener("load", function () {
+    win.removeEventListener("load", arguments.callee, false);
+
+    executeSoon(function() {
+
+      ok(true, "The private window got loaded");
+
+      let tab = win.gBrowser.addTab("http://example.org");
+      win.gBrowser.selectedTab = tab;
+      let newTabBrowser = win.gBrowser.getBrowserForTab(tab);
+
+      newTabBrowser.addEventListener("load", function eventHandler() {
+        newTabBrowser.removeEventListener("load", eventHandler, true);
+
+        executeSoon(function() {
+
+          let nrEntriesP = get_device_entry_count("memory");
+          is (nrEntriesP, 1, "Memory cache reports some entries from example.org domain");
+
+          let nrEntriesR2 = get_device_entry_count("disk");
+          is (nrEntriesR2, 0, "Disk cache reports 0KB and has no entries");
+
+          cleanup();
+
+          win.close();
+          finish();
+        });
+      }, true);
+    });
+  }, false);
+}