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 options tab | |
Devlin
2016/07/11 17:23:45
We're sticklers for grammar in comments, so there
catmullings
2016/07/12 18:13:47
Done.
| |
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 an 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")}, |
20 chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); | 23 function(tab) { |
24 // Check if tab returned is defined | |
Devlin
2016/07/11 17:23:45
indentation for callback functions is always kind
Devlin
2016/07/11 17:23:45
this comment just describes what the code is doing
catmullings
2016/07/12 18:13:47
Done.
catmullings
2016/07/12 18:13:48
Done.
| |
25 optionsTabId = tab.id; | |
26 }); | |
21 } | 27 } |
22 | 28 |
23 function optionsPageCallback() { | 29 function optionsPageCallback() { |
24 assertEq(3, chrome.extension.getViews().length); | 30 assertEq(3, chrome.extension.getViews().length); |
25 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); | 31 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); |
26 assertEq(2, chrome.extension.getViews( | 32 assertEq(2, chrome.extension.getViews( |
27 {"type": "tab", "windowId": window.id}).length); | 33 {"type": "tab", "windowId": window.id}).length); |
34 | |
35 chrome.tabs.query({"windowId": window.id}, function(tabs) { | |
Devlin
2016/07/11 17:23:45
I know you're just following the style from the re
catmullings
2016/07/12 18:13:47
Done.
catmullings
2016/07/12 18:13:48
I'll go ahead and update the rest of the test with
| |
36 // Assert 3 to account for new tab page, web popup, & new tab options.html | |
Devlin
2016/07/11 17:23:45
2-space indent here.
catmullings
2016/07/12 18:13:48
Done.
| |
37 assertEq(3, tabs.length); | |
38 | |
39 // Check that only 2 tabs belong to the extension | |
Devlin
2016/07/11 17:23:45
Here, use a comment to describe why, not what. Th
catmullings
2016/07/12 18:13:47
Done.
Devlin
2016/07/12 18:35:57
Was this actually done?
| |
40 assertEq(2, chrome.extension.getViews({"type":"tab"}).length); | |
41 | |
42 for (var i = 0; i < tabs.length; i++) { | |
43 if (tabs[i].windowId == popupWindowId) { | |
44 assertEq(1, chrome.extension.getViews({"tabId": tabs[i].id}).length); | |
45 // Test tabId tag with other parameters | |
46 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId, | |
47 "tabId": tabs[i].id}).length); | |
48 assertEq(1, chrome.extension.getViews({"type": "tab", | |
49 "tabId": tabs[i].id}).length); | |
50 } else if (tabs[i].id == optionsTabId) { | |
51 assertEq(1, chrome.extension.getViews({"tabId": tabs[i].id}).length); | |
52 } | |
53 } | |
54 | |
55 }); | |
56 | |
28 chrome.test.notifyPass(); | 57 chrome.test.notifyPass(); |
29 } | 58 } |
30 | 59 |
31 var tests = [ | 60 var tests = [ |
32 function getViews() { | 61 function getViews() { |
Devlin
2016/07/11 17:23:45
this indentation was probably more correct before.
| |
33 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); | 62 //printf("Other fn"); |
Devlin
2016/07/11 17:23:45
Don't forget to remove debugging code.
catmullings
2016/07/12 18:13:47
Done.
Devlin
2016/07/12 18:35:57
Ditto
| |
34 assertEq(1, chrome.extension.getViews().length); | 63 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); |
35 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); | 64 assertEq(1, chrome.extension.getViews().length); |
36 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); | 65 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); |
66 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); | |
37 | 67 |
38 chrome.windows.getAll({populate: true}, function(windows) { | 68 chrome.windows.getAll({populate: true}, function(windows) { |
39 assertEq(1, windows.length); | 69 assertEq(1, windows.length); |
40 | 70 |
41 // Create a popup window. | 71 // Create a popup window. |
72 | |
73 // TODO (catmullings): Fix potential race condition when/if | |
74 // popupCallback() is called before popupWindowId is set below | |
42 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), | 75 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), |
43 "type": "popup"}, function(window) { | 76 "type": "popup"}, function(window) { |
Devlin
2016/07/11 17:23:45
here, too, indentation was probably right before.
catmullings
2016/07/12 18:13:47
Done.
Devlin
2016/07/12 18:35:57
Ditto
| |
44 assertTrue(window.id > 0); | 77 assertTrue(window.id > 0); |
45 popupWindowId = window.id; | 78 popupWindowId = window.id; |
46 // The popup will call back to us through popupCallback (above). | 79 // The popup will call back to us through popupCallback (above). |
80 }); | |
47 }); | 81 }); |
48 }); | 82 } |
49 } | |
50 ]; | 83 ]; |
51 | 84 |
52 chrome.test.runTests(tests); | 85 chrome.test.runTests(tests); |
OLD | NEW |