| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import pyauto_functional | |
| 7 import pyauto | |
| 8 import test_utils | |
| 9 | |
| 10 | |
| 11 class IndexedDBTest(pyauto.PyUITest): | |
| 12 """Test of IndexedDB.""" | |
| 13 | |
| 14 _SESSION_STARTUP_NTP = 5 | |
| 15 | |
| 16 def _GetInnerText(self, selector, tab_index=0): | |
| 17 """Return the value of the innerText property of the target node. | |
| 18 The target node is identified by CSS selector, e.g. #id""" | |
| 19 | |
| 20 expression = 'document.querySelector("' + selector + '").innerText' | |
| 21 return self.GetDOMValue(expression, tab_index=tab_index) | |
| 22 | |
| 23 def _WaitForAndAssertResult(self, expected, tab_index=0): | |
| 24 """Wait for the element with id="result" to exist, and verify the value.""" | |
| 25 self.WaitForDomNode('id("result")', tab_index=tab_index) | |
| 26 self.assertEqual(self._GetInnerText('#result', tab_index=tab_index), | |
| 27 expected) | |
| 28 | |
| 29 def _ClearResult(self, tab_index=0): | |
| 30 """Delete the element with id="result" if it exists.""" | |
| 31 expression = """(function() { | |
| 32 var e = document.querySelector('#result'); | |
| 33 if (e) | |
| 34 e.parentNode.removeChild(e); | |
| 35 return 'ok'; | |
| 36 }())""" | |
| 37 self.assertEqual(self.GetDOMValue(expression, tab_index=tab_index), 'ok') | |
| 38 | |
| 39 def _AssertNewTabPage(self): | |
| 40 """Assert that the current tab is the new tab page, not a restored tab.""" | |
| 41 self.assertEqual(self.GetBrowserInfo()['windows'][0]['tabs'][0]['url'], | |
| 42 'chrome://newtab/') | |
| 43 | |
| 44 def testIndexedDBNullKeyPathPersistence(self): | |
| 45 """Verify null key path persists after restarting browser.""" | |
| 46 | |
| 47 # Don't restore tabs after restart | |
| 48 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP) | |
| 49 | |
| 50 url = self.GetHttpURLForDataPath('indexeddb', 'bug_90635.html') | |
| 51 | |
| 52 self.NavigateToURL(url + '#part1') | |
| 53 self._WaitForAndAssertResult('pass - first run') | |
| 54 | |
| 55 self.RestartBrowser(clear_profile=False) | |
| 56 self._AssertNewTabPage() | |
| 57 | |
| 58 self.NavigateToURL(url + '#part2') | |
| 59 self._WaitForAndAssertResult('pass - second run') | |
| 60 | |
| 61 def testVersionChangeCrashResilience(self): | |
| 62 """Verify that a VERSION_CHANGE transaction is rolled back | |
| 63 after a renderer/browser crash""" | |
| 64 | |
| 65 # Don't restore tabs after restart | |
| 66 self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP) | |
| 67 | |
| 68 url = self.GetHttpURLForDataPath('indexeddb', 'version_change_crash.html') | |
| 69 | |
| 70 self.NavigateToURL(url + '#part1') | |
| 71 self._WaitForAndAssertResult('pass - part1 - complete') | |
| 72 | |
| 73 self.RestartBrowser(clear_profile=False) | |
| 74 self._AssertNewTabPage() | |
| 75 | |
| 76 self.NavigateToURL(url + '#part2') | |
| 77 self._WaitForAndAssertResult('pass - part2 - crash me') | |
| 78 | |
| 79 test_utils.CrashBrowser(self) | |
| 80 | |
| 81 self.RestartBrowser(clear_profile=False) | |
| 82 self._AssertNewTabPage() | |
| 83 | |
| 84 self.NavigateToURL(url + '#part3') | |
| 85 self._WaitForAndAssertResult('pass - part3 - rolled back') | |
| 86 | |
| 87 def testConnectionsClosedOnTabClose(self): | |
| 88 """Verify that open DB connections are closed when a tab is destroyed.""" | |
| 89 | |
| 90 url = self.GetHttpURLForDataPath('indexeddb', 'version_change_blocked.html') | |
| 91 | |
| 92 self.NavigateToURL(url + '#tab1') | |
| 93 pid = self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid'] | |
| 94 self._WaitForAndAssertResult('setVersion(1) complete') | |
| 95 | |
| 96 # Start on a different URL to force a new renderer process. | |
| 97 self.AppendTab(pyauto.GURL('about:blank')) | |
| 98 self.NavigateToURL(url + '#tab2') | |
| 99 self._WaitForAndAssertResult('setVersion(2) blocked', tab_index=1) | |
| 100 self._ClearResult(tab_index=1) | |
| 101 | |
| 102 self.KillRendererProcess(pid) | |
| 103 self.assertEqual(self.GetTabCount(), 2) | |
| 104 self.CloseTab() | |
| 105 | |
| 106 self._WaitForAndAssertResult('setVersion(2) complete') | |
| 107 | |
| 108 | |
| 109 if __name__ == '__main__': | |
| 110 pyauto_functional.Main() | |
| OLD | NEW |