Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / tools / perf / page_sets / gmail_compose_discard.py
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.
4
5 import re
6
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
11
12
13 def _CreateXpathFunction(xpath):
14   return ('document.evaluate("%s",'
15                              'document,'
16                              'null,'
17                              'XPathResult.FIRST_ORDERED_NODE_TYPE,'
18                              'null)'
19           '.singleNodeValue' % re.escape(xpath))
20
21
22 class GmailComposeDiscardPage(page_module.Page):
23
24   """ Why: Compose and discard a new email """
25
26   def __init__(self, page_set):
27     super(GmailComposeDiscardPage, self).__init__(
28       url='https://mail.google.com/mail/',
29       page_set=page_set)
30     self.credentials_path = 'data/credentials.json'
31     self.credentials = 'google'
32     self.user_agent_type = 'desktop'
33
34   def RunNavigateSteps(self, action_runner):
35     action_runner.NavigateToPage(self)
36     action_runner.WaitForJavaScriptCondition(
37         'window.gmonkey !== undefined &&'
38         'document.getElementById("gb") !== null')
39
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)
44           .singleNodeValue;
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);''')
51
52   def RunEndure(self, action_runner):
53     action_runner.WaitForElement(
54         element_function=_CreateXpathFunction('//div[text()="COMPOSE"]'))
55     self.ComposeClick(action_runner)
56     action_runner.Wait(1)
57     action_runner.WaitForElement(
58         'div[class~="oh"][data-tooltip="Discard draft"]')
59     action_runner.ClickElement('div[class~="oh"][data-tooltip="Discard draft"]')
60     action_runner.Wait(1)
61
62
63 class GmailComposeDiscardPageSet(page_set_module.PageSet):
64
65   """
66   Description: Gmail endure test: compose and discard an email.
67   """
68
69   def __init__(self):
70     super(GmailComposeDiscardPageSet, self).__init__(
71       credentials_path='data/credentials.json',
72       user_agent_type='desktop')
73
74     self.AddPage(GmailComposeDiscardPage(self))