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 // This function is called by the infobar during the test run. | 11 // We need to remember the popupWindowId to be able to find it later. |
12 function infobarCallback() { | 12 var popupWindowId = 0; |
13 // We have now added an infobar so the total count goes up one. | 13 |
| 14 // This function is called by the popup during the test run. |
| 15 function popupCallback() { |
| 16 // We have now added an popup so the total count goes up one. |
14 assertEq(2, chrome.extension.getViews().length); | 17 assertEq(2, chrome.extension.getViews().length); |
15 assertEq(1, chrome.extension.getViews({"type": "infobar"}).length); | 18 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); |
16 | 19 |
17 // Now try the same, but specify the windowId. | 20 chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); |
18 chrome.windows.getCurrent(function(window) { | |
19 assertEq(1, chrome.extension.getViews( | |
20 {"type": "infobar", "windowId": window.id}).length); | |
21 chrome.tabs.create({"url": chrome.extension.getURL("options.html")}); | |
22 }); | |
23 } | 21 } |
24 | 22 |
25 function optionsPageCallback() { | 23 function optionsPageCallback() { |
26 assertEq(3, chrome.extension.getViews().length); | 24 assertEq(3, chrome.extension.getViews().length); |
27 assertEq(1, chrome.extension.getViews( | 25 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length); |
28 {"type": "infobar", "windowId": window.id}).length); | 26 assertEq(2, chrome.extension.getViews( |
29 assertEq(1, chrome.extension.getViews( | |
30 {"type": "tab", "windowId": window.id}).length); | 27 {"type": "tab", "windowId": window.id}).length); |
31 chrome.test.notifyPass(); | 28 chrome.test.notifyPass(); |
32 } | 29 } |
33 | 30 |
34 var tests = [ | 31 var tests = [ |
35 function getViews() { | 32 function getViews() { |
36 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); | 33 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined"); |
37 assertEq(1, chrome.extension.getViews().length); | 34 assertEq(1, chrome.extension.getViews().length); |
38 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); | 35 assertEq(0, chrome.extension.getViews({"type": "tab"}).length); |
39 assertEq(0, chrome.extension.getViews({"type": "infobar"}).length); | 36 assertEq(0, chrome.extension.getViews({"type": "popup"}).length); |
40 assertEq(0, chrome.extension.getViews({"type": "notification"}).length); | 37 assertEq(0, chrome.extension.getViews({"type": "notification"}).length); |
41 | 38 |
42 chrome.windows.getAll({populate: true}, function(windows) { | 39 chrome.windows.getAll({populate: true}, function(windows) { |
43 assertEq(1, windows.length); | 40 assertEq(1, windows.length); |
44 | 41 |
45 // Show an infobar. | 42 // Create a popup window. |
46 chrome.experimental.infobars.show({tabId: windows[0].tabs[0].id, | 43 chrome.windows.create({"url": chrome.extension.getURL("popup.html"), |
47 "path": "infobar.html"}, | 44 "type": "popup"}, function(window) { |
48 function(window) { | |
49 assertTrue(window.id > 0); | 45 assertTrue(window.id > 0); |
50 // The infobar will call back to us through infobarCallback (above). | 46 popupWindowId = window.id; |
| 47 // The popup will call back to us through popupCallback (above). |
51 }); | 48 }); |
52 | |
53 }); | 49 }); |
54 } | 50 } |
55 ]; | 51 ]; |
56 | 52 |
57 chrome.test.runTests(tests); | 53 chrome.test.runTests(tests); |
OLD | NEW |