Bug 1324176 - Control DOM storage testing paths with pref. r=mayhemer

MozReview-Commit-ID: CHrjGBPOEmg

--HG--
extra : rebase_source : 0f03c760f72adf622180c4246d1cf8681cf4d91d
This commit is contained in:
J. Ryan Stinnett 2016-12-19 11:48:33 -06:00
parent 088e601373
commit 227ff07d14
6 changed files with 47 additions and 10 deletions

View File

@ -22,6 +22,7 @@
#include "nsXULAppAPI.h"
#include "nsEscape.h"
#include "nsNetCID.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "nsServiceManagerUtils.h"
@ -31,6 +32,8 @@ namespace dom {
static const char kStartupTopic[] = "sessionstore-windows-restored";
static const uint32_t kStartupDelay = 0;
const char kTestingPref[] = "dom.storage.testing";
NS_IMPL_ISUPPORTS(DOMStorageObserver,
nsIObserver,
nsISupportsWeakReference)
@ -72,15 +75,9 @@ DOMStorageObserver::Init()
// Observe low device storage notifications.
obs->AddObserver(sSelf, "disk-space-watcher", true);
#ifdef DOM_STORAGE_TESTS
// Testing
obs->AddObserver(sSelf, "domstorage-test-flush-force", true);
if (XRE_IsParentProcess()) {
// Only to forward to child process.
obs->AddObserver(sSelf, "domstorage-test-flushed", true);
}
obs->AddObserver(sSelf, "domstorage-test-reload", true);
#ifdef DOM_STORAGE_TESTS
Preferences::RegisterCallbackAndCall(TestingPrefChanged, kTestingPref);
#endif
return NS_OK;
@ -98,6 +95,32 @@ DOMStorageObserver::Shutdown()
return NS_OK;
}
// static
void
DOMStorageObserver::TestingPrefChanged(const char* aPrefName, void* aClosure)
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (!obs) {
return;
}
if (Preferences::GetBool(kTestingPref)) {
obs->AddObserver(sSelf, "domstorage-test-flush-force", true);
if (XRE_IsParentProcess()) {
// Only to forward to child process.
obs->AddObserver(sSelf, "domstorage-test-flushed", true);
}
obs->AddObserver(sSelf, "domstorage-test-reload", true);
} else {
obs->RemoveObserver(sSelf, "domstorage-test-flush-force");
if (XRE_IsParentProcess()) {
// Only to forward to child process.
obs->RemoveObserver(sSelf, "domstorage-test-flushed");
}
obs->RemoveObserver(sSelf, "domstorage-test-reload");
}
}
void
DOMStorageObserver::AddSink(DOMStorageObserverSink* aObs)
{

View File

@ -54,6 +54,8 @@ public:
private:
virtual ~DOMStorageObserver() {}
static void TestingPrefChanged(const char* aPrefName, void* aClosure);
static DOMStorageObserver* sSelf;
// Weak references

View File

@ -43,3 +43,11 @@ function notify(top)
{
os().notifyObservers(null, top, null);
}
/**
* Enable testing observer notifications in DOMStorageObserver.cpp.
*/
function localStorageEnableTestingMode(cb)
{
SpecialPowers.pushPrefEnv({ "set": [["dom.storage.testing", true]] }, cb);
}

View File

@ -29,6 +29,9 @@ Case 3: set | set | clear | reload | count ?= 0
function startTest()
{
// Enable testing observer notifications
localStorageEnableTestingMode(function() {
// Have an untouched land
localStorage.clear();
@ -153,6 +156,7 @@ function startTest()
});
});
});
});
}
SimpleTest.waitForExplicitFinish();

View File

@ -3,7 +3,6 @@
<title>Test localStorage usage while in a low device storage situation</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="localStorageCommon.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript">
@ -23,7 +22,7 @@ This test does the following:
function lowDeviceStorage(lowStorage) {
var data = lowStorage ? "full" : "free";
os().notifyObservers(null, "disk-space-watcher", data);
SpecialPowers.Services.obs.notifyObservers(null, "disk-space-watcher", data);
}
function startTest() {

View File

@ -1157,6 +1157,7 @@ pref("dom.disable_open_click_delay", 1000);
pref("dom.storage.enabled", true);
pref("dom.storage.default_quota", 5120);
pref("dom.storage.testing", false);
pref("dom.send_after_paint_to_content", false);