Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // API test for chrome.extension.getViews. | 5 // API test for chrome.extension.getViews. |
| 6 // browser_tests.exe --gtest_filter=ExtensionApiTest.GetViews | 6 // browser_tests.exe --gtest_filter=ExtensionApiTest.GetViews |
| 7 | 7 |
| 8 const assertEq = chrome.test.assertEq; | 8 const assertEq = chrome.test.assertEq; |
| 9 const assertTrue = chrome.test.assertTrue; | 9 const assertTrue = chrome.test.assertTrue; |
| 10 | 10 |
| 11 // We need to remember the popupWindowId to be able to find it later. | 11 // We need to remember the popupWindowId to be able to find it later. |
| 12 var popupWindowId = 0; | 12 var popupWindowId = 0; |
| 13 | 13 |
| 14 // Updated and used later to check getViews() tabId tag for the options tab. | |
| 15 var optionsTabId = 0; | |
| 16 | |
| 14 // This function is called by the popup during the test run. | 17 // This function is called by the popup during the test run. |
| 15 function popupCallback() { | 18 function popupCallback() { |
| 16 // We have now added an popup so the total count goes up one. | 19 // We have now added a popup so the total count goes up one. |
| 17 assertEq(2, chrome.extension.getViews().length); | 20 assertEq(2, chrome.extension.getViews().length); |
| 18 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); | 21 assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length); |
| 19 | 22 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.
| |
| 20 chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); | 23 function(tab) { |
| 24 optionsTabId = tab.id; | |
| 25 }); | |
| 21 } | 26 } |
| 22 | 27 |
| 23 function optionsPageCallback() { | 28 function optionsPageCallback() { |
| 24 assertEq(3, chrome.extension.getViews().length); | 29 assertEq(3, chrome.extension.getViews().length); |
| 25 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); | 30 assertEq(1, chrome.extension.getViews({windowId: popupWindowId}).length); |
| 26 assertEq(2, chrome.extension.getViews( | 31 assertEq(2, chrome.extension.getViews( |
| 27 {"type": "tab", "windowId": window.id}).length); | 32 {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.
| |
| 33 | |
| 34 chrome.tabs.query({windowId: window.id}, function(tabs) { | |
| 35 // 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.
| |
| 36 assertEq(3, tabs.length); | |
| 37 | |
| 38 // Check that only 2 tabs belong to the extension | |
| 39 assertEq(2, chrome.extension.getViews({type:"tab"}).length); | |
| 40 | |
| 41 for (var i = 0; i < tabs.length; i++) { | |
| 42 if (tabs[i].windowId == popupWindowId) { | |
| 43 assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length); | |
| 44 // Test tabId tag with other parameters | |
| 45 assertEq(1, chrome.extension.getViews({windowId: popupWindowId, | |
| 46 tabId: tabs[i].id}).length); | |
| 47 assertEq(1, chrome.extension.getViews({type: "tab", | |
| 48 tabId: tabs[i].id}).length); | |
| 49 } else if (tabs[i].id == optionsTabId) { | |
| 50 assertEq(1, chrome.extension.getViews({tabId: tabs[i].id}).length); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 }); | |
| 55 | |
| 28 chrome.test.notifyPass(); | 56 chrome.test.notifyPass(); |
| 29 } | 57 } |
| 30 | 58 |
| 31 var tests = [ | 59 var tests = [ |
| 32 function getViews() { | 60 function getViews() { |
| 33 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); | 61 //printf("Other fn"); |
| 34 assertEq(1, chrome.extension.getViews().length); | 62 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); |
| 35 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); | 63 assertEq(1, chrome.extension.getViews().length); |
| 36 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); | 64 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); |
| 65 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); | |
| 37 | 66 |
| 38 chrome.windows.getAll({populate: true}, function(windows) { | 67 chrome.windows.getAll({populate: true}, function(windows) { |
| 39 assertEq(1, windows.length); | 68 assertEq(1, windows.length); |
| 40 | 69 |
| 41 // Create a popup window. | 70 // Create a popup window. |
| 71 | |
| 72 // TODO (catmullings): Fix potential race condition when/if | |
| 73 // popupCallback() is called before popupWindowId is set below | |
| 42 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), | 74 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), |
| 43 "type": "popup"}, function(window) { | 75 "type": "popup"}, function(window) { |
| 44 assertTrue(window.id > 0); | 76 assertTrue(window.id > 0); |
| 45 popupWindowId = window.id; | 77 popupWindowId = window.id; |
| 46 // The popup will call back to us through popupCallback (above). | 78 // The popup will call back to us through popupCallback (above). |
| 79 }); | |
| 47 }); | 80 }); |
| 48 }); | 81 } |
| 49 } | |
| 50 ]; | 82 ]; |
| 51 | 83 |
| 52 chrome.test.runTests(tests); | 84 chrome.test.runTests(tests); |
| OLD | NEW |