• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2014 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# pylint: disable=W0401,W0614
5from telemetry.page.actions.all_page_actions import *
6from telemetry.page import page as page_module
7from telemetry.page import page_set as page_set_module
8
9class PolymerPage(page_module.Page):
10
11  def __init__(self, url, page_set):
12    super(PolymerPage, self).__init__(
13      url=url,
14      page_set=page_set)
15    self.archive_data_file = "data/polymer.json"
16    self.script_to_evaluate_on_commit = '''
17      document.addEventListener("polymer-ready", function() {
18        window.__polymer_ready = true;
19      });
20    '''
21
22  def RunNavigateSteps(self, action_runner):
23    action_runner.NavigateToPage(self)
24    action_runner.WaitForJavaScriptCondition(
25        'window.__polymer_ready')
26
27
28class PolymerCalculatorPage(PolymerPage):
29
30  def __init__(self, page_set):
31    super(PolymerCalculatorPage, self).__init__(
32      url='http://localhost:8000/components/paper-calculator/demo.html',
33      page_set=page_set)
34
35  def RunSmoothness(self, action_runner):
36    self.TapButton(action_runner)
37    self.SlidePanel(action_runner)
38
39  def TapButton(self, action_runner):
40    interaction = action_runner.BeginInteraction(
41        'Action_TapAction', is_smooth=True)
42    action_runner.TapElement(element_function='''
43        document.querySelector(
44            'body /deep/ #outerPanels'
45        ).querySelector(
46            '#standard'
47        ).shadowRoot.querySelector(
48            'paper-calculator-key[label="5"]'
49        )''')
50    action_runner.Wait(2)
51    interaction.End()
52
53  def SlidePanel(self, action_runner):
54    interaction = action_runner.BeginInteraction(
55        'Action_SwipeAction', is_smooth=True)
56    action_runner.SwipeElement(
57        left_start_ratio=0.1, top_start_ratio=0.2,
58        direction='left', distance=300, speed=5000,
59        element_function='''
60            document.querySelector(
61              'body /deep/ #outerPanels'
62            ).querySelector(
63              '#advanced'
64            ).shadowRoot.querySelector(
65              '.handle-bar'
66            )''')
67    action_runner.WaitForJavaScriptCondition('''
68        var outer = document.querySelector("body /deep/ #outerPanels");
69        outer.opened || outer.wideMode;''')
70    interaction.End()
71
72
73class PolymerShadowPage(PolymerPage):
74
75  def __init__(self, page_set):
76    super(PolymerShadowPage, self).__init__(
77      url='http://localhost:8000/components/paper-shadow/demo.html',
78      page_set=page_set)
79    self.archive_data_file = 'data/polymer.json'
80
81  def RunSmoothness(self, action_runner):
82    action_runner.ExecuteJavaScript(
83        "document.getElementById('fab').scrollIntoView()")
84    action_runner.Wait(5)
85    self.AnimateShadow(action_runner, 'card')
86    self.AnimateShadow(action_runner, 'fab')
87
88  def AnimateShadow(self, action_runner, eid):
89    for i in range(1, 6):
90      action_runner.ExecuteJavaScript(
91          'document.getElementById("{0}").z = {1}'.format(eid, i))
92      action_runner.Wait(1)
93
94
95class PolymerPageSet(page_set_module.PageSet):
96
97  def __init__(self):
98    super(PolymerPageSet, self).__init__(
99      user_agent_type='mobile',
100      archive_data_file='data/polymer.json',
101      bucket=page_set_module.INTERNAL_BUCKET)
102
103    self.AddPage(PolymerCalculatorPage(self))
104    self.AddPage(PolymerShadowPage(self))
105