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

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

Issue 25114002: Finishing API error processing, and cleanup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 2 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
« no previous file with comments | « chrome/browser/resources/google_now/utility.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 464
465 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager2Sequential', function() { 465 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager2Sequential', function() {
466 // Tests that 2 tasks get successfully executed consecutively, even if the 466 // Tests that 2 tasks get successfully executed consecutively, even if the
467 // second one conflicts with the first. 467 // second one conflicts with the first.
468 468
469 // Setup. 469 // Setup.
470 var test = setUpTaskManagerTest(this); 470 var test = setUpTaskManagerTest(this);
471 471
472 // Step 1. Add 1st task that doesn't create pending callbacks. 472 // Step 1. Add 1st task that doesn't create pending callbacks.
473 // Expectations. 473 // Expectations.
474 this.mockLocalFunctions.expects(once()).task1(ANYTHING); 474 this.mockLocalFunctions.expects(once()).task1();
475 // Invocation. 475 // Invocation.
476 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 476 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
477 Mock4JS.verifyAllMocks(); 477 Mock4JS.verifyAllMocks();
478 478
479 // Step 2. Add 2nd task. 479 // Step 2. Add 2nd task.
480 // Expectations. 480 // Expectations.
481 this.mockLocalFunctions.expects(once()).task2(ANYTHING); 481 this.mockLocalFunctions.expects(once()).task2();
482 // Invocation. 482 // Invocation.
483 test.tasks.add(taskNameB, this.mockLocalFunctions.functions().task2); 483 test.tasks.add(taskNameB, this.mockLocalFunctions.functions().task2);
484 }); 484 });
485 485
486 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerConflicting', function() { 486 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerConflicting', function() {
487 // Tests that adding a task while a conflicting task is being executed causes 487 // Tests that adding a task while a conflicting task is being executed causes
488 // the second one to be ignored. 488 // the second one to be ignored.
489 489
490 // Setup. 490 // Setup.
491 var test = setUpTaskManagerTest(this); 491 var test = setUpTaskManagerTest(this);
492 var task1PluginInstance; 492 var task1PluginInstance;
493 493
494 // Step 1. Add 1st task that creates a pending callback. 494 // Step 1. Add 1st task that creates a pending callback.
495 // Expectations. 495 // Expectations.
496 this.mockLocalFunctions.expects(once()).task1(ANYTHING). 496 this.mockLocalFunctions.expects(once()).task1().
497 will(callFunction(function() { 497 will(callFunction(function() {
498 task1PluginInstance = test.pluginFactory(); 498 task1PluginInstance = test.pluginFactory();
499 })); 499 }));
500 // Invocation. 500 // Invocation.
501 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 501 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
502 Mock4JS.verifyAllMocks(); 502 Mock4JS.verifyAllMocks();
503 503
504 // Step 2. Add 2nd task. Since it conflicts with currently running task1 504 // Step 2. Add 2nd task. Since it conflicts with currently running task1
505 // (see areTasksConflicting), it should be ignored. 505 // (see areTasksConflicting), it should be ignored.
506 test.tasks.add(taskNameB, this.mockLocalFunctions.functions().task2); 506 test.tasks.add(taskNameB, this.mockLocalFunctions.functions().task2);
(...skipping 10 matching lines...) Expand all
517 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerNestedTaskEnqueue', function() { 517 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerNestedTaskEnqueue', function() {
518 // Tests that adding a task while a non-conflicting task is being executed 518 // Tests that adding a task while a non-conflicting task is being executed
519 // causes the second one to be executed after the first one completes. 519 // causes the second one to be executed after the first one completes.
520 520
521 // Setup. 521 // Setup.
522 var test = setUpTaskManagerTest(this); 522 var test = setUpTaskManagerTest(this);
523 var task1PluginInstance; 523 var task1PluginInstance;
524 524
525 // Step 1. Add 1st task that creates a pending callback. 525 // Step 1. Add 1st task that creates a pending callback.
526 // Expectations. 526 // Expectations.
527 this.mockLocalFunctions.expects(once()).task1(ANYTHING). 527 this.mockLocalFunctions.expects(once()).task1().
528 will(callFunction(function() { 528 will(callFunction(function() {
529 task1PluginInstance = test.pluginFactory(); 529 task1PluginInstance = test.pluginFactory();
530 })); 530 }));
531 // Invocation. 531 // Invocation.
532 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 532 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
533 Mock4JS.verifyAllMocks(); 533 Mock4JS.verifyAllMocks();
534 534
535 // Step 2. Add 2nd task. Since it doesn't conflict with currently running 535 // Step 2. Add 2nd task. Since it doesn't conflict with currently running
536 // task1 (see areTasksConflicting), it should not be ignored. 536 // task1 (see areTasksConflicting), it should not be ignored.
537 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2); 537 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2);
538 Mock4JS.verifyAllMocks(); 538 Mock4JS.verifyAllMocks();
539 539
540 // Step 3. Enter the callback of task1. 540 // Step 3. Enter the callback of task1.
541 task1PluginInstance.prologue(); 541 task1PluginInstance.prologue();
542 Mock4JS.verifyAllMocks(); 542 Mock4JS.verifyAllMocks();
543 543
544 // Step 4. Leave the callback of task1. 544 // Step 4. Leave the callback of task1.
545 // Expectations. 545 // Expectations.
546 this.mockLocalFunctions.expects(once()).task2(ANYTHING); 546 this.mockLocalFunctions.expects(once()).task2();
547 // Invocation. 547 // Invocation.
548 task1PluginInstance.epilogue(); 548 task1PluginInstance.epilogue();
549 }); 549 });
550 550
551 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerBranching', function() { 551 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerBranching', function() {
552 // Tests that task manager correctly detects completion of tasks that create 552 // Tests that task manager correctly detects completion of tasks that create
553 // branching chains of callbacks (in this test, task1 creates pending 553 // branching chains of callbacks (in this test, task1 creates pending
554 // callbacks 1 and 2, and callback 1 creates pending callback 3). 554 // callbacks 1 and 2, and callback 1 creates pending callback 3).
555 555
556 // Setup. 556 // Setup.
557 var test = setUpTaskManagerTest(this); 557 var test = setUpTaskManagerTest(this);
558 var task1PluginInstance1, task1PluginInstance2, task1PluginInstance3; 558 var task1PluginInstance1, task1PluginInstance2, task1PluginInstance3;
559 559
560 // Step 1. Add 1st task that creates a 2 pending callbacks. 560 // Step 1. Add 1st task that creates a 2 pending callbacks.
561 // Expectations. 561 // Expectations.
562 this.mockLocalFunctions.expects(once()).task1(ANYTHING). 562 this.mockLocalFunctions.expects(once()).task1().
563 will(callFunction(function() { 563 will(callFunction(function() {
564 task1PluginInstance1 = test.pluginFactory(); 564 task1PluginInstance1 = test.pluginFactory();
565 task1PluginInstance2 = test.pluginFactory(); 565 task1PluginInstance2 = test.pluginFactory();
566 })); 566 }));
567 // Invocation. 567 // Invocation.
568 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 568 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
569 Mock4JS.verifyAllMocks(); 569 Mock4JS.verifyAllMocks();
570 570
571 // Step 2. Add 2nd task, which is not conflicting (see areTasksConflicting) 571 // Step 2. Add 2nd task, which is not conflicting (see areTasksConflicting)
572 // with task1. 572 // with task1.
573 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2); 573 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2);
574 Mock4JS.verifyAllMocks(); 574 Mock4JS.verifyAllMocks();
575 575
576 // Step 3. Enter callback 1, create pending callback 3, exit callback 1. 576 // Step 3. Enter callback 1, create pending callback 3, exit callback 1.
577 // Enter/exit callback 2. Enter callback 3. 577 // Enter/exit callback 2. Enter callback 3.
578 task1PluginInstance1.prologue(); 578 task1PluginInstance1.prologue();
579 task1PluginInstance3 = test.pluginFactory(); 579 task1PluginInstance3 = test.pluginFactory();
580 task1PluginInstance1.epilogue(); 580 task1PluginInstance1.epilogue();
581 task1PluginInstance2.prologue(); 581 task1PluginInstance2.prologue();
582 task1PluginInstance2.epilogue(); 582 task1PluginInstance2.epilogue();
583 task1PluginInstance3.prologue(); 583 task1PluginInstance3.prologue();
584 Mock4JS.verifyAllMocks(); 584 Mock4JS.verifyAllMocks();
585 585
586 // Step 4. Leave 3rd callback of task1. Now task1 is complete, and task2 586 // Step 4. Leave 3rd callback of task1. Now task1 is complete, and task2
587 // should start. 587 // should start.
588 // Expectations. 588 // Expectations.
589 this.mockLocalFunctions.expects(once()).task2(ANYTHING); 589 this.mockLocalFunctions.expects(once()).task2();
590 // Invocation. 590 // Invocation.
591 task1PluginInstance3.epilogue(); 591 task1PluginInstance3.epilogue();
592 }); 592 });
593 593
594 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerSuspendError', function() { 594 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerSuspendError', function() {
595 // Tests that task manager's onSuspend method reports an error if there are 595 // Tests that task manager's onSuspend method reports an error if there are
596 // pending tasks. 596 // pending tasks.
597 597
598 // Setup. 598 // Setup.
599 var test = setUpTaskManagerTest(this); 599 var test = setUpTaskManagerTest(this);
600 var onSuspendHandlerContainer = getMockHandlerContainer('runtime.onSuspend'); 600 var onSuspendHandlerContainer = getMockHandlerContainer('runtime.onSuspend');
601 601
602 // Step 1. Add a task that creates a pending callback. 602 // Step 1. Add a task that creates a pending callback.
603 // Expectations. 603 // Expectations.
604 this.mockLocalFunctions.expects(once()).task1(ANYTHING). 604 this.mockLocalFunctions.expects(once()).task1().
605 will(callFunction(function() { 605 will(callFunction(function() {
606 test.pluginFactory(); 606 test.pluginFactory();
607 })); 607 }));
608 // Invocation. 608 // Invocation.
609 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 609 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
610 Mock4JS.verifyAllMocks(); 610 Mock4JS.verifyAllMocks();
611 611
612 // Step 2. Invoke onSuspend event of the task manager. 612 // Step 2. Invoke onSuspend event of the task manager.
613 // Setup and expectations. The 2 callbacks in onSuspendHandlerContainer are 613 // Setup and expectations. The 2 callbacks in onSuspendHandlerContainer are
614 // from the wrapper and the task manager. 614 // from the wrapper and the task manager.
615 assertEquals(2, onSuspendHandlerContainer.length); 615 assertEquals(2, onSuspendHandlerContainer.length);
616 this.mockGlobals.expects(once()).reportError(eqToString( 616 this.mockGlobals.expects(once()).reportError(eqToString(
617 'Error: ASSERT: Incomplete task when unloading event page,' + 617 'Error: ASSERT: Incomplete task when unloading event page,' +
618 ' queue = [{"name":"TASK A"}], testWrapperDebugState')); 618 ' queue = [{"name":"TASK A"}], testWrapperDebugState'));
619 // Invocation. 619 // Invocation.
620 onSuspendHandlerContainer[1](); 620 onSuspendHandlerContainer[1]();
621 }); 621 });
622 622
623 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerSuspendSuccess', function() { 623 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerSuspendSuccess', function() {
624 // Tests that task manager's onSuspend method does not report an error if all 624 // Tests that task manager's onSuspend method does not report an error if all
625 // tasks completed. 625 // tasks completed.
626 626
627 // Setup. 627 // Setup.
628 var test = setUpTaskManagerTest(this); 628 var test = setUpTaskManagerTest(this);
629 var onSuspendHandlerContainer = getMockHandlerContainer('runtime.onSuspend'); 629 var onSuspendHandlerContainer = getMockHandlerContainer('runtime.onSuspend');
630 var task1PluginInstance; 630 var task1PluginInstance;
631 631
632 // Step 1. Add a task that creates a pending callback. 632 // Step 1. Add a task that creates a pending callback.
633 // Expectations. 633 // Expectations.
634 this.mockLocalFunctions.expects(once()).task1(ANYTHING). 634 this.mockLocalFunctions.expects(once()).task1().
635 will(callFunction(function() { 635 will(callFunction(function() {
636 task1PluginInstance = test.pluginFactory(); 636 task1PluginInstance = test.pluginFactory();
637 })); 637 }));
638 // Invocation. 638 // Invocation.
639 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 639 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
640 Mock4JS.verifyAllMocks(); 640 Mock4JS.verifyAllMocks();
641 641
642 // Step 2. Invoke task's callback and the onSuspend event of the task manager. 642 // Step 2. Invoke task's callback and the onSuspend event of the task manager.
643 // The 2 callbacks in onSuspendHandlerContainer are from the wrapper and the 643 // The 2 callbacks in onSuspendHandlerContainer are from the wrapper and the
644 // task manager. 644 // task manager.
645 task1PluginInstance.prologue(); 645 task1PluginInstance.prologue();
646 task1PluginInstance.epilogue(); 646 task1PluginInstance.epilogue();
647 onSuspendHandlerContainer[1](); 647 onSuspendHandlerContainer[1]();
648 }); 648 });
649 649
650 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager3Tasks', function() { 650 TEST_F('GoogleNowUtilityUnitTest', 'TaskManager3Tasks', function() {
651 // Tests that 3 tasks can be executed too. In particular, that if the second 651 // Tests that 3 tasks can be executed too. In particular, that if the second
652 // task is a single-step task which execution was originally blocked by task1, 652 // task is a single-step task which execution was originally blocked by task1,
653 // unblocking it causes immediate synchronous execution of both tasks 2 and 3. 653 // unblocking it causes immediate synchronous execution of both tasks 2 and 3.
654 654
655 // Setup. 655 // Setup.
656 var test = setUpTaskManagerTest(this); 656 var test = setUpTaskManagerTest(this);
657 var task1PluginInstance; 657 var task1PluginInstance;
658 658
659 // Step 1. Add 1st task that creates a pending callback. 659 // Step 1. Add 1st task that creates a pending callback.
660 // Expectations. 660 // Expectations.
661 this.mockLocalFunctions.expects(once()).task1(ANYTHING). 661 this.mockLocalFunctions.expects(once()).task1().
662 will(callFunction(function() { 662 will(callFunction(function() {
663 task1PluginInstance = test.pluginFactory(); 663 task1PluginInstance = test.pluginFactory();
664 })); 664 }));
665 // Invocation. 665 // Invocation.
666 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 666 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
667 Mock4JS.verifyAllMocks(); 667 Mock4JS.verifyAllMocks();
668 668
669 // Step 2. Add 2nd and 3rd tasks, both non-conflicting (see 669 // Step 2. Add 2nd and 3rd tasks, both non-conflicting (see
670 // areTasksConflicting) with task1. 670 // areTasksConflicting) with task1.
671 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2); 671 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2);
672 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task3); 672 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task3);
673 Mock4JS.verifyAllMocks(); 673 Mock4JS.verifyAllMocks();
674 674
675 // Step 3. Enter the callback of task1. 675 // Step 3. Enter the callback of task1.
676 task1PluginInstance.prologue(); 676 task1PluginInstance.prologue();
677 Mock4JS.verifyAllMocks(); 677 Mock4JS.verifyAllMocks();
678 678
679 // Step 4. Leave the callback of task1. 679 // Step 4. Leave the callback of task1.
680 // Expectations. 680 // Expectations.
681 this.mockLocalFunctions.expects(once()).task2(ANYTHING); 681 this.mockLocalFunctions.expects(once()).task2();
682 this.mockLocalFunctions.expects(once()).task3(ANYTHING); 682 this.mockLocalFunctions.expects(once()).task3();
683 // Invocation. 683 // Invocation.
684 task1PluginInstance.epilogue(); 684 task1PluginInstance.epilogue();
685 }); 685 });
686 686
687 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerNestedNonTask', function() { 687 TEST_F('GoogleNowUtilityUnitTest', 'TaskManagerNestedNonTask', function() {
688 // Tests callbacks requested while a task is running, but not from a callback 688 // Tests callbacks requested while a task is running, but not from a callback
689 // belonging to a task, are not counted as a part of the task. 689 // belonging to a task, are not counted as a part of the task.
690 690
691 // Setup. 691 // Setup.
692 var test = setUpTaskManagerTest(this); 692 var test = setUpTaskManagerTest(this);
693 var task1PluginInstance; 693 var task1PluginInstance;
694 694
695 // Step 1. Add 1st task that creates a pending callback. 695 // Step 1. Add 1st task that creates a pending callback.
696 // Expectations. 696 // Expectations.
697 this.mockLocalFunctions.expects(once()).task1(ANYTHING). 697 this.mockLocalFunctions.expects(once()).task1().
698 will(callFunction(function() { 698 will(callFunction(function() {
699 task1PluginInstance = test.pluginFactory(); 699 task1PluginInstance = test.pluginFactory();
700 })); 700 }));
701 // Invocation. 701 // Invocation.
702 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1); 702 test.tasks.add(taskNameA, this.mockLocalFunctions.functions().task1);
703 Mock4JS.verifyAllMocks(); 703 Mock4JS.verifyAllMocks();
704 704
705 // Step 2. Create a pending callback from code that is not a part of the task. 705 // Step 2. Create a pending callback from code that is not a part of the task.
706 test.pluginFactory(); 706 test.pluginFactory();
707 Mock4JS.verifyAllMocks(); 707 Mock4JS.verifyAllMocks();
708 708
709 // Step 3. Enter the callback of task1. After this, task1 should be 709 // Step 3. Enter the callback of task1. After this, task1 should be
710 // finished despite the pending non-task callback. 710 // finished despite the pending non-task callback.
711 task1PluginInstance.prologue(); 711 task1PluginInstance.prologue();
712 task1PluginInstance.epilogue(); 712 task1PluginInstance.epilogue();
713 Mock4JS.verifyAllMocks(); 713 Mock4JS.verifyAllMocks();
714 714
715 // Step 4. Check that task1 is finished by submitting task2, which should 715 // Step 4. Check that task1 is finished by submitting task2, which should
716 // be executed immediately. 716 // be executed immediately.
717 this.mockLocalFunctions.expects(once()).task2(ANYTHING); 717 this.mockLocalFunctions.expects(once()).task2();
718 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2); 718 test.tasks.add(taskNameC, this.mockLocalFunctions.functions().task2);
719 }); 719 });
720 720
721 var testAttemptAlarmName = 'attempt-scheduler-testAttempts'; 721 var testAttemptAlarmName = 'attempt-scheduler-testAttempts';
722 var testAttemptStorageKey = 'current-delay-testAttempts'; 722 var testAttemptStorageKey = 'current-delay-testAttempts';
723 var testInitialDelaySeconds = 239; 723 var testInitialDelaySeconds = 239;
724 var testMaximumDelaySeconds = 2239; 724 var testMaximumDelaySeconds = 2239;
725 // Value to be returned by mocked Math.random(). We want the value returned by 725 // Value to be returned by mocked Math.random(). We want the value returned by
726 // Math.random() to be predictable to be able to check results against expected 726 // Math.random() to be predictable to be able to check results against expected
727 // values. A fixed seed would be okay, but fixed seeding isn't possible in JS at 727 // values. A fixed seed would be okay, but fixed seeding isn't possible in JS at
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 var alarmsGetSavedArgs = new SaveMockArguments(); 930 var alarmsGetSavedArgs = new SaveMockArguments();
931 this.mockApis.expects(once()). 931 this.mockApis.expects(once()).
932 instrumented_alarms_get( 932 instrumented_alarms_get(
933 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)), 933 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)),
934 alarmsGetSavedArgs.match(ANYTHING)). 934 alarmsGetSavedArgs.match(ANYTHING)).
935 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'})); 935 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'}));
936 this.mockLocalFunctions.expects(once()).attempt(); 936 this.mockLocalFunctions.expects(once()).attempt();
937 // Invocation. 937 // Invocation.
938 onAlarmHandlerContainer[0]({name: testAttemptAlarmName}); 938 onAlarmHandlerContainer[0]({name: testAttemptAlarmName});
939 }); 939 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/google_now/utility.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698