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

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: use states / rebased 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::WrapUnique(new 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 void WaitForDataRemoved(ArcSessionManager::State expected_state) {
106 ASSERT_EQ(ArcSessionManager::State::DELETING_DATA_FOLDER,
hidehiko 2016/12/06 05:05:30 This won't work. ASSERT_EQ is a macro to return f
khmel 2016/12/06 18:16:13 IIUC abort is called if any problem with ASSERT_EQ
hidehiko 2016/12/06 18:32:10 FYI: https://cs.chromium.org/chromium/src/testing/
107 arc_session_manager()->state());
108 base::RunLoop().RunUntilIdle();
109 ASSERT_EQ(expected_state, arc_session_manager()->state());
110 }
111
101 private: 112 private:
102 void StartPreferenceSyncing() const { 113 void StartPreferenceSyncing() const {
103 PrefServiceSyncableFromProfile(profile_.get()) 114 PrefServiceSyncableFromProfile(profile_.get())
104 ->GetSyncableService(syncer::PREFERENCES) 115 ->GetSyncableService(syncer::PREFERENCES)
105 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), 116 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(),
106 std::unique_ptr<syncer::SyncChangeProcessor>( 117 std::unique_ptr<syncer::SyncChangeProcessor>(
107 new syncer::FakeSyncChangeProcessor), 118 new syncer::FakeSyncChangeProcessor),
108 std::unique_ptr<syncer::SyncErrorFactory>( 119 std::unique_ptr<syncer::SyncErrorFactory>(
109 new syncer::SyncErrorFactoryMock())); 120 new syncer::SyncErrorFactoryMock()));
110 } 121 }
111 122
112 content::TestBrowserThreadBundle thread_bundle_; 123 content::TestBrowserThreadBundle thread_bundle_;
113 std::unique_ptr<FakeArcBridgeService> bridge_service_; 124 std::unique_ptr<FakeArcBridgeService> bridge_service_;
114 std::unique_ptr<TestingProfile> profile_; 125 std::unique_ptr<TestingProfile> profile_;
115 std::unique_ptr<ArcSessionManager> arc_session_manager_; 126 std::unique_ptr<ArcSessionManager> arc_session_manager_;
116 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 127 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
117 base::ScopedTempDir temp_dir_; 128 base::ScopedTempDir temp_dir_;
118 129
119 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 130 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
120 }; 131 };
121 132
122 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 133 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) {
123 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 134 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
124 arc_session_manager()->state()); 135 arc_session_manager()->state());
125 136
126 PrefService* const pref = profile()->GetPrefs(); 137 PrefService* const pref = profile()->GetPrefs();
127 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 138 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
128 139
129 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 140 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
130 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 141
142 WaitForDataRemoved(ArcSessionManager::State::STOPPED);
131 143
132 pref->SetBoolean(prefs::kArcEnabled, true); 144 pref->SetBoolean(prefs::kArcEnabled, true);
145 base::RunLoop().RunUntilIdle();
133 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 146 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
134 arc_session_manager()->state()); 147 arc_session_manager()->state());
135 148
136 pref->SetBoolean(prefs::kArcEnabled, false); 149 pref->SetBoolean(prefs::kArcEnabled, false);
137 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 150
151 WaitForDataRemoved(ArcSessionManager::State::STOPPED);
138 152
139 // Correctly stop service. 153 // Correctly stop service.
140 arc_session_manager()->Shutdown(); 154 arc_session_manager()->Shutdown();
141 } 155 }
142 156
143 TEST_F(ArcSessionManagerTest, DisabledForEphemeralDataUsers) { 157 TEST_F(ArcSessionManagerTest, DisabledForEphemeralDataUsers) {
144 PrefService* const prefs = profile()->GetPrefs(); 158 PrefService* const prefs = profile()->GetPrefs();
145 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); 159 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn));
146 prefs->SetBoolean(prefs::kArcEnabled, true); 160 prefs->SetBoolean(prefs::kArcEnabled, true);
147 161
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 200 }
187 201
188 TEST_F(ArcSessionManagerTest, BaseWorkflow) { 202 TEST_F(ArcSessionManagerTest, BaseWorkflow) {
189 ASSERT_FALSE(bridge_service()->ready()); 203 ASSERT_FALSE(bridge_service()->ready());
190 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 204 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
191 arc_session_manager()->state()); 205 arc_session_manager()->state());
192 206
193 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 207 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
194 208
195 // By default ARC is not enabled. 209 // By default ARC is not enabled.
196 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 210 WaitForDataRemoved(ArcSessionManager::State::STOPPED);
197 211
198 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 212 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
213 base::RunLoop().RunUntilIdle();
199 214
200 // Setting profile and pref initiates a code fetching process. 215 // Setting profile and pref initiates a code fetching process.
201 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 216 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
202 arc_session_manager()->state()); 217 arc_session_manager()->state());
203 218
204 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> 219 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE ->
205 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. 220 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager.
206 arc_session_manager()->StartArc(); 221 arc_session_manager()->StartArc();
207 222
208 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 223 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
(...skipping 20 matching lines...) Expand all
229 244
230 // Correctly stop service. 245 // Correctly stop service.
231 arc_session_manager()->Shutdown(); 246 arc_session_manager()->Shutdown();
232 } 247 }
233 248
234 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { 249 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) {
235 PrefService* const pref = profile()->GetPrefs(); 250 PrefService* const pref = profile()->GetPrefs();
236 251
237 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 252 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
238 pref->SetBoolean(prefs::kArcEnabled, true); 253 pref->SetBoolean(prefs::kArcEnabled, true);
254 base::RunLoop().RunUntilIdle();
255
239 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, 256 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
240 arc_session_manager()->state()); 257 arc_session_manager()->state());
241 258
242 arc_session_manager()->CancelAuthCode(); 259 arc_session_manager()->CancelAuthCode();
243 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); 260
261 // Wait until data is removed.
262 WaitForDataRemoved(ArcSessionManager::State::STOPPED);
263
244 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 264 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
245 265
246 // Correctly stop service. 266 // Correctly stop service.
247 arc_session_manager()->Shutdown(); 267 arc_session_manager()->Shutdown();
248 } 268 }
249 269
250 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { 270 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) {
251 PrefService* const pref = profile()->GetPrefs(); 271 PrefService* const pref = profile()->GetPrefs();
252 272
253 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); 273 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
254 pref->SetBoolean(prefs::kArcEnabled, true); 274 pref->SetBoolean(prefs::kArcEnabled, true);
275 base::RunLoop().RunUntilIdle();
255 276
256 arc_session_manager()->StartArc(); 277 arc_session_manager()->StartArc();
257 278
258 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 279 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
259 280
260 arc_session_manager()->CancelAuthCode(); 281 arc_session_manager()->CancelAuthCode();
261 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 282 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
262 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); 283 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled));
263 284
264 // Correctly stop service. 285 // Correctly stop service.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 GetFakeUserManager()->SwitchActiveUser(account_id); 391 GetFakeUserManager()->SwitchActiveUser(account_id);
371 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 392 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
372 393
373 // Check that non-primary user can't use Arc. 394 // Check that non-primary user can't use Arc.
374 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); 395 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get()));
375 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); 396 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get()));
376 397
377 arc_session_manager()->Shutdown(); 398 arc_session_manager()->Shutdown();
378 } 399 }
379 400
401 TEST_F(ArcSessionManagerTest, RemoveDataFolder) {
402 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
403 // Starting session manager with prefs::kArcEnabled off automatically removes
404 // Android's data folder.
405 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
406 EXPECT_TRUE(
407 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
408 EXPECT_EQ(ArcSessionManager::State::DELETING_DATA_FOLDER,
409 arc_session_manager()->state());
410 // Enable ARC. Data is removed asyncronously. At this moment session manager
411 // should be in DELETING_DATA_FOLDER state.
412 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
413 EXPECT_TRUE(
414 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
415 EXPECT_EQ(ArcSessionManager::State::DELETING_DATA_FOLDER,
416 arc_session_manager()->state());
417 // Wait until data is removed.
418 base::RunLoop().RunUntilIdle();
419 EXPECT_FALSE(
420 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
421 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE,
422 arc_session_manager()->state());
423 arc_session_manager()->StartArc();
424 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
425
426 // Now request to remove data and stop session manager.
427 arc_session_manager()->RemoveArcData();
428 ASSERT_TRUE(
429 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
430 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
431 arc_session_manager()->Shutdown();
432 base::RunLoop().RunUntilIdle();
433 // Request should persist.
434 ASSERT_TRUE(
435 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
436
437 // Emulate next sign-in. Data should be removed first and ARC started after.
438 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
439 EXPECT_TRUE(
440 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
441
442 WaitForDataRemoved(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE);
443
444 EXPECT_FALSE(
445 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested));
446
447 arc_session_manager()->StartArc();
448 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
449 arc_session_manager()->Shutdown();
450 }
451
380 } // namespace arc 452 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698