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/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)); | |
hidehiko
2016/12/06 05:05:30
nit: base::MakeUnique<chromeos::FakeSessionManager
khmel
2016/12/06 18:16:12
Done.
| |
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | 127 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
124 arc_session_manager()->state()); | 128 arc_session_manager()->state()); |
125 | 129 |
126 PrefService* const pref = profile()->GetPrefs(); | 130 PrefService* const pref = profile()->GetPrefs(); |
127 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 131 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
128 | 132 |
129 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 133 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
130 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 134 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
131 | 135 |
132 pref->SetBoolean(prefs::kArcEnabled, true); | 136 pref->SetBoolean(prefs::kArcEnabled, true); |
137 base::RunLoop().RunUntilIdle(); | |
133 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 138 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
134 arc_session_manager()->state()); | 139 arc_session_manager()->state()); |
135 | 140 |
136 pref->SetBoolean(prefs::kArcEnabled, false); | 141 pref->SetBoolean(prefs::kArcEnabled, false); |
137 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 142 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
138 | 143 |
139 // Correctly stop service. | 144 // Correctly stop service. |
140 arc_session_manager()->Shutdown(); | 145 arc_session_manager()->Shutdown(); |
141 } | 146 } |
142 | 147 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 ASSERT_FALSE(bridge_service()->ready()); | 194 ASSERT_FALSE(bridge_service()->ready()); |
190 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, | 195 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, |
191 arc_session_manager()->state()); | 196 arc_session_manager()->state()); |
192 | 197 |
193 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 198 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
194 | 199 |
195 // By default ARC is not enabled. | 200 // By default ARC is not enabled. |
196 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 201 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
197 | 202 |
198 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 203 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
204 base::RunLoop().RunUntilIdle(); | |
199 | 205 |
200 // Setting profile and pref initiates a code fetching process. | 206 // Setting profile and pref initiates a code fetching process. |
201 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 207 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
202 arc_session_manager()->state()); | 208 arc_session_manager()->state()); |
203 | 209 |
204 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> | 210 // TODO(hidehiko): Verify state transition from SHOWING_TERMS_OF_SERVICE -> |
205 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. | 211 // CHECKING_ANDROID_MANAGEMENT, when we extract ArcSessionManager. |
206 arc_session_manager()->StartArc(); | 212 arc_session_manager()->StartArc(); |
207 | 213 |
208 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 214 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
(...skipping 20 matching lines...) Expand all Loading... | |
229 | 235 |
230 // Correctly stop service. | 236 // Correctly stop service. |
231 arc_session_manager()->Shutdown(); | 237 arc_session_manager()->Shutdown(); |
232 } | 238 } |
233 | 239 |
234 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { | 240 TEST_F(ArcSessionManagerTest, CancelFetchingDisablesArc) { |
235 PrefService* const pref = profile()->GetPrefs(); | 241 PrefService* const pref = profile()->GetPrefs(); |
236 | 242 |
237 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 243 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
238 pref->SetBoolean(prefs::kArcEnabled, true); | 244 pref->SetBoolean(prefs::kArcEnabled, true); |
245 base::RunLoop().RunUntilIdle(); | |
246 | |
239 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | 247 ASSERT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, |
240 arc_session_manager()->state()); | 248 arc_session_manager()->state()); |
241 | 249 |
242 arc_session_manager()->CancelAuthCode(); | 250 arc_session_manager()->CancelAuthCode(); |
243 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | 251 ASSERT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); |
244 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 252 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
245 | 253 |
246 // Correctly stop service. | 254 // Correctly stop service. |
247 arc_session_manager()->Shutdown(); | 255 arc_session_manager()->Shutdown(); |
248 } | 256 } |
249 | 257 |
250 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { | 258 TEST_F(ArcSessionManagerTest, CloseUIKeepsArcEnabled) { |
251 PrefService* const pref = profile()->GetPrefs(); | 259 PrefService* const pref = profile()->GetPrefs(); |
252 | 260 |
253 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | 261 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); |
254 pref->SetBoolean(prefs::kArcEnabled, true); | 262 pref->SetBoolean(prefs::kArcEnabled, true); |
263 base::RunLoop().RunUntilIdle(); | |
255 | 264 |
256 arc_session_manager()->StartArc(); | 265 arc_session_manager()->StartArc(); |
257 | 266 |
258 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 267 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
259 | 268 |
260 arc_session_manager()->CancelAuthCode(); | 269 arc_session_manager()->CancelAuthCode(); |
261 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | 270 ASSERT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); |
262 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); | 271 ASSERT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); |
263 | 272 |
264 // Correctly stop service. | 273 // Correctly stop service. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 GetFakeUserManager()->SwitchActiveUser(account_id); | 377 GetFakeUserManager()->SwitchActiveUser(account_id); |
369 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 378 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
370 | 379 |
371 // Check that non-primary user can't use Arc. | 380 // Check that non-primary user can't use Arc. |
372 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); | 381 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); |
373 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); | 382 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); |
374 | 383 |
375 arc_session_manager()->Shutdown(); | 384 arc_session_manager()->Shutdown(); |
376 } | 385 } |
377 | 386 |
387 TEST_F(ArcSessionManagerTest, RemoveDataFolder) { | |
388 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | |
389 // Starting session manager with prefs::kArcEnabled off automatically removes | |
390 // Android's data folder. | |
391 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
392 EXPECT_TRUE( | |
393 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
394 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
395 // Enable ARC. Data is removed asyncronously. At this moment session manager | |
396 // still should be stopped and data removal request is active. | |
397 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | |
398 EXPECT_TRUE( | |
399 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
400 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
401 // Wait until data is removed. | |
402 base::RunLoop().RunUntilIdle(); | |
403 EXPECT_FALSE( | |
404 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
405 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
406 arc_session_manager()->state()); | |
407 arc_session_manager()->StartArc(); | |
408 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
409 | |
410 // Now request to remove data and stop session manager. | |
411 ArcSessionManager::Get()->RemoveArcData(); | |
hidehiko
2016/12/02 08:54:55
s/ArcSessionManager::Get()/arc_session_manager()/
khmel
2016/12/06 03:23:57
Done.
| |
412 ASSERT_TRUE( | |
413 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
414 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
415 ArcSessionManager::Get()->Shutdown(); | |
hidehiko
2016/12/02 08:54:55
Ditto.
khmel
2016/12/06 03:23:57
Done.
| |
416 base::RunLoop().RunUntilIdle(); | |
417 // Request should persist. | |
418 ASSERT_TRUE( | |
419 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
420 | |
421 // Emulate next sign-in. Data should be removed first and ARC started after. | |
hidehiko
2016/12/02 08:54:55
To emulate re-sign-in, shouldn't we re-instantiate
khmel
2016/12/06 03:23:57
Hmm, probably I did not get you. Second and next O
hidehiko
2016/12/06 05:05:30
Oh, sorry for my poor explanation.
I was wondering
khmel
2016/12/06 18:16:12
I did similar what you suggested in some other tes
hidehiko
2016/12/06 18:32:09
My understanding is, the check in the callback is
| |
422 arc_session_manager()->OnPrimaryUserProfilePrepared(profile()); | |
423 EXPECT_TRUE( | |
424 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
425 EXPECT_EQ(ArcSessionManager::State::STOPPED, arc_session_manager()->state()); | |
426 base::RunLoop().RunUntilIdle(); | |
427 EXPECT_FALSE( | |
428 profile()->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)); | |
429 EXPECT_EQ(ArcSessionManager::State::SHOWING_TERMS_OF_SERVICE, | |
430 arc_session_manager()->state()); | |
431 arc_session_manager()->StartArc(); | |
432 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); | |
433 ArcSessionManager::Get()->Shutdown(); | |
hidehiko
2016/12/02 08:54:55
Ditto.
khmel
2016/12/06 03:23:57
Done.
| |
434 } | |
435 | |
378 } // namespace arc | 436 } // namespace arc |
OLD | NEW |