Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(985)

Side by Side Diff: chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc

Issue 694593002: Profile unlock should always use session restore, regardless of system preference. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a profile manager instance to the unit test Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/startup/startup_browser_creator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
8 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/prefs/browser_prefs.h" 12 #include "chrome/browser/prefs/browser_prefs.h"
13 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/sessions/session_service_factory.h" 14 #include "chrome/browser/sessions/session_service_factory.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/browser_with_test_window_test.h" 17 #include "chrome/test/base/browser_with_test_window_test.h"
16 #include "chrome/test/base/scoped_testing_local_state.h" 18 #include "chrome/test/base/scoped_testing_local_state.h"
17 #include "chrome/test/base/testing_browser_process.h" 19 #include "chrome/test/base/testing_browser_process.h"
18 #include "components/infobars/core/infobar.h" 20 #include "components/infobars/core/infobar.h"
19 21
20 class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest { 22 class SessionCrashedInfoBarDelegateUnitTest : public BrowserWithTestWindowTest {
21 public: 23 public:
22 void SetUp() override { 24 void SetUp() override {
23 static_cast<TestingBrowserProcess*>(g_browser_process) 25 static_cast<TestingBrowserProcess*>(g_browser_process)
24 ->SetLocalState(&pref_service); 26 ->SetLocalState(&pref_service);
25 chrome::RegisterLocalState(pref_service.registry()); 27 chrome::RegisterLocalState(pref_service.registry());
26 28
27 // This needs to be called after the local state is set, because it will 29 // This needs to be called after the local state is set, because it will
28 // create a browser which will try to read from the local state. 30 // create a browser which will try to read from the local state.
29 BrowserWithTestWindowTest::SetUp(); 31 BrowserWithTestWindowTest::SetUp();
32
33 // Make sure we have a Profile Manager.
34 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
35 TestingBrowserProcess::GetGlobal()->SetProfileManager(
36 new ProfileManagerWithoutInit(temp_dir_.path()));
30 } 37 }
31 38
32 void TearDown() override { 39 void TearDown() override {
33 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); 40 static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL);
34 BrowserWithTestWindowTest::TearDown(); 41 BrowserWithTestWindowTest::TearDown();
42
43 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
35 } 44 }
36 45
37 private: 46 private:
38 TestingPrefServiceSimple pref_service; 47 TestingPrefServiceSimple pref_service;
48 base::ScopedTempDir temp_dir_;
39 }; 49 };
40 50
41 TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { 51 TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) {
42 SessionServiceFactory::SetForTestProfile( 52 SessionServiceFactory::SetForTestProfile(
43 browser()->profile(), 53 browser()->profile(),
44 static_cast<SessionService*>( 54 static_cast<SessionService*>(
45 SessionServiceFactory::GetInstance()->BuildServiceInstanceFor( 55 SessionServiceFactory::GetInstance()->BuildServiceInstanceFor(
46 browser()->profile()))); 56 browser()->profile())));
47 57
48 // Create a browser which we can close during the test. 58 // Create a browser which we can close during the test.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 infobar_service = 92 infobar_service =
83 InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0)); 93 InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0));
84 EXPECT_EQ(1U, infobar_service->infobar_count()); 94 EXPECT_EQ(1U, infobar_service->infobar_count());
85 95
86 // This used to crash. 96 // This used to crash.
87 infobar->Accept(); 97 infobar->Accept();
88 98
89 // Ramp down the test. 99 // Ramp down the test.
90 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE); 100 tab_strip->CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
91 } 101 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/startup/startup_browser_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698