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 // This function is called by the popup during the test run. | 14 // This function is called by the popup during the test run. |
15 function popupCallback() { | 15 function popupCallback() { |
16 // printf("Popup Callback"); | |
Devlin
2016/07/01 00:35:28
Don't forget to remove debugging code. :)
| |
16 // We have now added an popup so the total count goes up one. | 17 // We have now added an popup so the total count goes up one. |
17 assertEq(2, chrome.extension.getViews().length); | 18 assertEq(2, chrome.extension.getViews().length); |
18 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); | 19 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); |
19 | 20 |
20 chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); | 21 chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); |
21 } | 22 } |
22 | 23 |
23 function optionsPageCallback() { | 24 function optionsPageCallback() { |
25 //printf("Options Popup Callback"); | |
24 assertEq(3, chrome.extension.getViews().length); | 26 assertEq(3, chrome.extension.getViews().length); |
25 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); | 27 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); |
26 assertEq(2, chrome.extension.getViews( | 28 assertEq(2, chrome.extension.getViews( |
27 {"type": "tab", "windowId": window.id}).length); | 29 {"type": "tab", "windowId": window.id}).length); |
28 chrome.test.notifyPass(); | 30 chrome.test.notifyPass(); |
29 } | 31 } |
30 | 32 |
31 var tests = [ | 33 var tests = [ |
32 function getViews() { | 34 function getViews() { |
35 //printf("Other fn"); | |
33 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); | 36 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); |
34 assertEq(1, chrome.extension.getViews().length); | 37 assertEq(1, chrome.extension.getViews().length); |
35 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); | 38 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); |
36 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); | 39 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); |
37 | 40 |
38 chrome.windows.getAll({populate: true}, function(windows) { | 41 chrome.windows.getAll({populate: true}, function(windows) { |
39 assertEq(1, windows.length); | 42 assertEq(1, windows.length); |
40 | 43 |
41 // Create a popup window. | 44 // Create a popup window. |
42 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), | 45 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), |
43 "type": "popup"}, function(window) { | 46 "type": "popup"}, function(window) { |
44 assertTrue(window.id > 0); | 47 assertTrue(window.id > 0); |
45 popupWindowId = window.id; | 48 popupWindowId = window.id; |
46 // The popup will call back to us through popupCallback (above). | 49 // The popup will call back to us through popupCallback (above). |
47 }); | 50 }); |
48 }); | 51 }); |
49 } | 52 } |
50 ]; | 53 ]; |
51 | 54 |
52 chrome.test.runTests(tests); | 55 chrome.test.runTests(tests); |
OLD | NEW |