OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 |
| 5 import re |
| 6 |
4 # pylint: disable=W0401,W0614 | 7 # pylint: disable=W0401,W0614 |
5 from telemetry.page.actions.all_page_actions import * | 8 from telemetry.page.actions.all_page_actions import * |
6 from telemetry.page import page as page_module | 9 from telemetry.page import page as page_module |
7 from telemetry.page import page_set as page_set_module | 10 from telemetry.page import page_set as page_set_module |
8 | 11 |
9 | 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 |
10 class GmailAltThreadlistConversationPage( | 31 class GmailAltThreadlistConversationPage( |
11 page_module.Page): | 32 page_module.Page): |
12 | 33 |
13 """ Why: Alternate between Inbox and the first email conversation. """ | 34 """ Why: Alternate between Inbox and the first email conversation. """ |
14 | 35 |
15 def __init__(self, page_set): | 36 def __init__(self, page_set): |
16 super(GmailAltThreadlistConversationPage, self).__init__( | 37 super(GmailAltThreadlistConversationPage, self).__init__( |
17 url='https://mail.google.com/mail/', | 38 url='https://mail.google.com/mail/', |
18 page_set=page_set, | 39 page_set=page_set, |
19 name='gmail_alt_threadlist_conversation') | 40 name='gmail_alt_threadlist_conversation') |
20 self.credentials_path = 'data/credentials.json' | 41 self.credentials_path = 'data/credentials.json' |
21 self.user_agent_type = 'desktop' | 42 self.user_agent_type = 'desktop' |
22 self.archive_data_file = 'data/gmail_alt_threadlist_conversation.json' | 43 self.archive_data_file = 'data/gmail_alt_threadlist_conversation.json' |
23 self.credentials = 'google' | 44 self.credentials = 'google' |
24 | 45 |
25 def RunNavigateSteps(self, action_runner): | 46 def RunNavigateSteps(self, action_runner): |
26 action_runner.NavigateToPage(self) | 47 action_runner.NavigateToPage(self) |
27 action_runner.WaitForJavaScriptCondition( | 48 action_runner.WaitForJavaScriptCondition( |
28 'window.gmonkey !== undefined && ' | 49 'window.gmonkey !== undefined && ' |
29 'document.getElementById("gb") !== null') | 50 'document.getElementById("gb") !== null') |
30 | 51 |
31 def RunEndure(self, action_runner): | 52 def RunEndure(self, action_runner): |
32 action_runner.RunAction(ClickElementAction( | 53 old_href = _GetCurrentLocation(action_runner) |
33 { | 54 action_runner.ClickElement( |
34 'xpath': '//span[@email]', | 55 element_function=_CreateXpathFunction('//span[@email]')) |
35 'wait_until': {'condition': 'href_change'} | 56 _WaitForLocationChange(action_runner, old_href) |
36 })) | |
37 action_runner.Wait(1) | 57 action_runner.Wait(1) |
38 action_runner.RunAction(ClickElementAction( | 58 old_href = _GetCurrentLocation(action_runner) |
39 { | 59 action_runner.ClickElement( |
40 'wait_until': {'condition': 'href_change'}, | 60 'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]') |
41 'selector': 'a[href="https://mail.google.com/mail/u/0/?shva=1#inbox"]' | 61 _WaitForLocationChange(action_runner, old_href) |
42 })) | |
43 action_runner.Wait(1) | 62 action_runner.Wait(1) |
44 | 63 |
45 | 64 |
46 class GmailAltThreadlistConversationPageSet(page_set_module.PageSet): | 65 class GmailAltThreadlistConversationPageSet(page_set_module.PageSet): |
47 | 66 |
48 """ Chrome Endure test for GMail. """ | 67 """ Chrome Endure test for GMail. """ |
49 | 68 |
50 def __init__(self): | 69 def __init__(self): |
51 super(GmailAltThreadlistConversationPageSet, self).__init__( | 70 super(GmailAltThreadlistConversationPageSet, self).__init__( |
52 credentials_path='data/credentials.json', | 71 credentials_path='data/credentials.json', |
53 user_agent_type='desktop', | 72 user_agent_type='desktop', |
54 archive_data_file='data/gmail_alt_threadlist_conversation.json') | 73 archive_data_file='data/gmail_alt_threadlist_conversation.json') |
55 | 74 |
56 self.AddPage(GmailAltThreadlistConversationPage(self)) | 75 self.AddPage(GmailAltThreadlistConversationPage(self)) |
OLD | NEW |