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.
7 var highlighted_tabs = [];
10 var active_and_window_tabs = [];
12 chrome.test.runTests([
14 var tabs = ['http://example.org/a.html', 'http://www.google.com/favicon.ico'];
15 chrome.windows.create({url: tabs}, pass(function(window) {
16 assertEq(2, window.tabs.length);
17 testWindowId = window.id;
19 windowId: testWindowId,
22 }, pass(function(tab) {
23 assertTrue(tab.pinned);
24 assertEq(testWindowId, tab.windowId);
30 chrome.tabs.query({}, pass(function(tabs) {
31 assertEq(4, tabs.length);
32 for (var x = 0; x < tabs.length; x++) {
33 if (tabs[x].highlighted)
34 highlighted_tabs.push(tabs[x]);
36 active_tabs.push(tabs[x]);
37 if (tabs[x].windowId == testWindowId) {
38 window_tabs.push(tabs[x]);
40 active_and_window_tabs.push(tabs[x]);
43 pinned_tabs.push(tabs[x]);
48 function queryHighlighted() {
49 chrome.tabs.query({highlighted:true}, pass(function(tabs) {
50 assertEq(highlighted_tabs.length, tabs.length);
51 for (var x = 0; x < tabs.length; x++)
52 assertTrue(tabs[x].highlighted);
54 chrome.tabs.query({highlighted:false}, pass(function(tabs) {
55 assertEq(4-highlighted_tabs.length, tabs.length);
56 for (var x = 0; x < tabs.length; x++)
57 assertFalse(tabs[x].highlighted);
61 function queryActive() {
62 chrome.tabs.query({active: true}, pass(function(tabs) {
63 assertEq(active_tabs.length, tabs.length);
64 for (var x = 0; x < tabs.length; x++)
65 assertTrue(tabs[x].active);
67 chrome.tabs.query({active: false}, pass(function(tabs) {
68 assertEq(4-active_tabs.length, tabs.length);
69 for (var x = 0; x < tabs.length; x++)
70 assertFalse(tabs[x].active);
74 function queryWindowID() {
75 chrome.tabs.query({windowId: testWindowId}, pass(function(tabs) {
76 assertEq(window_tabs.length, tabs.length);
77 for (var x = 0; x < tabs.length; x++)
78 assertEq(testWindowId, tabs[x].windowId);
82 function queryCurrentWindow() {
83 chrome.windows.getCurrent(function(win) {
84 chrome.tabs.query({windowId: chrome.windows.WINDOW_ID_CURRENT},
86 // The current window should only contain this test page.
87 assertEq(1, tabs.length);
88 assertEq(win.id, tabs[0].windowId);
89 assertEq(location.href, tabs[0].url);
90 assertEq(location.href, tabs[0].title);
95 function queryPinned() {
96 chrome.tabs.query({pinned: true}, pass(function(tabs) {
97 assertEq(pinned_tabs.length, tabs.length);
98 for (var x = 0; x < tabs.length; x++)
99 assertTrue(tabs[x].pinned);
101 chrome.tabs.query({pinned: false}, pass(function(tabs) {
102 assertEq(4-pinned_tabs.length, tabs.length);
103 for (var x = 0; x < tabs.length; x++)
104 assertFalse(tabs[x].pinned);
108 function queryActiveAndWindowID() {
111 windowId: testWindowId
112 }, pass(function(tabs) {
113 assertEq(active_and_window_tabs.length, tabs.length);
114 for (var x = 0; x < tabs.length; x++) {
115 assertTrue(tabs[x].active);
116 assertEq(testWindowId, tabs[x].windowId);
121 function queryUrl() {
122 chrome.tabs.query({url: "http://*.example.org/*"}, pass(function(tabs) {
123 assertEq(1, tabs.length);
124 assertEq("http://example.org/a.html", tabs[0].url);
128 function queryUrlAsArray() {
129 chrome.tabs.query({url: ["http://*.example.org/*"]}, pass(function(tabs) {
130 assertEq(1, tabs.length);
131 assertEq("http://example.org/a.html", tabs[0].url);
135 function queryUrlAsArray2() {
136 chrome.tabs.query({url: ["http://*.example.org/*", "*://*.google.com/*"]}, pass(function(tabs) {
137 assertEq(2, tabs.length);
138 assertEq("http://example.org/a.html", tabs[0].url);
139 assertEq("http://www.google.com/favicon.ico", tabs[1].url);
143 function queryStatus() {
144 chrome.tabs.query({status: "complete"}, pass(function(tabs) {
145 for (var x = 0; x < tabs.length; x++)
146 assertEq("complete", tabs[x].status);
150 function queryTitle() {
151 chrome.tabs.query({title: "*query.html"}, pass(function(tabs) {
152 assertEq(1, tabs.length);
153 assertEq(chrome.extension.getURL("query.html"), tabs[0].title);
157 function queryWindowType() {
158 chrome.tabs.query({windowType: "normal"}, pass(function(tabs) {
159 assertEq(4, tabs.length);
160 for (var x = 0; x < tabs.length; x++) {
161 chrome.windows.get(tabs[x].windowId, pass(function(win) {
162 assertTrue(win.type == "normal");
163 assertEq(false, win.alwaysOnTop);
167 chrome.windows.create({
170 }, pass(function(win) {
171 chrome.windows.create({
174 }, pass(function(win) {
178 }, pass(function(tabs) {
179 assertEq(1, tabs.length);
181 chrome.tabs.query({windowType: 'popup'}, pass(function(tabs) {
182 assertEq(2, tabs.length);
183 for (var i = 0; i < tabs.length; i++)
184 assertFalse(tabs[i].id == chrome.tabs.TAB_ID_NONE);
189 }, pass(function(tabs) {
190 assertEq(2, tabs.length);
191 for (var i = 0; i < tabs.length; i++)
192 assertFalse(tabs[i].id == chrome.tabs.TAB_ID_NONE);
198 function queryIndex() {
199 chrome.tabs.query({index: 0}, pass(function(tabs) {
200 // Each of the 4 windows should have a tab at index 0.
201 assertEq(4, tabs.length);
202 for (var i = 0; i < tabs.length; i++)
203 assertEq(0, tabs[i].index);
207 function queryIncognito() {
208 chrome.windows.create(
209 {url: ['http://a.com', 'http://a.com'], incognito: true},
212 chrome.tabs.query({url: 'http://a.com/'}, pass(function(tabs) {
213 assertEq(0, tabs.length);