Bug 1041808 - Thousands of about:blank windows when cookies policy set to "Keep until: I close Firefox". r=smaug.
authorPeter Van der Beken <peterv@propagandism.org>
Wed, 13 Aug 2014 17:55:28 +0200
changeset 199454 acf50ee376c3
parent 199453 55126a7a7447
child 199455 e349895861e2
push id47655
push userpvanderbeken@mozilla.com
push date2014-08-14 11:34 +0000
treeherdermozilla-inbound@e349895861e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1041808
milestone34.0a1
Bug 1041808 - Thousands of about:blank windows when cookies policy set to "Keep until: I close Firefox". r=smaug.
extensions/cookie/nsCookiePromptService.cpp
extensions/cookie/test/mochitest.ini
extensions/cookie/test/test_bug1041808.html
--- a/extensions/cookie/nsCookiePromptService.cpp
+++ b/extensions/cookie/nsCookiePromptService.cpp
@@ -8,16 +8,17 @@
 #include "nsICookieAcceptDialog.h"
 #include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsIWindowWatcher.h"
 #include "nsIServiceManager.h"
 #include "nsString.h"
 #include "nsIDialogParamBlock.h"
 #include "nsIMutableArray.h"
+#include "mozilla/dom/ScriptSettings.h"
 
 /****************************************************************
  ************************ nsCookiePromptService *****************
  ****************************************************************/
 
 NS_IMPL_ISUPPORTS(nsCookiePromptService, nsICookiePromptService)
 
 nsCookiePromptService::nsCookiePromptService() {
@@ -66,16 +67,21 @@ nsCookiePromptService::CookieDialog(nsID
 
   if (parent) {
     nsCOMPtr<nsPIDOMWindow> privateParent(do_QueryInterface(parent));
     if (privateParent)
       privateParent = privateParent->GetPrivateRoot();
     parent = do_QueryInterface(privateParent);
   }
 
+  // We're opening a chrome window and passing in a nsIDialogParamBlock. Setting
+  // the nsIDialogParamBlock as the .arguments property on the chrome window
+  // requires system principals on the stack, so we use an AutoNoJSAPI for that.
+  mozilla::dom::AutoNoJSAPI nojsapi;
+
   // The cookie dialog will be modal for the root chrome window rather than the
   // tab containing the permission-requesting page.  This removes confusion
   // about which monitor is displaying the dialog (see bug 470356), but also
   // avoids unwanted tab switches (see bug 405239).
   rv = wwatcher->OpenWindow(parent, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank",
                             "centerscreen,chrome,modal,titlebar", arguments,
                             getter_AddRefs(dialog));
 
--- a/extensions/cookie/test/mochitest.ini
+++ b/extensions/cookie/test/mochitest.ini
@@ -33,8 +33,9 @@ support-files =
 [test_loadflags.html]
 [test_same_base_domain.html]
 [test_same_base_domain_2.html]
 [test_same_base_domain_3.html]
 [test_same_base_domain_4.html]
 [test_same_base_domain_5.html]
 [test_same_base_domain_6.html]
 [test_samedomain.html]
+[test_bug1041808.html]
new file mode 100644
--- /dev/null
+++ b/extensions/cookie/test/test_bug1041808.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1041808
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 1041808</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 1041808 **/
+
+SimpleTest.waitForExplicitFinish();
+
+var dialogsOpened = 0;
+var dialogsClosed = 0;
+function dismissDialog(aSubject, aTopic, aData)
+{
+  if (aTopic == "domwindowopened") {
+    var win = SpecialPowers.wrap(aSubject);
+    win.addEventListener("pageshow", function() {
+      win.removeEventListener("pageshow", arguments.callee, false);
+      sendKey("RETURN", aSubject);
+    }, false);
+    ++dialogsOpened;
+  } else if (aTopic == "domwindowclosed") {
+    ++dialogsClosed;
+  }
+}
+
+function runTest()
+{
+  SpecialPowers.Services.ww.registerNotification(dismissDialog);
+  document.cookie = "test1=testValue";
+  document.cookie = "test2=testValue";
+  document.cookie = "test3=testValue";
+  SpecialPowers.Services.ww.unregisterNotification(dismissDialog);
+  is(dialogsOpened, 3, "Setting a cookie should have asked for permission");
+  is(dialogsOpened - dialogsClosed, 0,
+     "Setting a cookie shouldn't have left any additional windows open");
+  SimpleTest.finish();
+}
+
+SpecialPowers.pushPrefEnv({"set": [["network.cookie.lifetimePolicy", 1]]},
+                          runTest);
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1041808">Mozilla Bug 1041808</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>