[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / page_sets / gmail_compose_discard.py
blob77b22abdc191484e739fa46f810a23a925b3545f
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.
5 import re
7 from telemetry.page import page as page_module
8 from telemetry.page import page_set as page_set_module
11 def _CreateXpathFunction(xpath):
12 return ('document.evaluate("%s",'
13 'document,'
14 'null,'
15 'XPathResult.FIRST_ORDERED_NODE_TYPE,'
16 'null)'
17 '.singleNodeValue' % re.escape(xpath))
20 class GmailComposeDiscardPage(page_module.Page):
22 """ Why: Compose and discard a new email """
24 def __init__(self, page_set):
25 super(GmailComposeDiscardPage, self).__init__(
26 url='https://mail.google.com/mail/',
27 page_set=page_set,
28 credentials_path = 'data/credentials.json')
29 self.credentials = 'google'
30 self.user_agent_type = 'desktop'
32 def RunNavigateSteps(self, action_runner):
33 super(GmailComposeDiscardPage, self).RunNavigateSteps(action_runner)
34 action_runner.WaitForJavaScriptCondition(
35 'window.gmonkey !== undefined &&'
36 'document.getElementById("gb") !== null')
38 def ComposeClick(self, action_runner):
39 action_runner.ExecuteJavaScript('''
40 var button=document.evaluate('//div[text()="COMPOSE"]',
41 document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null)
42 .singleNodeValue;
43 var mousedownevent=new MouseEvent('mousedown',true,true,window,0,0,0,0,0,
44 false,false,false,false,0,null);
45 var mouseupevent=new MouseEvent('mouseup',true,true,window,0,0,0,0,0,
46 false,false,false,false,0,null);
47 button.dispatchEvent(mousedownevent);
48 button.dispatchEvent(mouseupevent);''')
50 def RunEndure(self, action_runner):
51 action_runner.WaitForElement(
52 element_function=_CreateXpathFunction('//div[text()="COMPOSE"]'))
53 self.ComposeClick(action_runner)
54 action_runner.Wait(1)
55 action_runner.WaitForElement(
56 'div[class~="oh"][data-tooltip="Discard draft"]')
57 action_runner.ClickElement('div[class~="oh"][data-tooltip="Discard draft"]')
58 action_runner.Wait(1)
61 class GmailComposeDiscardPageSet(page_set_module.PageSet):
63 """
64 Description: Gmail endure test: compose and discard an email.
65 """
67 def __init__(self):
68 super(GmailComposeDiscardPageSet, self).__init__(
69 user_agent_type='desktop')
71 self.AddUserStory(GmailComposeDiscardPage(self))