OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" | 5 #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" |
6 | 6 |
7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/infobars/infobar.h" | 10 #include "chrome/browser/infobars/infobar.h" |
| 11 #include "chrome/browser/infobars/infobar_manager.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/browser/prefs/browser_prefs.h" | 13 #include "chrome/browser/prefs/browser_prefs.h" |
13 #include "chrome/browser/sessions/session_service_factory.h" | 14 #include "chrome/browser/sessions/session_service_factory.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/base/browser_with_test_window_test.h" | 18 #include "chrome/test/base/browser_with_test_window_test.h" |
18 #include "chrome/test/base/scoped_testing_local_state.h" | 19 #include "chrome/test/base/scoped_testing_local_state.h" |
19 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
20 | 21 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 scoped_ptr<Browser> first_browser( | 75 scoped_ptr<Browser> first_browser( |
75 chrome::CreateBrowserWithTestWindowForParams(¶ms)); | 76 chrome::CreateBrowserWithTestWindowForParams(¶ms)); |
76 AddTab(first_browser.get(), GURL(chrome::kChromeUINewTabURL)); | 77 AddTab(first_browser.get(), GURL(chrome::kChromeUINewTabURL)); |
77 | 78 |
78 // Attach the crashed infobar to it. | 79 // Attach the crashed infobar to it. |
79 SessionCrashedInfoBarDelegate::Create(first_browser.get()); | 80 SessionCrashedInfoBarDelegate::Create(first_browser.get()); |
80 | 81 |
81 TabStripModel* tab_strip = first_browser->tab_strip_model(); | 82 TabStripModel* tab_strip = first_browser->tab_strip_model(); |
82 ASSERT_EQ(1, tab_strip->count()); | 83 ASSERT_EQ(1, tab_strip->count()); |
83 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); | 84 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); |
84 InfoBarService* infobar_service = | 85 InfoBarManager* infobar_manager = |
85 InfoBarService::FromWebContents(web_contents); | 86 InfoBarService::FromWebContents(web_contents)->infobar_manager(); |
86 EXPECT_EQ(1U, infobar_service->infobar_count()); | 87 EXPECT_EQ(1U, infobar_manager->infobar_count()); |
87 ConfirmInfoBarDelegate* infobar = | 88 ConfirmInfoBarDelegate* infobar = |
88 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 89 infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
89 ASSERT_TRUE(infobar); | 90 ASSERT_TRUE(infobar); |
90 | 91 |
91 // Open another browser. | 92 // Open another browser. |
92 scoped_ptr<Browser> opened_browser( | 93 scoped_ptr<Browser> opened_browser( |
93 chrome::CreateBrowserWithTestWindowForParams(¶ms)); | 94 chrome::CreateBrowserWithTestWindowForParams(¶ms)); |
94 | 95 |
95 // Move the tab which is destroying the crash info bar to the new browser. | 96 // Move the tab which is destroying the crash info bar to the new browser. |
96 tab_strip->DetachWebContentsAt(0); | 97 tab_strip->DetachWebContentsAt(0); |
97 tab_strip = opened_browser->tab_strip_model(); | 98 tab_strip = opened_browser->tab_strip_model(); |
98 tab_strip->AppendWebContents(web_contents, true); | 99 tab_strip->AppendWebContents(web_contents, true); |
99 | 100 |
100 // Close the original browser. | 101 // Close the original browser. |
101 first_browser->window()->Close(); | 102 first_browser->window()->Close(); |
102 first_browser.reset(); | 103 first_browser.reset(); |
103 | 104 |
104 ASSERT_EQ(1, tab_strip->count()); | 105 ASSERT_EQ(1, tab_strip->count()); |
105 web_contents = tab_strip->GetWebContentsAt(0); | 106 InfoBarService* infobar_service = |
106 infobar_service = InfoBarService::FromWebContents(web_contents); | 107 InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0)); |
107 EXPECT_EQ(1U, infobar_service->infobar_count()); | 108 EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); |
108 | 109 |
109 // This used to crash. | 110 // This used to crash. |
110 infobar->Accept(); | 111 infobar->Accept(); |
111 | 112 |
112 // Ramp down the test. | 113 // Ramp down the test. |
113 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 114 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
114 } | 115 } |
115 | 116 |
116 #if defined(OS_CHROMEOS) | 117 #if defined(OS_CHROMEOS) |
117 INSTANTIATE_TEST_CASE_P(SessionCrashedInfoBarDelegateUnitTestInstantiation, | 118 INSTANTIATE_TEST_CASE_P(SessionCrashedInfoBarDelegateUnitTestInstantiation, |
118 SessionCrashedInfoBarDelegateUnitTest, | 119 SessionCrashedInfoBarDelegateUnitTest, |
119 testing::Bool()); | 120 testing::Bool()); |
120 #endif | 121 #endif |
OLD | NEW |