Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Unified Diff: chrome/test/data/extensions/api_test/sessions/sessions.js

Issue 201393002: Add onChanged callback for chrome.sessions API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/api/sessions.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/sessions/sessions.js
diff --git a/chrome/test/data/extensions/api_test/sessions/sessions.js b/chrome/test/data/extensions/api_test/sessions/sessions.js
index 431edbec72fb11ed0a052bebb3a721a68cc1e13f..80e6f8b788b986aceb7dc4433563698896fa7a9f 100644
--- a/chrome/test/data/extensions/api_test/sessions/sessions.js
+++ b/chrome/test/data/extensions/api_test/sessions/sessions.js
@@ -59,6 +59,32 @@ function checkEntries(expectedEntries, actualEntries) {
});
}
+function checkOnChangedEvent(expectedCallbackCount) {
+ var callbackCount = 0;
+ var done = chrome.test.listenForever(chrome.sessions.onChanged, function() {
+ callbackCount++;
+ }
+ );
+
+ return function() {
+ var retry = 0;
+ var checkEvent = function() {
+ if (callbackCount < expectedCallbackCount) {
+ retry++;
+ if (retry % 10 == 0)
+ console.log("Waiting for " +
+ (expectedCallbackCount - callbackCount) +
+ " more onChanged events");
+ window.setTimeout(checkEvent, 100);
not at google - send to devlin 2014/03/28 18:44:48 last nit: declare this 100 as a var up in the chec
+ } else {
+ assertEq(callbackCount, expectedCallbackCount);
+ done();
+ }
+ };
+ window.setTimeout(checkEvent, 100);
+ };
+}
+
chrome.test.runTests([
// After setupWindows
//
@@ -108,6 +134,8 @@ chrome.test.runTests([
function retrieveClosedTabs() {
// Check that the recently closed list contains what we expect
// after removing tabs.
+ var checkEvent = checkOnChangedEvent(2);
+
callForEach(
chrome.tabs.remove,
firstWindowTabIds.slice(0, 2).reverse(),
@@ -125,6 +153,7 @@ chrome.test.runTests([
entries.forEach(function(entry) {
recentlyClosedTabIds.push(entry.tab.sessionId);
});
+ checkEvent();
})
);
}
@@ -134,6 +163,8 @@ chrome.test.runTests([
function retrieveClosedWindows() {
// Check that the recently closed list contains what we expect
// after removing windows.
+ var checkEvent = checkOnChangedEvent(2);
+
callForEach(
chrome.windows.remove,
windowIds.slice(1, 3).reverse(),
@@ -154,6 +185,7 @@ chrome.test.runTests([
entries.forEach(function(entry) {
recentlyClosedWindowIds.push(entry.window.sessionId);
});
+ checkEvent();
})
);
}
@@ -197,6 +229,8 @@ chrome.test.runTests([
},
function restoreClosedTabs() {
+ var checkEvent = checkOnChangedEvent(2);
+
chrome.windows.get(windowIds[0], {"populate": true},
callbackPass(function(win) {
var tabCountBeforeRestore = win.tabs.length;
@@ -212,6 +246,7 @@ chrome.test.runTests([
win.tabs.forEach(function(tab, i) {
assertEq(pages[i++], tab.url);
});
+ checkEvent();
})
);
})
@@ -219,6 +254,8 @@ chrome.test.runTests([
},
function restoreTabInClosedWindow() {
+ var checkEvent = checkOnChangedEvent(1);
+
chrome.windows.getAll({"populate": true}, callbackPass(function(win) {
var windowCountBeforeRestore = win.length;
chrome.sessions.restore(recentlyClosedSecondWindowTabIds[0],
@@ -229,6 +266,7 @@ chrome.test.runTests([
assertEq(windowCountBeforeRestore + 1, win.length);
assertEq(1, win[win.length - 1].tabs.length);
assertEq(pages[0], win[win.length - 1].tabs[0].url);
+ checkEvent();
})
);
})
@@ -237,11 +275,14 @@ chrome.test.runTests([
},
function restoreClosedWindows() {
+ var checkEvent = checkOnChangedEvent(1);
+
chrome.windows.getAll({"populate": true}, callbackPass(function(win) {
var windowCountBeforeRestore = win.length;
chrome.sessions.restore(recentlyClosedWindowIds[0],
function(win_session) {
assertEq(1, win_session.window.tabs.length);
+ checkEvent();
});
function done() {
chrome.windows.getAll({"populate": true},
@@ -285,6 +326,8 @@ chrome.test.runTests([
},
function restoreMostRecentEntry() {
+ var checkEvent = checkOnChangedEvent(1);
+
chrome.windows.getAll({"populate": true}, callbackPass(function(win) {
var windowCountBeforeRestore = win.length;
chrome.sessions.restore(callbackPass(function(win_session) {
@@ -292,6 +335,7 @@ chrome.test.runTests([
chrome.windows.getAll({"populate": true},
callbackPass(function(win) {
assertEq(windowCountBeforeRestore + 1, win.length);
+ checkEvent();
})
);
}));
« no previous file with comments | « chrome/common/extensions/api/sessions.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698