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

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: robliao@ 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() {}
skare_ 2013/08/29 00:03:37 the extension is assembled with sourcefile concate
vadimt 2013/08/29 00:28:22 This is not a part of the extension. There are 3 i
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 add
14 * handlers to arrays stored inside mockEventHandlers.
skare_ 2013/08/29 00:03:37 hide implementation details? e.g. "mocked function
vadimt 2013/08/29 00:28:22 Done.
15 * @param {Object} topLevelContainer Top-level container of the original
16 * function. Can be either chrome or instrumented.
skare_ 2013/08/29 00:03:37 nit: maybe 'chrome' or 'instrumented'. for consi
vadimt 2013/08/29 00:28:22 Done.
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();
skare_ 2013/08/29 00:03:37 maybe check that (eventName != undefined) or (even
vadimt 2013/08/29 00:28:22 Then it will crash. This is just a test anyways.
23 var originalMethodContainer = topLevelContainer;
24 var mockEventContainer = mockEventHandlers;
25 eventIdentifierParts.forEach(function(fragment) {
skare_ 2013/08/29 00:03:37 js styleguide suggests using normal iteration over
vadimt 2013/08/29 00:28:22 This is because for-in can lead to errors, not bec
26 originalMethodContainer =
27 originalMethodContainer[fragment] =
skare_ 2013/08/29 00:03:37 quick check on this and 29-31 -- intended to be (x
vadimt 2013/08/29 00:28:22 This is exactly what happens: originalMethodContai
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