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.
7 # pylint: disable=W0401,W0614
8 from telemetry.page.actions.all_page_actions import *
9 from telemetry.page import page as page_module
10 from telemetry.page import page_set as page_set_module
13 def _CreateXpathFunction(xpath):
14 return ('document.evaluate("%s",'
17 'XPathResult.FIRST_ORDERED_NODE_TYPE,'
19 '.singleNodeValue' % re.escape(xpath))
22 class GmailComposeDiscardPage(page_module.Page):
24 """ Why: Compose and discard a new email """
26 def __init__(self, page_set):
27 super(GmailComposeDiscardPage, self).__init__(
28 url='https://mail.google.com/mail/',
30 self.credentials_path = 'data/credentials.json'
31 self.credentials = 'google'
32 self.user_agent_type = 'desktop'
34 def RunNavigateSteps(self, action_runner):
35 action_runner.NavigateToPage(self)
36 action_runner.WaitForJavaScriptCondition(
37 'window.gmonkey !== undefined &&'
38 'document.getElementById("gb") !== null')
40 def ComposeClick(self, action_runner):
41 action_runner.ExecuteJavaScript('''
42 var button=document.evaluate('//div[text()="COMPOSE"]',
43 document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null)
45 var mousedownevent=new MouseEvent('mousedown',true,true,window,0,0,0,0,0,
46 false,false,false,false,0,null);
47 var mouseupevent=new MouseEvent('mouseup',true,true,window,0,0,0,0,0,
48 false,false,false,false,0,null);
49 button.dispatchEvent(mousedownevent);
50 button.dispatchEvent(mouseupevent);''')
52 def RunEndure(self, action_runner):
53 action_runner.WaitForElement(
54 element_function=_CreateXpathFunction('//div[text()="COMPOSE"]'))
55 self.ComposeClick(action_runner)
57 action_runner.WaitForElement(
58 'div[class~="oh"][data-tooltip="Discard draft"]')
59 action_runner.ClickElement('div[class~="oh"][data-tooltip="Discard draft"]')
63 class GmailComposeDiscardPageSet(page_set_module.PageSet):
66 Description: Gmail endure test: compose and discard an email.
70 super(GmailComposeDiscardPageSet, self).__init__(
71 credentials_path='data/credentials.json',
72 user_agent_type='desktop')
74 self.AddPage(GmailComposeDiscardPage(self))