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 class IndexeddbOfflinePage(page_module.Page): 23 24 """ Why: Simulates user input while offline and sync while online. """ 25 26 def __init__(self, page_set): 27 super(IndexeddbOfflinePage, self).__init__( 28 url='file://endure/indexeddb_app.html', 29 page_set=page_set, 30 name='indexeddb_offline') 31 self.user_agent_type = 'desktop' 32 33 def RunNavigateSteps(self, action_runner): 34 action_runner.NavigateToPage(self) 35 action_runner.WaitForElement(text='initialized') 36 37 def RunEndure(self, action_runner): 38 action_runner.WaitForElement('button[id="online"]:not(disabled)') 39 action_runner.ClickElement('button[id="online"]:not(disabled)') 40 action_runner.WaitForElement( 41 element_function=_CreateXpathFunction('id("state")[text()="online"]')) 42 action_runner.Wait(1) 43 action_runner.WaitForElement('button[id="offline"]:not(disabled)') 44 action_runner.ClickElement('button[id="offline"]:not(disabled)') 45 action_runner.WaitForElement( 46 element_function=_CreateXpathFunction('id("state")[text()="offline"]')) 47 48 49 class IndexeddbOfflinePageSet(page_set_module.PageSet): 50 51 """ Chrome Endure test for IndexedDB. """ 52 53 def __init__(self): 54 super(IndexeddbOfflinePageSet, self).__init__( 55 user_agent_type='desktop') 56 57 self.AddPage(IndexeddbOfflinePage(self)) 58