[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / perf / page_sets / gmail_compose_discard.py
blob1a67c311d6215bdf6fe3121564e93b7e1db6b426
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 shared_page_state
9 from telemetry import story
12 def _CreateXpathFunction(xpath):
13 return ('document.evaluate("%s",'
14 'document,'
15 'null,'
16 'XPathResult.FIRST_ORDERED_NODE_TYPE,'
17 'null)'
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/',
28 page_set=page_set,
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)
43 .singleNodeValue;
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)
55 action_runner.Wait(1)
56 action_runner.WaitForElement(
57 'div[class~="oh"][data-tooltip="Discard draft"]')
58 action_runner.ClickElement('div[class~="oh"][data-tooltip="Discard draft"]')
59 action_runner.Wait(1)
62 class GmailComposeDiscardPageSet(story.StorySet):
64 """
65 Description: Gmail endure test: compose and discard an email.
66 """
68 def __init__(self):
69 super(GmailComposeDiscardPageSet, self).__init__()
71 self.AddStory(GmailComposeDiscardPage(self))