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 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",'
15 'XPathResult.FIRST_ORDERED_NODE_TYPE,'
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/',
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)
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
)
55 action_runner
.WaitForElement(
56 'div[class~="oh"][data-tooltip="Discard draft"]')
57 action_runner
.ClickElement('div[class~="oh"][data-tooltip="Discard draft"]')
61 class GmailComposeDiscardPageSet(page_set_module
.PageSet
):
64 Description: Gmail endure test: compose and discard an email.
68 super(GmailComposeDiscardPageSet
, self
).__init
__(
69 user_agent_type
='desktop')
71 self
.AddUserStory(GmailComposeDiscardPage(self
))