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
3 // found in the LICENSE file.
5 // API test for chrome.extension.getViews.
6 // browser_tests.exe --gtest_filter=ExtensionApiTest.GetViews
8 const assertEq = chrome.test.assertEq;
9 const assertTrue = chrome.test.assertTrue;
11 // We need to remember the popupWindowId to be able to find it later.
12 var popupWindowId = 0;
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.
17 assertEq(2, chrome.extension.getViews().length);
18 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length);
20 chrome.tabs.create({"url": chrome.extension.getURL("options.html")});
23 function optionsPageCallback() {
24 assertEq(3, chrome.extension.getViews().length);
25 assertEq(1, chrome.extension.getViews({"windowId": popupWindowId}).length);
26 assertEq(2, chrome.extension.getViews(
27 {"type": "tab", "windowId": window.id}).length);
28 chrome.test.notifyPass();
33 assertTrue(typeof(chrome.extension.getBackgroundPage()) != "undefined");
34 assertEq(1, chrome.extension.getViews().length);
35 assertEq(0, chrome.extension.getViews({"type": "tab"}).length);
36 assertEq(0, chrome.extension.getViews({"type": "popup"}).length);
37 assertEq(0, chrome.extension.getViews({"type": "notification"}).length);
39 chrome.windows.getAll({populate: true}, function(windows) {
40 assertEq(1, windows.length);
42 // Create a popup window.
43 chrome.windows.create({"url": chrome.extension.getURL("popup.html"),
44 "type": "popup"}, function(window) {
45 assertTrue(window.id > 0);
46 popupWindowId = window.id;
47 // The popup will call back to us through popupCallback (above).
53 chrome.test.runTests(tests);