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/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/ptr_util.h" |
8 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
10 #include "chrome/browser/prefs/browser_prefs.h" | 11 #include "chrome/browser/prefs/browser_prefs.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/sessions/session_service_factory.h" | 13 #include "chrome/browser/sessions/session_service_factory.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/browser_with_test_window_test.h" | 16 #include "chrome/test/base/browser_with_test_window_test.h" |
16 #include "chrome/test/base/scoped_testing_local_state.h" | 17 #include "chrome/test/base/scoped_testing_local_state.h" |
17 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
(...skipping 26 matching lines...) Expand all Loading... |
44 } | 45 } |
45 | 46 |
46 private: | 47 private: |
47 TestingPrefServiceSimple pref_service; | 48 TestingPrefServiceSimple pref_service; |
48 base::ScopedTempDir temp_dir_; | 49 base::ScopedTempDir temp_dir_; |
49 }; | 50 }; |
50 | 51 |
51 TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { | 52 TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { |
52 SessionServiceFactory::SetForTestProfile( | 53 SessionServiceFactory::SetForTestProfile( |
53 browser()->profile(), | 54 browser()->profile(), |
54 make_scoped_ptr(static_cast<SessionService*>( | 55 base::WrapUnique(static_cast<SessionService*>( |
55 SessionServiceFactory::GetInstance()->BuildServiceInstanceFor( | 56 SessionServiceFactory::GetInstance()->BuildServiceInstanceFor( |
56 browser()->profile())))); | 57 browser()->profile())))); |
57 | 58 |
58 // Create a browser which we can close during the test. | 59 // Create a browser which we can close during the test. |
59 Browser::CreateParams params(browser()->profile()); | 60 Browser::CreateParams params(browser()->profile()); |
60 scoped_ptr<Browser> first_browser( | 61 std::unique_ptr<Browser> first_browser( |
61 chrome::CreateBrowserWithTestWindowForParams(¶ms)); | 62 chrome::CreateBrowserWithTestWindowForParams(¶ms)); |
62 AddTab(first_browser.get(), GURL(chrome::kChromeUINewTabURL)); | 63 AddTab(first_browser.get(), GURL(chrome::kChromeUINewTabURL)); |
63 | 64 |
64 // Attach the crashed infobar to it. | 65 // Attach the crashed infobar to it. |
65 SessionCrashedInfoBarDelegate::Create(first_browser.get()); | 66 SessionCrashedInfoBarDelegate::Create(first_browser.get()); |
66 | 67 |
67 TabStripModel* tab_strip = first_browser->tab_strip_model(); | 68 TabStripModel* tab_strip = first_browser->tab_strip_model(); |
68 ASSERT_EQ(1, tab_strip->count()); | 69 ASSERT_EQ(1, tab_strip->count()); |
69 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); | 70 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); |
70 InfoBarService* infobar_service = | 71 InfoBarService* infobar_service = |
71 InfoBarService::FromWebContents(web_contents); | 72 InfoBarService::FromWebContents(web_contents); |
72 EXPECT_EQ(1U, infobar_service->infobar_count()); | 73 EXPECT_EQ(1U, infobar_service->infobar_count()); |
73 ConfirmInfoBarDelegate* infobar = | 74 ConfirmInfoBarDelegate* infobar = |
74 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 75 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
75 ASSERT_TRUE(infobar); | 76 ASSERT_TRUE(infobar); |
76 | 77 |
77 // Open another browser. | 78 // Open another browser. |
78 scoped_ptr<Browser> opened_browser( | 79 std::unique_ptr<Browser> opened_browser( |
79 chrome::CreateBrowserWithTestWindowForParams(¶ms)); | 80 chrome::CreateBrowserWithTestWindowForParams(¶ms)); |
80 | 81 |
81 // Move the tab which is destroying the crash info bar to the new browser. | 82 // Move the tab which is destroying the crash info bar to the new browser. |
82 tab_strip->DetachWebContentsAt(0); | 83 tab_strip->DetachWebContentsAt(0); |
83 tab_strip = opened_browser->tab_strip_model(); | 84 tab_strip = opened_browser->tab_strip_model(); |
84 tab_strip->AppendWebContents(web_contents, true); | 85 tab_strip->AppendWebContents(web_contents, true); |
85 | 86 |
86 // Close the original browser. | 87 // Close the original browser. |
87 first_browser->window()->Close(); | 88 first_browser->window()->Close(); |
88 first_browser.reset(); | 89 first_browser.reset(); |
89 | 90 |
90 ASSERT_EQ(1, tab_strip->count()); | 91 ASSERT_EQ(1, tab_strip->count()); |
91 infobar_service = | 92 infobar_service = |
92 InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0)); | 93 InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0)); |
93 EXPECT_EQ(1U, infobar_service->infobar_count()); | 94 EXPECT_EQ(1U, infobar_service->infobar_count()); |
94 | 95 |
95 // This used to crash. | 96 // This used to crash. |
96 infobar->Accept(); | 97 infobar->Accept(); |
97 | 98 |
98 // Ramp down the test. | 99 // Ramp down the test. |
99 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 100 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
100 } | 101 } |
OLD | NEW |