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

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: followups through message #33 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 // Do a c.t.query and return the found tab (or undefined) in a callback
not at google - send to devlin 2015/06/01 20:33:57 Huh, funny, I guess we should support a tabId prop
Jared Sohn 2015/06/02 08:54:38 Yeah, I like that better; updated. On 2015/06/01
61 function queryForTab(tabId, queryInfo, callback) {
62 chrome.tabs.query(queryInfo,
63 pass(function(tabs) {
64 var foundTabs = tabs.filter(function(tab) {
65 return (tab.id == tabId);
66 });
67 if (callback !== null)
68 callback(foundTabs.length ? foundTabs[0] : undefined);
not at google - send to devlin 2015/06/01 20:33:57 epic nit but this isn't "undefined", because we kn
Jared Sohn 2015/06/02 08:54:38 Done. (A previous iteration of the code would pass
69 })
70 );
71 }
72
73 // Check onUpdated for a queryable attribute such as muted or audible
74 // and then check that the tab, a query, and changeInfo are consistent
75 // with the expected value. Does similar checks for each
76 // (nonqueryable attribute, expected value) pair in nonqueryableAttribsDict
77 // except it does not check the query.
78 function onUpdatedExpect(queryableAttrib, expected, nonqueryableAttribsDict) {
79 var onUpdatedCompleted = chrome.test.listenForever(
80 chrome.tabs.onUpdated,
81 function(tabId, changeInfo, tab) {
82 if (nonqueryableAttribsDict !== null) {
83 var nonqueryableAttribs = Object.keys(nonqueryableAttribsDict);
84 nonqueryableAttribs.forEach(function(nonqueryableAttrib) {
85 if (typeof changeInfo[nonqueryableAttrib] !== "undefined") {
86 assertEq(nonqueryableAttribsDict[nonqueryableAttrib],
87 changeInfo[nonqueryableAttrib]);
88 assertEq(nonqueryableAttribsDict[nonqueryableAttrib],
89 tab[nonqueryableAttrib]);
90 }
91 });
92 }
93 if (queryableAttrib in changeInfo) {
not at google - send to devlin 2015/06/01 20:33:57 use hasOwnProperty, otherwise it will include prop
Jared Sohn 2015/06/02 08:54:38 Done.
94 assertEq(expected, changeInfo[queryableAttrib]);
95 assertEq(expected, tab[queryableAttrib]);
96 var queryInfo = {};
97 queryInfo[queryableAttrib] = expected;
98 queryForTab(tabId, queryInfo, pass(function(tab) {
99 assertEq(expected, tab[queryableAttrib]);
100 queryInfo[queryableAttrib] = !expected;
101
102 queryForTab(tabId, queryInfo, pass(function(tab) {
103 assertEq(undefined, tab);
104 onUpdatedCompleted();
105 }));
106 }));
107 }
108 }
109 );
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698