Home | History | Annotate | Download | only in page_sets
      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 def _GetCurrentLocation(action_runner):
     23   return action_runner.EvaluateJavaScript('document.location.href')
     24 
     25 
     26 def _WaitForLocationChange(action_runner, old_href):
     27   action_runner.WaitForJavaScriptCondition(
     28       'document.location.href != "%s"' % old_href)
     29 
     30 
     31 class GmailAltThreadlistConversationPage(
     32   page_module.Page):
     33 
     34   """ Why: Alternate between Inbox and the first email conversation. """
     35 
     36   def __init__(self, page_set):
     37     super(GmailAltThreadlistConversationPage, self).__init__(
     38       url='https://mail.google.com/mail/',
     39       page_set=page_set,
     40       name='gmail_alt_threadlist_conversation')
     41     self.credentials_path = 'data/credentials.json'
     42     self.user_agent_type = 'desktop'
     43     self.archive_data_file = 'data/gmail_alt_threadlist_conversation.json'
     44     self.credentials = 'google'
     45 
     46   def RunNavigateSteps(self, action_runner):
     47     action_runner.NavigateToPage(self)
     48     action_runner.WaitForJavaScriptCondition(
     49         'window.gmonkey !== undefined && '
     50         'document.getElementById("gb") !== null')
     51 
     52   def RunEndure(self, action_runner):
     53     old_href = _GetCurrentLocation(action_runner)
     54     action_runner.ClickElement(
     55         element_function=_CreateXpathFunction('//span[@email]'))
     56     _WaitForLocationChange(action_runner, old_href)
     57     action_runner.Wait(1)
     58     old_href = _GetCurrentLocation(action_runner)
     59     action_runner.ClickElement(
     60         'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]')
     61     _WaitForLocationChange(action_runner, old_href)
     62     action_runner.Wait(1)
     63 
     64 
     65 class GmailAltThreadlistConversationPageSet(page_set_module.PageSet):
     66 
     67   """ Chrome Endure test for GMail. """
     68 
     69   def __init__(self):
     70     super(GmailAltThreadlistConversationPageSet, self).__init__(
     71       credentials_path='data/credentials.json',
     72       user_agent_type='desktop',
     73       archive_data_file='data/gmail_alt_threadlist_conversation.json',
     74       bucket=page_set_module.PUBLIC_BUCKET)
     75 
     76     self.AddPage(GmailAltThreadlistConversationPage(self))
     77