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.
6 from telemetry
.page
import page
as page_module
7 from telemetry
.page
import page_set
as page_set_module
9 INTERACTION_NAME
= 'Interaction.PageLoading'
11 # How long to wait for the page to finish rendering.
15 class NewTabPagePage(page_module
.Page
):
17 def __init__(self
, page_set
):
18 super(NewTabPagePage
, self
).__init
__(
19 name
='newtabpagepage',
20 url
='chrome://newtab',
22 self
.archive_data_file
= 'data/new_tab_page_page.json'
23 self
.user_agent_type
= 'desktop'
24 self
.script_to_evaluate_on_commit
= (
25 "console.time('" + INTERACTION_NAME
+ "');")
27 def RunNavigateSteps(self
, action_runner
):
28 url
= self
.file_path_url_with_scheme
if self
.is_file
else self
.url
29 action_runner
.Navigate(
30 url
, script_to_evaluate_on_commit
=self
.script_to_evaluate_on_commit
)
31 # We pause for a while so the async JS gets a chance to run.
32 time
.sleep(LOADING_DELAY_S
)
33 # TODO(beaudoin): We have no guarantee the page has fully rendered and the
34 # JS has fully executed at that point. The right way to do it would be to
35 # toggle a Javascript variable in the page code and to wait for it here.
36 # This should be done when window.performance.mark is supported and we
37 # migrate to it instead of calling console.timeEnd here. If the test is
38 # failing flakily, we should use a better heuristic.
39 action_runner
.ExecuteJavaScript(
40 "console.timeEnd('" + INTERACTION_NAME
+ "');")
43 class NewTabPagePageSet(page_set_module
.PageSet
):
45 super(NewTabPagePageSet
, self
).__init
__(
46 user_agent_type
='desktop',
47 archive_data_file
='data/new_tab_page_page.json',
48 bucket
=page_set_module
.PUBLIC_BUCKET
)
49 self
.AddUserStory(NewTabPagePage(page_set
=self
))