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

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 28 matching lines...) Expand all
39 #include "components/user_manager/user_names.h" 39 #include "components/user_manager/user_names.h"
40 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
41 #include "content/public/test/test_browser_thread_bundle.h" 41 #include "content/public/test/test_browser_thread_bundle.h"
42 #include "google_apis/gaia/gaia_constants.h" 42 #include "google_apis/gaia/gaia_constants.h"
43 #include "google_apis/gaia/gaia_urls.h" 43 #include "google_apis/gaia/gaia_urls.h"
44 #include "net/http/http_status_code.h" 44 #include "net/http/http_status_code.h"
45 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
46 46
47 namespace arc { 47 namespace arc {
48 48
49 class ArcSessionManagerTest : public testing::Test { 49 class ArcSessionManagerTestBase : public testing::Test {
50 public: 50 public:
51 ArcSessionManagerTest() 51 ArcSessionManagerTestBase()
52 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 52 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
53 user_manager_enabler_(new chromeos::FakeChromeUserManager) {} 53 user_manager_enabler_(new chromeos::FakeChromeUserManager()) {}
54 ~ArcSessionManagerTest() override = default; 54 ~ArcSessionManagerTestBase() override = default;
55 55
56 void SetUp() override { 56 void SetUp() override {
57 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( 57 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
58 base::MakeUnique<chromeos::FakeSessionManagerClient>()); 58 base::MakeUnique<chromeos::FakeSessionManagerClient>());
59 59
60 chromeos::DBusThreadManager::Initialize(); 60 chromeos::DBusThreadManager::Initialize();
61 61
62 base::CommandLine::ForCurrentProcess()->AppendSwitch( 62 base::CommandLine::ForCurrentProcess()->AppendSwitch(
63 chromeos::switches::kEnableArc); 63 chromeos::switches::kEnableArc);
64 ArcSessionManager::DisableUIForTesting(); 64 ArcSessionManager::DisableUIForTesting();
65 65
66 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 66 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
67 TestingProfile::Builder profile_builder; 67 TestingProfile::Builder profile_builder;
68 profile_builder.SetProfileName("user@gmail.com");
68 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile")); 69 profile_builder.SetPath(temp_dir_.GetPath().AppendASCII("TestArcProfile"));
69 70
70 profile_ = profile_builder.Build(); 71 profile_ = profile_builder.Build();
71 StartPreferenceSyncing(); 72 StartPreferenceSyncing();
72 73
73 bridge_service_.reset(new FakeArcBridgeService()); 74 bridge_service_.reset(new FakeArcBridgeService());
74 arc_session_manager_.reset(new ArcSessionManager(bridge_service_.get())); 75 arc_session_manager_.reset(new ArcSessionManager(bridge_service_.get()));
75 76
76 // Check initial conditions. 77 // Check initial conditions.
77 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); 78 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get());
78 EXPECT_TRUE(ArcBridgeService::Get()->stopped()); 79 EXPECT_TRUE(ArcBridgeService::Get()->stopped());
79 80
80 const AccountId account_id(
81 AccountId::FromUserEmailGaiaId("user@gmail.com", "1234567890"));
82 GetFakeUserManager()->AddUser(account_id);
83 GetFakeUserManager()->LoginUser(account_id);
84
85 chromeos::WallpaperManager::Initialize(); 81 chromeos::WallpaperManager::Initialize();
86 } 82 }
87 83
88 void TearDown() override { 84 void TearDown() override {
89 chromeos::WallpaperManager::Shutdown(); 85 chromeos::WallpaperManager::Shutdown();
90 chromeos::DBusThreadManager::Shutdown(); 86 chromeos::DBusThreadManager::Shutdown();
91 } 87 }
92 88
93 chromeos::FakeChromeUserManager* GetFakeUserManager() const { 89 chromeos::FakeChromeUserManager* GetFakeUserManager() const {
94 return static_cast<chromeos::FakeChromeUserManager*>( 90 return static_cast<chromeos::FakeChromeUserManager*>(
(...skipping 16 matching lines...) Expand all
111 if (arc_session_manager()->state() != expected_state) 107 if (arc_session_manager()->state() != expected_state)
112 return false; 108 return false;
113 109
114 return true; 110 return true;
115 } 111 }
116 112
117 private: 113 private:
118 void StartPreferenceSyncing() const { 114 void StartPreferenceSyncing() const {
119 PrefServiceSyncableFromProfile(profile_.get()) 115 PrefServiceSyncableFromProfile(profile_.get())
120 ->GetSyncableService(syncer::PREFERENCES) 116 ->GetSyncableService(syncer::PREFERENCES)
121 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), 117 ->MergeDataAndStartSyncing(
122 std::unique_ptr<syncer::SyncChangeProcessor>( 118 syncer::PREFERENCES, syncer::SyncDataList(),
123 new syncer::FakeSyncChangeProcessor), 119 base::MakeUnique<syncer::FakeSyncChangeProcessor>(),
124 std::unique_ptr<syncer::SyncErrorFactory>( 120 base::MakeUnique<syncer::SyncErrorFactoryMock>());
125 new syncer::SyncErrorFactoryMock()));
126 } 121 }
127 122
128 content::TestBrowserThreadBundle thread_bundle_; 123 content::TestBrowserThreadBundle thread_bundle_;
129 std::unique_ptr<FakeArcBridgeService> bridge_service_; 124 std::unique_ptr<FakeArcBridgeService> bridge_service_;
130 std::unique_ptr<TestingProfile> profile_; 125 std::unique_ptr<TestingProfile> profile_;
131 std::unique_ptr<ArcSessionManager> arc_session_manager_; 126 std::unique_ptr<ArcSessionManager> arc_session_manager_;
132 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 127 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
133 base::ScopedTempDir temp_dir_; 128 base::ScopedTempDir temp_dir_;
134 129
130 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTestBase);
131 };
132
133 class ArcSessionManagerTest : public ArcSessionManagerTestBase {
134 public:
135 ArcSessionManagerTest() = default;
136
137 void SetUp() override {
138 ArcSessionManagerTestBase::SetUp();
139
140 const AccountId account_id(AccountId::FromUserEmailGaiaId(
141 profile()->GetProfileUserName(), "1234567890"));
142 GetFakeUserManager()->AddUser(account_id);
143 GetFakeUserManager()->LoginUser(account_id);
144 }
145
146 private:
135 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest); 147 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerTest);
136 }; 148 };
137 149
138 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) { 150 TEST_F(ArcSessionManagerTest, PrefChangeTriggersService) {
139 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED, 151 ASSERT_EQ(ArcSessionManager::State::NOT_INITIALIZED,
140 arc_session_manager()->state()); 152 arc_session_manager()->state());
141 153
142 PrefService* const pref = profile()->GetPrefs(); 154 PrefService* const pref = profile()->GetPrefs();
143 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); 155 ASSERT_FALSE(pref->GetBoolean(prefs::kArcEnabled));
144 156
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 481
470 // Try to send another error that stops the bridge if sent first. It should 482 // Try to send another error that stops the bridge if sent first. It should
471 // be ignored. 483 // be ignored.
472 arc_session_manager()->OnProvisioningFinished( 484 arc_session_manager()->OnProvisioningFinished(
473 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 485 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
474 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state()); 486 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
475 487
476 arc_session_manager()->Shutdown(); 488 arc_session_manager()->Shutdown();
477 } 489 }
478 490
491 class ArcSessionManagerKioskTest : public ArcSessionManagerTestBase {
492 public:
493 ArcSessionManagerKioskTest() = default;
494
495 void SetUp() override {
496 ArcSessionManagerTestBase::SetUp();
497 const AccountId account_id(
498 AccountId::FromUserEmail(profile()->GetProfileUserName()));
499 GetFakeUserManager()->AddArcKioskAppUser(account_id);
500 GetFakeUserManager()->LoginUser(account_id);
501 }
502
503 private:
504 DISALLOW_COPY_AND_ASSIGN(ArcSessionManagerKioskTest);
505 };
506
507 TEST_F(ArcSessionManagerKioskTest, AuthFailure) {
508 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
509 arc_session_manager()->OnPrimaryUserProfilePrepared(profile());
510 EXPECT_EQ(ArcSessionManager::State::ACTIVE, arc_session_manager()->state());
511
512 // Replace chrome::AttemptUserExit() for testing.
513 // At the end of test, leave the dangling pointer |terminated|,
514 // assuming the callback will never be called.
Luis Héctor Chávez 2016/12/08 17:36:13 I'm still a bit confused by this. If I understand
hidehiko 2016/12/08 18:01:00 Oh, I see your point, I believe. Updated the comme
Luis Héctor Chávez 2016/12/08 18:04:01 No need, the reworded comment is enough.
515 bool terminated = false;
516 arc_session_manager()->SetAttemptUserExitCallbackForTesting(
517 base::Bind([](bool* terminated) { *terminated = true; }, &terminated));
518
519 arc_session_manager()->OnProvisioningFinished(
520 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
521 EXPECT_TRUE(terminated);
522 }
523
479 } // namespace arc 524 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698