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://google.com'];
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 queryStatus() {
129 chrome.tabs.query({status: "complete"}, pass(function(tabs) {
130 for (var x = 0; x < tabs.length; x++)
131 assertEq("complete", tabs[x].status);
135 function queryTitle() {
136 chrome.tabs.query({title: "*query.html"}, pass(function(tabs) {
137 assertEq(1, tabs.length);
138 assertEq(chrome.extension.getURL("query.html"), tabs[0].title);
142 function queryWindowType() {
143 chrome.tabs.query({windowType: "normal"}, pass(function(tabs) {
144 assertEq(4, tabs.length);
145 for (var x = 0; x < tabs.length; x++) {
146 chrome.windows.get(tabs[x].windowId, pass(function(win) {
147 assertTrue(win.type == "normal");
148 assertEq(false, win.alwaysOnTop);
152 chrome.windows.create({
155 }, pass(function(win) {
156 chrome.windows.create({
159 }, pass(function(win) {
163 }, pass(function(tabs) {
164 assertEq(1, tabs.length);
166 chrome.tabs.query({windowType: 'popup'}, pass(function(tabs) {
167 assertEq(2, tabs.length);
172 }, pass(function(tabs) {
173 assertEq(2, tabs.length);
179 function queryIndex() {
180 chrome.tabs.query({index: 0}, pass(function(tabs) {
181 // Each of the 4 windows should have a tab at index 0.
182 assertEq(4, tabs.length);
183 for (var i = 0; i < tabs.length; i++)
184 assertEq(0, tabs[0].index);
188 function queryIncognito() {
189 chrome.windows.create(
190 {url: ['http://a.com', 'http://a.com'], incognito: true},
193 chrome.tabs.query({url: 'http://a.com/'}, pass(function(tabs) {
194 assertEq(0, tabs.length);