OLD | NEW |
| 1 <!-- |
| 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
| 3 * source code is governed by a BSD-style license that can be found in the |
| 4 * LICENSE file. |
| 5 --> |
1 <script src="tabs_util.js"></script> | 6 <script src="tabs_util.js"></script> |
2 | 7 <script src="highlight.js"></script> |
3 <script> | |
4 var testWindowId1, testWindowId2; | |
5 | |
6 function contains(arr, value) { | |
7 return arr.some(function(element) { return element == value; }); | |
8 } | |
9 | |
10 function checkEqualSets(set1, set2) { | |
11 if (set1.length != set2.length) | |
12 return false; | |
13 | |
14 for (var x = 0; x < set1.length; x++) { | |
15 if (!set2.some(function(v) { return v == set1[x]; })) | |
16 return false; | |
17 } | |
18 | |
19 return true; | |
20 } | |
21 | |
22 chrome.test.runTests([ | |
23 function setup() { | |
24 var tabs1 = ['http://e.com', 'http://a.com', 'http://a.com/b.html', | |
25 'http://b.com', 'http://a.com/d.html', 'http://a.com/c.html']; | |
26 var tabs2 = ['http://c.com/', 'http://a.com', 'http://a.com/b.html']; | |
27 chrome.windows.create({url: tabs1}, pass(function(win) { | |
28 testWindowId1 = win.id; | |
29 })); | |
30 chrome.windows.create({url: tabs2}, pass(function(win) { | |
31 testWindowId2 = win.id; | |
32 })); | |
33 }, | |
34 | |
35 function highlightA() { | |
36 chrome.tabs.query({windowId: testWindowId1, url: 'http://a.com/*'}, | |
37 pass(function(tabs) { | |
38 assertEq(4, tabs.length); | |
39 chrome.test.listenOnce(chrome.tabs.onHighlightChanged, | |
40 function(highlightInfo) { | |
41 var tabIds = tabs.map(function(tab) { return tab.id; }); | |
42 assertEq(highlightInfo.windowId, testWindowId1); | |
43 assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds)); | |
44 }); | |
45 var tabIndices = tabs.map(function(tab) { return tab.index; }); | |
46 chrome.tabs.highlight({ | |
47 windowId: testWindowId1, | |
48 tabs: tabIndices | |
49 }, pass(function(win) { | |
50 // Verify the 'highlighted' property for every tab. | |
51 win.tabs.forEach(function(tab) { | |
52 assertEq(contains(tabIndices, tab.index), tab.highlighted); | |
53 }); | |
54 })); | |
55 })); | |
56 }, | |
57 | |
58 function highlightB() { | |
59 chrome.tabs.query({windowId: testWindowId1, url: 'http://b.com/*'}, | |
60 pass(function(tabs) { | |
61 assertEq(1, tabs.length); | |
62 chrome.test.listenOnce(chrome.tabs.onHighlightChanged, | |
63 function(highlightInfo) { | |
64 var tabIds = tabs.map(function(tab) { return tab.id; }); | |
65 assertEq(highlightInfo.windowId, testWindowId1); | |
66 assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds)); | |
67 }); | |
68 var tabIndices = tabs.map(function(tab) { return tab.index; }); | |
69 chrome.tabs.highlight({windowId: testWindowId1, tabs: tabIndices}, | |
70 pass(function(win) { | |
71 // Verify the 'highlighted' property for every tab. | |
72 win.tabs.forEach(function(tab) { | |
73 assertEq(contains(tabIndices, tab.index), tab.highlighted); | |
74 }); | |
75 })); | |
76 })); | |
77 }, | |
78 | |
79 function highlightAWindow2() { | |
80 chrome.tabs.query({windowId: testWindowId2, url: 'http://a.com/*'}, | |
81 pass(function(tabs) { | |
82 assertEq(2, tabs.length); | |
83 chrome.test.listenOnce(chrome.tabs.onHighlightChanged, | |
84 function(highlightInfo) { | |
85 var tabIds = tabs.map(function(tab) { return tab.id; }); | |
86 assertEq(highlightInfo.windowId, testWindowId2); | |
87 assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds)); | |
88 }); | |
89 var tabIndices = tabs.map(function(tab) { return tab.index; }); | |
90 chrome.tabs.highlight({windowId: testWindowId2, tabs: tabIndices}, | |
91 pass(function(win) { | |
92 // Verify the 'highlighted' property for every tab. | |
93 win.tabs.forEach(function(tab) { | |
94 assertEq(contains(tabIndices, tab.index), tab.highlighted); | |
95 }); | |
96 | |
97 // Verify that nothing has changed in window 1. | |
98 chrome.tabs.query({windowId: testWindowId1, highlighted: true}, | |
99 pass(function(tabs) { | |
100 assertEq(1, tabs.length); | |
101 })); | |
102 })); | |
103 })); | |
104 }, | |
105 | |
106 function removeTab() { | |
107 chrome.tabs.query( | |
108 {windowId: testWindowId2, highlighted: true, active: false}, | |
109 pass(function(tabs) { | |
110 var tabId = tabs[0].id; | |
111 chrome.test.listenOnce(chrome.tabs.onHighlightChanged, | |
112 function(highlightInfo) { | |
113 assertEq(1, highlightInfo.tabIds.length); | |
114 assertTrue(tabId != highlightInfo.tabIds[0]); | |
115 }); | |
116 chrome.tabs.remove(tabId, pass(function() { assertTrue(true); })); | |
117 })); | |
118 }, | |
119 | |
120 function noTabsHighlighted() { | |
121 chrome.tabs.highlight({windowId: testWindowId1, tabs: []}, | |
122 fail("No highlighted tab")); | |
123 }, | |
124 | |
125 function indexNotFound() { | |
126 chrome.tabs.highlight({windowId: testWindowId1, tabs: [3333]}, | |
127 fail("No tab at index: 3333.")); | |
128 } | |
129 ]); | |
130 | |
131 </script> | |
OLD | NEW |