1 // Copyright 2013 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.
5 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8 #include "chrome/test/base/browser_with_test_window_test.h"
9 #include "content/public/browser/site_instance.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/test/web_contents_tester.h"
13 using content::SiteInstance
;
14 using content::WebContents
;
15 using content::WebContentsTester
;
17 class BrowserUnitTest
: public BrowserWithTestWindowTest
{
20 virtual ~BrowserUnitTest() {}
22 // Caller owns the memory.
23 WebContents
* CreateTestWebContents() {
24 return WebContentsTester::CreateTestWebContents(
25 profile(), SiteInstance::Create(profile()));
29 DISALLOW_COPY_AND_ASSIGN(BrowserUnitTest
);
32 // Don't build on platforms without a tab strip.
33 #if !defined(OS_ANDROID) && !defined(OS_IOS)
34 // Ensure crashed tabs are not reloaded when selected. crbug.com/232323
35 TEST_F(BrowserUnitTest
, ReloadCrashedTab
) {
36 TabStripModel
* tab_strip_model
= browser()->tab_strip_model();
38 // Start with a single foreground tab. |tab_strip_model| owns the memory.
39 WebContents
* contents1
= CreateTestWebContents();
40 tab_strip_model
->AppendWebContents(contents1
, true);
41 WebContentsTester::For(contents1
)->NavigateAndCommit(GURL("about:blank"));
42 WebContentsTester::For(contents1
)->TestSetIsLoading(false);
43 EXPECT_TRUE(tab_strip_model
->IsTabSelected(0));
44 EXPECT_FALSE(contents1
->IsLoading());
46 // Add a second tab in the background.
47 WebContents
* contents2
= CreateTestWebContents();
48 tab_strip_model
->AppendWebContents(contents2
, false);
49 WebContentsTester::For(contents2
)->NavigateAndCommit(GURL("about:blank"));
50 WebContentsTester::For(contents2
)->TestSetIsLoading(false);
51 EXPECT_EQ(2, browser()->tab_strip_model()->count());
52 EXPECT_TRUE(tab_strip_model
->IsTabSelected(0));
53 EXPECT_FALSE(contents2
->IsLoading());
55 // Simulate the second tab crashing.
56 contents2
->SetIsCrashed(base::TERMINATION_STATUS_PROCESS_CRASHED
, -1);
57 EXPECT_TRUE(contents2
->IsCrashed());
59 // Selecting the second tab does not cause a load or clear the crash.
60 tab_strip_model
->ActivateTabAt(1, true);
61 EXPECT_TRUE(tab_strip_model
->IsTabSelected(1));
62 EXPECT_FALSE(contents2
->IsLoading());
63 EXPECT_TRUE(contents2
->IsCrashed());
66 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)