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>
<head>
<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>
</head>
<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
// 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()
{
if (document.location.hash === '#part1') {
......@@ -21,7 +9,7 @@ function test()
} else if (document.location.hash === '#part2') {
testPart2();
} else {
document.title = 'fail - no hash';
result('fail - unexpected hash');
}
}
......@@ -72,8 +60,8 @@ function test_store(db, msg) {
if (store1.keyPath !== null ||
store2.keyPath !== '' ||
store3.keyPath !== 'some_path') {
document.title = 'fail - ' + msg;
result('fail - ' + msg);
} 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>
<head>
<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>
</head>
<body onLoad="test()">
......
......@@ -2,34 +2,20 @@
// 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;
function unexpectedErrorCallback()
{
document.title = 'fail - unexpected error callback';
}
function unexpectedAbortCallback()
{
document.title = 'fail - unexpected abort callback';
}
function unexpectedCompleteCallback()
function test()
{
document.title = 'fail - unexpected complete callback';
}
function test() {
if (document.location.hash === '#tab1') {
prepareDatabase(0, function () { doSetVersion(1); });
} else if (document.location.hash === '#tab2') {
doSetVersion(2);
} else {
document.title = 'fail';
result('fail - unexpected hash');
}
}
function prepareDatabase(version, callback) {
function prepareDatabase(version, callback)
{
// Prepare the database, then exit normally
var delreq = window.indexedDB.deleteDatabase('version-change-blocked');
delreq.onerror = unexpectedErrorCallback;
delreq.onsuccess = function() {
......@@ -51,7 +37,8 @@ function prepareDatabase(version, callback) {
};
}
function doSetVersion(version) {
function doSetVersion(version)
{
// Open the database and try a setVersion
var openreq = window.indexedDB.open('version-change-blocked');
openreq.onerror = unexpectedErrorCallback;
......@@ -60,10 +47,10 @@ function doSetVersion(version) {
var setverreq = window.db.setVersion(String(version));
setverreq.onerror = unexpectedErrorCallback;
setverreq.onblocked = function(e) {
document.title = 'setVersion(' + version + ') blocked';
result('setVersion(' + version + ') blocked');
};
setverreq.onsuccess = function(e) {
document.title = 'setVersion(' + version + ') complete';
result('setVersion(' + version + ') complete');
};
};
}
<html>
<head>
<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>
</head>
<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
// found in the LICENSE file.
window.indexedDB = window.indexedDB || window.webkitIndexedDB;
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()
function test()
{
document.title = 'fail - unexpected complete callback';
}
function test() {
if (document.location.hash === '#part1') {
testPart1();
} else if (document.location.hash === '#part2') {
......@@ -28,11 +11,12 @@ function test() {
} else if (document.location.hash === '#part3') {
testPart3();
} else {
document.title = 'fail';
result('fail - unexpected hash');
}
}
function testPart1() {
function testPart1()
{
// Prepare the database, then exit normally
// Set version 1, create store1
......@@ -50,14 +34,15 @@ function testPart1() {
db.createObjectStore('store1');
transaction.onabort = unexpectedAbortCallback;
transaction.oncomplete = function (e) {
document.title = 'pass - part1 - complete';
result('pass - part1 - complete');
};
};
};
};
}
function testPart2() {
function testPart2()
{
// Start a VERSION_CHANGE then crash
// Set version 2, twiddle stores and crash
......@@ -73,7 +58,7 @@ function testPart2() {
transaction.oncomplete = unexpectedCompleteCallback;
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
(function loop() { store.put(0, 0).onsuccess = loop; }());
......@@ -81,7 +66,8 @@ function testPart2() {
};
}
function testPart3() {
function testPart3()
{
// Validate that Part 2 never committed
// Check version
......@@ -90,20 +76,20 @@ function testPart3() {
openreq.onsuccess = function(e) {
var db = openreq.result;
if (db.version !== '1') {
document.title = 'fail - version incorrect';
result('fail - version incorrect');
return;
}
if (!db.objectStoreNames.contains('store1')) {
document.title = 'fail - store1 does not exist';
result('fail - store1 does not exist');
return;
}
if (db.objectStoreNames.contains('store2')) {
document.title = 'fail - store2 exists';
result('fail - store2 exists');
return;
}
document.title = 'pass - part3 - rolled back';
result('pass - part3 - rolled back');
};
}
......@@ -358,9 +358,6 @@
'-extensions.ExtensionsTest.testDisableEnableExtension',
# Need internal data dirs in autotest package. crosbug.com/6855
'-find_in_page.FindMatchTests.testSearchInPDF',
# crbug.com/123045
'-indexeddb.IndexedDBTest.testIndexedDBNullKeyPathPersistence',
'-indexeddb.IndexedDBTest.testVersionChangeCrashResilience',
# crosbug.com/24496
'-infobars.InfobarTest.testPluginCrashForMultiTabs',
# crbug.com/109035
......
......@@ -11,50 +11,78 @@ import test_utils
class IndexedDBTest(pyauto.PyUITest):
"""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):
"""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')
self.NavigateToURL(url + '#part1')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='pass - first run'),
msg='Key paths had unexpected values')
self._WaitForAndAssertResult('pass - first run')
self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part2')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='pass - second run'),
msg='Key paths had unexpected values')
self._WaitForAndAssertResult('pass - second run')
def testVersionChangeCrashResilience(self):
"""Verify that a VERSION_CHANGE transaction is rolled back
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')
self.NavigateToURL(url + '#part1')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='pass - part1 - complete'),
msg='Failed to prepare database')
self._WaitForAndAssertResult('pass - part1 - complete')
self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part2')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='pass - part2 - crash me'),
msg='Failed to start transaction')
self._WaitForAndAssertResult('pass - part2 - crash me')
test_utils.CrashBrowser(self)
self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part3')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='pass - part3 - rolled back'),
msg='VERSION_CHANGE not completely aborted')
self._WaitForAndAssertResult('pass - part3 - rolled back')
def testConnectionsClosedOnTabClose(self):
"""Verify that open DB connections are closed when a tab is destroyed."""
......@@ -63,20 +91,19 @@ class IndexedDBTest(pyauto.PyUITest):
self.NavigateToURL(url + '#tab1')
pid = self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='setVersion(1) complete'),
msg='Version change failed')
self._WaitForAndAssertResult('setVersion(1) complete')
# 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.NavigateToURL(url + '#tab2')
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='setVersion(2) blocked'),
msg='Version change not blocked as expected')
self._WaitForAndAssertResult('setVersion(2) blocked', tab_index=1)
self._ClearResult(tab_index=1)
self.KillRendererProcess(pid)
self.assertTrue(self.WaitUntil(self.GetActiveTabTitle,
expect_retval='setVersion(2) complete'),
msg='Version change never unblocked')
self.assertEqual(self.GetTabCount(), 2)
self.GetBrowserWindow(0).GetTab(0).Close(True)
self._WaitForAndAssertResult('setVersion(2) complete')
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