зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1363902 - Simplify some browser chrome tests by utilizing TestUtils.topicObserved. r=mikedeboer
MozReview-Commit-ID: Flc8iE19Gkt --HG-- extra : rebase_source : ece0308fbf7b8a24abd44ca9b8e3745abdf1cd17
This commit is contained in:
Родитель
62d93fdf1a
Коммит
bb5a155daa
|
@ -1,26 +1,6 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
const { addObserver, removeObserver } = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
|
||||
function receive(topic) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let timeout = setTimeout(() => {
|
||||
reject(new Error("Timeout"));
|
||||
}, 90000);
|
||||
|
||||
const observer = {
|
||||
observe: subject => {
|
||||
removeObserver(observer, topic);
|
||||
clearTimeout(timeout);
|
||||
resolve(subject);
|
||||
}
|
||||
};
|
||||
addObserver(observer, topic, false);
|
||||
});
|
||||
}
|
||||
|
||||
add_task(function* () {
|
||||
yield BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com");
|
||||
|
||||
|
@ -28,7 +8,7 @@ add_task(function* () {
|
|||
content.history.pushState({}, "2", "2.html");
|
||||
});
|
||||
|
||||
yield receive("sessionstore-state-write-complete");
|
||||
yield TestUtils.topicObserved("sessionstore-state-write-complete");
|
||||
|
||||
// Wait for the session data to be flushed before continuing the test
|
||||
yield new Promise(resolve => SessionStore.getSessionHistory(gBrowser.selectedTab, resolve));
|
||||
|
|
|
@ -68,20 +68,10 @@ add_task(async function testIntervalChanges() {
|
|||
// scheduled state write. This is needed since the `_lastSaveTime` in
|
||||
// runDelayed() should be set at least once, or the `_isIdle` flag will not
|
||||
// become effective.
|
||||
// We wait at most 30 sec which is about as long as the timeout for the
|
||||
// regular whole test case, and we don't expect the write event comes fast
|
||||
// enough for an immediate `waitForSaveState()` from now.
|
||||
await new Promise(function(resolve, reject) {
|
||||
waitForTopic("sessionstore-state-write-complete", 30 * 1000, function(isSuccessful) {
|
||||
if (!isSuccessful) {
|
||||
reject(new Error("Timeout: didn't get any `sessionstore-state-write-complete` event"));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
info("Waiting for sessionstore-state-write-complete notification");
|
||||
await TestUtils.topicObserved("sessionstore-state-write-complete");
|
||||
|
||||
info("Got the state write event, start to test idle mode...");
|
||||
info("Got the sessionstore-state-write-complete notification, now testing idle mode");
|
||||
|
||||
// Enter the "idle mode" (raise the `_isIdle` flag) by firing idle
|
||||
// observer of mock idle service.
|
||||
|
@ -108,15 +98,7 @@ add_task(async function testIntervalChanges() {
|
|||
info("Start to test active mode...");
|
||||
idleService._fireObservers("active");
|
||||
|
||||
await new Promise(function(resolve, reject) {
|
||||
waitForTopic("sessionstore-state-write-complete", PREF_SS_INTERVAL + 10000, function(isSuccessful) {
|
||||
if (!isSuccessful) {
|
||||
reject(new Error("Timeout: didn't get any `sessionstore-state-write-complete` event"));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
info("[Test 2] Has state write during active.");
|
||||
info("[Test 2] Waiting for sessionstore-state-write-complete during active");
|
||||
await TestUtils.topicObserved("sessionstore-state-write-complete");
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче