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..3d34d1df3b843e9798d0a1a5a68521f56c4a2e64 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,60 @@ function waitForAllTabs(callback) { |
} |
waitForTabs(); |
} |
+ |
+// Check if c.t.query finds that a queryableAttrib for tabId is equal or not |
+// equal to expectedValue (depending on expectedFound) and check that the |
+// attribute on the tab object has the same value. Calls callback afterward. |
+function checkQuery(tabId, |
+ queryableAttrib, |
+ expectedValue, |
+ expectedFound, |
+ callback) { |
+ var queryParams = {}; |
+ queryParams[queryableAttrib] = expectedValue; |
+ chrome.tabs.query(queryParams, |
+ pass(function(tabs) { |
+ var found = false; |
+ tabs.forEach(function(tab) { |
+ if (tab.id === tabId) |
+ found = true; |
+ }); |
+ assertEq(expectedFound, found); |
+ if (callback !== null) |
+ callback(); |
+ }) |
+ ); |
+} |
+ |
+// 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 |
+// with the exception of checking a 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) { |
+ assertEq(expected, changeInfo[queryableAttrib]); |
+ assertEq(expected, tab[queryableAttrib]); |
+ checkQuery(tabId, queryableAttrib, expected, true, pass(function() { |
+ checkQuery(tabId, queryableAttrib, !expected, false, pass(function() { |
+ onUpdatedCompleted(); |
+ })); |
+ })); |
+ } |
+ } |
+ ); |
+} |