| 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 | 4 |
| 5 import re | 5 import re |
| 6 | 6 |
| 7 # pylint: disable=W0401,W0614 | 7 # pylint: disable=W0401,W0614 |
| 8 from telemetry.page.actions.all_page_actions import * | 8 from telemetry.page.actions.all_page_actions import * |
| 9 from telemetry.page import page as page_module | 9 from telemetry.page import page as page_module |
| 10 from telemetry.page import page_set as page_set_module | 10 from telemetry.page import page_set as page_set_module |
| 11 | 11 |
| 12 | 12 |
| 13 def _CreateXpathFunction(xpath): | 13 def _CreateXpathFunction(xpath): |
| 14 return ('document.evaluate(%s, document, null, ' | 14 return ('document.evaluate("%s",' |
| 15 'XPathResult.FIRST_ORDERED_NODE_TYPE, null)' | 15 'document,' |
| 16 '.singleNodeEvaluate') % re.escape(xpath) | 16 'null,' |
| 17 'XPathResult.FIRST_ORDERED_NODE_TYPE,' |
| 18 'null)' |
| 19 '.singleNodeValue' % re.escape(xpath)) |
| 17 | 20 |
| 18 | 21 |
| 19 class IndexeddbOfflinePage(page_module.Page): | 22 class IndexeddbOfflinePage(page_module.Page): |
| 20 | 23 |
| 21 """ Why: Simulates user input while offline and sync while online. """ | 24 """ Why: Simulates user input while offline and sync while online. """ |
| 22 | 25 |
| 23 def __init__(self, page_set): | 26 def __init__(self, page_set): |
| 24 super(IndexeddbOfflinePage, self).__init__( | 27 super(IndexeddbOfflinePage, self).__init__( |
| 25 url='file://endure/indexeddb_app.html', | 28 url='file://endure/indexeddb_app.html', |
| 26 page_set=page_set, | 29 page_set=page_set, |
| 27 name='indexeddb_offline') | 30 name='indexeddb_offline') |
| 28 self.user_agent_type = 'desktop' | 31 self.user_agent_type = 'desktop' |
| 29 | 32 |
| 30 def RunNavigateSteps(self, action_runner): | 33 def RunNavigateSteps(self, action_runner): |
| 31 action_runner.NavigateToPage(self) | 34 action_runner.NavigateToPage(self) |
| 32 action_runner.WaitForElement(text='initialized') | 35 action_runner.WaitForElement(text='initialized') |
| 33 | 36 |
| 34 def RunEndure(self, action_runner): | 37 def RunEndure(self, action_runner): |
| 35 action_runner.WaitForElement('button[id="online"]:not(disabled)') | 38 action_runner.WaitForElement('button[id="online"]:not(disabled)') |
| 36 action_runner.RunAction(ClickElementAction( | 39 action_runner.ClickElement('button[id="online"]:not(disabled)') |
| 37 { | |
| 38 'selector': 'button[id="online"]:not(disabled)' | |
| 39 })) | |
| 40 action_runner.WaitForElement( | 40 action_runner.WaitForElement( |
| 41 element_function=_CreateXpathFunction('id("state")[text()="online"]')) | 41 element_function=_CreateXpathFunction('id("state")[text()="online"]')) |
| 42 action_runner.Wait(1) | 42 action_runner.Wait(1) |
| 43 action_runner.WaitForElement('button[id="offline"]:not(disabled)') | 43 action_runner.WaitForElement('button[id="offline"]:not(disabled)') |
| 44 action_runner.RunAction(ClickElementAction( | 44 action_runner.ClickElement('button[id="offline"]:not(disabled)') |
| 45 { | |
| 46 'selector': 'button[id="offline"]:not(disabled)' | |
| 47 })) | |
| 48 action_runner.WaitForElement( | 45 action_runner.WaitForElement( |
| 49 element_function=_CreateXpathFunction('id("state")[text()="offline"]')) | 46 element_function=_CreateXpathFunction('id("state")[text()="offline"]')) |
| 50 | 47 |
| 51 | 48 |
| 52 class IndexeddbOfflinePageSet(page_set_module.PageSet): | 49 class IndexeddbOfflinePageSet(page_set_module.PageSet): |
| 53 | 50 |
| 54 """ Chrome Endure test for IndexedDB. """ | 51 """ Chrome Endure test for IndexedDB. """ |
| 55 | 52 |
| 56 def __init__(self): | 53 def __init__(self): |
| 57 super(IndexeddbOfflinePageSet, self).__init__( | 54 super(IndexeddbOfflinePageSet, self).__init__( |
| 58 user_agent_type='desktop') | 55 user_agent_type='desktop') |
| 59 | 56 |
| 60 self.AddPage(IndexeddbOfflinePage(self)) | 57 self.AddPage(IndexeddbOfflinePage(self)) |
| OLD | NEW |