Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/get_views/test.js |
| diff --git a/chrome/test/data/extensions/api_test/get_views/test.js b/chrome/test/data/extensions/api_test/get_views/test.js |
| index 765c4c0fb42605d6414f40e033c306b5609b3342..d52728f8348157380640593dc8938fbcfbacdff3 100644 |
| --- a/chrome/test/data/extensions/api_test/get_views/test.js |
| +++ b/chrome/test/data/extensions/api_test/get_views/test.js |
| @@ -11,42 +11,74 @@ const assertTrue = chrome.test.assertTrue; |
| // We need to remember the popupWindowId to be able to find it later. |
| var popupWindowId = 0; |
| +// Updated and used later to check getViews() tabId tag for the options tab. |
| +var optionsTabId = 0; |
| + |
| // This function is called by the popup during the test run. |
| function popupCallback() { |
| - // We have now added an popup so the total count goes up one. |
| + // We have now added a popup so the total count goes up one. |
| assertEq(2, chrome.extension.getViews().length); |
| - assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); |
| - |
| - chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); |
| + assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length); |
| + chrome.tabs.create({"url": chrome.extension.getURL("options.html")}, |
|
Devlin
2016/07/12 18:35:58
s/"url"/url
catmullings
2016/07/13 00:04:30
Done.
|
| + function(tab) { |
| + optionsTabId = tab.id; |
| + }); |
| } |
| function optionsPageCallback() { |
| assertEq(3, chrome.extension.getViews().length); |
| - assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); |
| + assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length); |
| assertEq(2, chrome.extension.getViews( |
| - {"type": "tab", "windowId": window.id}).length); |
| + {type: "tab", windowId: window.id}).length); |
|
Devlin
2016/07/12 18:35:57
indentation seems off. Prefer:
assertEq(2,
catmullings
2016/07/13 00:04:29
Done.
|
| + |
| + chrome.tabs.query({windowId: window.id}, function(tabs) { |
| + // Assert 3 to account for new tab page, web popup, & new tab options.html |
|
Devlin
2016/07/12 18:35:58
indentation: only 2-space increase for function sc
catmullings
2016/07/13 00:04:30
Done.
|
| + assertEq(3, tabs.length); |
| + |
| + // Check that only 2 tabs belong to the extension |
| + assertEq(2, chrome.extension.getViews({type:"tab"}).length); |
| + |
| + for (var i = 0; i < tabs.length; i++) { |
| + if (tabs[i].windowId == popupWindowId) { |
| + assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length); |
| + // Test tabId tag with other parameters |
| + assertEq(1, chrome.extension.getViews({windowId: popupWindowId, |
| + tabId: tabs[i].id}).length); |
| + assertEq(1, chrome.extension.getViews({type: "tab", |
| + tabId: tabs[i].id}).length); |
| + } else if (tabs[i].id == optionsTabId) { |
| + assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length); |
| + } |
| + } |
| + |
| + }); |
| + |
| chrome.test.notifyPass(); |
| } |
| var tests = [ |
| - function getViews() { |
| - assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); |
| - assertEq(1, chrome.extension.getViews().length); |
| - assertEq(0, chrome.extension.getViews({"type": "tab"}).length); |
| - assertEq(0, chrome.extension.getViews({"type": "popup"}).length); |
| +function getViews() { |
| + //printf("Other fn"); |
| + assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); |
| + assertEq(1, chrome.extension.getViews().length); |
| + assertEq(0, chrome.extension.getViews({"type": "tab"}).length); |
| + assertEq(0, chrome.extension.getViews({"type": "popup"}).length); |
| - chrome.windows.getAll({populate: true}, function(windows) { |
| + chrome.windows.getAll({populate: true}, function(windows) { |
| assertEq(1, windows.length); |
| // Create a popup window. |
| + |
| + // TODO (catmullings): Fix potential race condition when/if |
| + // popupCallback() is called before popupWindowId is set below |
| chrome.windows.create({"url": chrome.extension.getURL("popup.html"), |
| - "type": "popup"}, function(window) { |
| + "type": "popup"}, function(window) { |
| assertTrue(window.id > 0); |
| popupWindowId = window.id; |
| // The popup will call back to us through popupCallback (above). |
| + }); |
| }); |
| - }); |
| - } |
| +} |
| ]; |
| chrome.test.runTests(tests); |