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

Side by Side Diff: chrome/browser/resources/google_now/common_test_util.js

Issue 23477006: Unit tests for utility.js (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comments Created 7 years, 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 // Common test utilities.
6
7 function emptyMock() {}
8
9 // Container for event handlers added by mocked 'addListener' functions.
10 var mockEventHandlers = {};
11
12 /**
13 * Mocks 'addListener' function of an API event. The mocked function will keep
14 * track of handlers.
15 * @param {Object} topLevelContainer Top-level container of the original
16 * function. Can be either 'chrome' or 'instrumented'.
17 * @param {string} eventIdentifier Event identifier, such as
18 * 'runtime.onSuspend'.
19 */
20 function mockChromeEvent(topLevelContainer, eventIdentifier) {
21 var eventIdentifierParts = eventIdentifier.split('.');
22 var eventName = eventIdentifierParts.pop();
23 var originalMethodContainer = topLevelContainer;
24 var mockEventContainer = mockEventHandlers;
25 eventIdentifierParts.forEach(function(fragment) {
26 originalMethodContainer =
skare_ 2013/08/29 21:28:22 if I'm reading this right (and I might not be) I t
skare_ 2013/08/29 21:46:33 never mind -- this can already exist and you need
vadimt 2013/08/29 21:46:58 Discussed in person. Needed to create intermediate
27 originalMethodContainer[fragment] =
28 originalMethodContainer[fragment] || {};
29 mockEventContainer =
30 mockEventContainer[fragment] =
31 mockEventContainer[fragment] || {};
32 });
33
34 mockEventContainer[eventName] = [];
35 originalMethodContainer[eventName] = {
36 addListener: function(callback) {
37 mockEventContainer[eventName].push(callback);
38 }
39 };
40 }
41
42 /**
43 * Gets the array of event handlers added by a mocked 'addListener' function.
44 * @param {string} eventIdentifier Event identifier, such as
45 * 'runtime.onSuspend'.
46 * @return {Array.<Function>} Array of handlers.
47 */
48 function getMockHandlerContainer(eventIdentifier) {
49 var eventIdentifierParts = eventIdentifier.split('.');
50 var mockEventContainer = mockEventHandlers;
51 eventIdentifierParts.forEach(function(fragment) {
52 mockEventContainer = mockEventContainer[fragment];
53 });
54
55 return mockEventContainer;
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698