[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / perf / page_sets / key_desktop_move_cases.py
bloba226a6204197d9e7ee5a3f40e99775e6a2c95e0c
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 from telemetry.page import page as page_module
5 from telemetry.page import shared_page_state
6 from telemetry import story
9 class KeyDesktopMoveCasesPage(page_module.Page):
11 def __init__(self, url, page_set, name='', credentials=None):
12 super(KeyDesktopMoveCasesPage, self).__init__(
13 url=url, page_set=page_set, name=name,
14 credentials_path='data/credentials.json',
15 shared_page_state_class=shared_page_state.SharedDesktopPageState)
16 self.archive_data_file = 'data/key_desktop_move_cases.json'
17 self.credentials = credentials
20 class GmailMouseScrollPage(KeyDesktopMoveCasesPage):
22 """ Why: productivity, top google properties """
24 def __init__(self, page_set):
25 super(GmailMouseScrollPage, self).__init__(
26 url='https://mail.google.com/mail/',
27 page_set=page_set)
29 self.scrollable_element_function = '''
30 function(callback) {
31 gmonkey.load('2.0', function(api) {
32 callback(api.getScrollableElement());
33 });
34 }'''
35 self.credentials = 'google'
37 def RunNavigateSteps(self, action_runner):
38 super(GmailMouseScrollPage, self).RunNavigateSteps(action_runner)
39 action_runner.WaitForJavaScriptCondition(
40 'window.gmonkey !== undefined &&'
41 'document.getElementById("gb") !== null')
42 # This check is needed for gmonkey to load completely.
43 action_runner.WaitForJavaScriptCondition(
44 'document.readyState == "complete"')
46 def RunPageInteractions(self, action_runner):
47 action_runner.ExecuteJavaScript('''
48 gmonkey.load('2.0', function(api) {
49 window.__scrollableElementForTelemetry = api.getScrollableElement();
50 });''')
51 action_runner.WaitForJavaScriptCondition(
52 'window.__scrollableElementForTelemetry != null')
53 scrollbar_x, start_y, end_y = self._CalculateScrollBarRatios(action_runner)
55 with action_runner.CreateGestureInteraction('DragAction'):
56 action_runner.DragPage(left_start_ratio=scrollbar_x,
57 top_start_ratio=start_y, left_end_ratio=scrollbar_x,
58 top_end_ratio=end_y, speed_in_pixels_per_second=100,
59 element_function='window.__scrollableElementForTelemetry')
61 def _CalculateScrollBarRatios(self, action_runner):
62 viewport_height = float(action_runner.EvaluateJavaScript(
63 'window.__scrollableElementForTelemetry.clientHeight'))
64 content_height = float(action_runner.EvaluateJavaScript(
65 'window.__scrollableElementForTelemetry.scrollHeight'))
66 viewport_width = float(action_runner.EvaluateJavaScript(
67 'window.__scrollableElementForTelemetry.offsetWidth'))
68 scrollbar_width = float(action_runner.EvaluateJavaScript('''
69 window.__scrollableElementForTelemetry.offsetWidth -
70 window.__scrollableElementForTelemetry.scrollWidth'''))
72 # This calculation is correct only when the element doesn't have border or
73 # padding or scroll buttons (eg: gmail mail element).
74 # Calculating the mid point of start of scrollbar.
75 scrollbar_height_ratio = viewport_height / content_height
76 scrollbar_start_mid_y = scrollbar_height_ratio / 2
77 scrollbar_width_ratio = scrollbar_width / viewport_width
78 scrollbar_mid_x_right_offset = scrollbar_width_ratio / 2
79 scrollbar_mid_x = 1 - scrollbar_mid_x_right_offset
81 # The End point of scrollbar (x remains same).
82 scrollbar_end_mid_y = 1 - scrollbar_start_mid_y
83 return scrollbar_mid_x, scrollbar_start_mid_y, scrollbar_end_mid_y
86 class GoogleMapsPage(KeyDesktopMoveCasesPage):
88 """ Why: productivity, top google properties; Supports drag gestures """
90 def __init__(self, page_set):
91 super(GoogleMapsPage, self).__init__(
92 url='https://www.google.co.uk/maps/@51.5043968,-0.1526806',
93 page_set=page_set,
94 name='Maps')
96 def RunNavigateSteps(self, action_runner):
97 super(GoogleMapsPage, self).RunNavigateSteps(action_runner)
98 action_runner.WaitForElement(selector='.widget-scene-canvas')
99 action_runner.WaitForElement(selector='.widget-zoom-in')
100 action_runner.WaitForElement(selector='.widget-zoom-out')
102 def RunPageInteractions(self, action_runner):
103 for _ in range(3):
104 action_runner.Wait(2)
105 with action_runner.CreateGestureInteraction(
106 'DragAction', repeatable=True):
107 action_runner.DragPage(left_start_ratio=0.5, top_start_ratio=0.75,
108 left_end_ratio=0.75, top_end_ratio=0.5)
109 # TODO(ssid): Add zoom gestures after fixing bug crbug.com/462214.
112 class KeyDesktopMoveCasesPageSet(story.StorySet):
114 """ Special cases for move gesture """
116 def __init__(self):
117 super(KeyDesktopMoveCasesPageSet, self).__init__(
118 archive_data_file='data/key_desktop_move_cases.json',
119 cloud_storage_bucket=story.PARTNER_BUCKET)
121 self.AddStory(GmailMouseScrollPage(self))
122 self.AddStory(GoogleMapsPage(self))