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

Side by Side Diff: chrome/browser/resources/google_now/utility_unittest.gtestjs

Issue 174053003: Task Management - Handle Promises "Then" or "Catch" callback case. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bug Fix Created 6 years, 10 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
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 /** 5 /**
6 * Test fixture for utility.js. 6 * Test fixture for utility.js.
7 * @constructor 7 * @constructor
8 * @extends {testing.Test} 8 * @extends {testing.Test}
9 */ 9 */
10 function GoogleNowUtilityUnitTest () { 10 function GoogleNowUtilityUnitTest () {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 callback('test string', 239). 200 callback('test string', 239).
201 will(callFunction(function() { 201 will(callFunction(function() {
202 wrapper.checkInWrappedCallback(); // it should succeed 202 wrapper.checkInWrappedCallback(); // it should succeed
203 })); 203 }));
204 204
205 // Invoking tested function. 205 // Invoking tested function.
206 wrappedCallback('test string', 239); 206 wrappedCallback('test string', 239);
207 Mock4JS.verifyAllMocks(); 207 Mock4JS.verifyAllMocks();
208 208
209 // Step 3. Check that after the callback we are again in non-instrumented 209 // Step 3. Check that after the callback we are again in non-instrumented
210 // code. 210 // code.
211 // Expectations. 211 // Expectations.
212 this.mockGlobals.expects(once()). 212 this.mockGlobals.expects(once()).
213 buildErrorWithMessageForServer('Not in instrumented callback'). 213 buildErrorWithMessageForServer('Not in instrumented callback').
214 will(returnValue(testError)); 214 will(returnValue(testError));
215 this.mockGlobals.expects(once()). 215 this.mockGlobals.expects(once()).
216 reportError(eqJSON(testError)); 216 reportError(eqJSON(testError));
217 217
218 // Invocation. 218 // Invocation.
219 wrapper.checkInWrappedCallback(); 219 wrapper.checkInWrappedCallback();
220 220
(...skipping 14 matching lines...) Expand all
235 ]); 235 ]);
236 236
237 // Step 1. Register plugin factory. 237 // Step 1. Register plugin factory.
238 wrapper.registerWrapperPluginFactory( 238 wrapper.registerWrapperPluginFactory(
239 this.mockLocalFunctions.functions().pluginFactory); 239 this.mockLocalFunctions.functions().pluginFactory);
240 Mock4JS.verifyAllMocks(); 240 Mock4JS.verifyAllMocks();
241 241
242 // Step 2. Wrap a callback. 242 // Step 2. Wrap a callback.
243 // Expectations. 243 // Expectations.
244 this.mockLocalFunctions.expects(once()). 244 this.mockLocalFunctions.expects(once()).
245 pluginFactory(). 245 pluginFactory(undefined).
246 will(returnValue({ 246 will(returnValue({
247 prologue: this.mockLocalFunctions.functions().prologue, 247 prologue: this.mockLocalFunctions.functions().prologue,
248 epilogue: this.mockLocalFunctions.functions().epilogue 248 epilogue: this.mockLocalFunctions.functions().epilogue
249 })); 249 }));
250 250
251 // Invoking tested function. 251 // Invoking tested function.
252 var wrappedCallback = 252 var wrappedCallback =
253 wrapper.wrapCallback(this.mockLocalFunctions.functions().callback, true); 253 wrapper.wrapCallback(this.mockLocalFunctions.functions().callback, true);
254 Mock4JS.verifyAllMocks(); 254 Mock4JS.verifyAllMocks();
255 255
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 wrapper.registerWrapperPluginFactory( 341 wrapper.registerWrapperPluginFactory(
342 this.mockLocalFunctions.functions().pluginFactory); 342 this.mockLocalFunctions.functions().pluginFactory);
343 Mock4JS.verifyAllMocks(); 343 Mock4JS.verifyAllMocks();
344 344
345 // Step 5. Bind the API to another function. 345 // Step 5. Bind the API to another function.
346 chrome.testApi.addListener = this.mockLocalFunctions.functions().apiFunction2; 346 chrome.testApi.addListener = this.mockLocalFunctions.functions().apiFunction2;
347 347
348 // Step 6. Invoke the API with another callback. 348 // Step 6. Invoke the API with another callback.
349 // Expectations. 349 // Expectations.
350 this.mockLocalFunctions.expects(once()). 350 this.mockLocalFunctions.expects(once()).
351 pluginFactory(). 351 pluginFactory(undefined).
352 will(returnValue({ 352 will(returnValue({
353 prologue: this.mockLocalFunctions.functions().prologue, 353 prologue: this.mockLocalFunctions.functions().prologue,
354 epilogue: this.mockLocalFunctions.functions().epilogue 354 epilogue: this.mockLocalFunctions.functions().epilogue
355 })); 355 }));
356 var function2SavedArgs = new SaveMockArguments(); 356 var function2SavedArgs = new SaveMockArguments();
357 this.mockLocalFunctions.expects(once()). 357 this.mockLocalFunctions.expects(once()).
358 apiFunction2( 358 apiFunction2(
359 function2SavedArgs.match(eq(239)), 359 function2SavedArgs.match(eq(239)),
360 function2SavedArgs.match(ANYTHING)); 360 function2SavedArgs.match(ANYTHING));
361 361
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 498
499 return { 499 return {
500 tasks: tasks, 500 tasks: tasks,
501 pluginFactory: registerWrapperPluginFactorySavedArgs.arguments[0] 501 pluginFactory: registerWrapperPluginFactorySavedArgs.arguments[0]
502 }; 502 };
503 } 503 }
504 504
505 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager2Sequential', function() { 505 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager2Sequential', function() {
506 // Tests that 2 tasks get successfully executed consecutively, even if the 506 // Tests that 2 tasks get successfully executed consecutively, even if the
507 // second one conflicts with the first. 507 // second one conflicts with the first.
508 508
509 // Setup. 509 // Setup.
510 var test = setUpTaskManagerTest(this); 510 var test = setUpTaskManagerTest(this);
511 511
512 // Step 1. Add 1st task that doesn't create pending callbacks. 512 // Step 1. Add 1st task that doesn't create pending callbacks.
513 // Expectations. 513 // Expectations.
514 this.mockLocalFunctions.expects(once()).task1(); 514 this.mockLocalFunctions.expects(once()).task1();
515 // Invocation. 515 // Invocation.
516 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 516 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
517 Mock4JS.verifyAllMocks(); 517 Mock4JS.verifyAllMocks();
518 518
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 681
682 // Step 2. Invoke task's callback and the onSuspend event of the task manager. 682 // Step 2. Invoke task's callback and the onSuspend event of the task manager.
683 // The 2 callbacks in onSuspendHandlerContainer are from the wrapper and the 683 // The 2 callbacks in onSuspendHandlerContainer are from the wrapper and the
684 // task manager. 684 // task manager.
685 task1PluginInstance.prologue(); 685 task1PluginInstance.prologue();
686 task1PluginInstance.epilogue(); 686 task1PluginInstance.epilogue();
687 onSuspendHandlerContainer[1](); 687 onSuspendHandlerContainer[1]();
688 }); 688 });
689 689
690 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager3Tasks', function() { 690 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager3Tasks', function() {
691 // Tests that 3 tasks can be executed too. In particular, that if the second 691 // Tests that 3 tasks can be executed too. In particular, that if the second
692 // task is a single-step task which execution was originally blocked by task1, 692 // task is a single-step task which execution was originally blocked by task1,
693 // unblocking it causes immediate synchronous execution of both tasks 2 and 3. 693 // unblocking it causes immediate synchronous execution of both tasks 2 and 3.
694 694
695 // Setup. 695 // Setup.
696 var test = setUpTaskManagerTest(this); 696 var test = setUpTaskManagerTest(this);
697 var task1PluginInstance; 697 var task1PluginInstance;
698 698
699 // Step 1. Add 1st task that creates a pending callback. 699 // Step 1. Add 1st task that creates a pending callback.
700 // Expectations. 700 // Expectations.
701 this.mockLocalFunctions.expects(once()).task1(). 701 this.mockLocalFunctions.expects(once()).task1().
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 var alarmsGetSavedArgs = new SaveMockArguments(); 970 var alarmsGetSavedArgs = new SaveMockArguments();
971 this.mockApis.expects(once()). 971 this.mockApis.expects(once()).
972 instrumented_alarms_get( 972 instrumented_alarms_get(
973 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)), 973 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)),
974 alarmsGetSavedArgs.match(ANYTHING)). 974 alarmsGetSavedArgs.match(ANYTHING)).
975 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'})); 975 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'}));
976 this.mockLocalFunctions.expects(once()).attempt(); 976 this.mockLocalFunctions.expects(once()).attempt();
977 // Invocation. 977 // Invocation.
978 onAlarmHandlerContainer[0]({name: testAttemptAlarmName}); 978 onAlarmHandlerContainer[0]({name: testAttemptAlarmName});
979 }); 979 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698