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

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

Issue 987583004: Add audible, muted to Tab, c.t.query, c.t.update, and c.t.onUpdated where relevant (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch1
Patch Set: header file order fixed Created 5 years, 6 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var pass = chrome.test.callbackPass; 5 var pass = chrome.test.callbackPass;
6 var fail = chrome.test.callbackFail; 6 var fail = chrome.test.callbackFail;
7 var assertEq = chrome.test.assertEq; 7 var assertEq = chrome.test.assertEq;
8 var assertFalse = chrome.test.assertFalse; 8 var assertFalse = chrome.test.assertFalse;
9 var assertTrue = chrome.test.assertTrue; 9 var assertTrue = chrome.test.assertTrue;
10 10
(...skipping 17 matching lines...) Expand all
28 callback(win.id, newTabIds); 28 callback(win.id, newTabIds);
29 }); 29 });
30 } 30 }
31 31
32 // Waits until all tabs (yes, in every window) have status "complete". 32 // Waits until all tabs (yes, in every window) have status "complete".
33 // This is useful to prevent test overlap when testing tab events. 33 // This is useful to prevent test overlap when testing tab events.
34 // |callback| should look like function() {...}. Note that |callback| expects 34 // |callback| should look like function() {...}. Note that |callback| expects
35 // zero arguments. 35 // zero arguments.
36 function waitForAllTabs(callback) { 36 function waitForAllTabs(callback) {
37 // Wait for all tabs to load. 37 // Wait for all tabs to load.
38 function waitForTabs(){ 38 function waitForTabs() {
39 chrome.windows.getAll({"populate": true}, function(windows) { 39 chrome.windows.getAll({"populate": true}, function(windows) {
40 var ready = true; 40 var ready = true;
41 for (var i in windows){ 41 for (var i in windows) {
42 for (var j in windows[i].tabs) { 42 for (var j in windows[i].tabs) {
43 if (windows[i].tabs[j].status != "complete") { 43 if (windows[i].tabs[j].status != "complete") {
44 ready = false; 44 ready = false;
45 break; 45 break;
46 } 46 }
47 } 47 }
48 if (!ready) 48 if (!ready)
49 break; 49 break;
50 } 50 }
51 if (ready) 51 if (ready)
52 callback(); 52 callback();
53 else 53 else
54 window.setTimeout(waitForTabs, 30); 54 window.setTimeout(waitForTabs, 30);
55 }); 55 });
56 } 56 }
57 waitForTabs(); 57 waitForTabs();
58 } 58 }
59
60 // Check if c.t.query finds that a queryableAttrib for tabId is equal or not
61 // equal to expectedValue (depending on expectedFound) and check that the
62 // attribute on the tab object has the same value. Calls callback afterward.
63 function checkQuery(tabId,
64 queryableAttrib,
65 expectedValue,
66 expectedFound,
67 callback) {
68 var queryParams = {};
69 queryParams[queryableAttrib] = expectedValue;
70 chrome.tabs.query(queryParams,
71 pass(function(tabs) {
72 var found = false;
73 tabs.forEach(function(tab) {
74 if (tab.id === tabId)
75 found = true;
76 });
77 assertEq(expectedFound, found);
78 if (callback !== null)
79 callback();
80 })
81 );
82 }
83
84 // Check onUpdated for a queryable attribute such as muted or audible
85 // and then check that the tab, a query, and changeInfo are consistent
86 // with the expected value. Does similar checks for each
87 // (nonqueryable attribute, expected value) pair in nonqueryableAttribsDict
88 // with the exception of checking a query.
89 function onUpdatedExpect(queryableAttrib, expected, nonqueryableAttribsDict) {
90 var onUpdatedCompleted = chrome.test.listenForever(
91 chrome.tabs.onUpdated,
92 function(tabId, changeInfo, tab) {
93 if (nonqueryableAttribsDict !== null) {
94 var nonqueryableAttribs = Object.keys(nonqueryableAttribsDict);
95 nonqueryableAttribs.forEach(function(nonqueryableAttrib) {
96 if (typeof changeInfo[nonqueryableAttrib] !== "undefined") {
97 assertEq(nonqueryableAttribsDict[nonqueryableAttrib],
98 changeInfo[nonqueryableAttrib]);
99 assertEq(nonqueryableAttribsDict[nonqueryableAttrib],
100 tab[nonqueryableAttrib]);
101 }
102 });
103 }
104 if (queryableAttrib in changeInfo) {
105 assertEq(expected, changeInfo[queryableAttrib]);
106 assertEq(expected, tab[queryableAttrib]);
107 checkQuery(tabId, queryableAttrib, expected, true, pass(function() {
108 checkQuery(tabId, queryableAttrib, !expected, false, pass(function() {
109 onUpdatedCompleted();
110 }));
111 }));
112 }
113 }
114 );
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698