summaryrefslogtreecommitdiffstats
path: root/tools/perf/page_sets/gmail_compose_discard.py
blob: 264878ba90b73baaca375f336e19b9f0bf8d7a3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# pylint: disable=W0401,W0614
from telemetry.page.actions.all_page_actions import *
from telemetry.page import page as page_module
from telemetry.page import page_set as page_set_module


class GmailComposeDiscardPage(page_module.Page):

  """ Why: Compose and discard a new email """

  def __init__(self, page_set):
    super(GmailComposeDiscardPage, self).__init__(
      url='https://mail.google.com/mail/',
      page_set=page_set)
    self.credentials_path = 'data/credentials.json'
    self.credentials = 'google'
    self.user_agent_type = 'desktop'

  def RunNavigateSteps(self, action_runner):
    action_runner.NavigateToPage(self)
    action_runner.RunAction(WaitAction(
      {
        'javascript': (
          'window.gmonkey !== undefined &&'
          'document.getElementById("gb") !== null')
      }))

  def ComposeClick(self, action_runner):
    action_runner.ExecuteJavaScript('''
      var button=document.evaluate('//div[text()="COMPOSE"]',
          document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null)
          .singleNodeValue;
      var mousedownevent=new MouseEvent('mousedown',true,true,window,0,0,0,0,0,
        false,false,false,false,0,null);
      var mouseupevent=new MouseEvent('mouseup',true,true,window,0,0,0,0,0,
        false,false,false,false,0,null);
      button.dispatchEvent(mousedownevent);
      button.dispatchEvent(mouseupevent);''')

  def RunEndure(self, action_runner):
    action_runner.RunAction(WaitAction(
      {
        'xpath': '//div[text()="COMPOSE"]',
        'condition': 'element'
      }))
    self.ComposeClick(action_runner)
    action_runner.RunAction(WaitAction({"seconds": 1}))
    action_runner.RunAction(WaitAction(
      {
        'condition': 'element',
        'selector': 'div[class~="oh"][data-tooltip="Discard draft"]'
      }))
    action_runner.RunAction(ClickElementAction(
      {
        'selector': 'div[class~="oh"][data-tooltip="Discard draft"]'
      }))
    action_runner.RunAction(WaitAction({'seconds': 1}))


class GmailComposeDiscardPageSet(page_set_module.PageSet):

  """
  Description: Gmail endure test: compose and discard an email.
  """

  def __init__(self):
    super(GmailComposeDiscardPageSet, self).__init__(
      credentials_path='data/credentials.json',
      user_agent_type='desktop')

    self.AddPage(GmailComposeDiscardPage(self))