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

Side by Side Diff: chrome/test/data/extensions/api_test/activity_log_private/test/test.js

Issue 19014003: Modifications to activity logging end to end tests. Reduces the number of window.open calls to make… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes after merge Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/data/extensions/api_test/activity_log_private/friend/reply.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // Setup the test cases. 5 // Setup the test cases.
6 var testCases = []; 6 var testCases = [];
7 testCases.push({ 7 testCases.push({
8 func: function triggerApiCall() { 8 func: function triggerApiCall() {
9 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 9 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
10 'api_call', function response() { }); 10 'api_call', function response() { });
11 }, 11 },
12 expected_activity: ['cookies.set'] 12 expected_activity: ['cookies.set']
13 }); 13 });
14 testCases.push({ 14 testCases.push({
15 func: function triggerSpecialCall() { 15 func: function triggerSpecialCall() {
16 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 16 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
17 'special_call', function response() { }); 17 'special_call', function response() { });
18 }, 18 },
19 expected_activity: [ 19 expected_activity: [
20 'extension.getURL', 20 'extension.getURL',
21 'extension.getViews' 21 'extension.getViews'
22 ] 22 ]
23 }); 23 });
24 testCases.push({ 24 testCases.push({
25 func: function triggerBlockedCall() {
26 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
27 'blocked_call', function response() { });
28 },
29 expected_activity: []
30 });
31 testCases.push({
32 func: function triggerInjectCS() {
33 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
34 'inject_cs', function response() { });
35 },
36 expected_activity: [
37 'tabs.onUpdated',
38 'tabs.onUpdated',
39 'tabs.executeScript',
40 'tabs.remove'
41 ]
42 });
43 testCases.push({
44 func: function triggerInjectCSIncognito() {
45 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
46 'inject_cs_incognito', function response() { });
47 },
48 is_incognito: true,
49 expected_activity: [
50 'windows.create',
51 'tabs.onUpdated',
52 'tabs.onUpdated',
53 'tabs.executeScript',
54 'tabs.remove'
55 ]
56 });
57 testCases.push({
58 func: function triggerInsertBlob() {
59 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
60 'inject_blob', function response() { });
61 },
62 expected_activity: [
63 'tabs.onUpdated',
64 'tabs.onUpdated',
65 'tabs.executeScript',
66 'tabs.remove']
67 });
68 testCases.push({
69 func: function triggerDouble() { 25 func: function triggerDouble() {
70 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 26 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
71 'double', function response() {}); 27 'double', function response() {});
72 }, 28 },
73 expected_activity: ['omnibox.setDefaultSuggestion'] 29 expected_activity: ['omnibox.setDefaultSuggestion']
74 }); 30 });
75 testCases.push({ 31 testCases.push({
76 func: function triggerAppBindings() { 32 func: function triggerAppBindings() {
77 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 33 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
78 'app_bindings', function response() { }); 34 'app_bindings', function response() { });
79 }, 35 },
80 expected_activity: [ 36 expected_activity: [
81 'app.GetDetails', 37 'app.GetDetails',
82 'app.GetIsInstalled', 38 'app.GetIsInstalled',
83 'app.getInstallState' 39 'app.getInstallState'
84 ] 40 ]
85 }); 41 });
86 testCases.push({ 42 testCases.push({
87 func: function triggerObjectProperties() { 43 func: function triggerBlockedCall() {
88 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 44 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
89 'object_properties', function response() { }); 45 'blocked_call', function response() { });
90 }, 46 },
91 expected_activity: [ 47 expected_activity: []
92 'tabs.onUpdated',
93 'tabs.onUpdated',
94 'tabs.remove']
95 }); 48 });
96 testCases.push({ 49 testCases.push({
97 func: function triggerObjectMethods() { 50 func: function triggerObjectMethods() {
98 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 51 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
99 'object_methods', function response() { }); 52 'object_methods', function response() { });
100 }, 53 },
101 expected_activity: ['storage.clear'] 54 expected_activity: ['storage.clear']
102 }); 55 });
103 testCases.push({ 56 testCases.push({
104 func: function triggerMessageCS() {
105 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
106 'message_cs', function response() { });
107 },
108 expected_activity: [
109 'tabs.onUpdated',
110 'tabs.onUpdated',
111 'tabs.connect',
112 'tabs.sendMessage',
113 'tabs.remove'
114 ]
115 });
116 testCases.push({
117 func: function triggerMessageSelf() { 57 func: function triggerMessageSelf() {
118 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 58 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
119 'message_self', function response() { }); 59 'message_self', function response() { });
120 }, 60 },
121 expected_activity: [ 61 expected_activity: [
122 'runtime.connect', 62 'runtime.connect',
123 'runtime.sendMessage' 63 'runtime.sendMessage'
124 ] 64 ]
125 }); 65 });
126 testCases.push({ 66 testCases.push({
127 func: function triggerMessageOther() { 67 func: function triggerMessageOther() {
128 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 68 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
129 'message_other', function response() { }); 69 'message_other', function response() { });
130 }, 70 },
131 expected_activity: [ 71 expected_activity: [
132 'runtime.connect', 72 'runtime.connect',
133 'runtime.sendMessage' 73 'runtime.sendMessage'
134 ] 74 ]
135 }); 75 });
136 testCases.push({ 76 testCases.push({
137 func: function triggerConnectOther() { 77 func: function triggerConnectOther() {
138 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 78 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
139 'connect_other', function response() { }); 79 'connect_other', function response() { });
140 }, 80 },
141 expected_activity: ['runtime.connect'] 81 expected_activity: ['runtime.connect']
142 }); 82 });
143 testCases.push({ 83 testCases.push({
144 func: function triggerLocationAccess() { 84 func: function triggerBackgroundXHR() {
145 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 85 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
146 'location_access', function response() { }); 86 'background_xhr', function response() { });
147 }, 87 },
148 expected_activity: [ 88 expected_activity: [
149 'tabs.onUpdated', 89 'XMLHttpRequest.open',
150 'tabs.onUpdated', 90 'XMLHttpRequest.setRequestHeader'
151 'tabs.executeScript',
152 'tabs.remove'
153 ] 91 ]
154 }); 92 });
155 testCases.push({ 93 testCases.push({
156 func: function triggerDomMutation1() {
157 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
158 'dom_mutation1', function response() { });
159 },
160 expected_activity: [
161 'tabs.onUpdated',
162 'tabs.onUpdated',
163 'tabs.executeScript',
164 'tabs.remove'
165 ]
166 });
167 testCases.push({
168 func: function triggerDomMutation2() {
169 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
170 'dom_mutation2', function response() { });
171 },
172 expected_activity: [
173 'tabs.onUpdated',
174 'tabs.onUpdated',
175 'tabs.executeScript',
176 'tabs.remove'
177 ]
178 });
179 testCases.push({
180 func: function triggerNavigatorAccess() {
181 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
182 'navigator_access', function response() { });
183 },
184 expected_activity: [
185 'tabs.onUpdated',
186 'tabs.onUpdated',
187 'tabs.executeScript',
188 'tabs.remove'
189 ]
190 });
191 testCases.push({
192 func: function triggerWebStorageAccess1() {
193 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
194 'web_storage_access1', function response() { });
195 },
196 expected_activity: [
197 'tabs.onUpdated',
198 'tabs.onUpdated',
199 'tabs.executeScript',
200 'tabs.remove'
201 ]
202 });
203 testCases.push({
204 func: function triggerWebStorageAccess2() {
205 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
206 'web_storage_access2', function response() { });
207 },
208 expected_activity: [
209 'tabs.onUpdated',
210 'tabs.onUpdated',
211 'tabs.executeScript',
212 'tabs.remove'
213 ]
214 });
215 testCases.push({
216 func: function triggerNotificationAccess() {
217 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
218 'notification_access', function response() { });
219 },
220 expected_activity: [
221 'tabs.onUpdated',
222 'tabs.onUpdated',
223 'tabs.executeScript',
224 'tabs.remove'
225 ]
226 });
227 testCases.push({
228 func: function triggerApplicationCacheAccess() {
229 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
230 'application_cache_access',
231 function response() { });
232 },
233 expected_activity: [
234 'tabs.onUpdated',
235 'tabs.onUpdated',
236 'tabs.executeScript',
237 'tabs.remove'
238 ]
239 });
240 testCases.push({
241 func: function triggerWebDatabaseAccess() {
242 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
243 'web_database_access',
244 function response() { });
245 },
246 expected_activity: [
247 'tabs.onUpdated',
248 'tabs.onUpdated',
249 'tabs.executeScript',
250 'tabs.remove'
251 ]
252 });
253 testCases.push({
254 func: function triggerCanvasAccess() {
255 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
256 'canvas_access', function response() { });
257 },
258 expected_activity: [
259 'tabs.onUpdated',
260 'tabs.onUpdated',
261 'tabs.executeScript',
262 'tabs.remove'
263 ]
264 });
265 testCases.push({
266 name: 'tab_ids',
267 func: function triggerTabIds() { 94 func: function triggerTabIds() {
268 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 95 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
269 'tab_ids', function response() { }); 96 'tab_ids', function response() { });
270 }, 97 },
271 expected_activity: [ 98 expected_activity: [
272 'tabs.onUpdated', 99 'tabs.onUpdated',
273 'tabs.onUpdated', 100 'tabs.onUpdated',
274 'tabs.executeScript', 101 'tabs.executeScript',
275 'tabs.onUpdated', 102 'tabs.onUpdated',
276 'tabs.onUpdated', 103 'tabs.onUpdated',
104 'tabs.move',
277 'tabs.remove' 105 'tabs.remove'
278 ] 106 ]
279 }); 107 });
280 testCases.push({ 108 testCases.push({
281 name: 'tab_ids_incognito',
282 func: function triggerTabIdsIncognito() { 109 func: function triggerTabIdsIncognito() {
283 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 110 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
284 'tab_ids_incognito', function response() { }); 111 'tab_ids_incognito', function response() { });
285 }, 112 },
286 is_incognito: true, 113 is_incognito: true,
287 expected_activity: [ 114 expected_activity: [
288 'windows.create', 115 'windows.create',
289 'tabs.onUpdated', 116 'tabs.onUpdated',
290 'tabs.onUpdated', 117 'tabs.onUpdated',
291 'tabs.executeScript', 118 'tabs.executeScript',
292 'windows.create', 119 'windows.create',
293 'tabs.onUpdated', 120 'tabs.onUpdated',
294 'tabs.onUpdated', 121 'tabs.onUpdated',
122 'tabs.move',
295 'tabs.remove' 123 'tabs.remove'
296 ] 124 ]
297 }); 125 });
298
299 testCases.push({ 126 testCases.push({
300 func: function triggerWebRequest() { 127 func: function triggerWebRequest() {
301 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 128 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
302 'webrequest', function response() { }); 129 'webrequest', function response() { });
303 }, 130 },
304 expected_activity: [ 131 expected_activity: [
305 'webRequestInternal.addEventListener', 132 'webRequestInternal.addEventListener',
306 'webRequestInternal.addEventListener', 133 'webRequestInternal.addEventListener',
307 'webRequest.onBeforeSendHeaders/1', 134 'webRequest.onBeforeSendHeaders/1',
308 'webRequestInternal.eventHandled', 135 'webRequestInternal.eventHandled',
309 'webRequest.onBeforeSendHeaders', 136 'webRequest.onBeforeSendHeaders',
310 'tabs.onUpdated', 137 'tabs.onUpdated',
311 'tabs.onUpdated', 138 'tabs.onUpdated',
312 'tabs.remove' 139 'tabs.remove'
313 ] 140 ]
314 }); 141 });
315
316 testCases.push({ 142 testCases.push({
317 func: function triggerWebRequestIncognito() { 143 func: function triggerWebRequestIncognito() {
318 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 144 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
319 'webrequest_incognito', function response() { }); 145 'webrequest_incognito', function response() { });
320 }, 146 },
321 is_incognito: true, 147 is_incognito: true,
322 expected_activity: [ 148 expected_activity: [
323 'webRequestInternal.addEventListener', 149 'webRequestInternal.addEventListener',
324 'webRequestInternal.addEventListener', 150 'webRequestInternal.addEventListener',
325 'windows.create', 151 'windows.create',
326 'webRequest.onBeforeSendHeaders/3', 152 'webRequest.onBeforeSendHeaders/3',
327 'webRequestInternal.eventHandled', 153 'webRequestInternal.eventHandled',
328 'webRequest.onBeforeSendHeaders', 154 'webRequest.onBeforeSendHeaders',
329 'tabs.onUpdated', 155 'tabs.onUpdated',
330 'tabs.onUpdated', 156 'tabs.onUpdated',
331 'tabs.remove' 157 'tabs.remove'
332 ] 158 ]
333 }); 159 });
334 160
335 testCases.push({ 161 testCases.push({
336 func: function triggerBackgroundXHR() { 162 func: function triggerApiCallsOnTabsUpdated() {
337 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji', 163 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
338 'cs_xhr', function response() { }); 164 'api_tab_updated', function response() { });
339 }, 165 },
340 expected_activity: [ 166 expected_activity: [
341 'tabs.onUpdated', 167 'tabs.onUpdated',
342 'tabs.onUpdated', 168 'tabs.onUpdated',
169 'tabs.connect',
170 'tabs.sendMessage',
171 'tabs.executeScript',
172 'tabs.executeScript',
173 'tabs.remove'
174 ]
175 });
176 testCases.push({
177 func: function triggerApiCallsOnTabsUpdatedIncognito() {
mvrable 2013/07/11 18:30:05 This test case should presumably also be marked is
karenlees 2013/07/11 19:00:46 Done.
178 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
179 'api_tab_updated_incognito',
180 function response() { });
181 },
182 expected_activity: [
183 'windows.create',
184 'tabs.onUpdated',
185 'tabs.onUpdated',
186 'tabs.connect',
187 'tabs.sendMessage',
188 'tabs.executeScript',
189 'tabs.executeScript',
190 'tabs.remove'
191 ]
192 });
193 testCases.push({
194 func: function triggerDOMChangesOnTabsUpdated() {
195 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
196 'dom_tab_updated', function response() { });
197 },
198 // TODO(karenlees): some dom activity should also be logged here.
199 // Add the expected dom calls when chrome issue 259079 is fixed.
200 expected_activity: [
201 'tabs.onUpdated',
202 'tabs.onUpdated',
343 'tabs.executeScript', 203 'tabs.executeScript',
344 'tabs.remove' 204 'tabs.remove'
345 ] 205 ]
346 }); 206 });
347 207
348 testCases.push({
349 func: function triggerBackgroundXHR() {
350 chrome.runtime.sendMessage('pknkgggnfecklokoggaggchhaebkajji',
351 'background_xhr', function response() { });
352 },
353 expected_activity: [
354 'XMLHttpRequest.open',
355 'XMLHttpRequest.setRequestHeader'
356 ]
357 });
358 208
359 // Listener to check the expected logging is done in the test cases. 209 // Listener to check the expected logging is done in the test cases.
360 var testCaseIndx = 0; 210 var testCaseIndx = 0;
361 var callIndx = -1; 211 var callIndx = -1;
362 chrome.activityLogPrivate.onExtensionActivity.addListener( 212 chrome.activityLogPrivate.onExtensionActivity.addListener(
363 function(activity) { 213 function(activity) {
364 var activityId = activity['extensionId']; 214 var activityId = activity['extensionId'];
365 chrome.test.assertEq('pknkgggnfecklokoggaggchhaebkajji', activityId); 215 chrome.test.assertEq('pknkgggnfecklokoggaggchhaebkajji', activityId);
366 216
367 // Get the api call info from either the chrome activity or dom activity. 217 // Get the api call info from the chrome activity, dom activity or blocked
218 // chrome activity detail depending on what type of activity this is.
368 var activityType = activity['activityType']; 219 var activityType = activity['activityType'];
369 var activityDetailName = 'chromeActivityDetail'; 220 var activityDetailName = 'chromeActivityDetail';
370 if (activity['activityType'] == 'dom') { 221 if (activity['activityType'] == 'dom') {
371 activityDetailName = 'domActivityDetail'; 222 activityDetailName = 'domActivityDetail';
223 } else if (activity['activityType'] == 'blocked_chrome') {
224 activityDetailName = 'blockedChromeActivityDetail';
372 } 225 }
373 226
374 // Check the api call is the one we expected next. 227 // Check the api call is the one we expected next.
375 var apiCall = activity[activityDetailName]['apiCall']; 228 var apiCall = activity[activityDetailName]['apiCall'];
376 expectedCall = 'runtime.onMessageExternal'; 229 expectedCall = 'runtime.onMessageExternal';
377 if (callIndx > -1) { 230 if (callIndx > -1) {
378 expectedCall = testCases[testCaseIndx].expected_activity[callIndx]; 231 expectedCall = testCases[testCaseIndx].expected_activity[callIndx];
379 } 232 }
380 console.log('Logged:' + apiCall + ' Expected:' + expectedCall); 233 console.log('Logged:' + apiCall + ' Expected:' + expectedCall);
381 chrome.test.assertEq(expectedCall, apiCall); 234 chrome.test.assertEq(expectedCall, apiCall);
382 235
383 // Check that no real URLs are logged in incognito-mode tests. 236 // Check that no real URLs are logged in incognito-mode tests.
384 if (activity['activityType'] == 'dom') { 237 if (activity['activityType'] == 'dom') {
385 var url = activity[activityDetailName]['url']; 238 var url = activity[activityDetailName]['url'];
386 if (url) { 239 if (url) {
387 if (testCases[testCaseIndx].is_incognito) { 240 if (testCases[testCaseIndx].is_incognito) {
388 chrome.test.assertEq('http://incognito/', url); 241 chrome.test.assertEq('http://incognito/', url);
389 } else { 242 } else {
390 chrome.test.assertTrue(url != 'http://incognito/', 243 chrome.test.assertTrue(url != 'http://incognito/',
391 'Non-incognito URL was anonymized'); 244 'Non-incognito URL was anonymized');
mvrable 2013/07/11 18:30:05 Looks like just a formatting change here, and I th
karenlees 2013/07/11 19:00:46 Sorry, was unintentional change when I pasted in t
392 } 245 }
393 } 246 }
394 } 247 }
395 248
396 // If all the expected calls have been logged for this test case then 249 // If all the expected calls have been logged for this test case then
397 // mark as suceeded and move to the next. Otherwise look for the next 250 // mark as suceeded and move to the next. Otherwise look for the next
398 // expected api call. 251 // expected api call.
399 if (callIndx == testCases[testCaseIndx].expected_activity.length - 1) { 252 if (callIndx == testCases[testCaseIndx].expected_activity.length - 1) {
400 chrome.test.succeed(); 253 chrome.test.succeed();
401 callIndx = -1; 254 callIndx = -1;
402 testCaseIndx++; 255 testCaseIndx++;
403 } else { 256 } else {
404 callIndx++; 257 callIndx++;
405 } 258 }
406 } 259 }
407 ); 260 );
408 261
409 function getTestCasesToRun() { 262 function getTestCasesToRun() {
410 var tests = []; 263 var tests = [];
411 for (var i = 0; i < testCases.length; i++) { 264 for (var i = 0; i < testCases.length; i++) {
412 if (testCases[i].func != undefined) { 265 if (testCases[i].func != undefined) {
413 tests.push(testCases[i].func); 266 tests.push(testCases[i].func);
414 } 267 }
415 } 268 }
416 return tests; 269 return tests;
417 } 270 }
418 chrome.test.runTests(getTestCasesToRun()); 271 chrome.test.runTests(getTestCasesToRun());
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/activity_log_private/friend/reply.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698