| 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 } |
| 252 dispatchCallbackForMessage('getApps'); | 255 assert(appData); |
| 256 dataMap['appRemoved'] = [appData, true, true]; |
| 257 dispatchCallbackForMessage('appRemoved'); |
| 253 }, | 258 }, |
| 254 }; | 259 }; |
| 255 | 260 |
| 256 //---------------------------------------------------------------------------- | 261 //---------------------------------------------------------------------------- |
| 257 // Debug | 262 // Debug |
| 258 //---------------------------------------------------------------------------- | 263 //---------------------------------------------------------------------------- |
| 259 | 264 |
| 260 var debugArgs = { | 265 var debugArgs = { |
| 261 debug: false, | 266 debug: false, |
| 262 slownessFactor: null, | 267 slownessFactor: null, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 354 |
| 350 //---------------------------------------------------------------------------- | 355 //---------------------------------------------------------------------------- |
| 351 // ChromeMock initialization | 356 // ChromeMock initialization |
| 352 //---------------------------------------------------------------------------- | 357 //---------------------------------------------------------------------------- |
| 353 | 358 |
| 354 if (shouldRegisterData) | 359 if (shouldRegisterData) |
| 355 interceptLoadData(); | 360 interceptLoadData(); |
| 356 | 361 |
| 357 window.chrome = ChromeMock; | 362 window.chrome = ChromeMock; |
| 358 })(); | 363 })(); |
| OLD | NEW |