| OLD | NEW |
| (Empty) |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 import time | |
| 5 | |
| 6 from telemetry.page import page as page_module | |
| 7 from telemetry.page import shared_page_state | |
| 8 from telemetry import story | |
| 9 | |
| 10 INTERACTION_NAME = 'Interaction.PageLoading' | |
| 11 | |
| 12 # How long to wait for the page to finish rendering. | |
| 13 LOADING_DELAY_S = 5 | |
| 14 | |
| 15 | |
| 16 class NewTabPagePage(page_module.Page): | |
| 17 | |
| 18 def __init__(self, page_set): | |
| 19 super(NewTabPagePage, self).__init__( | |
| 20 name='newtabpagepage', | |
| 21 url='chrome://newtab', | |
| 22 shared_page_state_class=shared_page_state.SharedDesktopPageState, | |
| 23 page_set=page_set) | |
| 24 self.archive_data_file = 'data/new_tab_page_page.json' | |
| 25 self.script_to_evaluate_on_commit = ( | |
| 26 "console.time('" + INTERACTION_NAME + "');") | |
| 27 | |
| 28 def RunNavigateSteps(self, action_runner): | |
| 29 url = self.file_path_url_with_scheme if self.is_file else self.url | |
| 30 action_runner.Navigate( | |
| 31 url, script_to_evaluate_on_commit=self.script_to_evaluate_on_commit) | |
| 32 # We pause for a while so the async JS gets a chance to run. | |
| 33 time.sleep(LOADING_DELAY_S) | |
| 34 # TODO(beaudoin): We have no guarantee the page has fully rendered and the | |
| 35 # JS has fully executed at that point. The right way to do it would be to | |
| 36 # toggle a Javascript variable in the page code and to wait for it here. | |
| 37 # This should be done when window.performance.mark is supported and we | |
| 38 # migrate to it instead of calling console.timeEnd here. If the test is | |
| 39 # failing flakily, we should use a better heuristic. | |
| 40 action_runner.ExecuteJavaScript( | |
| 41 "console.timeEnd('" + INTERACTION_NAME + "');") | |
| 42 | |
| 43 | |
| 44 class NewTabPagePageSet(story.StorySet): | |
| 45 def __init__(self): | |
| 46 super(NewTabPagePageSet, self).__init__( | |
| 47 archive_data_file='data/new_tab_page_page.json', | |
| 48 cloud_storage_bucket=story.PUBLIC_BUCKET) | |
| 49 self.AddStory(NewTabPagePage(page_set=self)) | |
| OLD | NEW |