14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// found in the LICENSE file. 44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/command_line.h" 64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/files/file_path.h" 74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/prefs/pref_registry_simple.h" 94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/prefs/pref_service.h" 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/prefs/pref_service_factory.h" 114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/prefs/testing_pref_store.h" 124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/profiles/profile.h" 134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/profiles/profiles_state.h" 144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_service.h" 154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/app_list/app_list_service_impl.h" 164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/app_list/test/fake_profile.h" 174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/browser/ui/app_list/test/fake_profile_store.h" 184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/common/chrome_constants.h" 194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/common/chrome_switches.h" 204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "chrome/common/pref_names.h" 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class TestingAppListServiceImpl : public AppListServiceImpl { 244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public: 254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) TestingAppListServiceImpl(const CommandLine& command_line, 264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) PrefService* local_state, 270529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch scoped_ptr<ProfileStore> profile_store) 280529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch : AppListServiceImpl(command_line, local_state, profile_store.Pass()), 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci showing_for_profile_(NULL), 301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci destroy_app_list_call_count_(0) {} 314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) Profile* showing_for_profile() const { 334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return showing_for_profile_; 344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int destroy_app_list_call_count() const { 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci return destroy_app_list_call_count_; 381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci } 391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void PerformStartupChecks(Profile* profile) { 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppListServiceImpl::PerformStartupChecks(profile); 424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // AppListService overrides: 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) virtual Profile* GetCurrentAppListProfile() OVERRIDE { 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // We don't return showing_for_profile_ here because that is only defined if 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // the app list is visible. 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return NULL; 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void CreateForProfile(Profile* requested_profile) OVERRIDE { 524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void ShowForProfile(Profile* requested_profile) OVERRIDE { 554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) showing_for_profile_ = requested_profile; 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) RecordAppListLaunch(); 574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void DismissAppList() OVERRIDE { 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) showing_for_profile_ = NULL; 614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual bool IsAppListVisible() const OVERRIDE { 644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return !!showing_for_profile_; 654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual gfx::NativeWindow GetAppListWindow() OVERRIDE { 684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return NULL; 694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual AppListControllerDelegate* GetControllerDelegate() OVERRIDE { 724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) return NULL; 734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // AppListServiceImpl overrides: 761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void DestroyAppList() OVERRIDE { ++destroy_app_list_call_count_; } 771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private: 794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) Profile* showing_for_profile_; 801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci int destroy_app_list_call_count_; 811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci DISALLOW_COPY_AND_ASSIGN(TestingAppListServiceImpl); 834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class AppListServiceUnitTest : public testing::Test { 864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public: 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppListServiceUnitTest() {} 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void SetUp() OVERRIDE { 904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) SetupWithCommandLine(CommandLine(CommandLine::NO_PROGRAM)); 914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected: 944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void SetupWithCommandLine(const CommandLine& command_line) { 954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) user_data_dir_ = base::FilePath(FILE_PATH_LITERAL("udd")); 964e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile1_.reset( 974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) new FakeProfile("p1", user_data_dir_.AppendASCII("profile1"))); 984e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile2_.reset( 994e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) new FakeProfile("p2", user_data_dir_.AppendASCII("profile2"))); 1004e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) PrefRegistrySimple* pref_registry = new PrefRegistrySimple; 1014e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) AppListService::RegisterPrefs(pref_registry); 1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profiles::RegisterPrefs(pref_registry); 1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 105f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::PrefServiceFactory factory; 106f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore)); 107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) local_state_ = factory.Create(pref_registry).Pass(); 1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_store_ = new FakeProfileStore(user_data_dir_); 1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_.reset(new TestingAppListServiceImpl( 1114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) command_line, 1124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) local_state_.get(), 1130529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch scoped_ptr<ProfileStore>(profile_store_))); 1144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 1154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void EnableAppList() { 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->EnableAppList(profile1_.get(), 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppListService::ENABLE_VIA_COMMAND_LINE); 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::FilePath user_data_dir_; 1224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<PrefService> local_state_; 1234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) FakeProfileStore* profile_store_; 1244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<TestingAppListServiceImpl> service_; 1254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<FakeProfile> profile1_; 1264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<FakeProfile> profile2_; 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AppListServiceUnitTest); 1294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 1304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(AppListServiceUnitTest, EnablingStateIsPersisted) { 1324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EnableAppList(); 1344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 1354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(profile1_->GetPath(), user_data_dir_.Append( 1364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) local_state_->GetFilePath(prefs::kAppListProfile))); 1374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(AppListServiceUnitTest, ShowingForProfileLoadsAProfile) { 1404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_store_->LoadProfile(profile1_.get()); 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EnableAppList(); 1424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->Show(); 1434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(profile1_.get(), service_->showing_for_profile()); 1444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(service_->IsAppListVisible()); 1454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(AppListServiceUnitTest, RemovedProfileResetsToInitialProfile) { 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EnableAppList(); 1494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_store_->RemoveProfile(profile1_.get()); 1504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::FilePath initial_profile_path = 1514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) user_data_dir_.AppendASCII(chrome::kInitialProfile); 1524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(initial_profile_path, 1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->GetProfilePath(profile_store_->GetUserDataDir())); 1544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(AppListServiceUnitTest, 1574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) RemovedProfileResetsToLastUsedProfileIfExists) { 1584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) local_state_->SetString(prefs::kProfileLastUsed, "last-used"); 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EnableAppList(); 1604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_store_->RemoveProfile(profile1_.get()); 1611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) base::FilePath last_used_profile_path = 1634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) user_data_dir_.AppendASCII("last-used"); 1644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(last_used_profile_path, 1654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->GetProfilePath(profile_store_->GetUserDataDir())); 1661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 1671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // For this test, the AppListViewDelegate is not created because the 1681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // app list is never shown, so there is nothing to destroy. 1691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci EXPECT_EQ(0, service_->destroy_app_list_call_count()); 1704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1714e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1724e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(AppListServiceUnitTest, SwitchingProfilesPersists) { 1734e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_store_->LoadProfile(profile1_.get()); 1744e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) profile_store_->LoadProfile(profile2_.get()); 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EnableAppList(); 1764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->SetProfilePath(profile2_->GetPath()); 1774e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->Show(); 1784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(profile2_.get(), service_->showing_for_profile()); 1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(profile2_->GetPath(), 1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->GetProfilePath(profile_store_->GetUserDataDir())); 1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->SetProfilePath(profile1_->GetPath()); 1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_EQ(profile1_->GetPath(), 1834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) service_->GetProfilePath(profile_store_->GetUserDataDir())); 1844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(AppListServiceUnitTest, EnableViaCommandLineFlag) { 1874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CommandLine command_line(CommandLine::NO_PROGRAM); 1884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) command_line.AppendSwitch(switches::kEnableAppList); 1894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) SetupWithCommandLine(command_line); 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->PerformStartupChecks(profile1_.get()); 1914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 1924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 1934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1944e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TEST_F(AppListServiceUnitTest, DisableViaCommandLineFlag) { 1954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CommandLine command_line(CommandLine::NO_PROGRAM); 1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) command_line.AppendSwitch(switches::kResetAppListInstallState); 1974e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) SetupWithCommandLine(command_line); 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->PerformStartupChecks(profile1_.get()); 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(AppListServiceUnitTest, UMAPrefStates) { 2034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXPECT_FALSE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(AppListService::ENABLE_NOT_RECORDED, 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->GetInteger(prefs::kAppListEnableMethod)); 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(0, local_state_->GetInt64(prefs::kAppListEnableTime)); 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->EnableAppList(profile1_.get(), 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppListService::ENABLE_FOR_APP_INSTALL); 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // After enable, method and time should be recorded. 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(local_state_->GetBoolean(prefs::kAppLauncherHasBeenEnabled)); 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->GetInteger(prefs::kAppListEnableMethod)); 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->ShowForProfile(profile1_.get()); 2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // After a regular "show", time should be cleared, so UMA is not re-recorded. 2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->GetInteger(prefs::kAppListEnableMethod)); 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(0, local_state_->GetInt64(prefs::kAppListEnableTime)); 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // A second enable should be a no-op. 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->EnableAppList(profile1_.get(), 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppListService::ENABLE_FOR_APP_INSTALL); 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->GetInteger(prefs::kAppListEnableMethod)); 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(0, local_state_->GetInt64(prefs::kAppListEnableTime)); 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // An auto-show here should keep the recorded enable method. 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->AutoShowForProfile(profile1_.get()); 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->GetInteger(prefs::kAppListEnableMethod)); 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Clear the enable state, so we can enable again. 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->SetBoolean(prefs::kAppLauncherHasBeenEnabled, false); 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->EnableAppList(profile1_.get(), 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AppListService::ENABLE_FOR_APP_INSTALL); 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(AppListService::ENABLE_FOR_APP_INSTALL, 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->GetInteger(prefs::kAppListEnableMethod)); 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_NE(0, local_state_->GetInt64(prefs::kAppListEnableTime)); 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // An auto-show here should update the enable method to prevent recording it 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // as ENABLE_FOR_APP_INSTALL. 2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) service_->AutoShowForProfile(profile1_.get()); 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(AppListService::ENABLE_SHOWN_UNDISCOVERED, 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) local_state_->GetInteger(prefs::kAppListEnableMethod)); 2504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} 251