Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/test/data/extensions/api_test/tabs/basics/highlight.js

Issue 8762014: Move another set of extension tests to manifest_version 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 testWindowId1, testWindowId2;
6
7 function contains(arr, value) {
8 return arr.some(function(element) { return element == value; });
9 }
10
11 function checkEqualSets(set1, set2) {
12 if (set1.length != set2.length)
13 return false;
14
15 for (var x = 0; x < set1.length; x++) {
16 if (!set2.some(function(v) { return v == set1[x]; }))
17 return false;
18 }
19
20 return true;
21 }
22
23 chrome.test.runTests([
24 function setup() {
25 var tabs1 = ['http://e.com', 'http://a.com', 'http://a.com/b.html',
26 'http://b.com', 'http://a.com/d.html', 'http://a.com/c.html'];
27 var tabs2 = ['http://c.com/', 'http://a.com', 'http://a.com/b.html'];
28 chrome.windows.create({url: tabs1}, pass(function(win) {
29 testWindowId1 = win.id;
30 }));
31 chrome.windows.create({url: tabs2}, pass(function(win) {
32 testWindowId2 = win.id;
33 }));
34 },
35
36 function highlightA() {
37 chrome.tabs.query({windowId: testWindowId1, url: 'http://a.com/*'},
38 pass(function(tabs) {
39 assertEq(4, tabs.length);
40 chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
41 function(highlightInfo) {
42 var tabIds = tabs.map(function(tab) { return tab.id; });
43 assertEq(highlightInfo.windowId, testWindowId1);
44 assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds));
45 });
46 var tabIndices = tabs.map(function(tab) { return tab.index; });
47 chrome.tabs.highlight({
48 windowId: testWindowId1,
49 tabs: tabIndices
50 }, pass(function(win) {
51 // Verify the 'highlighted' property for every tab.
52 win.tabs.forEach(function(tab) {
53 assertEq(contains(tabIndices, tab.index), tab.highlighted);
54 });
55 }));
56 }));
57 },
58
59 function highlightB() {
60 chrome.tabs.query({windowId: testWindowId1, url: 'http://b.com/*'},
61 pass(function(tabs) {
62 assertEq(1, tabs.length);
63 chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
64 function(highlightInfo) {
65 var tabIds = tabs.map(function(tab) { return tab.id; });
66 assertEq(highlightInfo.windowId, testWindowId1);
67 assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds));
68 });
69 var tabIndices = tabs.map(function(tab) { return tab.index; });
70 chrome.tabs.highlight({windowId: testWindowId1, tabs: tabIndices},
71 pass(function(win) {
72 // Verify the 'highlighted' property for every tab.
73 win.tabs.forEach(function(tab) {
74 assertEq(contains(tabIndices, tab.index), tab.highlighted);
75 });
76 }));
77 }));
78 },
79
80 function highlightAWindow2() {
81 chrome.tabs.query({windowId: testWindowId2, url: 'http://a.com/*'},
82 pass(function(tabs) {
83 assertEq(2, tabs.length);
84 chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
85 function(highlightInfo) {
86 var tabIds = tabs.map(function(tab) { return tab.id; });
87 assertEq(highlightInfo.windowId, testWindowId2);
88 assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds));
89 });
90 var tabIndices = tabs.map(function(tab) { return tab.index; });
91 chrome.tabs.highlight({windowId: testWindowId2, tabs: tabIndices},
92 pass(function(win) {
93 // Verify the 'highlighted' property for every tab.
94 win.tabs.forEach(function(tab) {
95 assertEq(contains(tabIndices, tab.index), tab.highlighted);
96 });
97
98 // Verify that nothing has changed in window 1.
99 chrome.tabs.query({windowId: testWindowId1, highlighted: true},
100 pass(function(tabs) {
101 assertEq(1, tabs.length);
102 }));
103 }));
104 }));
105 },
106
107 function removeTab() {
108 chrome.tabs.query(
109 {windowId: testWindowId2, highlighted: true, active: false},
110 pass(function(tabs) {
111 var tabId = tabs[0].id;
112 chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
113 function(highlightInfo) {
114 assertEq(1, highlightInfo.tabIds.length);
115 assertTrue(tabId != highlightInfo.tabIds[0]);
116 });
117 chrome.tabs.remove(tabId, pass(function() { assertTrue(true); }));
118 }));
119 },
120
121 function noTabsHighlighted() {
122 chrome.tabs.highlight({windowId: testWindowId1, tabs: []},
123 fail("No highlighted tab"));
124 },
125
126 function indexNotFound() {
127 chrome.tabs.highlight({windowId: testWindowId1, tabs: [3333]},
128 fail("No tab at index: 3333."));
129 }
130 ]);
131
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698