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

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: 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
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 30 matching lines...) Expand all
41 #include "components/user_manager/user_names.h" 41 #include "components/user_manager/user_names.h"
42 #include "content/public/browser/browser_thread.h" 42 #include "content/public/browser/browser_thread.h"
43 #include "content/public/test/test_browser_thread_bundle.h" 43 #include "content/public/test/test_browser_thread_bundle.h"
44 #include "google_apis/gaia/gaia_constants.h" 44 #include "google_apis/gaia/gaia_constants.h"
45 #include "google_apis/gaia/gaia_urls.h" 45 #include "google_apis/gaia/gaia_urls.h"
46 #include "net/http/http_status_code.h" 46 #include "net/http/http_status_code.h"
47 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
48 48
49 namespace arc { 49 namespace arc {
50 50
51 class ArcSessionManagerTest : public testing::Test { 51 class ArcSessionManagerTestBase : public testing::Test {
52 public: 52 public:
53 ArcSessionManagerTest() 53 ArcSessionManagerTestBase()
54 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 54 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
55 user_manager_enabler_(new chromeos::FakeChromeUserManager) {} 55 user_manager_enabler_(new chromeos::FakeChromeUserManager()) {}
56 ~ArcSessionManagerTest() override = default; 56 ~ArcSessionManagerTestBase() override = default;
57 57
58 void SetUp() override { 58 void SetUp() override {
59 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( 59 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
60 base::MakeUnique<chromeos::FakeSessionManagerClient>()); 60 base::MakeUnique<chromeos::FakeSessionManagerClient>());
61 61
62 chromeos::DBusThreadManager::Initialize(); 62 chromeos::DBusThreadManager::Initialize();
63 63
64 base::CommandLine::ForCurrentProcess()->AppendSwitch( 64 base::CommandLine::ForCurrentProcess()->AppendSwitch(
65 chromeos::switches::kEnableArc); 65 chromeos::switches::kEnableArc);
66 ArcSessionManager::DisableUIForTesting(); 66 ArcSessionManager::DisableUIForTesting();
67 67
68 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 68 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
69 TestingProfile::Builder profile_builder; 69 TestingProfile::Builder profile_builder;
70 profile_builder.SetProfileName("user@gmail.com");
70 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); 71 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
71 72
72 profile_ = profile_builder.Build(); 73 profile_ = profile_builder.Build();
73 StartPreferenceSyncing(); 74 StartPreferenceSyncing();
74 75
75 ArcServiceManager::SetArcBridgeServiceForTesting( 76 ArcServiceManager::SetArcBridgeServiceForTesting(
76 base::MakeUnique<FakeArcBridgeService>()); 77 base::MakeUnique<FakeArcBridgeService>());
77 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr); 78 arc_service_manager_ = base::MakeUnique<ArcServiceManager>(nullptr);
78 arc_session_manager_ = base::MakeUnique<ArcSessionManager>( 79 arc_session_manager_ = base::MakeUnique<ArcSessionManager>(
79 arc_service_manager_->arc_bridge_service()); 80 arc_service_manager_->arc_bridge_service());
80 81
81 // Check initial conditions. 82 // Check initial conditions.
82 EXPECT_TRUE(bridge_service()->stopped()); 83 EXPECT_TRUE(bridge_service()->stopped());
83 84
84 const AccountId account_id(
85 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890"));
86 GetFakeUserManager()->AddUser(account_id);
87 GetFakeUserManager()->LoginUser(account_id);
88
89 chromeos::WallpaperManager::Initialize(); 85 chromeos::WallpaperManager::Initialize();
90 } 86 }
91 87
92 void TearDown() override { 88 void TearDown() override {
93 chromeos::WallpaperManager::Shutdown(); 89 chromeos::WallpaperManager::Shutdown();
94 arc_session_manager_.reset(); 90 arc_session_manager_.reset();
95 arc_service_manager_.reset(); 91 arc_service_manager_.reset();
96 chromeos::DBusThreadManager::Shutdown(); 92 chromeos::DBusThreadManager::Shutdown();
97 } 93 }
98 94
(...skipping 21 matching lines...) Expand all
120 if (arc_session_manager()->state() != expected_state) 116 if (arc_session_manager()->state() != expected_state)
121 return false; 117 return false;
122 118
123 return true; 119 return true;
124 } 120 }
125 121
126 private: 122 private:
127 void StartPreferenceSyncing() const { 123 void StartPreferenceSyncing() const {
128 PrefServiceSyncableFromProfile(profile_.get()) 124 PrefServiceSyncableFromProfile(profile_.get())
129 ->GetSyncableService(syncer::PREFERENCES) 125 ->GetSyncableService(syncer::PREFERENCES)
130 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), 126 ->MergeDataAndStartSyncing(
131 std::unique_ptr<syncer::SyncChangeProcessor>( 127 syncer::PREFERENCES, syncer::SyncDataList(),
132 new syncer::FakeSyncChangeProcessor), 128 base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
133 std::unique_ptr<syncer::SyncErrorFactory>( 129 base::MakeUnique<syncer::SyncErrorFactoryMock>());
134 new syncer::SyncErrorFactoryMock()));
135 } 130 }
136 131
137 content::TestBrowserThreadBundle thread_bundle_; 132 content::TestBrowserThreadBundle thread_bundle_;
138 std::unique_ptr<TestingProfile> profile_; 133 std::unique_ptr<TestingProfile> profile_;
139 std::unique_ptr<ArcServiceManager> arc_service_manager_; 134 std::unique_ptr<ArcServiceManager> arc_service_manager_;
140 std::unique_ptr<ArcSessionManager> arc_session_manager_; 135 std::unique_ptr<ArcSessionManager> arc_session_manager_;
141 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 136 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
142 base::ScopedTempDir temp_dir_; 137 base::ScopedTempDir temp_dir_;
143 138
139 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTestBase);
140 };
141
142 class ArcSessionManagerTest : public ArcSessionManagerTestBase {
143 public:
144 ArcSessionManagerTest() = default;
145
146 void SetUp() override {
147 ArcSessionManagerTestBase::SetUp();
148
149 const AccountId account_id(AccountId::FromUserEmailGaiaId(
150 profile()->GetProfileUserName(), "1234567890"));
151 GetFakeUserManager()->AddUser(account_id);
152 GetFakeUserManager()->LoginUser(account_id);
153 }
154
155 private:
144 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 156 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
145 }; 157 };
146 158
147 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 159 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) {
148 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 160 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
149 arc_session_manager()->state()); 161 arc_session_manager()->state());
150 162
151 PrefService* const pref = profile()->GetPrefs(); 163 PrefService* const pref = profile()->GetPrefs();
152 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 164 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
153 165
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 490
479 // Try to send another error that stops the bridge if sent first. It should 491 // Try to send another error that stops the bridge if sent first. It should
480 // be ignored. 492 // be ignored.
481 arc_session_manager()->OnProvisioningFinished( 493 arc_session_manager()->OnProvisioningFinished(
482 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 494 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
483 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 495 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
484 496
485 arc_session_manager()->Shutdown(); 497 arc_session_manager()->Shutdown();
486 } 498 }
487 499
500 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase {
501 public:
502 ArcSessionManagerKioskTest() = default;
503
504 void SetUp() override {
505 ArcSessionManagerTestBase::SetUp();
506 const AccountId account_id(
507 AccountId::FromUserEmail(profile()->GetProfileUserName()));
508 GetFakeUserManager()->AddArcKioskAppUser(account_id);
509 GetFakeUserManager()->LoginUser(account_id);
510 }
511
512 private:
513 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerKioskTest);
514 };
515
516 TEST_F(ArcSessionManagerKioskTest, AuthFailure) {
517 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
518 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
519 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
520
521 // Replace chrome::AttemptUserExit() for testing.
522 // At the end of test, leave the dangling pointer |terminated|,
523 // assuming the callback is invoked exactly once in OnProvisioningFinished()
524 // and not invoked then, including TearDown().
525 bool terminated = false;
526 arc_session_manager()->SetAttemptUserExitCallbackForTesting(
527 base::Bind([](bool* terminated) { *terminated = true; }, &terminated));
528
529 arc_session_manager()->OnProvisioningFinished(
530 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
531 EXPECT_TRUE(terminated);
532 }
533
488 } // namespace arc 534 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698