| 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_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/prefs/browser_prefs.h" | 11 #include "chrome/browser/prefs/browser_prefs.h" |
| 12 #include "chrome/browser/sessions/session_service_factory.h" | 12 #include "chrome/browser/sessions/session_service_factory.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/test/base/browser_with_test_window_test.h" | 16 #include "chrome/test/base/browser_with_test_window_test.h" |
| 17 #include "chrome/test/base/scoped_testing_local_state.h" | 17 #include "chrome/test/base/scoped_testing_local_state.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "components/infobars/core/infobar.h" | 19 #include "components/infobars/core/infobar.h" |
| 20 | 20 |
| 21 class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest { | 21 class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest { |
| 22 public: | 22 public: |
| 23 virtual void SetUp() OVERRIDE { | 23 virtual void SetUp() override { |
| 24 static_cast<TestingBrowserProcess*>(g_browser_process) | 24 static_cast<TestingBrowserProcess*>(g_browser_process) |
| 25 ->SetLocalState(&pref_service); | 25 ->SetLocalState(&pref_service); |
| 26 chrome::RegisterLocalState(pref_service.registry()); | 26 chrome::RegisterLocalState(pref_service.registry()); |
| 27 | 27 |
| 28 // This needs to be called after the local state is set, because it will | 28 // This needs to be called after the local state is set, because it will |
| 29 // create a browser which will try to read from the local state. | 29 // create a browser which will try to read from the local state. |
| 30 BrowserWithTestWindowTest::SetUp(); | 30 BrowserWithTestWindowTest::SetUp(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 virtual void TearDown() OVERRIDE { | 33 virtual void TearDown() override { |
| 34 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); | 34 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); |
| 35 BrowserWithTestWindowTest::TearDown(); | 35 BrowserWithTestWindowTest::TearDown(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 TestingPrefServiceSimple pref_service; | 39 TestingPrefServiceSimple pref_service; |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { | 42 TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { |
| 43 SessionServiceFactory::SetForTestProfile( | 43 SessionServiceFactory::SetForTestProfile( |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 infobar_service = | 83 infobar_service = |
| 84 InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0)); | 84 InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0)); |
| 85 EXPECT_EQ(1U, infobar_service->infobar_count()); | 85 EXPECT_EQ(1U, infobar_service->infobar_count()); |
| 86 | 86 |
| 87 // This used to crash. | 87 // This used to crash. |
| 88 infobar->Accept(); | 88 infobar->Accept(); |
| 89 | 89 |
| 90 // Ramp down the test. | 90 // Ramp down the test. |
| 91 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); | 91 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); |
| 92 } | 92 } |
| OLD | NEW |