summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-20 19:43:58 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-20 19:43:58 +0000
commit8d57530e93957816266364782774635bc85aae99 (patch)
treebb825cef1d16c13c4d94c2c4270aa1509a84b9b2 /content
parent15dfc58b7d494dcf91885c3f39bf71ae0db66aba (diff)
downloadchromium_src-8d57530e93957816266364782774635bc85aae99.zip
chromium_src-8d57530e93957816266364782774635bc85aae99.tar.gz
chromium_src-8d57530e93957816266364782774635bc85aae99.tar.bz2
Convert the indexed db pyauto tests to content_browsertests.
BUG=140919,143637 Review URL: https://chromiumcodereview.appspot.com/10828378 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152373 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/in_process_webkit/indexed_db_browsertest.cc70
-rw-r--r--content/shell/shell.cc3
-rw-r--r--content/test/data/indexeddb/bug_90635.html11
-rw-r--r--content/test/data/indexeddb/bug_90635.js66
-rw-r--r--content/test/data/indexeddb/shared.js24
-rw-r--r--content/test/data/indexeddb/version_change_blocked.html11
-rw-r--r--content/test/data/indexeddb/version_change_blocked.js56
-rw-r--r--content/test/data/indexeddb/version_change_crash.html11
-rw-r--r--content/test/data/indexeddb/version_change_crash.js95
9 files changed, 346 insertions, 1 deletions
diff --git a/content/browser/in_process_webkit/indexed_db_browsertest.cc b/content/browser/in_process_webkit/indexed_db_browsertest.cc
index ca0f05f..c1b0d3d 100644
--- a/content/browser/in_process_webkit/indexed_db_browsertest.cc
+++ b/content/browser/in_process_webkit/indexed_db_browsertest.cc
@@ -8,6 +8,7 @@
#include "base/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
+#include "base/process_util.h"
#include "base/scoped_temp_dir.h"
#include "base/test/thread_test_helper.h"
#include "base/utf_string_conversions.h"
@@ -15,8 +16,11 @@
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_contents.h"
#include "content/public/common/content_paths.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
#include "content/shell/shell.h"
#include "content/test/content_browser_test.h"
@@ -55,6 +59,20 @@ class IndexedDBBrowserTest : public ContentBrowserTest {
FAIL() << "Failed: " << js_result;
}
}
+
+ void NavigateAndWaitForTitle(Shell* shell,
+ const char* filename,
+ const char* hash,
+ const char* expected_string) {
+ GURL url = GetTestUrl("indexeddb", filename);
+ if (hash)
+ url = GURL(url.spec() + hash);
+
+ string16 expected_title16(ASCIIToUTF16(expected_string));
+ TitleWatcher title_watcher(shell->web_contents(), expected_title16);
+ NavigateToURL(shell, url);
+ EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
+ }
};
IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, CursorTest) {
@@ -215,4 +233,56 @@ IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTestWithVersion0Schema, MigrationTest) {
SimpleTest(GetTestUrl("indexeddb", "migration_test.html"));
}
+// Verify null key path persists after restarting browser.
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, PRE_NullKeyPathPersistence) {
+ NavigateAndWaitForTitle(shell(), "bug_90635.html", "#part1",
+ "pass - first run");
+}
+
+// Verify null key path persists after restarting browser.
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, NullKeyPathPersistence) {
+ NavigateAndWaitForTitle(shell(), "bug_90635.html", "#part2",
+ "pass - second run");
+}
+
+// Verify that a VERSION_CHANGE transaction is rolled back after a
+// renderer/browser crash
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest,
+ PRE_PRE_VersionChangeCrashResilience) {
+ NavigateAndWaitForTitle(shell(), "version_change_crash.html", "#part1",
+ "pass - part1 - complete");
+}
+
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, PRE_VersionChangeCrashResilience) {
+ NavigateAndWaitForTitle(shell(), "version_change_crash.html", "#part2",
+ "pass - part2 - crash me");
+ NavigateToURL(shell(), GURL(chrome::kChromeUIBrowserCrashHost));
+}
+
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, VersionChangeCrashResilience) {
+ NavigateAndWaitForTitle(shell(), "version_change_crash.html", "#part3",
+ "pass - part3 - rolled back");
+}
+
+// Verify that open DB connections are closed when a tab is destroyed.
+IN_PROC_BROWSER_TEST_F(IndexedDBBrowserTest, ConnectionsClosedOnTabClose) {
+ NavigateAndWaitForTitle(shell(), "version_change_blocked.html", "#tab1",
+ "setVersion(1) complete");
+
+ // Start on a different URL to force a new renderer process.
+ Shell* new_shell = CreateBrowser();
+ NavigateToURL(new_shell, GURL(chrome::kAboutBlankURL));
+ NavigateAndWaitForTitle(new_shell, "version_change_blocked.html", "#tab2",
+ "setVersion(2) blocked");
+
+ string16 expected_title16(ASCIIToUTF16("setVersion(2) complete"));
+ TitleWatcher title_watcher(new_shell->web_contents(), expected_title16);
+
+ base::KillProcess(
+ shell()->web_contents()->GetRenderProcessHost()->GetHandle(), 0, true);
+ shell()->Close();
+
+ EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
+}
+
} // namespace content
diff --git a/content/shell/shell.cc b/content/shell/shell.cc
index ea0ce4d..52f2346 100644
--- a/content/shell/shell.cc
+++ b/content/shell/shell.cc
@@ -126,7 +126,8 @@ void Shell::LoadURL(const GURL& url) {
web_contents_->GetController().LoadURL(
url,
Referrer(),
- PAGE_TRANSITION_TYPED,
+ static_cast<PageTransition>(
+ PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR),
std::string());
web_contents_->Focus();
}
diff --git a/content/test/data/indexeddb/bug_90635.html b/content/test/data/indexeddb/bug_90635.html
new file mode 100644
index 0000000..eaffe72
--- /dev/null
+++ b/content/test/data/indexeddb/bug_90635.html
@@ -0,0 +1,11 @@
+<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()">
+ <div id="status">Starting...</div>
+ </body>
+</html>
+
diff --git a/content/test/data/indexeddb/bug_90635.js b/content/test/data/indexeddb/bug_90635.js
new file mode 100644
index 0000000..a208cb8
--- /dev/null
+++ b/content/test/data/indexeddb/bug_90635.js
@@ -0,0 +1,66 @@
+// 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.
+
+function test()
+{
+ if (document.location.hash === '#part1') {
+ testPart1();
+ } else if (document.location.hash === '#part2') {
+ testPart2();
+ } else {
+ result('fail - unexpected hash');
+ }
+}
+
+function testPart1()
+{
+ var delreq = window.indexedDB.deleteDatabase('bug90635');
+ delreq.onerror = unexpectedErrorCallback;
+ delreq.onsuccess = function() {
+ var openreq = window.indexedDB.open('bug90635');
+ openreq.onerror = unexpectedErrorCallback;
+ openreq.onsuccess = function(e) {
+ var db = openreq.result;
+ var setverreq = db.setVersion('1');
+ setverreq.onerror = unexpectedErrorCallback;
+ setverreq.onsuccess = function(e) {
+ var transaction = setverreq.result;
+
+ db.createObjectStore('store1');
+ db.createObjectStore('store2', {keyPath: ''});
+ db.createObjectStore('store3', {keyPath: 'some_path'});
+
+ transaction.onabort = unexpectedAbortCallback;
+ transaction.oncomplete = function() {
+ test_store(db, 'first run');
+ };
+ };
+ };
+ };
+}
+
+function testPart2()
+{
+ var openreq = window.indexedDB.open('bug90635');
+ openreq.onerror = unexpectedErrorCallback;
+ openreq.onsuccess = function(e) {
+ var db = openreq.result;
+ test_store(db, 'second run');
+ };
+}
+
+function test_store(db, msg) {
+ var transaction = db.transaction(['store1', 'store2', 'store3'], 'readonly');
+ var store1 = transaction.objectStore('store1');
+ var store2 = transaction.objectStore('store2');
+ var store3 = transaction.objectStore('store3');
+
+ if (store1.keyPath !== null ||
+ store2.keyPath !== '' ||
+ store3.keyPath !== 'some_path') {
+ result('fail - ' + msg);
+ } else {
+ result('pass - ' + msg);
+ }
+}
diff --git a/content/test/data/indexeddb/shared.js b/content/test/data/indexeddb/shared.js
new file mode 100644
index 0000000..9442623
--- /dev/null
+++ b/content/test/data/indexeddb/shared.js
@@ -0,0 +1,24 @@
+// 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;
+
+function result(message) {
+ document.title = message;
+}
+
+function unexpectedErrorCallback()
+{
+ result('fail - unexpected error callback');
+}
+
+function unexpectedAbortCallback()
+{
+ result('fail - unexpected abort callback');
+}
+
+function unexpectedCompleteCallback()
+{
+ result('fail - unexpected complete callback');
+}
diff --git a/content/test/data/indexeddb/version_change_blocked.html b/content/test/data/indexeddb/version_change_blocked.html
new file mode 100644
index 0000000..8802ae8
--- /dev/null
+++ b/content/test/data/indexeddb/version_change_blocked.html
@@ -0,0 +1,11 @@
+<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()">
+ <div id="status">Starting...</div>
+ </body>
+</html>
+
diff --git a/content/test/data/indexeddb/version_change_blocked.js b/content/test/data/indexeddb/version_change_blocked.js
new file mode 100644
index 0000000..17048b3
--- /dev/null
+++ b/content/test/data/indexeddb/version_change_blocked.js
@@ -0,0 +1,56 @@
+// 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.
+
+function test()
+{
+ if (document.location.hash === '#tab1') {
+ prepareDatabase(0, function () { doSetVersion(1); });
+ } else if (document.location.hash === '#tab2') {
+ doSetVersion(2);
+ } else {
+ result('fail - unexpected hash');
+ }
+}
+
+function prepareDatabase(version, callback)
+{
+ // Prepare the database, then exit normally
+ var delreq = window.indexedDB.deleteDatabase('version-change-blocked');
+ delreq.onerror = unexpectedErrorCallback;
+ delreq.onsuccess = function() {
+ var openreq = window.indexedDB.open('version-change-blocked');
+ openreq.onerror = unexpectedErrorCallback;
+ openreq.onsuccess = function(e) {
+ var db = openreq.result;
+ var setverreq = db.setVersion(String(version));
+ setverreq.onerror = unexpectedErrorCallback;
+ setverreq.onsuccess = function(e) {
+ var transaction = setverreq.result;
+ transaction.onabort = unexpectedAbortCallback;
+ transaction.oncomplete = function (e) {
+ db.close();
+ callback();
+ };
+ };
+ };
+ };
+}
+
+function doSetVersion(version)
+{
+ // Open the database and try a setVersion
+ var openreq = window.indexedDB.open('version-change-blocked');
+ openreq.onerror = unexpectedErrorCallback;
+ openreq.onsuccess = function(e) {
+ window.db = openreq.result;
+ var setverreq = window.db.setVersion(String(version));
+ setverreq.onerror = unexpectedErrorCallback;
+ setverreq.onblocked = function(e) {
+ result('setVersion(' + version + ') blocked');
+ };
+ setverreq.onsuccess = function(e) {
+ result('setVersion(' + version + ') complete');
+ };
+ };
+}
diff --git a/content/test/data/indexeddb/version_change_crash.html b/content/test/data/indexeddb/version_change_crash.html
new file mode 100644
index 0000000..fa0e4df
--- /dev/null
+++ b/content/test/data/indexeddb/version_change_crash.html
@@ -0,0 +1,11 @@
+<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()">
+ <div id="status">Starting...</div>
+ </body>
+</html>
+
diff --git a/content/test/data/indexeddb/version_change_crash.js b/content/test/data/indexeddb/version_change_crash.js
new file mode 100644
index 0000000..3833c98
--- /dev/null
+++ b/content/test/data/indexeddb/version_change_crash.js
@@ -0,0 +1,95 @@
+// 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.
+
+function test()
+{
+ if (document.location.hash === '#part1') {
+ testPart1();
+ } else if (document.location.hash === '#part2') {
+ testPart2();
+ } else if (document.location.hash === '#part3') {
+ testPart3();
+ } else {
+ result('fail - unexpected hash');
+ }
+}
+
+function testPart1()
+{
+ // Prepare the database, then exit normally
+
+ // Set version 1, create store1
+ var delreq = window.indexedDB.deleteDatabase('version-change-crash');
+ delreq.onerror = unexpectedErrorCallback;
+ delreq.onsuccess = function() {
+ var openreq = window.indexedDB.open('version-change-crash');
+ openreq.onerror = unexpectedErrorCallback;
+ openreq.onsuccess = function(e) {
+ var db = openreq.result;
+ var setverreq = db.setVersion('1');
+ setverreq.onerror = unexpectedErrorCallback;
+ setverreq.onsuccess = function(e) {
+ var transaction = setverreq.result;
+ db.createObjectStore('store1');
+ transaction.onabort = unexpectedAbortCallback;
+ transaction.oncomplete = function (e) {
+ result('pass - part1 - complete');
+ };
+ };
+ };
+ };
+}
+
+function testPart2()
+{
+ // Start a VERSION_CHANGE then crash
+
+ // Set version 2, twiddle stores and crash
+ var openreq = window.indexedDB.open('version-change-crash');
+ openreq.onerror = unexpectedErrorCallback;
+ openreq.onsuccess = function(e) {
+ var db = openreq.result;
+ var setverreq = db.setVersion('2');
+ setverreq.onerror = unexpectedErrorCallback;
+ setverreq.onsuccess = function(e) {
+ var transaction = setverreq.result;
+ transaction.onabort = unexpectedAbortCallback;
+ transaction.oncomplete = unexpectedCompleteCallback;
+
+ var store = db.createObjectStore('store2');
+ result('pass - part2 - crash me');
+
+ // Keep adding to the transaction so it can't commit
+ (function loop() { store.put(0, 0).onsuccess = loop; }());
+ };
+ };
+}
+
+function testPart3()
+{
+ // Validate that Part 2 never committed
+
+ // Check version
+ var openreq = window.indexedDB.open('version-change-crash');
+ openreq.onerror = unexpectedErrorCallback;
+ openreq.onsuccess = function(e) {
+ var db = openreq.result;
+ if (db.version !== '1') {
+ result('fail - version incorrect');
+ return;
+ }
+
+ if (!db.objectStoreNames.contains('store1')) {
+ result('fail - store1 does not exist');
+ return;
+ }
+
+ if (db.objectStoreNames.contains('store2')) {
+ result('fail - store2 exists');
+ return;
+ }
+
+ result('pass - part3 - rolled back');
+ };
+}