Commit 8d57530e authored by jam@chromium.org's avatar jam@chromium.org

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
parent 15dfc58b
......@@ -55,7 +55,6 @@
'https',
'gtalk.test_basic',
'imports',
'indexeddb',
'infobars',
'instant',
'multiprofile',
......@@ -872,7 +871,6 @@
'-policy_prefs_ui.PolicyPrefsUITest.testNoUserPoliciesNoBanner',
'-policy_prefs_ui.PolicyPrefsUITest.testToggleUserPolicyTogglesBanner',
'-policy_prefs_ui.PolicyPrefsUITest.testUserPoliciesShowBanner',
'-indexeddb.IndexedDBTest.testVersionChangeCrashResilience',
'-popups.PopupsTest.testMultiplePopups',
'-popups.PopupsTest.testPopupBlockedEverySec',
'-search_engines.SearchEnginesTest.testDiscoverSearchEngine',
......
#!/usr/bin/env python
# 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.
import pyauto_functional
import pyauto
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._WaitForAndAssertResult('pass - first run')
self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part2')
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._WaitForAndAssertResult('pass - part1 - complete')
self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part2')
self._WaitForAndAssertResult('pass - part2 - crash me')
test_utils.CrashBrowser(self)
self.RestartBrowser(clear_profile=False)
self._AssertNewTabPage()
self.NavigateToURL(url + '#part3')
self._WaitForAndAssertResult('pass - part3 - rolled back')
def testConnectionsClosedOnTabClose(self):
"""Verify that open DB connections are closed when a tab is destroyed."""
url = self.GetHttpURLForDataPath('indexeddb', 'version_change_blocked.html')
self.NavigateToURL(url + '#tab1')
pid = self.GetBrowserInfo()['windows'][0]['tabs'][0]['renderer_pid']
self._WaitForAndAssertResult('setVersion(1) complete')
# Start on a different URL to force a new renderer process.
self.AppendTab(pyauto.GURL('about:blank'))
self.NavigateToURL(url + '#tab2')
self._WaitForAndAssertResult('setVersion(2) blocked', tab_index=1)
self._ClearResult(tab_index=1)
self.KillRendererProcess(pid)
self.assertEqual(self.GetTabCount(), 2)
self.CloseTab()
self._WaitForAndAssertResult('setVersion(2) complete')
if __name__ == '__main__':
pyauto_functional.Main()
......@@ -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
......@@ -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();
}
......
......@@ -5,10 +5,7 @@
window.indexedDB = window.indexedDB || window.webkitIndexedDB;
function result(message) {
var div = document.createElement('div');
div.id = "result";
div.innerText = message;
document.body.appendChild(div);
document.title = message;
}
function unexpectedErrorCallback()
......
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