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

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

Issue 2553193002: Remove explicit singletonness of ArcBridgeService part 4. (Closed)
Patch Set: 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"
(...skipping 27 matching lines...) Expand all
38 #include "components/user_manager/user_names.h" 38 #include "components/user_manager/user_names.h"
39 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
40 #include "content/public/test/test_browser_thread_bundle.h" 40 #include "content/public/test/test_browser_thread_bundle.h"
41 #include "google_apis/gaia/gaia_constants.h" 41 #include "google_apis/gaia/gaia_constants.h"
42 #include "google_apis/gaia/gaia_urls.h" 42 #include "google_apis/gaia/gaia_urls.h"
43 #include "net/http/http_status_code.h" 43 #include "net/http/http_status_code.h"
44 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
45 45
46 namespace arc { 46 namespace arc {
47 47
48 class ArcSessionManagerTest : public testing::Test { 48 class ArcSessionManagerTestBase : public testing::Test {
49 public: 49 public:
50 ArcSessionManagerTest() 50 ArcSessionManagerTestBase()
51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 51 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
52 user_manager_enabler_(new chromeos::FakeChromeUserManager) {} 52 user_manager_enabler_(new chromeos::FakeChromeUserManager()) {}
53 ~ArcSessionManagerTest() override = default; 53 ~ArcSessionManagerTestBase() override = default;
54 54
55 void SetUp() override { 55 void SetUp() override {
56 chromeos::DBusThreadManager::Initialize(); 56 chromeos::DBusThreadManager::Initialize();
57 57
58 base::CommandLine::ForCurrentProcess()->AppendSwitch( 58 base::CommandLine::ForCurrentProcess()->AppendSwitch(
59 chromeos::switches::kEnableArc); 59 chromeos::switches::kEnableArc);
60 ArcSessionManager::DisableUIForTesting(); 60 ArcSessionManager::DisableUIForTesting();
61 61
62 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 62 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
63 TestingProfile::Builder profile_builder; 63 TestingProfile::Builder profile_builder;
64 profile_builder.SetProfileName("user@gmail.com");
64 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); 65 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
65 66
66 profile_ = profile_builder.Build(); 67 profile_ = profile_builder.Build();
67 StartPreferenceSyncing(); 68 StartPreferenceSyncing();
68 69
69 bridge_service_.reset(new FakeArcBridgeService()); 70 bridge_service_.reset(new FakeArcBridgeService());
70 arc_session_manager_.reset(new ArcSessionManager(bridge_service_.get())); 71 arc_session_manager_.reset(new ArcSessionManager(bridge_service_.get()));
71 72
72 // Check initial conditions. 73 // Check initial conditions.
73 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); 74 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get());
74 EXPECT_TRUE(ArcBridgeService::Get()->stopped()); 75 EXPECT_TRUE(ArcBridgeService::Get()->stopped());
75 76
76 const AccountId account_id(
77 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890"));
78 GetFakeUserManager()->AddUser(account_id);
79 GetFakeUserManager()->LoginUser(account_id);
80
81 chromeos::WallpaperManager::Initialize(); 77 chromeos::WallpaperManager::Initialize();
82 } 78 }
83 79
84 void TearDown() override { 80 void TearDown() override {
85 chromeos::WallpaperManager::Shutdown(); 81 chromeos::WallpaperManager::Shutdown();
86 chromeos::DBusThreadManager::Shutdown(); 82 chromeos::DBusThreadManager::Shutdown();
87 } 83 }
88 84
89 chromeos::FakeChromeUserManager* GetFakeUserManager() const { 85 chromeos::FakeChromeUserManager* GetFakeUserManager() const {
90 return static_cast<chromeos::FakeChromeUserManager*>( 86 return static_cast<chromeos::FakeChromeUserManager*>(
91 user_manager::UserManager::Get()); 87 user_manager::UserManager::Get());
92 } 88 }
93 89
94 protected: 90 protected:
95 Profile* profile() { return profile_.get(); } 91 Profile* profile() { return profile_.get(); }
96 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } 92 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); }
97 ArcSessionManager* arc_session_manager() { 93 ArcSessionManager* arc_session_manager() {
98 return arc_session_manager_.get(); 94 return arc_session_manager_.get();
99 } 95 }
100 96
101 private: 97 private:
102 void StartPreferenceSyncing() const { 98 void StartPreferenceSyncing() const {
103 PrefServiceSyncableFromProfile(profile_.get()) 99 PrefServiceSyncableFromProfile(profile_.get())
104 ->GetSyncableService(syncer::PREFERENCES) 100 ->GetSyncableService(syncer::PREFERENCES)
105 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), 101 ->MergeDataAndStartSyncing(
106 std::unique_ptr<syncer::SyncChangeProcessor>( 102 syncer::PREFERENCES, syncer::SyncDataList(),
107 new syncer::FakeSyncChangeProcessor), 103 base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
108 std::unique_ptr<syncer::SyncErrorFactory>( 104 base::MakeUnique<syncer::SyncErrorFactoryMock>());
109 new syncer::SyncErrorFactoryMock()));
110 } 105 }
111 106
112 content::TestBrowserThreadBundle thread_bundle_; 107 content::TestBrowserThreadBundle thread_bundle_;
113 std::unique_ptr<FakeArcBridgeService> bridge_service_; 108 std::unique_ptr<FakeArcBridgeService> bridge_service_;
114 std::unique_ptr<TestingProfile> profile_; 109 std::unique_ptr<TestingProfile> profile_;
115 std::unique_ptr<ArcSessionManager> arc_session_manager_; 110 std::unique_ptr<ArcSessionManager> arc_session_manager_;
116 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 111 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
117 base::ScopedTempDir temp_dir_; 112 base::ScopedTempDir temp_dir_;
118 113
114 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTestBase);
115 };
116
117 class ArcSessionManagerTest : public ArcSessionManagerTestBase {
118 public:
119 ArcSessionManagerTest() = default;
120
121 void SetUp() override {
122 ArcSessionManagerTestBase::SetUp();
123
124 const AccountId account_id(AccountId::FromUserEmailGaiaId(
125 profile()->GetProfileUserName(), "1234567890"));
126 GetFakeUserManager()->AddUser(account_id);
127 GetFakeUserManager()->LoginUser(account_id);
128 }
129
130 private:
119 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 131 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
120 }; 132 };
121 133
122 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 134 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) {
123 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 135 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
124 arc_session_manager()->state()); 136 arc_session_manager()->state());
125 137
126 PrefService* const pref = profile()->GetPrefs(); 138 PrefService* const pref = profile()->GetPrefs();
127 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 139 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
128 140
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 GetFakeUserManager()->SwitchActiveUser(account_id); 382 GetFakeUserManager()->SwitchActiveUser(account_id);
371 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 383 second_profile->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
372 384
373 // Check that non-primary user can't use Arc. 385 // Check that non-primary user can't use Arc.
374 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get())); 386 EXPECT_FALSE(chromeos::ProfileHelper::IsPrimaryProfile(second_profile.get()));
375 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get())); 387 EXPECT_FALSE(ArcAppListPrefs::Get(second_profile.get()));
376 388
377 arc_session_manager()->Shutdown(); 389 arc_session_manager()->Shutdown();
378 } 390 }
379 391
392 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase {
393 public:
394 ArcSessionManagerKioskTest() = default;
395
396 void SetUp() override {
397 ArcSessionManagerTestBase::SetUp();
398 const AccountId account_id(
399 AccountId::FromUserEmail(profile()->GetProfileUserName()));
400 GetFakeUserManager()->AddArcKioskAppUser(account_id);
401 GetFakeUserManager()->LoginUser(account_id);
402 }
403
404 private:
405 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerKioskTest);
406 };
407
408 TEST_F(ArcSessionManagerKioskTest, AuthFailure) {
409 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
410 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
411 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
412
413 // Replace chrome::AttemptUserExit() for testing.
414 // At the end of test, we leave the dangling pointer |terminated|,
Luis Héctor Chávez 2016/12/06 19:08:56 I don't understand this comment. You are calling E
hidehiko 2016/12/08 14:29:33 The attempt_user_exit_callback_ in ArcSessionManag
415 // assuming the callback will never be called.
416 bool terminated = false;
417 arc_session_manager()->SetAttemptUserExitCallbackForTesting(
418 base::Bind([](bool* terminated) { *terminated = true; }, &terminated));
419
420 arc_session_manager()->OnProvisioningFinished(
421 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
422 EXPECT_TRUE(terminated);
423 }
424
380 } // namespace arc 425 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698