OLD | NEW |
---|---|
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 Loading... | |
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 query finds that queryAttrib is equal or not equal to value | |
61 // (depending on expectedFound) and check that the attribute on the tab | |
62 // object has the same value. Calls callback afterward. | |
63 var checkQuery = function(tabId, queryAttrib, value, expectedFound, callback) { | |
not at google - send to devlin
2015/05/26 23:09:48
1. Declare with "function checkQuery" not "var che
Jared Sohn
2015/05/27 14:52:02
Done
not at google - send to devlin
2015/05/28 23:04:42
I *think* understand what you mean, and if that un
| |
64 var queryParams = {}; | |
65 queryParams[queryAttrib] = value; | |
66 chrome.tabs.query(queryParams, | |
67 pass(function(tabs) { | |
68 var found = false; | |
69 tabs.forEach(function(tab) { | |
70 if (tab.id === tabId) | |
71 found = true; | |
72 }); | |
73 assertEq(expectedFound, found); | |
74 if (callback !== null) | |
75 callback(); | |
76 }) | |
77 ); | |
78 }; | |
79 | |
80 // Check onUpdated for a queryable attribute such as {muted, audible} | |
81 // and then check that expected, changeInfo, the tab, and the query are | |
82 // consistent. Also checks that the expected values, changeInfo and tab | |
83 // object for entries in otherAttribsDict are consistent. | |
84 function onUpdatedExpect(attrib, expected, otherAttribsDict) { | |
not at google - send to devlin
2015/05/26 23:09:48
1. I find the name confusing, perhaps because it d
Jared Sohn
2015/05/27 14:52:02
How about expectAfterOnUpdated?
| |
85 var onUpdatedCompleted = chrome.test.listenForever( | |
86 chrome.tabs.onUpdated, | |
87 function(tabId, changeInfo, tab) { | |
88 if (otherAttribsDict !== null) { | |
89 var otherAttribsKeys = Object.keys(otherAttribsDict); | |
90 otherAttribsKeys.forEach(function(attrib) { | |
91 if (typeof changeInfo[attrib] !== "undefined") { | |
92 assertEq(otherAttribsDict[attrib], changeInfo[attrib]); | |
93 assertEq(otherAttribsDict[attrib], tab[attrib]); | |
94 } | |
95 }); | |
96 } | |
97 if (attrib in changeInfo) { | |
98 assertEq(expected, changeInfo[attrib]); | |
99 assertEq(expected, tab[attrib]); | |
100 checkQuery(tabId, attrib, expected, true, pass(function() { | |
101 checkQuery(tabId, attrib, !expected, false, pass(function() { | |
102 onUpdatedCompleted(); | |
103 })); | |
104 })); | |
105 } | |
106 } | |
107 ); | |
108 } | |
OLD | NEW |