summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 20:43:53 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 20:43:53 +0000
commit3a4f703d736db716a5279b821574dcedd170509c (patch)
tree8699fb7a08eac8afde6fcf6ab87b7a308b7a8c1a
parent8f327a0086540250d2af9454c2138bbe514a3aea (diff)
downloadchromium_src-3a4f703d736db716a5279b821574dcedd170509c.zip
chromium_src-3a4f703d736db716a5279b821574dcedd170509c.tar.gz
chromium_src-3a4f703d736db716a5279b821574dcedd170509c.tar.bz2
Convert crash recovery tests to browser test framework, which should reduce flakiness.
TEST=none http://crbug.com/16054 Review URL: http://codereview.chromium.org/149235 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20182 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/crash_recovery_browsertest.cc97
-rw-r--r--chrome/browser/crash_recovery_uitest.cc88
-rw-r--r--chrome/chrome.gyp3
-rw-r--r--chrome/test/ui_test_utils.cc23
-rw-r--r--chrome/test/ui_test_utils.h8
5 files changed, 128 insertions, 91 deletions
diff --git a/chrome/browser/crash_recovery_browsertest.cc b/chrome/browser/crash_recovery_browsertest.cc
new file mode 100644
index 0000000..1a61b15
--- /dev/null
+++ b/chrome/browser/crash_recovery_browsertest.cc
@@ -0,0 +1,97 @@
+// Copyright (c) 2009 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.
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/tab_contents/navigation_entry.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/notification_registrar.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/page_transition_types.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/glue/window_open_disposition.h"
+
+namespace {
+
+// Used to block until a navigation completes.
+class RendererCrashObserver : public NotificationObserver {
+ public:
+ RendererCrashObserver() {}
+
+ void WaitForRendererCrash() {
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
+ NotificationService::AllSources());
+ ui_test_utils::RunMessageLoop();
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::TAB_CONTENTS_DISCONNECTED) {
+ registrar_.Remove(this, NotificationType::TAB_CONTENTS_DISCONNECTED,
+ NotificationService::AllSources());
+ MessageLoopForUI::current()->Quit();
+ } else {
+ NOTREACHED();
+ }
+ }
+
+ private:
+ NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(RendererCrashObserver);
+};
+
+void SimulateRendererCrash(Browser* browser) {
+ browser->OpenURL(GURL("about:crash"), GURL(), CURRENT_TAB,
+ PageTransition::TYPED);
+ RendererCrashObserver crash_observer;
+ crash_observer.WaitForRendererCrash();
+
+}
+
+} // namespace
+
+class CrashRecoveryBrowserTest : public InProcessBrowserTest {
+};
+
+// Test that reload works after a crash.
+IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) {
+ // The title of the active tab should change each time this URL is loaded.
+ GURL url(
+ "data:text/html,<script>document.title=new Date().valueOf()</script>");
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ string16 title_before_crash;
+ string16 title_after_crash;
+
+ ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
+ &title_before_crash));
+ SimulateRendererCrash(browser());
+ ASSERT_TRUE(ui_test_utils::ReloadCurrentTab(browser()));
+ ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
+ &title_after_crash));
+ EXPECT_NE(title_before_crash, title_after_crash);
+}
+
+// Tests that loading a crashed page in a new tab correctly updates the title.
+// There was an earlier bug (1270510) in process-per-site in which the max page
+// ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab
+// was not committed. This prevents regression of that bug.
+IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) {
+ ui_test_utils::NavigateToURL(browser(),
+ ui_test_utils::GetTestUrl(L".", L"title2.html"));
+
+ string16 title_before_crash;
+ string16 title_after_crash;
+
+ ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
+ &title_before_crash));
+ SimulateRendererCrash(browser());
+ ASSERT_TRUE(ui_test_utils::ReloadCurrentTab(browser()));
+ ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
+ &title_after_crash));
+ EXPECT_EQ(title_before_crash, title_after_crash);
+}
diff --git a/chrome/browser/crash_recovery_uitest.cc b/chrome/browser/crash_recovery_uitest.cc
deleted file mode 100644
index e016156..0000000
--- a/chrome/browser/crash_recovery_uitest.cc
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright (c) 2006-2008 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.
-
-#include "base/file_path.h"
-#include "base/platform_thread.h"
-#include "chrome/test/automation/browser_proxy.h"
-#include "chrome/test/automation/tab_proxy.h"
-#include "chrome/test/ui/ui_test.h"
-#include "net/base/net_util.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-typedef UITest CrashRecoveryUITest;
-
-TEST_F(CrashRecoveryUITest, Reload) {
- // Test that reload works after a crash.
-
- // This test only works in multi-process mode
- if (in_process_renderer())
- return;
-
- // The title of the active tab should change each time this URL is loaded.
- GURL url(
- "data:text/html,<script>document.title=new Date().valueOf()</script>");
-
- NavigateToURL(url);
-
- std::wstring title1 = GetActiveTabTitle();
-
- scoped_refptr<TabProxy> tab(GetActiveTab());
- ASSERT_TRUE(tab.get());
-
- // Cause the renderer to crash.
- // TODO: Need to port crash_service.exe.
-#if defined(OS_WIN)
- expected_crashes_ = 1;
-#endif
- tab->NavigateToURLAsync(GURL("about:crash"));
-
- // Wait for the browser to notice the renderer crash.
- PlatformThread::Sleep(1000);
-
- tab->Reload();
-
- std::wstring title2 = GetActiveTabTitle();
- EXPECT_NE(title1, title2);
-}
-
-// Tests that loading a crashed page in a new tab correctly updates the title.
-// There was an earlier bug (1270510) in process-per-site in which the max page
-// ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab
-// was not committed. This prevents regression of that bug.
-TEST_F(CrashRecoveryUITest, LoadInNewTab) {
- // This test only works in multi-process mode
- if (in_process_renderer())
- return;
-
- // The title of the active tab should change each time this URL is loaded.
- FilePath test_file(test_data_directory_);
- test_file = test_file.AppendASCII("title2.html");
- GURL url(net::FilePathToFileURL(test_file));
-
- NavigateToURL(url);
-
- const std::wstring title(L"Title Of Awesomeness");
- EXPECT_EQ(title, GetActiveTabTitle());
-
- scoped_refptr<TabProxy> tab(GetActiveTab());
- ASSERT_TRUE(tab.get());
-
- // Cause the renderer to crash.
- // TODO: Need to port crash_service.exe.
-#if defined(OS_WIN)
- expected_crashes_ = 1;
-#endif
-
- tab->NavigateToURLAsync(GURL("about:crash"));
-
- // Wait for the browser to notice the renderer crash.
- PlatformThread::Sleep(1000);
-
- scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
- ASSERT_TRUE(browser_proxy->AppendTab(url));
-
- // Ensure the title of the new tab is updated, indicating that the navigation
- // entry was properly committed.
- EXPECT_EQ(title, GetActiveTabTitle());
-}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 5e86d99..b554d24 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -20,6 +20,7 @@
],
'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/chrome',
'browser_tests_sources': [
+ 'browser/crash_recovery_browsertest.cc',
'browser/ssl/ssl_browser_tests.cc',
],
'browser_tests_sources_win_specific': [
@@ -3235,7 +3236,6 @@
'sources': [
'app/chrome_main_uitest.cc',
'browser/browser_uitest.cc',
- 'browser/crash_recovery_uitest.cc',
'browser/download/download_uitest.cc',
'browser/download/save_page_uitest.cc',
'browser/errorpage_uitest.cc',
@@ -3309,7 +3309,6 @@
'sources!': [
# TODO(port)
'app/chrome_main_uitest.cc',
- 'browser/crash_recovery_uitest.cc',
'browser/login_prompt_uitest.cc',
'browser/metrics/metrics_service_uitest.cc',
# leaves an extra window on screen after test completes.
diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc
index ac55380..4f65c35 100644
--- a/chrome/test/ui_test_utils.cc
+++ b/chrome/test/ui_test_utils.cc
@@ -12,6 +12,7 @@
#include "chrome/browser/dom_operation_notification_details.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
+#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/notification_registrar.h"
@@ -120,7 +121,7 @@ class DownloadsCompleteObserver : public DownloadManager::Observer,
// CheckAllDownloadsComplete will be called when the DownloadManager
// fires it's ModelChanged() call, and also when incomplete downloads
- // fire their OnDownloadUpdated().
+ // fire their OnDownloadUpdated().
bool CheckAllDownloadsComplete() {
if (downloads_.size() < wait_count_)
return false;
@@ -208,6 +209,17 @@ void RunMessageLoop() {
loop->SetNestableTasksAllowed(did_allow_task_nesting);
}
+bool GetCurrentTabTitle(const Browser* browser, string16* title) {
+ TabContents* tab_contents = browser->GetSelectedTabContents();
+ if (!tab_contents)
+ return false;
+ NavigationEntry* last_entry = tab_contents->controller().GetActiveEntry();
+ if (!last_entry)
+ return false;
+ title->assign(last_entry->title());
+ return true;
+}
+
void WaitForNavigation(NavigationController* controller) {
WaitForNavigations(controller, 1);
}
@@ -230,6 +242,15 @@ void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,
WaitForNavigations(controller, number_of_navigations);
}
+bool ReloadCurrentTab(Browser* browser) {
+ browser->Reload();
+ TabContents* tab_contents = browser->GetSelectedTabContents();
+ if (!tab_contents)
+ return false;
+ WaitForNavigation(&tab_contents->controller());
+ return true;
+}
+
Value* ExecuteJavaScript(RenderViewHost* render_view_host,
const std::wstring& frame_xpath,
const std::wstring& original_script) {
diff --git a/chrome/test/ui_test_utils.h b/chrome/test/ui_test_utils.h
index bdae24c..34c8545 100644
--- a/chrome/test/ui_test_utils.h
+++ b/chrome/test/ui_test_utils.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/string16.h"
#include "chrome/common/notification_observer.h"
class Browser;
@@ -25,6 +26,9 @@ namespace ui_test_utils {
// process browser tests that need to block until a condition is met.
void RunMessageLoop();
+// Puts the current tab title in |title|. Returns true on success.
+bool GetCurrentTabTitle(const Browser* browser, string16* title);
+
// Waits for |controller| to complete a navigation. This blocks until
// the navigation finishes.
void WaitForNavigation(NavigationController* controller);
@@ -38,6 +42,10 @@ void WaitForNavigations(NavigationController* controller,
// navigation finishes.
void NavigateToURL(Browser* browser, const GURL& url);
+// Reloads current tab contents and waits for navigation to finish.
+// Returns true on success.
+bool ReloadCurrentTab(Browser* browser);
+
// Navigates the selected tab of |browser| to |url|, blocking until the
// number of navigations specified complete.
void NavigateToURLBlockUntilNavigationsComplete(Browser* browser,