Commit a95dc509 authored by jsbell@chromium.org's avatar jsbell@chromium.org

IndexedDB pyauto tests rely on restarting the browser and navigating to a new...

IndexedDB pyauto tests rely on restarting the browser and navigating to a new tab. On CrOS the restart was causing the previous session's tabs to be restored, which confused the test.

Set a preference to start sessions on the new tab page, , and refactor to avoid polling for results so that failures are detected immediately and with useful error messages.

BUG=123045
TEST=python chrome/test/functional/indexeddb.py
R=nirnimesh@chromium.org


Review URL: http://codereview.chromium.org/10216002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133993 0039d316-1c4b-4281-b951-d872f2087c98
parent f9782c63
<html> <html>
<head> <head>
<title>IndexedDB regression test for bug 90635</title> <title>IndexedDB regression test for bug 90635</title>
<script type="text/javascript" src="shared.js"></script>
<script type="text/javascript" src="bug_90635.js"></script> <script type="text/javascript" src="bug_90635.js"></script>
</head> </head>
<body onLoad="test()"> <body onLoad="test()">
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
window.indexedDB = window.indexedDB || window.webkitIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
function unexpectedErrorCallback()
{
document.title = 'fail - unexpected error callback';
}
function unexpectedAbortCallback()
{
document.title = 'fail - unexpected abort callback';
}
function test() function test()
{ {
if (document.location.hash === '#part1') { if (document.location.hash === '#part1') {
...@@ -21,7 +9,7 @@ function test() ...@@ -21,7 +9,7 @@ function test()
} else if (document.location.hash === '#part2') { } else if (document.location.hash === '#part2') {
testPart2(); testPart2();
} else { } else {
document.title = 'fail - no hash'; result('fail - unexpected hash');
} }
} }
...@@ -72,8 +60,8 @@ function test_store(db, msg) { ...@@ -72,8 +60,8 @@ function test_store(db, msg) {
if (store1.keyPath !== null || if (store1.keyPath !== null ||
store2.keyPath !== '' || store2.keyPath !== '' ||
store3.keyPath !== 'some_path') { store3.keyPath !== 'some_path') {
document.title = 'fail - ' + msg; result('fail - ' + msg);
} else { } else {
document.title = 'pass - ' + msg; result('pass - ' + msg);
} }
} }
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
window.indexedDB = window.indexedDB || window.webkitIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
function result(message) {
var div = document.createElement('div');
div.id = "result";
div.innerText = message;
document.body.appendChild(div);
}
function unexpectedErrorCallback()
{
result('fail - unexpected error callback');
}
function unexpectedAbortCallback()
{
result('fail - unexpected abort callback');
}
function unexpectedCompleteCallback()
{
result('fail - unexpected complete callback');
}
<html> <html>
<head> <head>
<title>IndexedDB regression test for bug 80111</title> <title>IndexedDB regression test for bug 80111</title>
<script type="text/javascript" src="shared.js"></script>
<script type="text/javascript" src="version_change_blocked.js"></script> <script type="text/javascript" src="version_change_blocked.js"></script>
</head> </head>
<body onLoad="test()"> <body onLoad="test()">
......
...@@ -2,34 +2,20 @@ ...@@ -2,34 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
window.indexedDB = window.indexedDB || window.webkitIndexedDB; function test()
function unexpectedErrorCallback()
{
document.title = 'fail - unexpected error callback';
}
function unexpectedAbortCallback()
{
document.title = 'fail - unexpected abort callback';
}
function unexpectedCompleteCallback()
{ {
document.title = 'fail - unexpected complete callback';
}
function test() {
if (document.location.hash === '#tab1') { if (document.location.hash === '#tab1') {
prepareDatabase(0, function () { doSetVersion(1); }); prepareDatabase(0, function () { doSetVersion(1); });
} else if (document.location.hash === '#tab2') { } else if (document.location.hash === '#tab2') {
doSetVersion(2); doSetVersion(2);
} else { } else {
document.title = 'fail'; result('fail - unexpected hash');
} }
} }
function prepareDatabase(version, callback) { function prepareDatabase(version, callback)
{
// Prepare the database, then exit normally // Prepare the database, then exit normally
var delreq = window.indexedDB.deleteDatabase('version-change-blocked'); var delreq = window.indexedDB.deleteDatabase('version-change-blocked');
delreq.onerror = unexpectedErrorCallback; delreq.onerror = unexpectedErrorCallback;
delreq.onsuccess = function() { delreq.onsuccess = function() {
...@@ -51,7 +37,8 @@ function prepareDatabase(version, callback) { ...@@ -51,7 +37,8 @@ function prepareDatabase(version, callback) {
}; };
} }
function doSetVersion(version) { function doSetVersion(version)
{
// Open the database and try a setVersion // Open the database and try a setVersion
var openreq = window.indexedDB.open('version-change-blocked'); var openreq = window.indexedDB.open('version-change-blocked');
openreq.onerror = unexpectedErrorCallback; openreq.onerror = unexpectedErrorCallback;
...@@ -60,10 +47,10 @@ function doSetVersion(version) { ...@@ -60,10 +47,10 @@ function doSetVersion(version) {
var setverreq = window.db.setVersion(String(version)); var setverreq = window.db.setVersion(String(version));
setverreq.onerror = unexpectedErrorCallback; setverreq.onerror = unexpectedErrorCallback;
setverreq.onblocked = function(e) { setverreq.onblocked = function(e) {
document.title = 'setVersion(' + version + ') blocked'; result('setVersion(' + version + ') blocked');
}; };
setverreq.onsuccess = function(e) { setverreq.onsuccess = function(e) {
document.title = 'setVersion(' + version + ') complete'; result('setVersion(' + version + ') complete');
}; };
}; };
} }
<html> <html>
<head> <head>
<title>IndexedDB regression test for bug 98562</title> <title>IndexedDB regression test for bug 98562</title>
<script type="text/javascript" src="shared.js"></script>
<script type="text/javascript" src="version_change_crash.js"></script> <script type="text/javascript" src="version_change_crash.js"></script>
</head> </head>
<body onLoad="test()"> <body onLoad="test()">
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
window.indexedDB = window.indexedDB || window.webkitIndexedDB; function test()
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
window.testResult = '';
function unexpectedErrorCallback()
{
document.title = 'fail - unexpected error callback';
}
function unexpectedAbortCallback()
{
document.title = 'fail - unexpected abort callback';
}
function unexpectedCompleteCallback()
{ {
document.title = 'fail - unexpected complete callback';
}
function test() {
if (document.location.hash === '#part1') { if (document.location.hash === '#part1') {
testPart1(); testPart1();
} else if (document.location.hash === '#part2') { } else if (document.location.hash === '#part2') {
...@@ -28,11 +11,12 @@ function test() { ...@@ -28,11 +11,12 @@ function test() {
} else if (document.location.hash === '#part3') { } else if (document.location.hash === '#part3') {
testPart3(); testPart3();
} else { } else {
document.title = 'fail'; result('fail - unexpected hash');
} }
} }
function testPart1() { function testPart1()
{
// Prepare the database, then exit normally // Prepare the database, then exit normally
// Set version 1, create store1 // Set version 1, create store1
...@@ -50,14 +34,15 @@ function testPart1() { ...@@ -50,14 +34,15 @@ function testPart1() {
db.createObjectStore('store1'); db.createObjectStore('store1');
transaction.onabort = unexpectedAbortCallback; transaction.onabort = unexpectedAbortCallback;
transaction.oncomplete = function (e) { transaction.oncomplete = function (e) {
document.title = 'pass - part1 - complete'; result('pass - part1 - complete');
}; };
}; };
}; };
}; };
} }
function testPart2() { function testPart2()
{
// Start a VERSION_CHANGE then crash // Start a VERSION_CHANGE then crash
// Set version 2, twiddle stores and crash // Set version 2, twiddle stores and crash
...@@ -73,7 +58,7 @@ function testPart2() { ...@@ -73,7 +58,7 @@ function testPart2() {
transaction.oncomplete = unexpectedCompleteCallback; transaction.oncomplete = unexpectedCompleteCallback;
var store = db.createObjectStore('store2'); var store = db.createObjectStore('store2');
document.title = 'pass - part2 - crash me'; result('pass - part2 - crash me');
// Keep adding to the transaction so it can't commit // Keep adding to the transaction so it can't commit
(function loop() { store.put(0, 0).onsuccess = loop; }()); (function loop() { store.put(0, 0).onsuccess = loop; }());
...@@ -81,7 +66,8 @@ function testPart2() { ...@@ -81,7 +66,8 @@ function testPart2() {
}; };
} }
function testPart3() { function testPart3()
{
// Validate that Part 2 never committed // Validate that Part 2 never committed
// Check version // Check version
...@@ -90,20 +76,20 @@ function testPart3() { ...@@ -90,20 +76,20 @@ function testPart3() {
openreq.onsuccess = function(e) { openreq.onsuccess = function(e) {
var db = openreq.result; var db = openreq.result;
if (db.version !== '1') { if (db.version !== '1') {
document.title = 'fail - version incorrect'; result('fail - version incorrect');
return; return;
} }
if (!db.objectStoreNames.contains('store1')) { if (!db.objectStoreNames.contains('store1')) {
document.title = 'fail - store1 does not exist'; result('fail - store1 does not exist');
return; return;
} }
if (db.objectStoreNames.contains('store2')) { if (db.objectStoreNames.contains('store2')) {
document.title = 'fail - store2 exists'; result('fail - store2 exists');
return; return;
} }
document.title = 'pass - part3 - rolled back'; result('pass - part3 - rolled back');
}; };
} }
...@@ -358,9 +358,6 @@ ...@@ -358,9 +358,6 @@
'-extensions.ExtensionsTest.testDisableEnableExtension', '-extensions.ExtensionsTest.testDisableEnableExtension',
# Need internal data dirs in autotest package. crosbug.com/6855 # Need internal data dirs in autotest package. crosbug.com/6855
'-find_in_page.FindMatchTests.testSearchInPDF', '-find_in_page.FindMatchTests.testSearchInPDF',
# crbug.com/123045
'-indexeddb.IndexedDBTest.testIndexedDBNullKeyPathPersistence',
'-indexeddb.IndexedDBTest.testVersionChangeCrashResilience',
# crosbug.com/24496 # crosbug.com/24496
'-infobars.InfobarTest.testPluginCrashForMultiTabs', '-infobars.InfobarTest.testPluginCrashForMultiTabs',
# crbug.com/109035 # crbug.com/109035
......
...@@ -11,50 +11,78 @@ import test_utils ...@@ -11,50 +11,78 @@ import test_utils
class IndexedDBTest(pyauto.PyUITest): class IndexedDBTest(pyauto.PyUITest):
"""Test of IndexedDB.""" """Test of IndexedDB."""
_SESSION_STARTUP_NTP = 5
def _GetInnerText(self, selector, tab_index=0):
"""Return the value of the innerText property of the target node.
The target node is identified by CSS selector, e.g. #id"""
expression = 'document.querySelector("' + selector + '").innerText'
return self.GetDOMValue(expression, tab_index=tab_index)
def _WaitForAndAssertResult(self, expected, tab_index=0):
"""Wait for the element with id="result" to exist, and verify the value."""
self.WaitForDomNode('id("result")', tab_index=tab_index)
self.assertEqual(self._GetInnerText('#result', tab_index=tab_index),
expected)
def _ClearResult(self, tab_index=0):
"""Delete the element with id="result" if it exists."""
expression = """(function() {
var e = document.querySelector('#result');
if (e)
e.parentNode.removeChild(e);
return 'ok';
}())"""
self.assertEqual(self.GetDOMValue(expression, tab_index=tab_index), 'ok')
def _AssertNewTabPage(self):
"""Assert that the current tab is the new tab page, not a restored tab."""
self.assertEqual(self.GetBrowserInfo()['windows'][0]['tabs'][0]['url'],
'chrome://newtab/')
def testIndexedDBNullKeyPathPersistence(self): def testIndexedDBNullKeyPathPersistence(self):
"""Verify null key path persists after restarting browser.""" """Verify null key path persists after restarting browser."""
# Don't restore tabs after restart
self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP)
url = self.GetHttpURLForDataPath('indexeddb', 'bug_90635.html') url = self.GetHttpURLForDataPath('indexeddb', 'bug_90635.html')
self.NavigateToURL(url + '#part1') self.NavigateToURL(url + '#part1')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self._WaitForAndAssertResult('pass - first run')
expect_retval='pass - first run'),
msg='Key paths had unexpected values')
self.RestartBrowser(clear_profile=False) self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part2') self.NavigateToURL(url + '#part2')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self._WaitForAndAssertResult('pass - second run')
expect_retval='pass - second run'),
msg='Key paths had unexpected values')
def testVersionChangeCrashResilience(self): def testVersionChangeCrashResilience(self):
"""Verify that a VERSION_CHANGE transaction is rolled back """Verify that a VERSION_CHANGE transaction is rolled back
after a renderer/browser crash""" after a renderer/browser crash"""
# Don't restore tabs after restart
self.SetPrefs(pyauto.kRestoreOnStartup, self._SESSION_STARTUP_NTP)
url = self.GetHttpURLForDataPath('indexeddb', 'version_change_crash.html') url = self.GetHttpURLForDataPath('indexeddb', 'version_change_crash.html')
self.NavigateToURL(url + '#part1') self.NavigateToURL(url + '#part1')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self._WaitForAndAssertResult('pass - part1 - complete')
expect_retval='pass - part1 - complete'),
msg='Failed to prepare database')
self.RestartBrowser(clear_profile=False) self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part2') self.NavigateToURL(url + '#part2')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self._WaitForAndAssertResult('pass - part2 - crash me')
expect_retval='pass - part2 - crash me'),
msg='Failed to start transaction')
test_utils.CrashBrowser(self) test_utils.CrashBrowser(self)
self.RestartBrowser(clear_profile=False) self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part3') self.NavigateToURL(url + '#part3')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self._WaitForAndAssertResult('pass - part3 - rolled back')
expect_retval='pass - part3 - rolled back'),
msg='VERSION_CHANGE not completely aborted')
def testConnectionsClosedOnTabClose(self): def testConnectionsClosedOnTabClose(self):
"""Verify that open DB connections are closed when a tab is destroyed.""" """Verify that open DB connections are closed when a tab is destroyed."""
...@@ -63,20 +91,19 @@ class IndexedDBTest(pyauto.PyUITest): ...@@ -63,20 +91,19 @@ class IndexedDBTest(pyauto.PyUITest):
self.NavigateToURL(url + '#tab1') self.NavigateToURL(url + '#tab1')
pid = self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid'] pid = self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self._WaitForAndAssertResult('setVersion(1) complete')
expect_retval='setVersion(1) complete'),
msg='Version change failed')
# Start to a different URL to force a new renderer process # Start on a different URL to force a new renderer process.
self.AppendTab(pyauto.GURL('about:blank')) self.AppendTab(pyauto.GURL('about:blank'))
self.NavigateToURL(url + '#tab2') self.NavigateToURL(url + '#tab2')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self._WaitForAndAssertResult('setVersion(2) blocked', tab_index=1)
expect_retval='setVersion(2) blocked'), self._ClearResult(tab_index=1)
msg='Version change not blocked as expected')
self.KillRendererProcess(pid) self.KillRendererProcess(pid)
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle, self.assertEqual(self.GetTabCount(), 2)
expect_retval='setVersion(2) complete'), self.GetBrowserWindow(0).GetTab(0).Close(True)
msg='Version change never unblocked')
self._WaitForAndAssertResult('setVersion(2) complete')
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment