OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // If you set this variable to true, then compile and run Chrome, all messages | 5 // If you set this variable to true, then compile and run Chrome, all messages |
6 // sent with chrome.send() will be intercepted and their callback data will be | 6 // sent with chrome.send() will be intercepted and their callback data will be |
7 // recorded. You can later see the recorded data by executing chrome.mock() | 7 // recorded. You can later see the recorded data by executing chrome.mock() |
8 // on Web Developer Tools' console. | 8 // on Web Developer Tools' console. |
9 var recordMockData = false; | 9 var recordMockData = false; |
10 | 10 |
11 (recordMockData || !/^chrome:\/\/./.test(location.href)) && (function() { | 11 (recordMockData || !/^chrome:\/\/./.test(location.href)) && (function() { |
12 | 12 |
13 var __chrome__ = chrome; | 13 var __chrome__ = chrome; |
14 var shouldRegisterData = !!window.chrome && !!window.chrome.send; | 14 var shouldRegisterData = !!window.chrome && !!window.chrome.send; |
15 | 15 |
16 var NO_CALLBACK = 1; | 16 var NO_CALLBACK = 1; |
17 | 17 |
18 // Only messages registered in the callback map will be intercepted. | 18 // Only messages registered in the callback map will be intercepted. |
19 var callbackMap = { | 19 var callbackMap = { |
20 'appRemoved': 'ntp.appRemoved', | |
20 'blacklistURLFromMostVisited': NO_CALLBACK, | 21 'blacklistURLFromMostVisited': NO_CALLBACK, |
21 'clearMostVisitedURLsBlacklist': NO_CALLBACK, | 22 'clearMostVisitedURLsBlacklist': NO_CALLBACK, |
22 'getApps': 'ntp.getAppsCallback', | 23 'getApps': 'ntp.getAppsCallback', |
23 'getForeignSessions': 'ntp.setForeignSessions', | 24 'getForeignSessions': 'ntp.setForeignSessions', |
24 'getMostVisited': 'ntp.setMostVisitedPages', | 25 'getMostVisited': 'ntp.setMostVisitedPages', |
25 'getRecentlyClosedTabs': 'ntp.setRecentlyClosedTabs', | 26 'getRecentlyClosedTabs': 'ntp.setRecentlyClosedTabs', |
26 'metricsHandler:logEventTime': NO_CALLBACK, | 27 'metricsHandler:logEventTime': NO_CALLBACK, |
27 'metricsHandler:recordInHistogram': NO_CALLBACK, | 28 'metricsHandler:recordInHistogram': NO_CALLBACK, |
28 'removeURLsFromMostVisitedBlacklist': NO_CALLBACK, | 29 'removeURLsFromMostVisitedBlacklist': NO_CALLBACK, |
29 'uninstallApp': NO_CALLBACK, | 30 'uninstallApp': NO_CALLBACK, |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 } | 236 } |
236 dispatchCallbackForMessage('getMostVisited'); | 237 dispatchCallbackForMessage('getMostVisited'); |
237 }, | 238 }, |
238 | 239 |
239 clearMostVisitedURLsBlacklist: function() { | 240 clearMostVisitedURLsBlacklist: function() { |
240 mostVisitedBlackList = {}; | 241 mostVisitedBlackList = {}; |
241 dispatchCallbackForMessage('getMostVisited'); | 242 dispatchCallbackForMessage('getMostVisited'); |
242 }, | 243 }, |
243 | 244 |
244 uninstallApp: function(id) { | 245 uninstallApp: function(id) { |
246 var appData; | |
245 var data = dataMap['getApps'][0].apps; | 247 var data = dataMap['getApps'][0].apps; |
246 for (var i = 0, length = data.length; i < length; i++) { | 248 for (var i = 0, length = data.length; i < length; i++) { |
247 if (data[i].id == id) { | 249 if (data[i].id == id) { |
250 appData = data[i]; | |
248 data.splice(i, 1); | 251 data.splice(i, 1); |
249 break; | 252 break; |
250 } | 253 } |
251 } | 254 } |
Dan Beam
2012/11/30 23:41:45
perhaps it doesn't matter if this is mock code, bu
pedro (no code reviews)
2012/12/01 00:02:29
Done.
| |
252 dispatchCallbackForMessage('getApps'); | 255 dataMap['appRemoved'] = [appData, true, true]; |
256 dispatchCallbackForMessage('appRemoved'); | |
253 }, | 257 }, |
254 }; | 258 }; |
255 | 259 |
256 //---------------------------------------------------------------------------- | 260 //---------------------------------------------------------------------------- |
257 // Debug | 261 // Debug |
258 //---------------------------------------------------------------------------- | 262 //---------------------------------------------------------------------------- |
259 | 263 |
260 var debugArgs = { | 264 var debugArgs = { |
261 debug: false, | 265 debug: false, |
262 slownessFactor: null, | 266 slownessFactor: null, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 | 353 |
350 //---------------------------------------------------------------------------- | 354 //---------------------------------------------------------------------------- |
351 // ChromeMock initialization | 355 // ChromeMock initialization |
352 //---------------------------------------------------------------------------- | 356 //---------------------------------------------------------------------------- |
353 | 357 |
354 if (shouldRegisterData) | 358 if (shouldRegisterData) |
355 interceptLoadData(); | 359 interceptLoadData(); |
356 | 360 |
357 window.chrome = ChromeMock; | 361 window.chrome = ChromeMock; |
358 })(); | 362 })(); |
OLD | NEW |