Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js |
| diff --git a/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js b/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js |
| index 757cd6b46539e019144ad5639f0ef65675a89c5e..d85b058e7b905dc0e6cd418bf4a44c4a1edd317e 100644 |
| --- a/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js |
| +++ b/chrome/test/data/extensions/api_test/tabs/basics/tabs_util.js |
| @@ -35,10 +35,10 @@ function createWindow(tabUrls, winOptions, callback) { |
| // zero arguments. |
| function waitForAllTabs(callback) { |
| // Wait for all tabs to load. |
| - function waitForTabs(){ |
| + function waitForTabs() { |
| chrome.windows.getAll({"populate": true}, function(windows) { |
| var ready = true; |
| - for (var i in windows){ |
| + for (var i in windows) { |
| for (var j in windows[i].tabs) { |
| if (windows[i].tabs[j].status != "complete") { |
| ready = false; |
| @@ -56,3 +56,55 @@ function waitForAllTabs(callback) { |
| } |
| waitForTabs(); |
| } |
| + |
| +// Do a c.t.query and return the found tab (or undefined) in a callback |
|
not at google - send to devlin
2015/06/01 20:33:57
Huh, funny, I guess we should support a tabId prop
Jared Sohn
2015/06/02 08:54:38
Yeah, I like that better; updated.
On 2015/06/01
|
| +function queryForTab(tabId, queryInfo, callback) { |
| + chrome.tabs.query(queryInfo, |
| + pass(function(tabs) { |
| + var foundTabs = tabs.filter(function(tab) { |
| + return (tab.id == tabId); |
| + }); |
| + if (callback !== null) |
| + callback(foundTabs.length ? foundTabs[0] : undefined); |
|
not at google - send to devlin
2015/06/01 20:33:57
epic nit but this isn't "undefined", because we kn
Jared Sohn
2015/06/02 08:54:38
Done. (A previous iteration of the code would pass
|
| + }) |
| + ); |
| +} |
| + |
| +// Check onUpdated for a queryable attribute such as muted or audible |
| +// and then check that the tab, a query, and changeInfo are consistent |
| +// with the expected value. Does similar checks for each |
| +// (nonqueryable attribute, expected value) pair in nonqueryableAttribsDict |
| +// except it does not check the query. |
| +function onUpdatedExpect(queryableAttrib, expected, nonqueryableAttribsDict) { |
| + var onUpdatedCompleted = chrome.test.listenForever( |
| + chrome.tabs.onUpdated, |
| + function(tabId, changeInfo, tab) { |
| + if (nonqueryableAttribsDict !== null) { |
| + var nonqueryableAttribs = Object.keys(nonqueryableAttribsDict); |
| + nonqueryableAttribs.forEach(function(nonqueryableAttrib) { |
| + if (typeof changeInfo[nonqueryableAttrib] !== "undefined") { |
| + assertEq(nonqueryableAttribsDict[nonqueryableAttrib], |
| + changeInfo[nonqueryableAttrib]); |
| + assertEq(nonqueryableAttribsDict[nonqueryableAttrib], |
| + tab[nonqueryableAttrib]); |
| + } |
| + }); |
| + } |
| + if (queryableAttrib in changeInfo) { |
|
not at google - send to devlin
2015/06/01 20:33:57
use hasOwnProperty, otherwise it will include prop
Jared Sohn
2015/06/02 08:54:38
Done.
|
| + assertEq(expected, changeInfo[queryableAttrib]); |
| + assertEq(expected, tab[queryableAttrib]); |
| + var queryInfo = {}; |
| + queryInfo[queryableAttrib] = expected; |
| + queryForTab(tabId, queryInfo, pass(function(tab) { |
| + assertEq(expected, tab[queryableAttrib]); |
| + queryInfo[queryableAttrib] = !expected; |
| + |
| + queryForTab(tabId, queryInfo, pass(function(tab) { |
| + assertEq(undefined, tab); |
| + onUpdatedCompleted(); |
| + })); |
| + })); |
| + } |
| + } |
| + ); |
| +} |