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_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
11 #include "chrome/browser/sessions/session_service_factory.h" | 12 #include "chrome/browser/sessions/session_service_factory.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.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" |
18 | 19 |
19 class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest { | 20 class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 55 |
55 // Attach the crashed infobar to it. | 56 // Attach the crashed infobar to it. |
56 SessionCrashedInfoBarDelegate::Create(first_browser.get()); | 57 SessionCrashedInfoBarDelegate::Create(first_browser.get()); |
57 | 58 |
58 TabStripModel* tab_strip = first_browser->tab_strip_model(); | 59 TabStripModel* tab_strip = first_browser->tab_strip_model(); |
59 ASSERT_EQ(1, tab_strip->count()); | 60 ASSERT_EQ(1, tab_strip->count()); |
60 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); | 61 content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); |
61 InfoBarService* infobar_service = | 62 InfoBarService* infobar_service = |
62 InfoBarService::FromWebContents(web_contents); | 63 InfoBarService::FromWebContents(web_contents); |
63 EXPECT_EQ(1U, infobar_service->infobar_count()); | 64 EXPECT_EQ(1U, infobar_service->infobar_count()); |
64 scoped_ptr<ConfirmInfoBarDelegate> infobar(InfoBarService::FromWebContents( | 65 ConfirmInfoBarDelegate* infobar = |
65 web_contents)->infobar_at(0)->AsConfirmInfoBarDelegate()); | 66 infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
66 ASSERT_TRUE(infobar); | 67 ASSERT_TRUE(infobar); |
67 | 68 |
68 // Open another browser. | 69 // Open another browser. |
69 scoped_ptr<Browser> opened_browser( | 70 scoped_ptr<Browser> opened_browser( |
70 chrome::CreateBrowserWithTestWindowForParams(¶ms)); | 71 chrome::CreateBrowserWithTestWindowForParams(¶ms)); |
71 | 72 |
72 // Move the tab which is destroying the crash info bar to the new browser. | 73 // Move the tab which is destroying the crash info bar to the new browser. |
73 tab_strip->DetachWebContentsAt(0); | 74 tab_strip->DetachWebContentsAt(0); |
74 tab_strip = opened_browser->tab_strip_model(); | 75 tab_strip = opened_browser->tab_strip_model(); |
75 tab_strip->AppendWebContents(web_contents, true); | 76 tab_strip->AppendWebContents(web_contents, true); |
76 | 77 |
77 // Close the original browser. | 78 // Close the original browser. |
78 first_browser->window()->Close(); | 79 first_browser->window()->Close(); |
79 first_browser.reset(); | 80 first_browser.reset(); |
80 | 81 |
81 ASSERT_EQ(1, tab_strip->count()); | 82 ASSERT_EQ(1, tab_strip->count()); |
82 web_contents = tab_strip->GetWebContentsAt(0); | 83 web_contents = tab_strip->GetWebContentsAt(0); |
83 infobar_service = InfoBarService::FromWebContents(web_contents); | 84 infobar_service = InfoBarService::FromWebContents(web_contents); |
84 EXPECT_EQ(1U, infobar_service->infobar_count()); | 85 EXPECT_EQ(1U, infobar_service->infobar_count()); |
85 | 86 |
86 // This used to crash. | 87 // This used to crash. |
87 infobar->Accept(); | 88 infobar->Accept(); |
88 | 89 |
89 // Ramp down the test. | 90 // Ramp down the test. |
90 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 91 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
91 } | 92 } |
OLD | NEW |