crash_recovery_browsertest.cc revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "base/file_path.h" 6#include "chrome/browser/tab_contents/navigation_entry.h" 7#include "chrome/browser/ui/browser.h" 8#include "chrome/common/notification_type.h" 9#include "chrome/common/page_transition_types.h" 10#include "chrome/common/url_constants.h" 11#include "chrome/test/in_process_browser_test.h" 12#include "chrome/test/ui_test_utils.h" 13#include "testing/gtest/include/gtest/gtest.h" 14 15namespace { 16 17void SimulateRendererCrash(Browser* browser) { 18 browser->OpenURL(GURL(chrome::kAboutCrashURL), GURL(), CURRENT_TAB, 19 PageTransition::TYPED); 20 ui_test_utils::WaitForNotification( 21 NotificationType::TAB_CONTENTS_DISCONNECTED); 22} 23 24} // namespace 25 26class CrashRecoveryBrowserTest : public InProcessBrowserTest { 27}; 28 29// http://crbug.com/29331 - Causes an OS crash dialog in release mode, needs to 30// be fixed before it can be enabled to not cause the bots issues. 31#if defined(OS_MACOSX) 32#define MAYBE_Reload DISABLED_Reload 33#else 34#define MAYBE_Reload Reload 35#endif 36 37// Test that reload works after a crash. 38IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, MAYBE_Reload) { 39 // The title of the active tab should change each time this URL is loaded. 40 GURL url( 41 "data:text/html,<script>document.title=new Date().valueOf()</script>"); 42 ui_test_utils::NavigateToURL(browser(), url); 43 44 string16 title_before_crash; 45 string16 title_after_crash; 46 47 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 48 &title_before_crash)); 49 SimulateRendererCrash(browser()); 50 browser()->Reload(CURRENT_TAB); 51 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 52 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 53 &title_after_crash)); 54 EXPECT_NE(title_before_crash, title_after_crash); 55} 56 57// Tests that loading a crashed page in a new tab correctly updates the title. 58// There was an earlier bug (1270510) in process-per-site in which the max page 59// ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab 60// was not committed. This prevents regression of that bug. 61// http://crbug.com/57158 - Times out sometimes on all platforms. 62IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, DISABLED_LoadInNewTab) { 63 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); 64 65 ui_test_utils::NavigateToURL(browser(), 66 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 67 FilePath(kTitle2File))); 68 69 string16 title_before_crash; 70 string16 title_after_crash; 71 72 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 73 &title_before_crash)); 74 SimulateRendererCrash(browser()); 75 browser()->Reload(CURRENT_TAB); 76 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 77 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 78 &title_after_crash)); 79 EXPECT_EQ(title_before_crash, title_after_crash); 80} 81