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

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager_unittest.cc

Issue 2557513004: Remove explicit singletonness of ArcBridgeService part 3. (Closed)
Patch Set: Address comments. Created 4 years 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/chromeos/arc/intent_helper/arc_settings_service_browsertest.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 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 "chromeos/dbus/fake_session_manager_client.h" 31 #include "chromeos/dbus/fake_session_manager_client.h"
31 #include "components/arc/arc_bridge_service.h" 32 #include "components/arc/arc_bridge_service.h"
33 #include "components/arc/arc_service_manager.h"
32 #include "components/arc/test/fake_arc_bridge_service.h" 34 #include "components/arc/test/fake_arc_bridge_service.h"
33 #include "components/prefs/pref_service.h" 35 #include "components/prefs/pref_service.h"
34 #include "components/signin/core/account_id/account_id.h" 36 #include "components/signin/core/account_id/account_id.h"
35 #include "components/sync/model/fake_sync_change_processor.h" 37 #include "components/sync/model/fake_sync_change_processor.h"
36 #include "components/sync/model/sync_error_factory_mock.h" 38 #include "components/sync/model/sync_error_factory_mock.h"
37 #include "components/sync_preferences/testing_pref_service_syncable.h" 39 #include "components/sync_preferences/testing_pref_service_syncable.h"
38 #include "components/user_manager/user_manager.h" 40 #include "components/user_manager/user_manager.h"
39 #include "components/user_manager/user_names.h" 41 #include "components/user_manager/user_names.h"
40 #include "content/public/browser/browser_thread.h" 42 #include "content/public/browser/browser_thread.h"
41 #include "content/public/test/test_browser_thread_bundle.h" 43 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 21 matching lines...) Expand all
63 chromeos::switches::kEnableArc); 65 chromeos::switches::kEnableArc);
64 ArcSessionManager::DisableUIForTesting(); 66 ArcSessionManager::DisableUIForTesting();
65 67
66 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 68 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
67 TestingProfile::Builder profile_builder; 69 TestingProfile::Builder profile_builder;
68 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); 70 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
69 71
70 profile_ = profile_builder.Build(); 72 profile_ = profile_builder.Build();
71 StartPreferenceSyncing(); 73 StartPreferenceSyncing();
72 74
73 bridge_service_.reset(new FakeArcBridgeService()); 75 ArcServiceManager::SetArcBridgeServiceForTesting(
74 arc_session_manager_.reset(new ArcSessionManager(bridge_service_.get())); 76 base::MakeUnique<FakeArcBridgeService>());
77 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr);
78 arc_session_manager_ = base::MakeUnique<ArcSessionManager>(
79 arc_service_manager_->arc_bridge_service());
75 80
76 // Check initial conditions. 81 // Check initial conditions.
77 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); 82 EXPECT_TRUE(bridge_service()->stopped());
78 EXPECT_TRUE(ArcBridgeService::Get()->stopped());
79 83
80 const AccountId account_id( 84 const AccountId account_id(
81 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890")); 85 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890"));
82 GetFakeUserManager()->AddUser(account_id); 86 GetFakeUserManager()->AddUser(account_id);
83 GetFakeUserManager()->LoginUser(account_id); 87 GetFakeUserManager()->LoginUser(account_id);
84 88
85 chromeos::WallpaperManager::Initialize(); 89 chromeos::WallpaperManager::Initialize();
86 } 90 }
87 91
88 void TearDown() override { 92 void TearDown() override {
89 chromeos::WallpaperManager::Shutdown(); 93 chromeos::WallpaperManager::Shutdown();
94 arc_session_manager_.reset();
95 arc_service_manager_.reset();
90 chromeos::DBusThreadManager::Shutdown(); 96 chromeos::DBusThreadManager::Shutdown();
91 } 97 }
92 98
93 chromeos::FakeChromeUserManager* GetFakeUserManager() const { 99 chromeos::FakeChromeUserManager* GetFakeUserManager() const {
94 return static_cast<chromeos::FakeChromeUserManager*>( 100 return static_cast<chromeos::FakeChromeUserManager*>(
95 user_manager::UserManager::Get()); 101 user_manager::UserManager::Get());
96 } 102 }
97 103
98 protected: 104 protected:
99 Profile* profile() { return profile_.get(); } 105 Profile* profile() { return profile_.get(); }
100 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } 106 FakeArcBridgeService* bridge_service() {
107 return static_cast<FakeArcBridgeService*>(
108 arc_service_manager_->arc_bridge_service());
109 }
101 ArcSessionManager* arc_session_manager() { 110 ArcSessionManager* arc_session_manager() {
102 return arc_session_manager_.get(); 111 return arc_session_manager_.get();
103 } 112 }
104 113
105 bool WaitForDataRemoved(ArcSessionManager::State expected_state) { 114 bool WaitForDataRemoved(ArcSessionManager::State expected_state) {
106 if (arc_session_manager()->state() != 115 if (arc_session_manager()->state() !=
107 ArcSessionManager::State::REMOVING_DATA_DIR) 116 ArcSessionManager::State::REMOVING_DATA_DIR)
108 return false; 117 return false;
109 118
110 base::RunLoop().RunUntilIdle(); 119 base::RunLoop().RunUntilIdle();
111 if (arc_session_manager()->state() != expected_state) 120 if (arc_session_manager()->state() != expected_state)
112 return false; 121 return false;
113 122
114 return true; 123 return true;
115 } 124 }
116 125
117 private: 126 private:
118 void StartPreferenceSyncing() const { 127 void StartPreferenceSyncing() const {
119 PrefServiceSyncableFromProfile(profile_.get()) 128 PrefServiceSyncableFromProfile(profile_.get())
120 ->GetSyncableService(syncer::PREFERENCES) 129 ->GetSyncableService(syncer::PREFERENCES)
121 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), 130 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(),
122 std::unique_ptr<syncer::SyncChangeProcessor>( 131 std::unique_ptr<syncer::SyncChangeProcessor>(
123 new syncer::FakeSyncChangeProcessor), 132 new syncer::FakeSyncChangeProcessor),
124 std::unique_ptr<syncer::SyncErrorFactory>( 133 std::unique_ptr<syncer::SyncErrorFactory>(
125 new syncer::SyncErrorFactoryMock())); 134 new syncer::SyncErrorFactoryMock()));
126 } 135 }
127 136
128 content::TestBrowserThreadBundle thread_bundle_; 137 content::TestBrowserThreadBundle thread_bundle_;
129 std::unique_ptr<FakeArcBridgeService> bridge_service_;
130 std::unique_ptr<TestingProfile> profile_; 138 std::unique_ptr<TestingProfile> profile_;
139 std::unique_ptr<ArcServiceManager> arc_service_manager_;
131 std::unique_ptr<ArcSessionManager> arc_session_manager_; 140 std::unique_ptr<ArcSessionManager> arc_session_manager_;
132 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 141 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
133 base::ScopedTempDir temp_dir_; 142 base::ScopedTempDir temp_dir_;
134 143
135 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 144 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
136 }; 145 };
137 146
138 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 147 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) {
139 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 148 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
140 arc_session_manager()->state()); 149 arc_session_manager()->state());
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // Try to send another error that stops the bridge if sent first. It should 479 // Try to send another error that stops the bridge if sent first. It should
471 // be ignored. 480 // be ignored.
472 arc_session_manager()->OnProvisioningFinished( 481 arc_session_manager()->OnProvisioningFinished(
473 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 482 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
474 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 483 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
475 484
476 arc_session_manager()->Shutdown(); 485 arc_session_manager()->Shutdown();
477 } 486 }
478 487
479 } // namespace arc 488 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/arc/intent_helper/arc_settings_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698