OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // API test for chrome.extension.infobars. | |
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.Infobars | |
7 | |
8 const assertEq = chrome.test.assertEq; | |
9 | |
10 var windowA = 0; | |
11 var windowB = 0; | |
12 var tabA = 0; | |
13 var tabB = 0; | |
14 | |
15 var tests = [ | |
16 function createInfobars() { | |
17 // Only background page should be active at the start. | |
18 assertEq(1, chrome.extension.getViews().length); | |
19 | |
20 // Get the current tab and window (window A), then create a new | |
21 // one (window B). | |
22 chrome.tabs.getSelected(null, function(tab) { | |
23 tabA = tab.id; | |
24 windowA = tab.windowId; | |
25 console.log('tabid: ' + tabA + ' windowA: ' + windowA); | |
26 | |
27 chrome.windows.create({"url": "about:blank"}, function(window) { | |
28 windowB = window.id; | |
29 console.log('windowB: ' + windowB); | |
30 | |
31 // Show infobarA in window A (tab A) (and specify no callback). | |
32 chrome.infobars.show({"path": "infobarA.html", "tabId": tabA}); | |
33 // Flow continues in infobarCallbackA. | |
34 }); | |
35 }); | |
36 } | |
37 ]; | |
38 | |
39 function infobarCallbackA() { | |
40 // We have now added an infobar so the total count goes up one. | |
41 assertEq(2, chrome.extension.getViews().length); | |
42 assertEq(1, chrome.extension.getViews({"type": "infobar"}).length); | |
43 // Window A should have 1 infobar. | |
44 assertEq(1, chrome.extension.getViews({"type": "infobar", | |
45 "windowId": windowA}).length); | |
46 // Window B should have no infobars. | |
47 assertEq(0, chrome.extension.getViews({"type": "infobar", | |
48 "windowId": windowB}).length); | |
49 | |
50 chrome.tabs.getAllInWindow(windowB, function(tabs) { | |
51 assertEq(1, tabs.length); | |
52 tabB = tabs[0].id; | |
53 | |
54 // Show infobarB in (current) window B (with callback). | |
55 chrome.infobars.show({"path": "infobarB.html", "tabId": tabB}, | |
56 function(window) { | |
57 assertEq(window.id, windowB); | |
58 // This infobar will call back to us through infobarCallbackB (below). | |
59 }); | |
60 }); | |
61 } | |
62 | |
63 function infobarCallbackB() { | |
64 // We have now added an infobar so the total count goes up one. | |
65 assertEq(3, chrome.extension.getViews().length); | |
66 assertEq(2, chrome.extension.getViews({"type": "infobar"}).length); | |
67 | |
68 // Window A should have 1 infobar. | |
69 assertEq(1, chrome.extension.getViews({"type": "infobar", | |
70 "windowId": windowA}).length); | |
71 // Window B should have 1 infobar. | |
72 assertEq(1, chrome.extension.getViews({"type": "infobar", | |
73 "windowId": windowB}).length); | |
74 | |
75 chrome.test.notifyPass(); | |
76 } | |
77 | |
78 chrome.test.runTests(tests); | |
OLD | NEW |