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

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

Issue 2541173002: arc: Make request to remove Android's data folder persistent. (Closed)
Patch Set: fix browser tests 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
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/run_loop.h" 15 #include "base/run_loop.h"
16 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 16 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
17 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 17 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" 18 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 19 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
20 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 20 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" 21 #include "chrome/browser/chromeos/profiles/profile_helper.h"
22 #include "chrome/browser/prefs/pref_service_syncable_util.h" 22 #include "chrome/browser/prefs/pref_service_syncable_util.h"
23 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" 24 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h"
25 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 25 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "chromeos/chromeos_switches.h" 28 #include "chromeos/chromeos_switches.h"
29 #include "chromeos/dbus/dbus_thread_manager.h" 29 #include "chromeos/dbus/dbus_thread_manager.h"
30 #include "chromeos/dbus/fake_session_manager_client.h"
30 #include "components/arc/arc_bridge_service.h" 31 #include "components/arc/arc_bridge_service.h"
31 #include "components/arc/test/fake_arc_bridge_service.h" 32 #include "components/arc/test/fake_arc_bridge_service.h"
32 #include "components/prefs/pref_service.h" 33 #include "components/prefs/pref_service.h"
33 #include "components/signin/core/account_id/account_id.h" 34 #include "components/signin/core/account_id/account_id.h"
34 #include "components/sync/model/fake_sync_change_processor.h" 35 #include "components/sync/model/fake_sync_change_processor.h"
35 #include "components/sync/model/sync_error_factory_mock.h" 36 #include "components/sync/model/sync_error_factory_mock.h"
36 #include "components/sync_preferences/testing_pref_service_syncable.h" 37 #include "components/sync_preferences/testing_pref_service_syncable.h"
37 #include "components/user_manager/user_manager.h" 38 #include "components/user_manager/user_manager.h"
38 #include "components/user_manager/user_names.h" 39 #include "components/user_manager/user_names.h"
39 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
40 #include "content/public/test/test_browser_thread_bundle.h" 41 #include "content/public/test/test_browser_thread_bundle.h"
41 #include "google_apis/gaia/gaia_constants.h" 42 #include "google_apis/gaia/gaia_constants.h"
42 #include "google_apis/gaia/gaia_urls.h" 43 #include "google_apis/gaia/gaia_urls.h"
43 #include "net/http/http_status_code.h" 44 #include "net/http/http_status_code.h"
44 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
45 46
46 namespace arc { 47 namespace arc {
47 48
48 class ArcSessionManagerTest : public testing::Test { 49 class ArcSessionManagerTest : public testing::Test {
49 public: 50 public:
50 ArcSessionManagerTest() 51 ArcSessionManagerTest()
51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 52 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
52 user_manager_enabler_(new chromeos::FakeChromeUserManager) {} 53 user_manager_enabler_(new chromeos::FakeChromeUserManager) {}
53 ~ArcSessionManagerTest() override = default; 54 ~ArcSessionManagerTest() override = default;
54 55
55 void SetUp() override { 56 void SetUp() override {
57 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
58 base::MakeUnique<chromeos::FakeSessionManagerClient>());
59
56 chromeos::DBusThreadManager::Initialize(); 60 chromeos::DBusThreadManager::Initialize();
57 61
58 base::CommandLine::ForCurrentProcess()->AppendSwitch( 62 base::CommandLine::ForCurrentProcess()->AppendSwitch(
59 chromeos::switches::kEnableArc); 63 chromeos::switches::kEnableArc);
60 ArcSessionManager::DisableUIForTesting(); 64 ArcSessionManager::DisableUIForTesting();
61 65
62 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 66 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
63 TestingProfile::Builder profile_builder; 67 TestingProfile::Builder profile_builder;
64 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); 68 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
65 69
(...skipping 25 matching lines...) Expand all
91 user_manager::UserManager::Get()); 95 user_manager::UserManager::Get());
92 } 96 }
93 97
94 protected: 98 protected:
95 Profile* profile() { return profile_.get(); } 99 Profile* profile() { return profile_.get(); }
96 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } 100 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); }
97 ArcSessionManager* arc_session_manager() { 101 ArcSessionManager* arc_session_manager() {
98 return arc_session_manager_.get(); 102 return arc_session_manager_.get();
99 } 103 }
100 104
105 bool WaitForDataRemoved(ArcSessionManager::State expected_state) {
106 if (arc_session_manager()->state() !=
107 ArcSessionManager::State::REMOVING_DATA_DIR)
108 return false;
109
110 base::RunLoop().RunUntilIdle();
111 if (arc_session_manager()->state() != expected_state)
112 return false;
113
114 return true;
115 }
116
101 private: 117 private:
102 void StartPreferenceSyncing() const { 118 void StartPreferenceSyncing() const {
103 PrefServiceSyncableFromProfile(profile_.get()) 119 PrefServiceSyncableFromProfile(profile_.get())
104 ->GetSyncableService(syncer::PREFERENCES) 120 ->GetSyncableService(syncer::PREFERENCES)
105 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), 121 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(),
106 std::unique_ptr<syncer::SyncChangeProcessor>( 122 std::unique_ptr<syncer::SyncChangeProcessor>(
107 new syncer::FakeSyncChangeProcessor), 123 new syncer::FakeSyncChangeProcessor),
108 std::unique_ptr<syncer::SyncErrorFactory>( 124 std::unique_ptr<syncer::SyncErrorFactory>(
109 new syncer::SyncErrorFactoryMock())); 125 new syncer::SyncErrorFactoryMock()));
110 } 126 }
111 127
112 content::TestBrowserThreadBundle thread_bundle_; 128 content::TestBrowserThreadBundle thread_bundle_;
113 std::unique_ptr<FakeArcBridgeService> bridge_service_; 129 std::unique_ptr<FakeArcBridgeService> bridge_service_;
114 std::unique_ptr<TestingProfile> profile_; 130 std::unique_ptr<TestingProfile> profile_;
115 std::unique_ptr<ArcSessionManager> arc_session_manager_; 131 std::unique_ptr<ArcSessionManager> arc_session_manager_;
116 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 132 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
117 base::ScopedTempDir temp_dir_; 133 base::ScopedTempDir temp_dir_;
118 134
119 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 135 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
120 }; 136 };
121 137
122 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 138 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) {
123 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 139 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
124 arc_session_manager()->state()); 140 arc_session_manager()->state());
125 141
126 PrefService* const pref = profile()->GetPrefs(); 142 PrefService* const pref = profile()->GetPrefs();
127 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 143 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
128 144
129 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 145 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
130 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 146
147 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
131 148
132 pref->SetBoolean(prefs::kArcEnabled, true); 149 pref->SetBoolean(prefs::kArcEnabled, true);
150 base::RunLoop().RunUntilIdle();
133 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 151 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
134 arc_session_manager()->state()); 152 arc_session_manager()->state());
135 153
136 pref->SetBoolean(prefs::kArcEnabled, false); 154 pref->SetBoolean(prefs::kArcEnabled, false);
137 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 155
156 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
138 157
139 // Correctly stop service. 158 // Correctly stop service.
140 arc_session_manager()->Shutdown(); 159 arc_session_manager()->Shutdown();
141 } 160 }
142 161
143 TEST_F(ArcSessionManagerTest, DisabledForEphemeralDataUsers) { 162 TEST_F(ArcSessionManagerTest, DisabledForEphemeralDataUsers) {
144 PrefService* const prefs = profile()->GetPrefs(); 163 PrefService* const prefs = profile()->GetPrefs();
145 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 164 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
146 prefs->SetBoolean(prefs::kArcEnabled, true); 165 prefs->SetBoolean(prefs::kArcEnabled, true);
147 166
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 205 }
187 206
188 TEST_F(ArcSessionManagerTest, BaseWorkflow) { 207 TEST_F(ArcSessionManagerTest, BaseWorkflow) {
189 ASSERT_FALSE(bridge_service()->ready()); 208 ASSERT_FALSE(bridge_service()->ready());
190 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 209 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
191 arc_session_manager()->state()); 210 arc_session_manager()->state());
192 211
193 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 212 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
194 213
195 // By default ARC is not enabled. 214 // By default ARC is not enabled.
196 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 215 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
197 216
198 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 217 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
218 base::RunLoop().RunUntilIdle();
199 219
200 // Setting profile and pref initiates a code fetching process. 220 // Setting profile and pref initiates a code fetching process.
201 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 221 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
202 arc_session_manager()->state()); 222 arc_session_manager()->state());
203 223
204 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> 224 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE ->
205 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. 225 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager.
206 arc_session_manager()->StartArc(); 226 arc_session_manager()->StartArc();
207 227
208 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 228 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
(...skipping 20 matching lines...) Expand all
229 249
230 // Correctly stop service. 250 // Correctly stop service.
231 arc_session_manager()->Shutdown(); 251 arc_session_manager()->Shutdown();
232 } 252 }
233 253
234 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { 254 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) {
235 PrefService* const pref = profile()->GetPrefs(); 255 PrefService* const pref = profile()->GetPrefs();
236 256
237 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 257 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
238 pref->SetBoolean(prefs::kArcEnabled, true); 258 pref->SetBoolean(prefs::kArcEnabled, true);
259 base::RunLoop().RunUntilIdle();
260
239 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 261 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
240 arc_session_manager()->state()); 262 arc_session_manager()->state());
241 263
242 arc_session_manager()->CancelAuthCode(); 264 arc_session_manager()->CancelAuthCode();
243 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 265
266 // Wait until data is removed.
267 ASSERT_TRUE(WaitForDataRemoved(ArcSessionManager::State::STOPPED));
268
244 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 269 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
245 270
246 // Correctly stop service. 271 // Correctly stop service.
247 arc_session_manager()->Shutdown(); 272 arc_session_manager()->Shutdown();
248 } 273 }
249 274
250 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { 275 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) {
251 PrefService* const pref = profile()->GetPrefs(); 276 PrefService* const pref = profile()->GetPrefs();
252 277
253 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 278 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
254 pref->SetBoolean(prefs::kArcEnabled, true); 279 pref->SetBoolean(prefs::kArcEnabled, true);
280 base::RunLoop().RunUntilIdle();
255 281
256 arc_session_manager()->StartArc(); 282 arc_session_manager()->StartArc();
257 283
258 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 284 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
259 285
260 arc_session_manager()->CancelAuthCode(); 286 arc_session_manager()->CancelAuthCode();
261 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 287 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
262 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); 288 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled));
263 289
264 // Correctly stop service. 290 // Correctly stop service.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 GetFakeUserManager()->SwitchActiveUser(account_id); 396 GetFakeUserManager()->SwitchActiveUser(account_id);
371 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 397 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
372 398
373 // Check that non-primary user can't use Arc. 399 // Check that non-primary user can't use Arc.
374 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); 400 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get()));
375 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); 401 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get()));
376 402
377 arc_session_manager()->Shutdown(); 403 arc_session_manager()->Shutdown();
378 } 404 }
379 405
406 TEST_F(ArcSessionManagerTest, RemoveDataFolder) {
407 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
408 // Starting session manager with prefs::kArcEnabled off automatically removes
409 // Android's data folder.
410 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
411 EXPECT_TRUE(
412 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
413 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
414 arc_session_manager()->state());
415 // Enable ARC. Data is removed asyncronously. At this moment session manager
416 // should be in REMOVING_DATA_DIR state.
417 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
418 EXPECT_TRUE(
419 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
420 EXPECT_EQ(ArcSessionManager::State::REMOVING_DATA_DIR,
421 arc_session_manager()->state());
422 // Wait until data is removed.
423 base::RunLoop().RunUntilIdle();
424 EXPECT_FALSE(
425 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
426 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
427 arc_session_manager()->state());
428 arc_session_manager()->StartArc();
429 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
430
431 // Now request to remove data and stop session manager.
432 arc_session_manager()->RemoveArcData();
433 ASSERT_TRUE(
434 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
435 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
436 arc_session_manager()->Shutdown();
437 base::RunLoop().RunUntilIdle();
438 // Request should persist.
439 ASSERT_TRUE(
440 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
441
442 // Emulate next sign-in. Data should be removed first and ARC started after.
443 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
444 EXPECT_TRUE(
445 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
446
447 ASSERT_TRUE(
448 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE));
449
450 EXPECT_FALSE(
451 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
452
453 arc_session_manager()->StartArc();
454 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
455 arc_session_manager()->Shutdown();
456 }
457
380 } // namespace arc 458 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698