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.
5 // API test for chrome.extension.infobars.
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.Infobars
8 const assertEq = chrome.test.assertEq;
16 function createInfobars() {
17 // Only background page should be active at the start.
18 assertEq(1, chrome.extension.getViews().length);
20 // Get the current tab and window (window A), then create a new
22 chrome.tabs.getSelected(null, function(tab) {
24 windowA = tab.windowId;
25 console.log('tabid: ' + tabA + ' windowA: ' + windowA);
27 chrome.windows.create({"url": "about:blank"}, function(window) {
29 console.log('windowB: ' + windowB);
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.
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);
50 chrome.tabs.getAllInWindow(windowB, function(tabs) {
51 assertEq(1, tabs.length);
54 // Show infobarB in (current) window B (with callback).
55 chrome.infobars.show({"path": "infobarB.html", "tabId": tabB},
57 assertEq(window.id, windowB);
58 // This infobar will call back to us through infobarCallbackB (below).
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);
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);
75 chrome.test.notifyPass();
78 chrome.test.runTests(tests);