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 shared_page_state
9 from telemetry
import story
12 def _CreateXpathFunction(xpath
):
13 return ('document.evaluate("%s",'
16 'XPathResult.FIRST_ORDERED_NODE_TYPE,'
18 '.singleNodeValue' % re
.escape(xpath
))
21 class GmailComposeDiscardPage(page_module
.Page
):
23 """ Why: Compose and discard a new email """
25 def __init__(self
, page_set
):
26 super(GmailComposeDiscardPage
, self
).__init
__(
27 url
='https://mail.google.com/mail/',
29 shared_page_state_class
=shared_page_state
.SharedDesktopPageState
,
30 credentials_path
= 'data/credentials.json')
31 self
.credentials
= 'google'
33 def RunNavigateSteps(self
, action_runner
):
34 super(GmailComposeDiscardPage
, self
).RunNavigateSteps(action_runner
)
35 action_runner
.WaitForJavaScriptCondition(
36 'window.gmonkey !== undefined &&'
37 'document.getElementById("gb") !== null')
39 def ComposeClick(self
, action_runner
):
40 action_runner
.ExecuteJavaScript('''
41 var button=document.evaluate('//div[text()="COMPOSE"]',
42 document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null)
44 var mousedownevent=new MouseEvent('mousedown',true,true,window,0,0,0,0,0,
45 false,false,false,false,0,null);
46 var mouseupevent=new MouseEvent('mouseup',true,true,window,0,0,0,0,0,
47 false,false,false,false,0,null);
48 button.dispatchEvent(mousedownevent);
49 button.dispatchEvent(mouseupevent);''')
51 def RunEndure(self
, action_runner
):
52 action_runner
.WaitForElement(
53 element_function
=_CreateXpathFunction('//div[text()="COMPOSE"]'))
54 self
.ComposeClick(action_runner
)
56 action_runner
.WaitForElement(
57 'div[class~="oh"][data-tooltip="Discard draft"]')
58 action_runner
.ClickElement('div[class~="oh"][data-tooltip="Discard draft"]')
62 class GmailComposeDiscardPageSet(story
.StorySet
):
65 Description: Gmail endure test: compose and discard an email.
69 super(GmailComposeDiscardPageSet
, self
).__init
__()
71 self
.AddStory(GmailComposeDiscardPage(self
))