OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 var testWindowId; |
| 6 var active_tabs = []; |
| 7 var highlighted_tabs = []; |
| 8 var window_tabs = []; |
| 9 var pinned_tabs = []; |
| 10 var active_and_window_tabs = []; |
| 11 |
| 12 chrome.test.runTests([ |
| 13 function setup() { |
| 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; |
| 18 chrome.tabs.create({ |
| 19 windowId: testWindowId, |
| 20 url: 'about:blank', |
| 21 pinned: true |
| 22 }, pass(function(tab) { |
| 23 assertTrue(tab.pinned); |
| 24 assertEq(testWindowId, tab.windowId); |
| 25 })); |
| 26 })); |
| 27 }, |
| 28 |
| 29 function queryAll() { |
| 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]); |
| 35 if (tabs[x].active) |
| 36 active_tabs.push(tabs[x]); |
| 37 if (tabs[x].windowId == testWindowId) { |
| 38 window_tabs.push(tabs[x]); |
| 39 if (tabs[x].active) |
| 40 active_and_window_tabs.push(tabs[x]); |
| 41 } |
| 42 if (tabs[x].pinned) |
| 43 pinned_tabs.push(tabs[x]); |
| 44 } |
| 45 })); |
| 46 }, |
| 47 |
| 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); |
| 53 })); |
| 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); |
| 58 })); |
| 59 }, |
| 60 |
| 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); |
| 66 })); |
| 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); |
| 71 })); |
| 72 }, |
| 73 |
| 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); |
| 79 })); |
| 80 }, |
| 81 |
| 82 function queryPinned() { |
| 83 chrome.tabs.query({pinned: true}, pass(function(tabs) { |
| 84 assertEq(pinned_tabs.length, tabs.length); |
| 85 for (var x = 0; x < tabs.length; x++) |
| 86 assertTrue(tabs[x].pinned); |
| 87 })); |
| 88 chrome.tabs.query({pinned: false}, pass(function(tabs) { |
| 89 assertEq(4-pinned_tabs.length, tabs.length); |
| 90 for (var x = 0; x < tabs.length; x++) |
| 91 assertFalse(tabs[x].pinned); |
| 92 })); |
| 93 }, |
| 94 |
| 95 function queryActiveAndWindowID() { |
| 96 chrome.tabs.query({ |
| 97 active: true, |
| 98 windowId: testWindowId |
| 99 }, pass(function(tabs) { |
| 100 assertEq(active_and_window_tabs.length, tabs.length); |
| 101 for (var x = 0; x < tabs.length; x++) { |
| 102 assertTrue(tabs[x].active); |
| 103 assertEq(testWindowId, tabs[x].windowId); |
| 104 } |
| 105 })); |
| 106 }, |
| 107 |
| 108 function queryUrl() { |
| 109 chrome.tabs.query({url: "http://*.example.org/*"}, pass(function(tabs) { |
| 110 assertEq(1, tabs.length); |
| 111 assertEq("http://example.org/a.html", tabs[0].url); |
| 112 })); |
| 113 }, |
| 114 |
| 115 function queryStatus() { |
| 116 chrome.tabs.query({status: "complete"}, pass(function(tabs) { |
| 117 for (var x = 0; x < tabs.length; x++) |
| 118 assertEq("complete", tabs[x].status); |
| 119 })); |
| 120 }, |
| 121 |
| 122 function queryTitle() { |
| 123 chrome.tabs.query({title: "*query.html"}, pass(function(tabs) { |
| 124 assertEq(1, tabs.length); |
| 125 assertEq(chrome.extension.getURL("query.html"), tabs[0].title); |
| 126 })); |
| 127 }, |
| 128 |
| 129 function queryWindowType() { |
| 130 chrome.tabs.query({windowType: "normal"}, pass(function(tabs) { |
| 131 assertEq(4, tabs.length); |
| 132 for (var x = 0; x < tabs.length; x++) { |
| 133 chrome.windows.get(tabs[x].windowId, pass(function(win) { |
| 134 assertTrue(win.type == "normal"); |
| 135 })); |
| 136 } |
| 137 })); |
| 138 chrome.windows.create({ |
| 139 url: 'about:blank', |
| 140 type: 'popup' |
| 141 }, pass(function(win) { |
| 142 chrome.windows.create({ |
| 143 url: 'about:blank', |
| 144 type: 'popup' |
| 145 }, pass(function(win) { |
| 146 chrome.tabs.query({ |
| 147 windowId: win.id, |
| 148 windowType: 'popup' |
| 149 }, pass(function(tabs) { |
| 150 assertEq(1, tabs.length); |
| 151 })); |
| 152 chrome.tabs.query({windowType: 'popup'}, pass(function(tabs) { |
| 153 assertEq(2, tabs.length); |
| 154 })); |
| 155 chrome.tabs.query({ |
| 156 windowType: 'popup', |
| 157 url: 'about:*' |
| 158 }, pass(function(tabs) { |
| 159 assertEq(2, tabs.length); |
| 160 })); |
| 161 })); |
| 162 })); |
| 163 } |
| 164 ]); |
| 165 |
OLD | NEW |