Chromium Code Reviews| 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 RunPageInteractions(self, action_runner): | |
| 812 with action_runner.CreateInteraction('Load'): | |
| 813 action_runner.WaitForJavaScriptCondition( | |
| 814 'document.body != null && ' | |
| 815 'document.body.scrollHeight > window.innerHeight && ' | |
| 816 '!document.body.addEventListener("touchstart", function() {})') | |
| 817 with action_runner.CreateInteraction('Wait'): | |
| 818 action_runner.Wait(self.TIME_TO_WAIT_BEFORE_STARTING_IN_SECONDS) | |
| 819 with action_runner.CreateInteraction('GC'): | |
| 820 action_runner.ForceGarbageCollection() | |
| 821 with action_runner.CreateInteraction('Begin'): | |
| 822 action_runner.tab.browser.DumpMemory() | |
| 823 with action_runner.CreateInteraction('Scrolling'): | |
| 824 self._Scroll(action_runner, self.SCROLL_DISTANCE, self.SCROLL_STEP) | |
| 825 with action_runner.CreateInteraction('End'): | |
| 826 action_runner.tab.browser.DumpMemory() | |
| 827 | |
| 828 def _Scroll(self, action_runner, distance, step_size): | |
| 829 """ This function scrolls the webpage by the given scroll distance in | |
| 830 multiple steps, where each step (except the last one) has the given size. | |
| 831 | |
| 832 If scrolling gets stuck, the functions retries scrolling MAX_SCROLL_RETRIES | |
| 833 times waiting TIME_BEFORE_SCROLL_RETRY_IN_SECONDS seconds between retries. | |
| 834 """ | |
| 835 remaining = distance - action_runner.EvaluateJavaScript('window.scrollY') | |
| 836 retry_count = 0 | |
| 837 # Scroll until the window.scrollY is within 1 pixel of the target distance. | |
| 838 while remaining > 1: | |
| 839 action_runner.ScrollPage(distance=min(remaining, step_size) + 1) | |
| 840 new_remaining = (distance - | |
| 841 action_runner.EvaluateJavaScript('window.scrollY')) | |
| 842 if remaining == new_remaining: | |
| 843 # Scrolling is stuck. This can happen if the page is loading | |
| 844 # resources. Give the page some time and retry scrolling. | |
| 845 if retry_count == self.MAX_SCROLL_RETRIES: | |
| 846 raise Exception('Scrolling stuck at %d' % remaining) | |
| 847 retry_count += 1 | |
| 848 action_runner.Wait(self.TIME_BEFORE_SCROLL_RETRY_IN_SECONDS) | |
| 849 else: | |
| 850 retry_count = 0 | |
| 851 remaining = new_remaining | |
| 852 | |
| 853 @classmethod | |
| 854 def GenerateStoryDescription(cls): | |
| 855 return 'Load %s then make a very long scroll.' % cls.URL | |
| 856 | |
| 857 | |
| 858 class DiscourseDesktopStory(_InfiniteScrollStory): | |
| 859 NAME = 'browse:tech:discourse_infinite_scroll' | |
| 860 URL = ('https://meta.discourse.org/t/the-official-discourse-tags-plugin' + | |
|
perezju
2017/05/24 15:39:41
nit: for urls it's fine to let them go over 80 cha
nednguyen
2017/05/24 21:08:49
Done.
| |
| 861 '-discourse-tagging/26482') | |
| 862 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 863 TAGS = [story_tags.INFINITE_SCROLL] | |
| 864 | |
| 865 | |
| 866 class DiscourseMobileStory(_InfiniteScrollStory): | |
| 867 NAME = 'browse:tech:discourse_infinite_scroll' | |
| 868 URL = ('https://meta.discourse.org/t/the-official-discourse-tags-plugin' + | |
|
perezju
2017/05/24 15:39:41
nit: ditto
nednguyen
2017/05/24 21:08:49
Done.
| |
| 869 '-discourse-tagging/26482') | |
| 870 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 871 SCROLL_DISTANCE = 15000 | |
| 872 TAGS = [story_tags.INFINITE_SCROLL] | |
| 873 | |
| 874 | |
| 875 class FacebookScrollDesktopStory(_InfiniteScrollStory): | |
| 876 NAME = 'browse:social:facebook_infinite_scroll' | |
| 877 URL = 'https://www.facebook.com/shakira' | |
| 878 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 879 TAGS = [story_tags.INFINITE_SCROLL] | |
| 880 | |
| 881 | |
| 882 class FacebookScrollMobileStory(_InfiniteScrollStory): | |
| 883 NAME = 'browse:social:facebook_infinite_scroll' | |
| 884 URL = 'https://m.facebook.com/shakira' | |
| 885 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 886 TAGS = [story_tags.INFINITE_SCROLL] | |
| 887 | |
| 888 def RunNavigateSteps(self, action_runner): | |
| 889 facebook_login.LoginWithMobileSite( | |
| 890 action_runner, 'facebook3', self.credentials_path) | |
| 891 super(FacebookScrollMobileStory, self).RunNavigateSteps(action_runner) | |
| 892 | |
| 893 | |
| 894 class FlickrDesktopStory(_InfiniteScrollStory): | |
| 895 NAME = 'browse:media:flickr_infinite_scroll' | |
| 896 URL = 'https://www.flickr.com/explore' | |
| 897 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 898 TAGS = [story_tags.INFINITE_SCROLL] | |
| 899 | |
| 900 | |
| 901 class FlickrMobileStory(_InfiniteScrollStory): | |
| 902 NAME = 'browse:media:flickr_infinite_scroll' | |
| 903 URL = 'https://www.flickr.com/explore' | |
| 904 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 905 SCROLL_DISTANCE = 10000 | |
| 906 TAGS = [story_tags.INFINITE_SCROLL] | |
| 907 | |
| 908 | |
| 909 class PinterestMobileStory(_InfiniteScrollStory): | |
| 910 NAME = 'browse:social:pinterest_infinite_scroll' | |
| 911 URL = 'https://www.pinterest.com/all' | |
| 912 SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY | |
| 913 TAGS = [story_tags.INFINITE_SCROLL] | |
| 914 | |
| 915 | |
| 916 class TumblrStory(_InfiniteScrollStory): | |
| 917 NAME = 'browse:social:tumblr_infinite_scroll' | |
| 918 URL = 'http://techcrunch.tumblr.com/' | |
| 919 TAGS = [story_tags.INFINITE_SCROLL] | |
| 920 | |
| 921 | |
| 922 class TwitterScrollDesktopStory(_InfiniteScrollStory): | |
| 923 NAME = 'browse:social:twitter_infinite_scroll' | |
| 924 URL = 'https://twitter.com/taylorswift13' | |
| 925 SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY | |
| 926 TAGS = [story_tags.INFINITE_SCROLL] | |
| OLD | NEW |