| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 17 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | 18 #include "chrome/browser/chromeos/arc/arc_session_manager.h" |
| 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 20 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 21 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 22 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 23 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 25 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 25 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 26 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
| 28 #include "chromeos/chromeos_switches.h" | 29 #include "chromeos/chromeos_switches.h" |
| 29 #include "chromeos/dbus/dbus_thread_manager.h" | 30 #include "chromeos/dbus/dbus_thread_manager.h" |
| 30 #include "components/arc/arc_bridge_service.h" | 31 #include "components/arc/arc_bridge_service.h" |
| 32 #include "components/arc/arc_service_manager.h" |
| 31 #include "components/arc/test/fake_arc_bridge_service.h" | 33 #include "components/arc/test/fake_arc_bridge_service.h" |
| 32 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
| 33 #include "components/signin/core/account_id/account_id.h" | 35 #include "components/signin/core/account_id/account_id.h" |
| 34 #include "components/sync/model/fake_sync_change_processor.h" | 36 #include "components/sync/model/fake_sync_change_processor.h" |
| 35 #include "components/sync/model/sync_error_factory_mock.h" | 37 #include "components/sync/model/sync_error_factory_mock.h" |
| 36 #include "components/sync_preferences/testing_pref_service_syncable.h" | 38 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 37 #include "components/user_manager/user_manager.h" | 39 #include "components/user_manager/user_manager.h" |
| 38 #include "components/user_manager/user_names.h" | 40 #include "components/user_manager/user_names.h" |
| 39 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
| 40 #include "content/public/test/test_browser_thread_bundle.h" | 42 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 59 chromeos::switches::kEnableArc); | 61 chromeos::switches::kEnableArc); |
| 60 ArcSessionManager::DisableUIForTesting(); | 62 ArcSessionManager::DisableUIForTesting(); |
| 61 | 63 |
| 62 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 64 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 63 TestingProfile::Builder profile_builder; | 65 TestingProfile::Builder profile_builder; |
| 64 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); | 66 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); |
| 65 | 67 |
| 66 profile_ = profile_builder.Build(); | 68 profile_ = profile_builder.Build(); |
| 67 StartPreferenceSyncing(); | 69 StartPreferenceSyncing(); |
| 68 | 70 |
| 69 bridge_service_.reset(new FakeArcBridgeService()); | 71 ArcServiceManager::SetArcBridgeServiceForTesting( |
| 70 arc_session_manager_.reset(new ArcSessionManager(bridge_service_.get())); | 72 base::MakeUnique<FakeArcBridgeService>()); |
| 73 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr); |
| 74 arc_session_manager_ = base::MakeUnique<ArcSessionManager>( |
| 75 arc_service_manager_->arc_bridge_service()); |
| 71 | 76 |
| 72 // Check initial conditions. | 77 // Check initial conditions. |
| 73 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); | 78 EXPECT_TRUE(bridge_service()->stopped()); |
| 74 EXPECT_TRUE(ArcBridgeService::Get()->stopped()); | |
| 75 | 79 |
| 76 const AccountId account_id( | 80 const AccountId account_id( |
| 77 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890")); | 81 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890")); |
| 78 GetFakeUserManager()->AddUser(account_id); | 82 GetFakeUserManager()->AddUser(account_id); |
| 79 GetFakeUserManager()->LoginUser(account_id); | 83 GetFakeUserManager()->LoginUser(account_id); |
| 80 | 84 |
| 81 chromeos::WallpaperManager::Initialize(); | 85 chromeos::WallpaperManager::Initialize(); |
| 82 } | 86 } |
| 83 | 87 |
| 84 void TearDown() override { | 88 void TearDown() override { |
| 85 chromeos::WallpaperManager::Shutdown(); | 89 chromeos::WallpaperManager::Shutdown(); |
| 90 arc_session_manager_.reset(); |
| 91 arc_service_manager_.reset(); |
| 86 chromeos::DBusThreadManager::Shutdown(); | 92 chromeos::DBusThreadManager::Shutdown(); |
| 87 } | 93 } |
| 88 | 94 |
| 89 chromeos::FakeChromeUserManager* GetFakeUserManager() const { | 95 chromeos::FakeChromeUserManager* GetFakeUserManager() const { |
| 90 return static_cast<chromeos::FakeChromeUserManager*>( | 96 return static_cast<chromeos::FakeChromeUserManager*>( |
| 91 user_manager::UserManager::Get()); | 97 user_manager::UserManager::Get()); |
| 92 } | 98 } |
| 93 | 99 |
| 94 protected: | 100 protected: |
| 95 Profile* profile() { return profile_.get(); } | 101 Profile* profile() { return profile_.get(); } |
| 96 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } | 102 FakeArcBridgeService* bridge_service() { |
| 103 return static_cast<FakeArcBridgeService*>( |
| 104 arc_service_manager_->arc_bridge_service()); |
| 105 } |
| 97 ArcSessionManager* arc_session_manager() { | 106 ArcSessionManager* arc_session_manager() { |
| 98 return arc_session_manager_.get(); | 107 return arc_session_manager_.get(); |
| 99 } | 108 } |
| 100 | 109 |
| 101 private: | 110 private: |
| 102 void StartPreferenceSyncing() const { | 111 void StartPreferenceSyncing() const { |
| 103 PrefServiceSyncableFromProfile(profile_.get()) | 112 PrefServiceSyncableFromProfile(profile_.get()) |
| 104 ->GetSyncableService(syncer::PREFERENCES) | 113 ->GetSyncableService(syncer::PREFERENCES) |
| 105 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), | 114 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), |
| 106 std::unique_ptr<syncer::SyncChangeProcessor>( | 115 std::unique_ptr<syncer::SyncChangeProcessor>( |
| 107 new syncer::FakeSyncChangeProcessor), | 116 new syncer::FakeSyncChangeProcessor), |
| 108 std::unique_ptr<syncer::SyncErrorFactory>( | 117 std::unique_ptr<syncer::SyncErrorFactory>( |
| 109 new syncer::SyncErrorFactoryMock())); | 118 new syncer::SyncErrorFactoryMock())); |
| 110 } | 119 } |
| 111 | 120 |
| 112 content::TestBrowserThreadBundle thread_bundle_; | 121 content::TestBrowserThreadBundle thread_bundle_; |
| 113 std::unique_ptr<FakeArcBridgeService> bridge_service_; | |
| 114 std::unique_ptr<TestingProfile> profile_; | 122 std::unique_ptr<TestingProfile> profile_; |
| 123 std::unique_ptr<ArcServiceManager> arc_service_manager_; |
| 115 std::unique_ptr<ArcSessionManager> arc_session_manager_; | 124 std::unique_ptr<ArcSessionManager> arc_session_manager_; |
| 116 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | 125 chromeos::ScopedUserManagerEnabler user_manager_enabler_; |
| 117 base::ScopedTempDir temp_dir_; | 126 base::ScopedTempDir temp_dir_; |
| 118 | 127 |
| 119 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); | 128 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); |
| 120 }; | 129 }; |
| 121 | 130 |
| 122 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { | 131 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { |
| 123 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | 132 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
| 124 arc_session_manager()->state()); | 133 arc_session_manager()->state()); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 380 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 372 | 381 |
| 373 // Check that non-primary user can't use Arc. | 382 // Check that non-primary user can't use Arc. |
| 374 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); | 383 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); |
| 375 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); | 384 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); |
| 376 | 385 |
| 377 arc_session_manager()->Shutdown(); | 386 arc_session_manager()->Shutdown(); |
| 378 } | 387 } |
| 379 | 388 |
| 380 } // namespace arc | 389 } // namespace arc |
| OLD | NEW |