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

Unified 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, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/tabs/basics/highlight.js
===================================================================
--- chrome/test/data/extensions/api_test/tabs/basics/highlight.js (revision 0)
+++ chrome/test/data/extensions/api_test/tabs/basics/highlight.js (revision 0)
@@ -0,0 +1,131 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var testWindowId1, testWindowId2;
+
+function contains(arr, value) {
+ return arr.some(function(element) { return element == value; });
+}
+
+function checkEqualSets(set1, set2) {
+ if (set1.length != set2.length)
+ return false;
+
+ for (var x = 0; x < set1.length; x++) {
+ if (!set2.some(function(v) { return v == set1[x]; }))
+ return false;
+ }
+
+ return true;
+}
+
+chrome.test.runTests([
+ function setup() {
+ var tabs1 = ['http://e.com', 'http://a.com', 'http://a.com/b.html',
+ 'http://b.com', 'http://a.com/d.html', 'http://a.com/c.html'];
+ var tabs2 = ['http://c.com/', 'http://a.com', 'http://a.com/b.html'];
+ chrome.windows.create({url: tabs1}, pass(function(win) {
+ testWindowId1 = win.id;
+ }));
+ chrome.windows.create({url: tabs2}, pass(function(win) {
+ testWindowId2 = win.id;
+ }));
+ },
+
+ function highlightA() {
+ chrome.tabs.query({windowId: testWindowId1, url: 'http://a.com/*'},
+ pass(function(tabs) {
+ assertEq(4, tabs.length);
+ chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
+ function(highlightInfo) {
+ var tabIds = tabs.map(function(tab) { return tab.id; });
+ assertEq(highlightInfo.windowId, testWindowId1);
+ assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds));
+ });
+ var tabIndices = tabs.map(function(tab) { return tab.index; });
+ chrome.tabs.highlight({
+ windowId: testWindowId1,
+ tabs: tabIndices
+ }, pass(function(win) {
+ // Verify the 'highlighted' property for every tab.
+ win.tabs.forEach(function(tab) {
+ assertEq(contains(tabIndices, tab.index), tab.highlighted);
+ });
+ }));
+ }));
+ },
+
+ function highlightB() {
+ chrome.tabs.query({windowId: testWindowId1, url: 'http://b.com/*'},
+ pass(function(tabs) {
+ assertEq(1, tabs.length);
+ chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
+ function(highlightInfo) {
+ var tabIds = tabs.map(function(tab) { return tab.id; });
+ assertEq(highlightInfo.windowId, testWindowId1);
+ assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds));
+ });
+ var tabIndices = tabs.map(function(tab) { return tab.index; });
+ chrome.tabs.highlight({windowId: testWindowId1, tabs: tabIndices},
+ pass(function(win) {
+ // Verify the 'highlighted' property for every tab.
+ win.tabs.forEach(function(tab) {
+ assertEq(contains(tabIndices, tab.index), tab.highlighted);
+ });
+ }));
+ }));
+ },
+
+ function highlightAWindow2() {
+ chrome.tabs.query({windowId: testWindowId2, url: 'http://a.com/*'},
+ pass(function(tabs) {
+ assertEq(2, tabs.length);
+ chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
+ function(highlightInfo) {
+ var tabIds = tabs.map(function(tab) { return tab.id; });
+ assertEq(highlightInfo.windowId, testWindowId2);
+ assertTrue(checkEqualSets(tabIds, highlightInfo.tabIds));
+ });
+ var tabIndices = tabs.map(function(tab) { return tab.index; });
+ chrome.tabs.highlight({windowId: testWindowId2, tabs: tabIndices},
+ pass(function(win) {
+ // Verify the 'highlighted' property for every tab.
+ win.tabs.forEach(function(tab) {
+ assertEq(contains(tabIndices, tab.index), tab.highlighted);
+ });
+
+ // Verify that nothing has changed in window 1.
+ chrome.tabs.query({windowId: testWindowId1, highlighted: true},
+ pass(function(tabs) {
+ assertEq(1, tabs.length);
+ }));
+ }));
+ }));
+ },
+
+ function removeTab() {
+ chrome.tabs.query(
+ {windowId: testWindowId2, highlighted: true, active: false},
+ pass(function(tabs) {
+ var tabId = tabs[0].id;
+ chrome.test.listenOnce(chrome.tabs.onHighlightChanged,
+ function(highlightInfo) {
+ assertEq(1, highlightInfo.tabIds.length);
+ assertTrue(tabId != highlightInfo.tabIds[0]);
+ });
+ chrome.tabs.remove(tabId, pass(function() { assertTrue(true); }));
+ }));
+ },
+
+ function noTabsHighlighted() {
+ chrome.tabs.highlight({windowId: testWindowId1, tabs: []},
+ fail("No highlighted tab"));
+ },
+
+ function indexNotFound() {
+ chrome.tabs.highlight({windowId: testWindowId1, tabs: [3333]},
+ fail("No tab at index: 3333."));
+ }
+]);
+

Powered by Google App Engine
This is Rietveld 408576698