Bug 1149497 - Wildcard domain cookies are not displayed. r=mratcliffe
authorJarda Snajdr <jsnajdr@gmail.com>
Wed, 20 Apr 2016 22:50:00 +0200
changeset 331976 2ca0a1672d8ff4500d37bbb7d753fc03b729cabf
parent 331975 766c8d6d4198c7612a457137b8fc5944a63e1270
child 331977 a4dc7ffd8a5fe88f29080999a5b1cbef6c3bb70e
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmratcliffe
bugs1149497
milestone48.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 1149497 - Wildcard domain cookies are not displayed. r=mratcliffe
devtools/client/storage/test/browser.ini
devtools/client/storage/test/browser_storage_cookies_domain.js
devtools/client/storage/test/storage-cookies.html
devtools/server/actors/storage.js
--- a/devtools/client/storage/test/browser.ini
+++ b/devtools/client/storage/test/browser.ini
@@ -15,16 +15,17 @@ support-files =
   storage-unsecured-iframe.html
   storage-updates.html
   head.js
   !/devtools/client/framework/test/shared-head.js
 
 [browser_storage_basic.js]
 [browser_storage_cache_error.js]
 [browser_storage_cookies_delete_all.js]
+[browser_storage_cookies_domain.js]
 [browser_storage_cookies_edit.js]
 [browser_storage_cookies_edit_keyboard.js]
 [browser_storage_cookies_tab_navigation.js]
 [browser_storage_delete.js]
 [browser_storage_delete_all.js]
 [browser_storage_delete_tree.js]
 [browser_storage_dynamic_updates.js]
 [browser_storage_empty_objectstores.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/storage/test/browser_storage_cookies_domain.js
@@ -0,0 +1,21 @@
+/* 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/. */
+
+/* import-globals-from ../../framework/test/shared-head.js */
+
+"use strict";
+
+// Test that cookies with domain equal to full host name are listed.
+// E.g., ".example.org" vs. example.org). Bug 1149497.
+
+add_task(function* () {
+  yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-cookies.html");
+
+  yield checkState([
+    [["cookies", "test1.example.org"],
+      ["test1", "test2", "test3", "test4", "test5"]],
+  ]);
+
+  yield finishTests();
+});
--- a/devtools/client/storage/test/storage-cookies.html
+++ b/devtools/client/storage/test/storage-cookies.html
@@ -5,21 +5,20 @@
   -->
   <head>
     <meta charset="utf-8">
     <title>Storage inspector cookie test</title>
   </head>
   <body>
     <script type="application/javascript;version=1.7">
     "use strict";
-    let partialHostname = location.hostname.match(/^[^.]+(\..*)$/)[1];
     let expiresIn24Hours = new Date(Date.now() + 60 * 60 * 24 * 1000).toUTCString();
     for (let i = 1; i <= 5; i++) {
-    let cookieString = "test" + i + "=value" + i +
-    ";expires=" + expiresIn24Hours + ";path=/browser";
-    if (i % 2) {
-    cookieString += ";domain=.example.org";
-    }
-    document.cookie = cookieString;
+      let cookieString = "test" + i + "=value" + i +
+        ";expires=" + expiresIn24Hours + ";path=/browser";
+      if (i % 2) {
+        cookieString += ";domain=test1.example.org";
+      }
+      document.cookie = cookieString;
     }
     </script>
   </body>
 </html>
--- a/devtools/server/actors/storage.js
+++ b/devtools/server/actors/storage.js
@@ -526,17 +526,17 @@ StorageActors.createActor({
    * Given a cookie object and a host, figure out if the cookie is valid for
    * that host.
    */
   isCookieAtHost: function(cookie, host) {
     if (cookie.host == null) {
       return host == null;
     }
     if (cookie.host.startsWith(".")) {
-      return host.endsWith(cookie.host);
+      return ("." + host).endsWith(cookie.host);
     }
     if (cookie.host === "") {
       return host.startsWith("file://" + cookie.path);
     }
     return cookie.host == host;
   },
 
   toStoreObject: function(cookie) {
@@ -897,17 +897,17 @@ var cookieHelpers = {
   },
 
   _removeCookies: function(host, opts = {}) {
     function hostMatches(cookieHost, matchHost) {
       if (cookieHost == null) {
         return matchHost == null;
       }
       if (cookieHost.startsWith(".")) {
-        return matchHost.endsWith(cookieHost);
+        return ("." + matchHost).endsWith(cookieHost);
       }
       return cookieHost == host;
     }
 
     let enumerator = Services.cookies.getCookiesFromHost(host);
     while (enumerator.hasMoreElements()) {
       let cookie = enumerator.getNext().QueryInterface(Ci.nsICookie2);
       if (hostMatches(cookie.host, host) &&