Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // Common test utilities. | 5 // Common test utilities. |
| 6 | 6 |
| 7 /** | |
| 8 * Allows console.log output. | |
| 9 */ | |
| 10 var showConsoleLogOutput = false; | |
|
vadimt
2014/01/28 21:07:12
showConsoleLogOutput seems to be a constant set to
robliao
2014/01/28 21:56:02
One of the main complaints is that the unit tests
| |
| 11 | |
| 12 /** | |
| 13 * Conditionally allow console.log output based off of showConsoleLogOutput. | |
| 14 */ | |
| 15 console.log = function() { | |
| 16 var originalConsoleLog = console.log; | |
| 17 return function() { | |
| 18 if (showConsoleLogOutput) { | |
| 19 originalConsoleLog.apply(console, arguments); | |
| 20 } | |
| 21 }; | |
| 22 }(); | |
| 23 | |
| 7 function emptyMock() {} | 24 function emptyMock() {} |
| 8 | 25 |
| 9 // Container for event handlers added by mocked 'addListener' functions. | 26 // Container for event handlers added by mocked 'addListener' functions. |
| 10 var mockEventHandlers = {}; | 27 var mockEventHandlers = {}; |
| 11 | 28 |
| 12 /** | 29 /** |
| 13 * Mocks 'addListener' function of an API event. The mocked function will keep | 30 * Mocks 'addListener' function of an API event. The mocked function will keep |
| 14 * track of handlers. | 31 * track of handlers. |
| 15 * @param {Object} topLevelContainer Top-level container of the original | 32 * @param {Object} topLevelContainer Top-level container of the original |
| 16 * function. Can be either 'chrome' or 'instrumented'. | 33 * function. Can be either 'chrome' or 'instrumented'. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 47 */ | 64 */ |
| 48 function getMockHandlerContainer(eventIdentifier) { | 65 function getMockHandlerContainer(eventIdentifier) { |
| 49 var eventIdentifierParts = eventIdentifier.split('.'); | 66 var eventIdentifierParts = eventIdentifier.split('.'); |
| 50 var mockEventContainer = mockEventHandlers; | 67 var mockEventContainer = mockEventHandlers; |
| 51 eventIdentifierParts.forEach(function(fragment) { | 68 eventIdentifierParts.forEach(function(fragment) { |
| 52 mockEventContainer = mockEventContainer[fragment]; | 69 mockEventContainer = mockEventContainer[fragment]; |
| 53 }); | 70 }); |
| 54 | 71 |
| 55 return mockEventContainer; | 72 return mockEventContainer; |
| 56 } | 73 } |
| OLD | NEW |