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

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

Issue 19822007: Updated Google Now to Check the Geolocation Access Preference (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@r213016
Patch Set: Update Unit Tests Created 7 years, 5 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
OLDNEW
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 // Mocks for globals needed for loading background.js. 5 // Mocks for globals needed for loading background.js.
6 6
7 function emptyMock() {} 7 function emptyMock() {}
8 function buildTaskManager() { 8 function buildTaskManager() {
9 return {instrumentApiFunction: emptyMock}; 9 return {
10 add: function(taskname, task) {
11 task(function() {});
12 },
13 debugSetStepName: emptyMock,
14 instrumentApiFunction: emptyMock,
15 };
10 } 16 }
11 var instrumentApiFunction = emptyMock; 17 var instrumentApiFunction = emptyMock;
12 var buildAttemptManager = emptyMock; 18 var buildAttemptManager = function() {
19 var isRunningState = false;
20 return {
21 isRunning: function(callback) {
22 callback(isRunningState);
23 },
24 start: function() {
25 isRunningState = true;
26 },
27 stop: function() {
28 isRunningState = false;
29 }
30 };
31 };
13 var emptyListener = {addListener: emptyMock}; 32 var emptyListener = {addListener: emptyMock};
14 chrome['location'] = {onLocationUpdate: emptyListener}; 33 chrome['location'] = {
34 onLocationUpdate: emptyListener,
35 clearWatch: emptyMock
vadimt 2013/07/25 20:48:01 We mock in background_test_util.js only methods th
robliao 2013/07/25 22:35:48 Done.
36 };
15 chrome['notifications'] = { 37 chrome['notifications'] = {
16 onButtonClicked: emptyListener, 38 onButtonClicked: emptyListener,
17 onClicked: emptyListener, 39 onClicked: emptyListener,
18 onClosed: emptyListener 40 onClosed: emptyListener
19 }; 41 };
20 chrome['omnibox'] = {onInputEntered: emptyListener}; 42 chrome['omnibox'] = {onInputEntered: emptyListener};
43 chrome['preferencesPrivate'] = {
44 googleGeolocationAccessEnabled: {
45 onChange: emptyListener
46 }
47 };
21 chrome['runtime'] = { 48 chrome['runtime'] = {
22 onInstalled: emptyListener, 49 onInstalled: emptyListener,
23 onStartup: emptyListener 50 onStartup: emptyListener
24 }; 51 };
25 52
26 var storage = {}; 53 var storage = {set: emptyMock};
27 54
28 /** 55 /**
29 * Syntactic sugar for use with will() on a Mock4JS.Mock. 56 * Syntactic sugar for use with will() on a Mock4JS.Mock.
30 * Creates an action for will() that invokes a callback that the tested code 57 * Creates an action for will() that invokes a callback that the tested code
31 * passes to a mocked function. 58 * passes to a mocked function.
32 * @param {SaveMockArguments} savedArgs Arguments that will contain the 59 * @param {SaveMockArguments} savedArgs Arguments that will contain the
33 * callback once the mocked function is called. 60 * callback once the mocked function is called.
34 * @param {number} callbackParameter Index of the callback parameter in 61 * @param {number} callbackParameter Index of the callback parameter in
35 * |savedArgs|. 62 * |savedArgs|.
36 * @param {...Object} var_args Arguments to pass to the callback. 63 * @param {...Object} var_args Arguments to pass to the callback.
37 * @return {CallFunctionAction} Action for use in will(). 64 * @return {CallFunctionAction} Action for use in will().
38 */ 65 */
39 function invokeCallback(savedArgs, callbackParameter, var_args) { 66 function invokeCallback(savedArgs, callbackParameter, var_args) {
40 var callbackArguments = Array.prototype.slice.call(arguments, 2); 67 var callbackArguments = Array.prototype.slice.call(arguments, 2);
41 return callFunction(function() { 68 return callFunction(function() {
42 savedArgs.arguments[callbackParameter].apply(null, callbackArguments); 69 savedArgs.arguments[callbackParameter].apply(null, callbackArguments);
70
71 // Mock4JS does not clear the saved args after invocation.
72 // To allow reuse of the same SaveMockArguments for multiple
73 // invocations with similar arguments, clear them here.
74 savedArgs.arguments.splice(0, savedArgs.arguments.length);
43 }); 75 });
44 } 76 }
45 77
46 /** 78 /**
47 * Mock4JS matcher object that matches the actual agrument and the expected 79 * Mock4JS matcher object that matches the actual agrument and the expected
48 * value iff their JSON represenations are same. 80 * value iff their JSON represenations are same.
49 * @param {Object} expectedValue Expected value. 81 * @param {Object} expectedValue Expected value.
50 * @constructor 82 * @constructor
51 */ 83 */
52 function MatchJSON(expectedValue) { 84 function MatchJSON(expectedValue) {
(...skipping 22 matching lines...) Expand all
75 }; 107 };
76 108
77 /** 109 /**
78 * Builds a MatchJSON agrument matcher for a given expected value. 110 * Builds a MatchJSON agrument matcher for a given expected value.
79 * @param {Object} expectedValue Expected value. 111 * @param {Object} expectedValue Expected value.
80 * @return {MatchJSON} Resulting Mock4JS matcher. 112 * @return {MatchJSON} Resulting Mock4JS matcher.
81 */ 113 */
82 function eqJSON(expectedValue) { 114 function eqJSON(expectedValue) {
83 return new MatchJSON(expectedValue); 115 return new MatchJSON(expectedValue);
84 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698