OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import copy | 6 import copy |
7 import os | 7 import os |
8 | 8 |
9 import pyauto_functional # Must be imported before pyauto | 9 import pyauto_functional # Must be imported before pyauto |
10 import pyauto | 10 import pyauto |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 # Verify that a second window exists (at index 1), and that its first tab | 522 # Verify that a second window exists (at index 1), and that its first tab |
523 # is the app launch URL. | 523 # is the app launch URL. |
524 info = self.GetBrowserInfo() | 524 info = self.GetBrowserInfo() |
525 self.assertTrue(len(info['windows']) == 2, | 525 self.assertTrue(len(info['windows']) == 2, |
526 msg='A second window does not exist.') | 526 msg='A second window does not exist.') |
527 actual_tab_url = info['windows'][1]['tabs'][0]['url'] | 527 actual_tab_url = info['windows'][1]['tabs'][0]['url'] |
528 expected_app_url_start = 'chrome-extension://' + installed_app_id | 528 expected_app_url_start = 'chrome-extension://' + installed_app_id |
529 self.assertTrue(actual_tab_url.startswith(expected_app_url_start), | 529 self.assertTrue(actual_tab_url.startswith(expected_app_url_start), |
530 msg='The app was not launched in the new window.') | 530 msg='The app was not launched in the new window.') |
531 | 531 |
532 def _VerifyThumbnailOrMenuMode(self, actual_info, expected_info): | |
533 """Verifies that the expected thumbnail/menu info matches the actual info. | |
534 | |
535 This function verifies that the expected info is contained within the | |
536 actual info. It's ok for the expected info to be a subset of the actual | |
537 info. Only the specified expected info will be verified. | |
538 | |
539 Args: | |
540 actual_info: A dictionary representing the actual thumbnail or menu mode | |
541 information for all relevant sections of the NTP. | |
542 expected_info: A dictionary representing the expected thumbnail or menu | |
543 mode information for the relevant sections of the NTP. | |
544 """ | |
545 for sec_name in expected_info: | |
546 # Ensure the expected section name is present in the actual info. | |
547 self.assertTrue(sec_name in actual_info, | |
548 msg='The actual info is missing information for section ' | |
549 '"%s".' % (sec_name)) | |
550 # Ensure the expected section value matches what's in the actual info. | |
551 self.assertTrue(expected_info[sec_name] == actual_info[sec_name], | |
552 msg='For section "%s", expected value %s, but instead ' | |
553 'was %s.' % (sec_name, expected_info[sec_name], | |
554 actual_info[sec_name])) | |
555 | |
556 def testGetThumbnailModeInNewProfile(self): | |
557 """Ensures only the most visited thumbnails are present in a new profile.""" | |
558 thumb_info = self.GetNTPThumbnailMode() | |
559 self._VerifyThumbnailOrMenuMode(thumb_info, | |
560 self._EXPECTED_DEFAULT_THUMB_INFO) | |
561 | |
562 def testSetThumbnailModeOn(self): | |
563 """Ensures that we can turn on thumbnail mode properly.""" | |
564 # Turn on thumbnail mode for the Apps section and verify that only this | |
565 # section is in thumbnail mode (since at most one section can be in | |
566 # thumbnail mode at any given time). | |
567 self.SetNTPThumbnailMode('apps', True) | |
568 thumb_info = self.GetNTPThumbnailMode() | |
569 expected_thumb_info = { | |
570 u'apps': True, | |
571 u'most_visited': False | |
572 } | |
573 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
574 | |
575 # Now turn on thumbnail mode for the Most Visited section, and verify that | |
576 # it gets turned on while the Apps section has thumbnail mode turned off. | |
577 self.SetNTPThumbnailMode('most_visited', True) | |
578 thumb_info = self.GetNTPThumbnailMode() | |
579 expected_thumb_info = { | |
580 u'apps': False, | |
581 u'most_visited': True | |
582 } | |
583 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
584 | |
585 # Now turn on thumbnail mode for both sections and verify that only the last | |
586 # one has thumbnail mode turned on. | |
587 self.SetNTPThumbnailMode('most_visited', True) | |
588 self.SetNTPThumbnailMode('apps', True) | |
589 thumb_info = self.GetNTPThumbnailMode() | |
590 expected_thumb_info = { | |
591 u'apps': True, | |
592 u'most_visited': False | |
593 } | |
594 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
595 | |
596 def testSetThumbnailModeOff(self): | |
597 """Ensures that we can turn off thumbnail mode properly.""" | |
598 # First, ensure that only the Most Visited section is in thumbnail mode. | |
599 self.SetNTPThumbnailMode('most_visited', True) | |
600 thumb_info = self.GetNTPThumbnailMode() | |
601 expected_thumb_info = { | |
602 u'apps': False, | |
603 u'most_visited': True | |
604 } | |
605 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
606 | |
607 # Turn off thumbnail mode for the Most Visited section and verify. | |
608 self.SetNTPThumbnailMode('most_visited', False) | |
609 thumb_info = self.GetNTPThumbnailMode() | |
610 expected_thumb_info = { | |
611 u'apps': False, | |
612 u'most_visited': False | |
613 } | |
614 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
615 | |
616 # Turn off thumbnail mode for the Most Visited section and verify that it | |
617 # remains off. | |
618 self.SetNTPThumbnailMode('most_visited', False) | |
619 thumb_info = self.GetNTPThumbnailMode() | |
620 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
621 | |
622 def testGetMenuModeInNewProfile(self): | |
623 """Ensures that all NTP sections are not in menu mode in a fresh profile.""" | |
624 menu_info = self.GetNTPMenuMode() | |
625 self._VerifyThumbnailOrMenuMode(menu_info, self._EXPECTED_DEFAULT_MENU_INFO) | |
626 | |
627 def testSetMenuModeOn(self): | |
628 """Ensures that we can turn on menu mode properly.""" | |
629 # Turn on menu mode for the Apps section and verify that it's turned on. | |
630 self.SetNTPMenuMode('apps', True) | |
631 menu_info = self.GetNTPMenuMode() | |
632 expected_menu_info = copy.copy(self._EXPECTED_DEFAULT_MENU_INFO) | |
633 expected_menu_info[u'apps'] = True | |
634 self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) | |
635 | |
636 # Turn on menu mode for the remaining sections and verify that they're all | |
637 # on. | |
638 self.SetNTPMenuMode('most_visited', True) | |
639 self.SetNTPMenuMode('recently_closed', True) | |
640 menu_info = self.GetNTPMenuMode() | |
641 expected_menu_info[u'most_visited'] = True | |
642 expected_menu_info[u'recently_closed'] = True | |
643 self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) | |
644 | |
645 def testSetMenuModeOff(self): | |
646 # Turn on menu mode for all sections, then turn it off for only the Apps | |
647 # section, then verify. | |
648 self.SetNTPMenuMode('apps', True) | |
649 self.SetNTPMenuMode('most_visited', True) | |
650 self.SetNTPMenuMode('recently_closed', True) | |
651 self.SetNTPMenuMode('apps', False) | |
652 menu_info = self.GetNTPMenuMode() | |
653 expected_menu_info = { | |
654 u'apps': False, | |
655 u'most_visited': True, | |
656 u'recently_closed': True | |
657 } | |
658 self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) | |
659 | |
660 # Turn off menu mode for the remaining sections and verify. | |
661 self.SetNTPMenuMode('most_visited', False) | |
662 self.SetNTPMenuMode('recently_closed', False) | |
663 menu_info = self.GetNTPMenuMode() | |
664 expected_menu_info[u'most_visited'] = False | |
665 expected_menu_info[u'recently_closed'] = False | |
666 self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) | |
667 | |
668 # Turn off menu mode for the Apps section again, and verify that it | |
669 # remains off. | |
670 self.SetNTPMenuMode('apps', False) | |
671 menu_info = self.GetNTPMenuMode() | |
672 self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) | |
673 | |
674 def testSetThumbnailModeDoesNotAffectMenuModeAndViceVersa(self): | |
675 """Verifies that setting thumbnail/menu mode does not affect the other.""" | |
676 # Set thumbnail mode for the Apps section, set and unset menu mode for a | |
677 # few sections, and verify that all sections are in thumbnail/menu mode as | |
678 # expected. | |
679 self.SetNTPThumbnailMode('apps', True) | |
680 self.SetNTPMenuMode('apps', True) | |
681 self.SetNTPMenuMode('recently_closed', True) | |
682 self.SetNTPMenuMode('apps', False) | |
683 self.SetNTPMenuMode('most_visited', True) | |
684 self.SetNTPMenuMode('recently_closed', False) | |
685 self.SetNTPMenuMode('apps', True) | |
686 thumb_info = self.GetNTPThumbnailMode() | |
687 expected_thumb_info = { | |
688 u'apps': True, | |
689 u'most_visited': False | |
690 } | |
691 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
692 menu_info = self.GetNTPMenuMode() | |
693 expected_menu_info = { | |
694 u'apps': True, | |
695 u'most_visited': True, | |
696 u'recently_closed': False | |
697 } | |
698 self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) | |
699 | |
700 # Turn off menu mode for all sections. | |
701 self.SetNTPMenuMode('apps', False) | |
702 self.SetNTPMenuMode('most_visited', False) | |
703 self.SetNTPMenuMode('recently_closed', False) | |
704 | |
705 # Set menu mode for the Most Visited and Recently Closed sections, set and | |
706 # unset thumbnail mode for a few sections, and verify all is as expected. | |
707 self.SetNTPMenuMode('most_visited', True) | |
708 self.SetNTPMenuMode('recently_closed', True) | |
709 self.SetNTPThumbnailMode('apps', True) | |
710 self.SetNTPThumbnailMode('most_visited', True) | |
711 self.SetNTPThumbnailMode('apps', False) | |
712 self.SetNTPThumbnailMode('most_visited', False) | |
713 self.SetNTPThumbnailMode('apps', True) | |
714 self.SetNTPThumbnailMode('most_visited', True) | |
715 menu_info = self.GetNTPMenuMode() | |
716 expected_menu_info = { | |
717 u'apps': False, | |
718 u'most_visited': True, | |
719 u'recently_closed': True | |
720 } | |
721 self._VerifyThumbnailOrMenuMode(menu_info, expected_menu_info) | |
722 thumb_info = self.GetNTPThumbnailMode() | |
723 expected_thumb_info = { | |
724 u'apps': False, | |
725 u'most_visited': True | |
726 } | |
727 self._VerifyThumbnailOrMenuMode(thumb_info, expected_thumb_info) | |
728 | |
729 | |
730 if __name__ == '__main__': | 532 if __name__ == '__main__': |
731 pyauto_functional.Main() | 533 pyauto_functional.Main() |
OLD | NEW |