Bug 1286798 - Part 11: Enable tests for session only mode (but only for the old local storage implementation); r=asuth
authorJan Varga <jan.varga@gmail.com>
Thu, 29 Nov 2018 21:47:48 +0100
changeset 505229 4e938b6813e3e8dcb10998d89243678463f4b42a
parent 505228 75c28b78f8ee02018ccaec9c2f4035d46182d10e
child 505230 a4324eecfb06d326abe06677339bf153c627af33
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1286798
milestone65.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 1286798 - Part 11: Enable tests for session only mode (but only for the old local storage implementation); r=asuth An attribute for checking if the next gen local storage implementation is enabled is exposed via a new interface nsILocalStorageManager which should be used for any other local storage specific stuff.
dom/localstorage/LocalStorageManager2.cpp
dom/localstorage/LocalStorageManager2.h
dom/localstorage/moz.build
dom/localstorage/nsILocalStorageManager.idl
dom/storage/LocalStorage.cpp
dom/storage/LocalStorageManager.cpp
dom/storage/LocalStorageManager.h
dom/tests/mochitest/localstorage/mochitest.ini
dom/tests/mochitest/localstorage/test_cookieSession.html
dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html
dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html
dom/tests/mochitest/localstorage/test_localStorageSessionPrefOverride.html
toolkit/modules/Services.jsm
--- a/dom/localstorage/LocalStorageManager2.cpp
+++ b/dom/localstorage/LocalStorageManager2.cpp
@@ -17,17 +17,19 @@ LocalStorageManager2::LocalStorageManage
   MOZ_ASSERT(NextGenLocalStorageEnabled());
 }
 
 LocalStorageManager2::~LocalStorageManager2()
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
-NS_IMPL_ISUPPORTS(LocalStorageManager2, nsIDOMStorageManager)
+NS_IMPL_ISUPPORTS(LocalStorageManager2,
+                  nsIDOMStorageManager,
+                  nsILocalStorageManager)
 
 NS_IMETHODIMP
 LocalStorageManager2::PrecacheStorage(nsIPrincipal* aPrincipal,
                                       Storage** _retval)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aPrincipal);
   MOZ_ASSERT(_retval);
@@ -79,10 +81,20 @@ LocalStorageManager2::CheckStorage(nsIPr
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aPrincipal);
   MOZ_ASSERT(aStorage);
   MOZ_ASSERT(_retval);
 
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
+NS_IMETHODIMP
+LocalStorageManager2::GetNextGenLocalStorageEnabled(bool* aResult)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aResult);
+
+  *aResult = NextGenLocalStorageEnabled();
+  return NS_OK;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/localstorage/LocalStorageManager2.h
+++ b/dom/localstorage/LocalStorageManager2.h
@@ -3,28 +3,31 @@
 /* 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/. */
 
 #ifndef mozilla_dom_localstorage_LocalStorageManager2_h
 #define mozilla_dom_localstorage_LocalStorageManager2_h
 
 #include "nsIDOMStorageManager.h"
+#include "nsILocalStorageManager.h"
 
 namespace mozilla {
 namespace dom {
 
 class LocalStorageManager2 final
   : public nsIDOMStorageManager
+  , public nsILocalStorageManager
 {
 public:
   LocalStorageManager2();
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMSTORAGEMANAGER
+  NS_DECL_NSILOCALSTORAGEMANAGER
 
 private:
   ~LocalStorageManager2();
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/dom/localstorage/moz.build
+++ b/dom/localstorage/moz.build
@@ -1,14 +1,20 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
+XPIDL_SOURCES += [
+    'nsILocalStorageManager.idl',
+]
+
+XPIDL_MODULE = 'dom_localstorage'
+
 EXPORTS.mozilla.dom.localstorage += [
     'ActorsParent.h',
 ]
 
 EXPORTS.mozilla.dom += [
     'LocalStorageCommon.h',
     'LocalStorageManager2.h',
     'LSObject.h',
new file mode 100644
--- /dev/null
+++ b/dom/localstorage/nsILocalStorageManager.idl
@@ -0,0 +1,15 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#include "nsISupports.idl"
+
+interface nsIPrincipal;
+
+[scriptable, builtinclass, uuid(d4f534da-2744-4db3-8774-8b187c64ade9)]
+interface nsILocalStorageManager : nsISupports
+{
+  readonly attribute boolean nextGenLocalStorageEnabled;
+};
--- a/dom/storage/LocalStorage.cpp
+++ b/dom/storage/LocalStorage.cpp
@@ -28,17 +28,26 @@
 #include "nsServiceManagerUtils.h"
 
 namespace mozilla {
 
 using namespace ipc;
 
 namespace dom {
 
-NS_IMPL_CYCLE_COLLECTION_INHERITED(LocalStorage, Storage, mManager);
+NS_IMPL_CYCLE_COLLECTION_CLASS(LocalStorage)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(LocalStorage, Storage)
+NS_IMPL_CYCLE_COLLECTION_UNLINK(mManager)
+NS_IMPL_CYCLE_COLLECTION_UNLINK_END
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(LocalStorage, Storage)
+  CycleCollectionNoteChild(cb,
+                           NS_ISUPPORTS_CAST(nsIDOMStorageManager*,
+                                             tmp->mManager.get()),
+                           "mManager");
+NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(LocalStorage)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
 NS_INTERFACE_MAP_END_INHERITING(Storage)
 
 NS_IMPL_ADDREF_INHERITED(LocalStorage, Storage)
 NS_IMPL_RELEASE_INHERITED(LocalStorage, Storage)
 
--- a/dom/storage/LocalStorageManager.cpp
+++ b/dom/storage/LocalStorageManager.cpp
@@ -52,17 +52,18 @@ LocalStorageManager::GetQuota()
                                          DEFAULT_QUOTA_LIMIT);
     preferencesInitialized = true;
   }
 
   return gQuotaLimit * 1024; // pref is in kBs
 }
 
 NS_IMPL_ISUPPORTS(LocalStorageManager,
-                  nsIDOMStorageManager)
+                  nsIDOMStorageManager,
+                  nsILocalStorageManager)
 
 LocalStorageManager::LocalStorageManager()
   : mCaches(8)
 {
   MOZ_ASSERT(!NextGenLocalStorageEnabled());
 
   StorageObserver* observer = StorageObserver::Self();
   NS_ASSERTION(observer, "No StorageObserver, cannot observe private data delete notifications!");
@@ -365,16 +366,26 @@ LocalStorageManager::CheckStorage(nsIPri
   if (!storage->PrincipalEquals(aPrincipal)) {
     return NS_OK;
   }
 
   *aRetval = true;
   return NS_OK;
 }
 
+NS_IMETHODIMP
+LocalStorageManager::GetNextGenLocalStorageEnabled(bool* aResult)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  MOZ_ASSERT(aResult);
+
+  *aResult = NextGenLocalStorageEnabled();
+  return NS_OK;
+}
+
 void
 LocalStorageManager::ClearCaches(uint32_t aUnloadFlags,
                                  const OriginAttributesPattern& aPattern,
                                  const nsACString& aOriginScope)
 {
   for (auto iter1 = mCaches.Iter(); !iter1.Done(); iter1.Next()) {
     OriginAttributes oa;
     DebugOnly<bool> rv = oa.PopulateFromSuffix(iter1.Key());
--- a/dom/storage/LocalStorageManager.h
+++ b/dom/storage/LocalStorageManager.h
@@ -3,16 +3,17 @@
 /* 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/. */
 
 #ifndef mozilla_dom_StorageManager_h
 #define mozilla_dom_StorageManager_h
 
 #include "nsIDOMStorageManager.h"
+#include "nsILocalStorageManager.h"
 #include "StorageObserver.h"
 
 #include "LocalStorage.h"
 #include "LocalStorageCache.h"
 #include "mozilla/dom/Storage.h"
 
 #include "nsTHashtable.h"
 #include "nsDataHashtable.h"
@@ -21,20 +22,22 @@
 
 namespace mozilla {
 
 class OriginAttributesPattern;
 
 namespace dom {
 
 class LocalStorageManager final : public nsIDOMStorageManager
+                                , public nsILocalStorageManager
                                 , public StorageObserverSink
 {
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMSTORAGEMANAGER
+  NS_DECL_NSILOCALSTORAGEMANAGER
 
 public:
   LocalStorageManager();
 
   // Reads the preference for DOM storage quota
   static uint32_t GetQuota();
 
   // Gets (but not ensures) cache for the given scope
--- a/dom/tests/mochitest/localstorage/mochitest.ini
+++ b/dom/tests/mochitest/localstorage/mochitest.ini
@@ -19,35 +19,35 @@ support-files =
   file_tryAccessSessionStorage.html
 
 [test_brokenUTF-16.html]
 #[test_bug600307-DBOps.html]
 [test_bug746272-1.html]
 [test_bug746272-2.html]
 skip-if = os == "android" || verify # bug 962029
 [test_cookieBlock.html]
-#[test_cookieSession.html]
+[test_cookieSession.html]
 [test_embededNulls.html]
 [test_keySync.html]
 [test_localStorageBase.html]
 skip-if = e10s
-#[test_localStorageBaseSessionOnly.html]
+[test_localStorageBaseSessionOnly.html]
 [test_localStorageCookieSettings.html]
 #[test_localStorageEnablePref.html]
 [test_localStorageKeyOrder.html]
 [test_localStorageOriginsDiff.html]
 [test_localStorageOriginsDomainDiffs.html]
 [test_localStorageOriginsEquals.html]
 skip-if = toolkit == 'android'
 [test_localStorageOriginsPortDiffs.html]
 [test_localStorageOriginsSchemaDiffs.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 #[test_localStorageQuota.html]
 #skip-if = toolkit == 'android' #TIMED_OUT
-#[test_localStorageQuotaSessionOnly.html]
-#skip-if = toolkit == 'android' || (verify && (os == 'linux' || os == 'win')) #TIMED_OUT
+[test_localStorageQuotaSessionOnly.html]
+skip-if = toolkit == 'android' || (verify && (os == 'linux' || os == 'mac' || os == 'win')) #TIMED_OUT
 [test_localStorageQuotaSessionOnly2.html]
 skip-if = true # bug 1347690
 [test_localStorageReplace.html]
 skip-if = toolkit == 'android'
 [test_storageConstructor.html]
-#[test_localStorageSessionPrefOverride.html]
+[test_localStorageSessionPrefOverride.html]
 [test_firstPartyOnlyPermission.html]
--- a/dom/tests/mochitest/localstorage/test_cookieSession.html
+++ b/dom/tests/mochitest/localstorage/test_cookieSession.html
@@ -113,16 +113,23 @@ function startTest() {
     case '?5':
       test5();
       break;
     case '?6':
       test6();
       break;
     default:
       SimpleTest.waitForExplicitFinish();
+
+      if (SpecialPowers.Services.lsm.nextGenLocalStorageEnabled) {
+        ok(true, "Test ignored when the next gen local storage is enabled.");
+        SimpleTest.finish();
+        return;
+      }
+
       var iframe = document.createElement('iframe');
       iframe.src = 'test_cookieSession.html?1';
       document.body.appendChild(iframe);
   }
 }
 </script>
 
 </head>
--- a/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageBaseSessionOnly.html
@@ -4,16 +4,22 @@
 
 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 
 <script type="text/javascript">
 
 function startTest()
 {
+  if (SpecialPowers.Services.lsm.nextGenLocalStorageEnabled) {
+    ok(true, "Test ignored when the next gen local storage is enabled.");
+    SimpleTest.finish();
+    return;
+  }
+
   SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 'context': document}], test1);
 }
 
 function test1() {
   // Initially check the localStorage is empty
   is(localStorage.length, 0, "The storage is empty [1]");
   is(localStorage.key(0), null, "key() should return null for out-of-bounds access");
   is(localStorage.key(-1), null, "key() should return null for out-of-bounds access");
--- a/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html
@@ -91,16 +91,22 @@ function doNextTest()
 
 function doStep()
 {
 }
 
 SimpleTest.waitForExplicitFinish();
 
 function startTest() {
+  if (SpecialPowers.Services.lsm.nextGenLocalStorageEnabled) {
+    ok(true, "Test ignored when the next gen local storage is enabled.");
+    SimpleTest.finish();
+    return;
+  }
+
   SpecialPowers.pushPermissions([{'type': 'cookie', 'allow': SpecialPowers.Ci.nsICookiePermission.ACCESS_SESSION, 'context': document}], function() {
     // Initialy setup the quota to testing value of 1024B and
     // set a 500 bytes key with name length 1 (allocate 501 bytes)
     SpecialPowers.pushPrefEnv({"set": [["dom.storage.default_quota", 1], ["security.mixed_content.block_display_content", false], ["security.mixed_content.block_active_content", false]]}, doNextTest);
   });
 }
 </script>
 
--- a/dom/tests/mochitest/localstorage/test_localStorageSessionPrefOverride.html
+++ b/dom/tests/mochitest/localstorage/test_localStorageSessionPrefOverride.html
@@ -3,16 +3,21 @@
     <title>Local Storage Session Pref Override</title>
     <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     <script type="text/javascript" src="/tests/SimpleTest/AddTask.js"></script>
     <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     <script>
       const ACCEPT_SESSION = 2;
 
       add_task(async function() {
+        if (SpecialPowers.Services.lsm.nextGenLocalStorageEnabled) {
+          ok(true, "Test ignored when the next gen local storage is enabled.");
+          return;
+        }
+
         await SpecialPowers.pushPrefEnv({"set": [["network.cookie.lifetimePolicy",
                                                   ACCEPT_SESSION]]});
 
         // Before setting permission
         await new Promise((resolve) => {
           var frame = document.createElement('iframe');
           frame.src = "frameLocalStorageSessionOnly.html";
 
--- a/toolkit/modules/Services.jsm
+++ b/toolkit/modules/Services.jsm
@@ -75,16 +75,17 @@ var initTable = {
   obs: ["@mozilla.org/observer-service;1", "nsIObserverService"],
   perms: ["@mozilla.org/permissionmanager;1", "nsIPermissionManager"],
   ppmm: ["@mozilla.org/parentprocessmessagemanager;1", "nsISupports"],
   prompt: ["@mozilla.org/embedcomp/prompt-service;1", "nsIPromptService"],
   scriptloader: ["@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader"],
   scriptSecurityManager: ["@mozilla.org/scriptsecuritymanager;1", "nsIScriptSecurityManager"],
   storage: ["@mozilla.org/storage/service;1", "mozIStorageService"],
   domStorageManager: ["@mozilla.org/dom/localStorage-manager;1", "nsIDOMStorageManager"],
+  lsm: ["@mozilla.org/dom/localStorage-manager;1", "nsILocalStorageManager"],
   strings: ["@mozilla.org/intl/stringbundle;1", "nsIStringBundleService"],
   telemetry: ["@mozilla.org/base/telemetry;1", "nsITelemetry"],
   textToSubURI: ["@mozilla.org/intl/texttosuburi;1", "nsITextToSubURI"],
   tm: ["@mozilla.org/thread-manager;1", "nsIThreadManager"],
   urlFormatter: ["@mozilla.org/toolkit/URLFormatterService;1", "nsIURLFormatter"],
   vc: ["@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator"],
   wm: ["@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator"],
   ww: ["@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher"],