OLD | NEW |
---|---|
1 # encoding: utf-8 | 1 # encoding: utf-8 |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 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 from page_sets.system_health import platforms | 6 from page_sets.system_health import platforms |
7 from page_sets.system_health import story_tags | 7 from page_sets.system_health import story_tags |
8 from page_sets.system_health import system_health_story | 8 from page_sets.system_health import system_health_story |
9 | 9 |
10 from page_sets.login_helpers import facebook_login | |
10 from page_sets.login_helpers import pinterest_login | 11 from page_sets.login_helpers import pinterest_login |
11 | 12 |
12 from telemetry import decorators | 13 from telemetry import decorators |
13 from telemetry.util import js_template | 14 from telemetry.util import js_template |
14 | 15 |
15 | 16 |
16 class _BrowsingStory(system_health_story.SystemHealthStory): | 17 class _BrowsingStory(system_health_story.SystemHealthStory): |
17 """Abstract base class for browsing stories. | 18 """Abstract base class for browsing stories. |
18 | 19 |
19 A browsing story visits items on the main page. Subclasses provide | 20 A browsing story visits items on the main page. Subclasses provide |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 # Reduce the speed (the current wpr is recorded with speed set to 50) when | 777 # Reduce the speed (the current wpr is recorded with speed set to 50) when |
777 # recording the wpr. If we scroll too fast, the data will not be recorded | 778 # recording the wpr. If we scroll too fast, the data will not be recorded |
778 # well. After recording reset it back to the original value to have a more | 779 # well. After recording reset it back to the original value to have a more |
779 # realistic scroll. | 780 # realistic scroll. |
780 action_runner.RepeatableBrowserDrivenScroll( | 781 action_runner.RepeatableBrowserDrivenScroll( |
781 x_scroll_distance_ratio = 0.0, y_scroll_distance_ratio = 1, | 782 x_scroll_distance_ratio = 0.0, y_scroll_distance_ratio = 1, |
782 repeat_count=3, speed=400, timeout=120) | 783 repeat_count=3, speed=400, timeout=120) |
783 action_runner.RepeatableBrowserDrivenScroll( | 784 action_runner.RepeatableBrowserDrivenScroll( |
784 x_scroll_distance_ratio = 1, y_scroll_distance_ratio = 0, | 785 x_scroll_distance_ratio = 1, y_scroll_distance_ratio = 0, |
785 repeat_count=3, speed=500, timeout=120) | 786 repeat_count=3, speed=500, timeout=120) |
787 | |
788 | |
789 ############################################################################## | |
790 # Browsing stories with infinite scrolling | |
791 ############################################################################## | |
792 | |
793 | |
794 class _InfiniteScrollStory(system_health_story.SystemHealthStory): | |
795 SUPPORTED_PLATFORMS = platforms.ALL_PLATFORMS | |
796 | |
797 SCROLL_DISTANCE = 25000 | |
798 SCROLL_STEP = 1000 | |
799 MAX_SCROLL_RETRIES = 3 | |
800 TIME_BEFORE_SCROLL_RETRY_IN_SECONDS = 1 | |
801 TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS = 5 | |
802 | |
803 def __init__(self, story_set, take_memory_measurement): | |
804 super(_InfiniteScrollStory, self).__init__(story_set, | |
805 take_memory_measurement) | |
806 self.script_to_evaluate_on_commit = ''' | |
807 window.WebSocket = undefined; | |
808 window.Worker = undefined; | |
809 window.performance = undefined;''' | |
810 | |
811 def _DidLoadDocument(self, action_runner): | |
812 action_runner.WaitForJavaScriptCondition( | |
813 'document.body != null && ' | |
814 'document.body.scrollHeight > window.innerHeight && ' | |
815 '!document.body.addEventListener("touchstart", function() {})') | |
816 action_runner.Wait(self.TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS) | |
817 self._Scroll(action_runner, self.SCROLL_DISTANCE, self.SCROLL_STEP) | |
818 | |
819 | |
820 def _Scroll(self, action_runner, distance, step_size): | |
821 """ This function scrolls the webpage by the given scroll distance in | |
822 multiple steps, where each step (except the last one) has the given size. | |
823 | |
824 If scrolling gets stuck, the functions retries scrolling MAX_SCROLL_RETRIES | |
825 times waiting TIME_BEFORE_SCROLL_RETRY_IN_SECONDS seconds between retries. | |
826 """ | |
827 remaining = distance - action_runner.EvaluateJavaScript('window.scrollY') | |
828 retry_count = 0 | |
829 # Scroll until the window.scrollY is within 1 pixel of the target distance. | |
830 while remaining > 1: | |
831 action_runner.ScrollPage(distance=min(remaining, step_size) + 1) | |
832 new_remaining = (distance - | |
833 action_runner.EvaluateJavaScript('window.scrollY')) | |
834 if remaining >= new_remaining: | |
835 # Scrolling is stuck. This can happen if the page is loading | |
836 # resources. Give the page some time and retry scrolling. | |
837 if retry_count == self.MAX_SCROLL_RETRIES: | |
838 raise Exception('Scrolling stuck at %d' % remaining) | |
839 retry_count += 1 | |
840 action_runner.Wait(self.TIME_BEFORE_SCROLL_RETRY_IN_SECONDS) | |
841 else: | |
842 retry_count = 0 | |
843 remaining = new_remaining | |
844 | |
845 @classmethod | |
846 def GenerateStoryDescription(cls): | |
847 return 'Load %s then make a very long scroll.' % cls.URL | |
848 | |
849 | |
850 class DiscourseDesktopStory(_InfiniteScrollStory): | |
851 NAME = 'browse:tech:discourse_infinite_scroll' | |
852 URL = ('https://meta.discourse.org/t/the-official-discourse-tags-plugin-discou rse-tagging/26482') | |
perezju
2017/05/25 08:27:42
nit: no need for parenthesis anymore :)
| |
853 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
854 TAGS = [story_tags.INFINITE_SCROLL] | |
855 | |
856 | |
857 class DiscourseMobileStory(_InfiniteScrollStory): | |
858 NAME = 'browse:tech:discourse_infinite_scroll' | |
859 URL = ('https://meta.discourse.org/t/the-official-discourse-tags-plugin-discou rse-tagging/26482') | |
860 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
861 SCROLL_DISTANCE = 15000 | |
862 TAGS = [story_tags.INFINITE_SCROLL] | |
863 | |
864 | |
865 class FacebookScrollDesktopStory(_InfiniteScrollStory): | |
866 NAME = 'browse:social:facebook_infinite_scroll' | |
867 URL = 'https://www.facebook.com/shakira' | |
868 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
869 TAGS = [story_tags.INFINITE_SCROLL] | |
870 | |
871 | |
872 class FacebookScrollMobileStory(_InfiniteScrollStory): | |
873 NAME = 'browse:social:facebook_infinite_scroll' | |
874 URL = 'https://m.facebook.com/shakira' | |
875 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
perezju
2017/05/25 08:27:42
missing TAGS, probably by mistake
| |
876 | |
877 def _Login(self, action_runner): | |
878 facebook_login.LoginWithMobileSite( | |
879 action_runner, 'facebook3', self.credentials_path) | |
880 | |
881 | |
882 class FlickrDesktopStory(_InfiniteScrollStory): | |
883 NAME = 'browse:media:flickr_infinite_scroll' | |
884 URL = 'https://www.flickr.com/explore' | |
885 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
886 TAGS = [story_tags.INFINITE_SCROLL] | |
887 | |
888 | |
889 class FlickrMobileStory(_InfiniteScrollStory): | |
890 NAME = 'browse:media:flickr_infinite_scroll' | |
891 URL = 'https://www.flickr.com/explore' | |
892 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
893 SCROLL_DISTANCE = 10000 | |
894 TAGS = [story_tags.INFINITE_SCROLL] | |
895 | |
896 | |
897 class PinterestMobileStory(_InfiniteScrollStory): | |
898 NAME = 'browse:social:pinterest_infinite_scroll' | |
899 URL = 'https://www.pinterest.com/all' | |
900 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
901 TAGS = [story_tags.INFINITE_SCROLL] | |
902 | |
903 | |
904 class TumblrStory(_InfiniteScrollStory): | |
905 NAME = 'browse:social:tumblr_infinite_scroll' | |
906 URL = 'http://techcrunch.tumblr.com/' # This page doesn't support HTTPS. | |
907 TAGS = [story_tags.INFINITE_SCROLL] | |
908 | |
909 | |
910 class TwitterScrollDesktopStory(_InfiniteScrollStory): | |
911 NAME = 'browse:social:twitter_infinite_scroll' | |
912 URL = 'https://twitter.com/taylorswift13' | |
913 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
914 TAGS = [story_tags.INFINITE_SCROLL] | |
OLD | NEW |