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..6ac4cde0f80b7cededbb58b87bc960a8ab128de9 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,53 @@ function waitForAllTabs(callback) { |
| } |
| waitForTabs(); |
| } |
| + |
| +// Check if query finds that queryAttrib is equal or not equal to value |
| +// (depending on expectedFound) and check that the attribute on the tab |
| +// object has the same value. Calls callback afterward. |
| +var checkQuery = function(tabId, queryAttrib, value, expectedFound, callback) { |
|
not at google - send to devlin
2015/05/26 23:09:48
1. Declare with "function checkQuery" not "var che
Jared Sohn
2015/05/27 14:52:02
Done
not at google - send to devlin
2015/05/28 23:04:42
I *think* understand what you mean, and if that un
|
| + var queryParams = {}; |
| + queryParams[queryAttrib] = value; |
| + 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, audible} |
| +// and then check that expected, changeInfo, the tab, and the query are |
| +// consistent. Also checks that the expected values, changeInfo and tab |
| +// object for entries in otherAttribsDict are consistent. |
| +function onUpdatedExpect(attrib, expected, otherAttribsDict) { |
|
not at google - send to devlin
2015/05/26 23:09:48
1. I find the name confusing, perhaps because it d
Jared Sohn
2015/05/27 14:52:02
How about expectAfterOnUpdated?
|
| + var onUpdatedCompleted = chrome.test.listenForever( |
| + chrome.tabs.onUpdated, |
| + function(tabId, changeInfo, tab) { |
| + if (otherAttribsDict !== null) { |
| + var otherAttribsKeys = Object.keys(otherAttribsDict); |
| + otherAttribsKeys.forEach(function(attrib) { |
| + if (typeof changeInfo[attrib] !== "undefined") { |
| + assertEq(otherAttribsDict[attrib], changeInfo[attrib]); |
| + assertEq(otherAttribsDict[attrib], tab[attrib]); |
| + } |
| + }); |
| + } |
| + if (attrib in changeInfo) { |
| + assertEq(expected, changeInfo[attrib]); |
| + assertEq(expected, tab[attrib]); |
| + checkQuery(tabId, attrib, expected, true, pass(function() { |
| + checkQuery(tabId, attrib, !expected, false, pass(function() { |
| + onUpdatedCompleted(); |
| + })); |
| + })); |
| + } |
| + } |
| + ); |
| +} |