[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / page_sets / key_desktop_move_cases.py
blobded7d62931674bca3d0cf17f16db1080ba15c7d0
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 page_set as page_set_module
8 class KeyDesktopMoveCasesPage(page_module.Page):
10 def __init__(self, url, page_set, name='', credentials=None):
11 super(KeyDesktopMoveCasesPage, self).__init__(
12 url=url, page_set=page_set, name=name,
13 credentials_path='data/credentials.json')
14 self.archive_data_file = 'data/key_desktop_move_cases.json'
15 self.user_agent_type = 'desktop'
16 self.credentials = credentials
19 class GmailMouseScrollPage(KeyDesktopMoveCasesPage):
21 """ Why: productivity, top google properties """
23 def __init__(self, page_set):
24 super(GmailMouseScrollPage, self).__init__(
25 url='https://mail.google.com/mail/',
26 page_set=page_set)
28 self.scrollable_element_function = '''
29 function(callback) {
30 gmonkey.load('2.0', function(api) {
31 callback(api.getScrollableElement());
32 });
33 }'''
34 self.credentials = 'google'
36 def RunNavigateSteps(self, action_runner):
37 super(GmailMouseScrollPage, self).RunNavigateSteps(action_runner)
38 action_runner.WaitForJavaScriptCondition(
39 'window.gmonkey !== undefined &&'
40 'document.getElementById("gb") !== null')
41 # This check is needed for gmonkey to load completely.
42 action_runner.WaitForJavaScriptCondition(
43 'document.readyState == "complete"')
45 def RunPageInteractions(self, action_runner):
46 action_runner.ExecuteJavaScript('''
47 gmonkey.load('2.0', function(api) {
48 window.__scrollableElementForTelemetry = api.getScrollableElement();
49 });''')
50 action_runner.WaitForJavaScriptCondition(
51 'window.__scrollableElementForTelemetry != null')
52 scrollbar_x, start_y, end_y = self._CalculateScrollBarRatios(action_runner)
54 interaction = action_runner.BeginGestureInteraction(
55 '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')
60 interaction.End()
62 def _CalculateScrollBarRatios(self, action_runner):
63 viewport_height = float(action_runner.EvaluateJavaScript(
64 'window.__scrollableElementForTelemetry.clientHeight'))
65 content_height = float(action_runner.EvaluateJavaScript(
66 'window.__scrollableElementForTelemetry.scrollHeight'))
67 viewport_width = float(action_runner.EvaluateJavaScript(
68 'window.__scrollableElementForTelemetry.offsetWidth'))
69 scrollbar_width = float(action_runner.EvaluateJavaScript('''
70 window.__scrollableElementForTelemetry.offsetWidth -
71 window.__scrollableElementForTelemetry.scrollWidth'''))
73 # This calculation is correct only when the element doesn't have border or
74 # padding or scroll buttons (eg: gmail mail element).
75 # Calculating the mid point of start of scrollbar.
76 scrollbar_height_ratio = viewport_height / content_height
77 scrollbar_start_mid_y = scrollbar_height_ratio / 2
78 scrollbar_width_ratio = scrollbar_width / viewport_width
79 scrollbar_mid_x_right_offset = scrollbar_width_ratio / 2
80 scrollbar_mid_x = 1 - scrollbar_mid_x_right_offset
82 # The End point of scrollbar (x remains same).
83 scrollbar_end_mid_y = 1 - scrollbar_start_mid_y
84 return scrollbar_mid_x, scrollbar_start_mid_y, scrollbar_end_mid_y
87 class GoogleMapsPage(KeyDesktopMoveCasesPage):
89 """ Why: productivity, top google properties; Supports drag gesturee """
91 def __init__(self, page_set):
92 super(GoogleMapsPage, self).__init__(
93 url='https://www.google.co.uk/maps/@51.5043968,-0.1526806',
94 page_set=page_set,
95 name='Maps')
97 def RunNavigateSteps(self, action_runner):
98 super(GoogleMapsPage, self).RunNavigateSteps(action_runner)
99 action_runner.WaitForElement(selector='.widget-scene-canvas')
100 action_runner.WaitForElement(selector='.widget-zoom-in')
101 action_runner.WaitForElement(selector='.widget-zoom-out')
103 def RunPageInteractions(self, action_runner):
104 for _ in range(3):
105 action_runner.Wait(2)
106 interaction = action_runner.BeginGestureInteraction(
107 'DragAction', repeatable=True)
108 action_runner.DragPage(left_start_ratio=0.5, top_start_ratio=0.75,
109 left_end_ratio=0.75, top_end_ratio=0.5)
110 interaction.End()
111 # TODO(ssid): Add zoom gestures after fixing bug crbug.com/462214.
114 class KeyDesktopMoveCasesPageSet(page_set_module.PageSet):
116 """ Special cases for move gesture """
118 def __init__(self):
119 super(KeyDesktopMoveCasesPageSet, self).__init__(
120 archive_data_file='data/key_desktop_move_cases.json',
121 bucket=page_set_module.PARTNER_BUCKET)
123 self.AddUserStory(GmailMouseScrollPage(self))
124 self.AddUserStory(GoogleMapsPage(self))