| 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, document, null, ' |
| 15 'XPathResult.FIRST_ORDERED_NODE_TYPE, null)' |
| 16 '.singleNodeEvaluate') % re.escape(xpath) |
| 17 |
| 18 |
| 10 class IndexeddbOfflinePage(page_module.Page): | 19 class IndexeddbOfflinePage(page_module.Page): |
| 11 | 20 |
| 12 """ Why: Simulates user input while offline and sync while online. """ | 21 """ Why: Simulates user input while offline and sync while online. """ |
| 13 | 22 |
| 14 def __init__(self, page_set): | 23 def __init__(self, page_set): |
| 15 super(IndexeddbOfflinePage, self).__init__( | 24 super(IndexeddbOfflinePage, self).__init__( |
| 16 url='file://endure/indexeddb_app.html', | 25 url='file://endure/indexeddb_app.html', |
| 17 page_set=page_set, | 26 page_set=page_set, |
| 18 name='indexeddb_offline') | 27 name='indexeddb_offline') |
| 19 self.user_agent_type = 'desktop' | 28 self.user_agent_type = 'desktop' |
| 20 | 29 |
| 21 def RunNavigateSteps(self, action_runner): | 30 def RunNavigateSteps(self, action_runner): |
| 22 action_runner.NavigateToPage(self) | 31 action_runner.NavigateToPage(self) |
| 23 action_runner.RunAction(WaitAction( | 32 action_runner.WaitForElement(contains_text='initialized') |
| 24 { | |
| 25 'text': 'initialized', | |
| 26 'condition': 'element' | |
| 27 })) | |
| 28 | 33 |
| 29 def RunEndure(self, action_runner): | 34 def RunEndure(self, action_runner): |
| 30 action_runner.RunAction(WaitAction( | 35 action_runner.WaitForElement('button[id="online"]:not(disabled)') |
| 31 { | |
| 32 'condition': 'element', | |
| 33 'selector': 'button[id="online"]:not(disabled)' | |
| 34 })) | |
| 35 action_runner.RunAction(ClickElementAction( | 36 action_runner.RunAction(ClickElementAction( |
| 36 { | 37 { |
| 37 'selector': 'button[id="online"]:not(disabled)' | 38 'selector': 'button[id="online"]:not(disabled)' |
| 38 })) | 39 })) |
| 39 action_runner.RunAction(WaitAction( | 40 action_runner.WaitForElement( |
| 40 { | 41 element_function=_CreateXpathFunction('id("state")[text()="online"]')) |
| 41 'xpath': 'id("state")[text()="online"]', | 42 action_runner.Wait(1) |
| 42 'condition': 'element' | |
| 43 })) | |
| 44 action_runner.RunAction(WaitAction( | |
| 45 { | |
| 46 "seconds": 1 | |
| 47 })) | |
| 48 action_runner.RunAction(WaitAction( | 43 action_runner.RunAction(WaitAction( |
| 49 { | 44 { |
| 50 'condition': 'element', | 45 'condition': 'element', |
| 51 'selector': 'button[id="offline"]:not(disabled)' | 46 'selector': 'button[id="offline"]:not(disabled)' |
| 52 })) | 47 })) |
| 53 action_runner.RunAction(ClickElementAction( | 48 action_runner.RunAction(ClickElementAction( |
| 54 { | 49 { |
| 55 'selector': 'button[id="offline"]:not(disabled)' | 50 'selector': 'button[id="offline"]:not(disabled)' |
| 56 })) | 51 })) |
| 57 action_runner.RunAction(WaitAction( | 52 action_runner.WaitForElement( |
| 58 { | 53 element_function=_CreateXpathFunction('id("state")[text()="offline"]')) |
| 59 'xpath': 'id("state")[text()="offline"]', | |
| 60 'condition': 'element' | |
| 61 })) | |
| 62 | 54 |
| 63 | 55 |
| 64 class IndexeddbOfflinePageSet(page_set_module.PageSet): | 56 class IndexeddbOfflinePageSet(page_set_module.PageSet): |
| 65 | 57 |
| 66 """ Chrome Endure test for IndexedDB. """ | 58 """ Chrome Endure test for IndexedDB. """ |
| 67 | 59 |
| 68 def __init__(self): | 60 def __init__(self): |
| 69 super(IndexeddbOfflinePageSet, self).__init__( | 61 super(IndexeddbOfflinePageSet, self).__init__( |
| 70 user_agent_type='desktop') | 62 user_agent_type='desktop') |
| 71 | 63 |
| 72 self.AddPage(IndexeddbOfflinePage(self)) | 64 self.AddPage(IndexeddbOfflinePage(self)) |
| OLD | NEW |