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

Side by Side Diff: chrome/browser/ui/app_list/app_list_service_unittest.cc

Issue 1113333003: Don't create a new profile when cleaning up stale ephemeral profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: fix Created 5 years, 7 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/pref_service_factory.h" 10 #include "base/prefs/pref_service_factory.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 public: 79 public:
80 AppListServiceUnitTest() {} 80 AppListServiceUnitTest() {}
81 81
82 void SetUp() override { 82 void SetUp() override {
83 SetupWithCommandLine(base::CommandLine(base::CommandLine::NO_PROGRAM)); 83 SetupWithCommandLine(base::CommandLine(base::CommandLine::NO_PROGRAM));
84 } 84 }
85 85
86 protected: 86 protected:
87 void SetupWithCommandLine(const base::CommandLine& command_line) { 87 void SetupWithCommandLine(const base::CommandLine& command_line) {
88 user_data_dir_ = base::FilePath(FILE_PATH_LITERAL("udd")); 88 user_data_dir_ = base::FilePath(FILE_PATH_LITERAL("udd"));
89 initial_profile_ = "ip";
89 profile1_.reset( 90 profile1_.reset(
90 new FakeProfile("p1", user_data_dir_.AppendASCII("profile1"))); 91 new FakeProfile("p1", user_data_dir_.AppendASCII("profile1")));
91 profile2_.reset( 92 profile2_.reset(
92 new FakeProfile("p2", user_data_dir_.AppendASCII("profile2"))); 93 new FakeProfile("p2", user_data_dir_.AppendASCII("profile2")));
93 PrefRegistrySimple* pref_registry = new PrefRegistrySimple; 94 PrefRegistrySimple* pref_registry = new PrefRegistrySimple;
94 95
95 AppListService::RegisterPrefs(pref_registry); 96 AppListService::RegisterPrefs(pref_registry);
96 profiles::RegisterPrefs(pref_registry); 97 profiles::RegisterPrefs(pref_registry);
97 98
98 base::PrefServiceFactory factory; 99 base::PrefServiceFactory factory;
99 factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore)); 100 factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore));
100 local_state_ = factory.Create(pref_registry).Pass(); 101 local_state_ = factory.Create(pref_registry).Pass();
101 102
102 profile_store_ = new FakeProfileStore(user_data_dir_); 103 profile_store_ = new FakeProfileStore(user_data_dir_, initial_profile_);
103 service_.reset(new TestingAppListServiceImpl( 104 service_.reset(new TestingAppListServiceImpl(
104 command_line, 105 command_line,
105 local_state_.get(), 106 local_state_.get(),
106 scoped_ptr<ProfileStore>(profile_store_))); 107 scoped_ptr<ProfileStore>(profile_store_)));
107 } 108 }
108 109
109 void EnableAppList() { 110 void EnableAppList() {
110 service_->EnableAppList(profile1_.get(), 111 service_->EnableAppList(profile1_.get(),
111 AppListService::ENABLE_VIA_COMMAND_LINE); 112 AppListService::ENABLE_VIA_COMMAND_LINE);
112 } 113 }
113 114
114 base::FilePath user_data_dir_; 115 base::FilePath user_data_dir_;
116 std::string initial_profile_;
115 scoped_ptr<PrefService> local_state_; 117 scoped_ptr<PrefService> local_state_;
116 FakeProfileStore* profile_store_; 118 FakeProfileStore* profile_store_;
117 scoped_ptr<TestingAppListServiceImpl> service_; 119 scoped_ptr<TestingAppListServiceImpl> service_;
118 scoped_ptr<FakeProfile> profile1_; 120 scoped_ptr<FakeProfile> profile1_;
119 scoped_ptr<FakeProfile> profile2_; 121 scoped_ptr<FakeProfile> profile2_;
120 122
121 DISALLOW_COPY_AND_ASSIGN(AppListServiceUnitTest); 123 DISALLOW_COPY_AND_ASSIGN(AppListServiceUnitTest);
122 }; 124 };
123 125
124 TEST_F(AppListServiceUnitTest, EnablingStateIsPersisted) { 126 TEST_F(AppListServiceUnitTest, EnablingStateIsPersisted) {
125 EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 127 EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled));
126 EnableAppList(); 128 EnableAppList();
127 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 129 EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled));
128 EXPECT_EQ(profile1_->GetPath(), user_data_dir_.Append( 130 EXPECT_EQ(profile1_->GetPath(), user_data_dir_.Append(
129 local_state_->GetFilePath(prefs::kAppListProfile))); 131 local_state_->GetFilePath(prefs::kAppListProfile)));
130 } 132 }
131 133
132 TEST_F(AppListServiceUnitTest, ShowingForProfileLoadsAProfile) { 134 TEST_F(AppListServiceUnitTest, ShowingForProfileLoadsAProfile) {
133 profile_store_->LoadProfile(profile1_.get()); 135 profile_store_->LoadProfile(profile1_.get());
134 EnableAppList(); 136 EnableAppList();
135 service_->Show(); 137 service_->Show();
136 EXPECT_EQ(profile1_.get(), service_->showing_for_profile()); 138 EXPECT_EQ(profile1_.get(), service_->showing_for_profile());
137 EXPECT_TRUE(service_->IsAppListVisible()); 139 EXPECT_TRUE(service_->IsAppListVisible());
138 } 140 }
139 141
140 TEST_F(AppListServiceUnitTest, RemovedProfileResetsToInitialProfile) { 142 TEST_F(AppListServiceUnitTest, RemovedProfileResetsToInitialProfile) {
141 EnableAppList(); 143 EnableAppList();
142 profile_store_->RemoveProfile(profile1_.get()); 144 profile_store_->RemoveProfile(profile1_.get());
143 base::FilePath initial_profile_path = 145 base::FilePath initial_profile_path =
144 user_data_dir_.AppendASCII(chrome::kInitialProfile); 146 user_data_dir_.AppendASCII(initial_profile_);
145 EXPECT_EQ(initial_profile_path, 147 EXPECT_EQ(initial_profile_path,
146 service_->GetProfilePath(profile_store_->GetUserDataDir())); 148 service_->GetProfilePath(profile_store_->GetUserDataDir()));
147 } 149 }
148 150
149 TEST_F(AppListServiceUnitTest, 151 TEST_F(AppListServiceUnitTest,
150 RemovedProfileResetsToLastUsedProfileIfExists) { 152 RemovedProfileResetsToLastUsedProfileIfExists) {
151 local_state_->SetString(prefs::kProfileLastUsed, "last-used"); 153 local_state_->SetString(prefs::kProfileLastUsed, "last-used");
152 EnableAppList(); 154 EnableAppList();
153 profile_store_->RemoveProfile(profile1_.get()); 155 profile_store_->RemoveProfile(profile1_.get());
154 156
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, 236 EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL,
235 local_state_->GetInteger(prefs::kAppListEnableMethod)); 237 local_state_->GetInteger(prefs::kAppListEnableMethod));
236 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); 238 EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime));
237 239
238 // An auto-show here should update the enable method to prevent recording it 240 // An auto-show here should update the enable method to prevent recording it
239 // as ENABLE_FOR_APP_INSTALL. 241 // as ENABLE_FOR_APP_INSTALL.
240 service_->ShowForAppInstall(profile1_.get(), "", false); 242 service_->ShowForAppInstall(profile1_.get(), "", false);
241 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, 243 EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED,
242 local_state_->GetInteger(prefs::kAppListEnableMethod)); 244 local_state_->GetInteger(prefs::kAppListEnableMethod));
243 } 245 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/app_list_service_impl.cc ('k') | chrome/browser/ui/app_list/profile_loader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698