Add tests for private browsing in indexedDB, no bug. a=tests.
authorBen Turner <bent.mozilla@gmail.com>
Thu, 30 Dec 2010 10:04:24 -0800
changeset 59741 b725b46f03ed0f7c257de2a523f474662321632a
parent 59740 97e0776740d37912dbcf49fd8e63038d2ad24b3a
child 59742 5344d5110a0f8fc4fadb4bd1287911e0d003dd76
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewerstests
milestone2.0b9pre
Add tests for private browsing in indexedDB, no bug. a=tests.
dom/indexedDB/test/Makefile.in
dom/indexedDB/test/browser_privateBrowsing.js
--- a/dom/indexedDB/test/Makefile.in
+++ b/dom/indexedDB/test/Makefile.in
@@ -96,16 +96,17 @@ TEST_FILES = \
   $(NULL)
 
 ifeq (browser,$(MOZ_BUILD_APP))
 BROWSER_TEST_FILES = \
   browserHelpers.js \
   browser_permissionsPrompt.html \
   browser_permissionsPromptAllow.js \
   browser_permissionsPromptDeny.js \
+  browser_privateBrowsing.js \
   browser_quotaPrompt.html \
   browser_quotaPromptAllow.js \
   browser_quotaPromptDeny.js \
   head.js \
   $(NULL)
 
 libs:: $(BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/test/browser_privateBrowsing.js
@@ -0,0 +1,71 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const testPageURL = "http://mochi.test:8888/browser/" +
+  "dom/indexedDB/test/browser_permissionsPrompt.html";
+const notificationID = "indexedDB-permissions-prompt";
+const exceptionText = "5: A mutation operation was attempted on a database " +
+                      "that did not allow mutations.";
+
+function test()
+{
+  waitForExplicitFinish();
+  // Avoids the actual prompt
+  setPermission(testPageURL, "indexedDB");
+  executeSoon(test2);
+}
+
+function test1()
+{
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.addEventListener("load", function () {
+    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+
+    setFinishedCallback(function(result, exception) {
+      ok(result instanceof Components.interfaces.nsIIDBDatabase,
+         "First database creation was successful");
+      ok(!exception, "No exception");
+      gBrowser.removeCurrentTab();
+
+      executeSoon(test2);
+    });
+  }, true);
+  content.location = testPageURL;
+}
+
+function test2()
+{
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+  pb.privateBrowsingEnabled = true;
+
+  executeSoon(test3);
+}
+
+function test3()
+{
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.selectedBrowser.addEventListener("load", function () {
+    gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
+
+    setFinishedCallback(function(result, exception) {
+      ok(!result, "No database");
+      is(exception, exceptionText, "Correct exception");
+      gBrowser.removeCurrentTab();
+
+      executeSoon(test4);
+    });
+  }, true);
+  content.location = testPageURL;
+}
+
+function test4()
+{
+  let pb = Cc["@mozilla.org/privatebrowsing;1"].
+           getService(Ci.nsIPrivateBrowsingService);
+  pb.privateBrowsingEnabled = false;
+
+  executeSoon(finish);
+}