1// Copyright (c) 2011 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/ui/browser.h" 7#include "chrome/common/url_constants.h" 8#include "chrome/test/in_process_browser_test.h" 9#include "chrome/test/ui_test_utils.h" 10#include "content/browser/tab_contents/navigation_entry.h" 11#include "content/common/notification_type.h" 12#include "content/common/page_transition_types.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 LOG(ERROR) << "SimulateRendererCrash, before WaitForNotification"; 21 ui_test_utils::WaitForNotification( 22 NotificationType::TAB_CONTENTS_DISCONNECTED); 23 LOG(ERROR) << "SimulateRendererCrash, after WaitForNotification"; 24} 25 26} // namespace 27 28class CrashRecoveryBrowserTest : public InProcessBrowserTest { 29}; 30 31// Test that reload works after a crash. 32// Disabled, http://crbug.com/29331, http://crbug.com/69637. 33IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) { 34 // The title of the active tab should change each time this URL is loaded. 35 GURL url( 36 "data:text/html,<script>document.title=new Date().valueOf()</script>"); 37 ui_test_utils::NavigateToURL(browser(), url); 38 39 string16 title_before_crash; 40 string16 title_after_crash; 41 42 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 43 &title_before_crash)); 44 SimulateRendererCrash(browser()); 45 browser()->Reload(CURRENT_TAB); 46 LOG(ERROR) << "Before WaitForNavigationInCurrentTab"; 47 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 48 LOG(ERROR) << "After WaitForNavigationInCurrentTab"; 49 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 50 &title_after_crash)); 51 EXPECT_NE(title_before_crash, title_after_crash); 52} 53 54// Tests that loading a crashed page in a new tab correctly updates the title. 55// There was an earlier bug (1270510) in process-per-site in which the max page 56// ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab 57// was not committed. This prevents regression of that bug. 58// http://crbug.com/57158 - Times out sometimes on all platforms. 59IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) { 60 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); 61 62 ui_test_utils::NavigateToURL(browser(), 63 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 64 FilePath(kTitle2File))); 65 66 string16 title_before_crash; 67 string16 title_after_crash; 68 69 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 70 &title_before_crash)); 71 SimulateRendererCrash(browser()); 72 browser()->Reload(CURRENT_TAB); 73 LOG(ERROR) << "Before WaitForNavigationInCurrentTab"; 74 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 75 LOG(ERROR) << "After WaitForNavigationInCurrentTab"; 76 ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), 77 &title_after_crash)); 78 EXPECT_EQ(title_before_crash, title_after_crash); 79} 80