Upstream version 7.36.149.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 # pylint: disable=W0401,W0614
5 from telemetry.page.actions.all_page_actions import *
6 from telemetry.page import page as page_module
7 from telemetry.page import page_set as page_set_module
8
9
10 class GmailComposeDiscardPage(page_module.Page):
11
12   """ Why: Compose and discard a new email """
13
14   def __init__(self, page_set):
15     super(GmailComposeDiscardPage, self).__init__(
16       url='https://mail.google.com/mail/',
17       page_set=page_set)
18     self.credentials_path = 'data/credentials.json'
19     self.credentials = 'google'
20     self.user_agent_type = 'desktop'
21
22   def RunNavigateSteps(self, action_runner):
23     action_runner.RunAction(NavigateAction())
24     action_runner.RunAction(WaitAction(
25       {
26         'javascript': (
27           'window.gmonkey !== undefined &&'
28           'document.getElementById("gb") !== null')
29       }))
30
31   def ComposeClick(self, action_runner):
32     action_runner.RunAction(JavascriptAction({
33       'expression': '''
34       var button=document.evaluate('//div[text()="COMPOSE"]',
35         document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null)
36           .singleNodeValue;
37       var mousedownevent=new MouseEvent('mousedown',true,true,window,0,0,0,0,0,
38         false,false,false,false,0,null);
39       var mouseupevent=new MouseEvent('mouseup',true,true,window,0,0,0,0,0,
40         false,false,false,false,0,null);
41       button.dispatchEvent(mousedownevent);
42       button.dispatchEvent(mouseupevent);'''
43     }))
44
45   def RunEndure(self, action_runner):
46     action_runner.RunAction(WaitAction(
47       {
48         'xpath': '//div[text()="COMPOSE"]',
49         'condition': 'element'
50       }))
51     self.ComposeClick(action_runner)
52     action_runner.RunAction(WaitAction({"seconds": 1}))
53     action_runner.RunAction(WaitAction(
54       {
55         'condition': 'element',
56         'selector': 'div[class~="oh"][data-tooltip="Discard draft"]'
57       }))
58     action_runner.RunAction(ClickElementAction(
59       {
60         'selector': 'div[class~="oh"][data-tooltip="Discard draft"]'
61       }))
62     action_runner.RunAction(WaitAction({'seconds': 1}))
63
64
65 class GmailComposeDiscardPageSet(page_set_module.PageSet):
66
67   """
68   Description: Gmail endure test: compose and discard an email.
69   """
70
71   def __init__(self):
72     super(GmailComposeDiscardPageSet, self).__init__(
73       credentials_path='data/credentials.json',
74       user_agent_type='desktop',
75       archive_data_file='data/gmail_compose_discard.json')
76
77     self.AddPage(GmailComposeDiscardPage(self))