Home | History | Annotate | Download | only in browser
      1 // Copyright (c) 2012 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/files/file_path.h"
      6 #include "chrome/browser/ui/browser.h"
      7 #include "chrome/browser/ui/browser_commands.h"
      8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
      9 #include "chrome/common/url_constants.h"
     10 #include "chrome/test/base/in_process_browser_test.h"
     11 #include "chrome/test/base/ui_test_utils.h"
     12 #include "content/public/browser/notification_service.h"
     13 #include "content/public/browser/notification_types.h"
     14 #include "content/public/browser/web_contents.h"
     15 #include "content/public/common/page_transition_types.h"
     16 #include "testing/gtest/include/gtest/gtest.h"
     17 
     18 using content::NavigationController;
     19 using content::OpenURLParams;
     20 using content::Referrer;
     21 
     22 namespace {
     23 
     24 void SimulateRendererCrash(Browser* browser) {
     25   content::WindowedNotificationObserver observer(
     26       content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
     27       content::NotificationService::AllSources());
     28   browser->OpenURL(OpenURLParams(
     29       GURL(content::kChromeUICrashURL), Referrer(), CURRENT_TAB,
     30       content::PAGE_TRANSITION_TYPED, false));
     31   observer.Wait();
     32 }
     33 
     34 }  // namespace
     35 
     36 class CrashRecoveryBrowserTest : public InProcessBrowserTest {
     37 };
     38 
     39 // Test that reload works after a crash.
     40 // Disabled, http://crbug.com/29331 , http://crbug.com/69637 .
     41 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, Reload) {
     42   // The title of the active tab should change each time this URL is loaded.
     43   GURL url(
     44       "data:text/html,<script>document.title=new Date().valueOf()</script>");
     45   ui_test_utils::NavigateToURL(browser(), url);
     46 
     47   string16 title_before_crash;
     48   string16 title_after_crash;
     49 
     50   ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
     51                                                 &title_before_crash));
     52   SimulateRendererCrash(browser());
     53   content::WindowedNotificationObserver observer(
     54       content::NOTIFICATION_LOAD_STOP,
     55       content::Source<NavigationController>(
     56           &browser()->tab_strip_model()->GetActiveWebContents()->
     57               GetController()));
     58   chrome::Reload(browser(), CURRENT_TAB);
     59   observer.Wait();
     60   ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
     61                                                 &title_after_crash));
     62   EXPECT_NE(title_before_crash, title_after_crash);
     63 }
     64 
     65 // Tests that loading a crashed page in a new tab correctly updates the title.
     66 // There was an earlier bug (1270510) in process-per-site in which the max page
     67 // ID of the RenderProcessHost was stale, so the NavigationEntry in the new tab
     68 // was not committed.  This prevents regression of that bug.
     69 IN_PROC_BROWSER_TEST_F(CrashRecoveryBrowserTest, LoadInNewTab) {
     70   const base::FilePath::CharType* kTitle2File =
     71       FILE_PATH_LITERAL("title2.html");
     72 
     73   ui_test_utils::NavigateToURL(
     74       browser(), ui_test_utils::GetTestUrl(
     75                      base::FilePath(base::FilePath::kCurrentDirectory),
     76                      base::FilePath(kTitle2File)));
     77 
     78   string16 title_before_crash;
     79   string16 title_after_crash;
     80 
     81   ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
     82                                                 &title_before_crash));
     83   SimulateRendererCrash(browser());
     84   content::WindowedNotificationObserver observer(
     85       content::NOTIFICATION_LOAD_STOP,
     86       content::Source<NavigationController>(
     87           &browser()->tab_strip_model()->GetActiveWebContents()->
     88               GetController()));
     89   chrome::Reload(browser(), CURRENT_TAB);
     90   observer.Wait();
     91   ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(),
     92                                                 &title_after_crash));
     93   EXPECT_EQ(title_before_crash, title_after_crash);
     94 }
     95