Chromium Code Reviews| 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 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.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 "chromeos/dbus/fake_session_manager_client.h" |
| 31 #include "chromeos/dbus/session_manager_client.h" | 31 #include "chromeos/dbus/session_manager_client.h" |
| 32 #include "components/arc/arc_bridge_service_impl.h" | 32 #include "components/arc/arc_bridge_service_impl.h" |
| 33 #include "components/arc/arc_service_manager.h" | 33 #include "components/arc/arc_service_manager.h" |
| 34 #include "components/arc/test/fake_arc_bridge_bootstrap.h" | 34 #include "components/arc/test/fake_arc_bridge_bootstrap.h" |
| 35 #include "components/arc/test/fake_arc_bridge_instance.h" | |
| 36 #include "components/policy/core/common/policy_switches.h" | 35 #include "components/policy/core/common/policy_switches.h" |
| 37 #include "components/prefs/pref_member.h" | 36 #include "components/prefs/pref_member.h" |
| 38 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
| 39 #include "components/signin/core/account_id/account_id.h" | 38 #include "components/signin/core/account_id/account_id.h" |
| 40 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 39 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 41 #include "components/user_manager/user_manager.h" | 40 #include "components/user_manager/user_manager.h" |
| 42 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 43 #include "url/gurl.h" | 42 #include "url/gurl.h" |
| 44 | 43 |
| 45 namespace { | 44 namespace { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 void OnShutdownBridge() override { | 103 void OnShutdownBridge() override { |
| 105 if (!run_loop_) | 104 if (!run_loop_) |
| 106 return; | 105 return; |
| 107 run_loop_->Quit(); | 106 run_loop_->Quit(); |
| 108 } | 107 } |
| 109 | 108 |
| 110 private: | 109 private: |
| 111 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceShutdownObserver); | 110 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceShutdownObserver); |
| 112 }; | 111 }; |
| 113 | 112 |
| 114 class ArcAuthServiceTest : public InProcessBrowserTest { | 113 class ArcAuthServiceTest : public InProcessBrowserTest, |
| 114 public ArcBridgeServiceImpl::Delegate { | |
| 115 protected: | 115 protected: |
| 116 ArcAuthServiceTest() {} | 116 ArcAuthServiceTest() {} |
| 117 | 117 |
| 118 // InProcessBrowserTest: | 118 // InProcessBrowserTest: |
| 119 ~ArcAuthServiceTest() override {} | 119 ~ArcAuthServiceTest() override {} |
| 120 | 120 |
| 121 void SetUpInProcessBrowserTestFixture() override { | 121 void SetUpInProcessBrowserTestFixture() override { |
| 122 // Start test device management server. | 122 // Start test device management server. |
| 123 test_server_.reset(new policy::LocalPolicyTestServer()); | 123 test_server_.reset(new policy::LocalPolicyTestServer()); |
| 124 ASSERT_TRUE(test_server_->Start()); | 124 ASSERT_TRUE(test_server_->Start()); |
| 125 | 125 |
| 126 // Specify device management server URL. | 126 // Specify device management server URL. |
| 127 std::string url = test_server_->GetServiceURL().spec(); | 127 std::string url = test_server_->GetServiceURL().spec(); |
| 128 base::CommandLine* const command_line = | 128 base::CommandLine* const command_line = |
| 129 base::CommandLine::ForCurrentProcess(); | 129 base::CommandLine::ForCurrentProcess(); |
| 130 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, | 130 command_line->AppendSwitchASCII(policy::switches::kDeviceManagementUrl, |
| 131 url); | 131 url); |
| 132 | 132 |
| 133 // Enable ARC. | 133 // Enable ARC. |
| 134 command_line->AppendSwitch(chromeos::switches::kEnableArc); | 134 command_line->AppendSwitch(chromeos::switches::kEnableArc); |
| 135 chromeos::FakeSessionManagerClient* const fake_session_manager_client = | 135 chromeos::FakeSessionManagerClient* const fake_session_manager_client = |
| 136 new chromeos::FakeSessionManagerClient; | 136 new chromeos::FakeSessionManagerClient; |
| 137 fake_session_manager_client->set_arc_available(true); | 137 fake_session_manager_client->set_arc_available(true); |
| 138 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 138 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 139 std::unique_ptr<chromeos::SessionManagerClient>( | 139 std::unique_ptr<chromeos::SessionManagerClient>( |
| 140 fake_session_manager_client)); | 140 fake_session_manager_client)); |
| 141 | 141 |
| 142 // Mock out ARC bridge. | 142 // Mock out ARC bridge. |
| 143 fake_arc_bridge_instance_.reset(new FakeArcBridgeInstance); | 143 std::unique_ptr<ArcBridgeServiceImpl> service(new ArcBridgeServiceImpl); |
| 144 ArcServiceManager::SetArcBridgeServiceForTesting( | 144 service->SetDelegateForTesting(this); |
| 145 base::MakeUnique<ArcBridgeServiceImpl>(base::WrapUnique( | 145 ArcServiceManager::SetArcBridgeServiceForTesting(std::move(service)); |
| 146 new FakeArcBridgeBootstrap(fake_arc_bridge_instance_.get())))); | |
| 147 } | 146 } |
| 148 | 147 |
| 149 void SetUpOnMainThread() override { | 148 void SetUpOnMainThread() override { |
| 150 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( | 149 user_manager_enabler_.reset(new chromeos::ScopedUserManagerEnabler( |
| 151 new chromeos::FakeChromeUserManager)); | 150 new chromeos::FakeChromeUserManager)); |
| 152 // Init ArcAuthService for testing. | 151 // Init ArcAuthService for testing. |
| 153 ArcAuthService::DisableUIForTesting(); | 152 ArcAuthService::DisableUIForTesting(); |
| 154 ArcAuthService::EnableCheckAndroidManagementForTesting(); | 153 ArcAuthService::EnableCheckAndroidManagementForTesting(); |
| 155 | 154 |
| 156 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 155 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 | 197 |
| 199 void set_profile_name(const std::string& username) { | 198 void set_profile_name(const std::string& username) { |
| 200 profile_->set_profile_name(username); | 199 profile_->set_profile_name(username); |
| 201 } | 200 } |
| 202 | 201 |
| 203 Profile* profile() { return profile_.get(); } | 202 Profile* profile() { return profile_.get(); } |
| 204 | 203 |
| 205 FakeProfileOAuth2TokenService* token_service() { return token_service_; } | 204 FakeProfileOAuth2TokenService* token_service() { return token_service_; } |
| 206 | 205 |
| 207 private: | 206 private: |
| 207 // ArcBridgeServiceImpl::Delegate override: | |
| 208 std::unique_ptr<ArcBridgeBootstrap> CreateBootstrap() override { | |
| 209 return base::WrapUnique(new FakeArcBridgeBootstrap); | |
|
Luis Héctor Chávez
2016/09/07 23:38:32
prefer base::MakeUnique<FakeArcBridgeBootstrap>().
hidehiko
2016/09/08 16:53:41
Acknowledged.
| |
| 210 } | |
| 211 | |
| 208 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; | 212 std::unique_ptr<policy::LocalPolicyTestServer> test_server_; |
| 209 std::unique_ptr<FakeArcBridgeInstance> fake_arc_bridge_instance_; | |
| 210 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; | 213 std::unique_ptr<chromeos::ScopedUserManagerEnabler> user_manager_enabler_; |
| 211 base::ScopedTempDir temp_dir_; | 214 base::ScopedTempDir temp_dir_; |
| 212 std::unique_ptr<TestingProfile> profile_; | 215 std::unique_ptr<TestingProfile> profile_; |
| 213 FakeProfileOAuth2TokenService* token_service_; | 216 FakeProfileOAuth2TokenService* token_service_; |
| 214 | 217 |
| 215 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceTest); | 218 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceTest); |
| 216 }; | 219 }; |
| 217 | 220 |
| 218 IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, ConsumerAccount) { | 221 IN_PROC_BROWSER_TEST_F(ArcAuthServiceTest, ConsumerAccount) { |
| 219 PrefService* const prefs = profile()->GetPrefs(); | 222 PrefService* const prefs = profile()->GetPrefs(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 247 | 250 |
| 248 prefs->SetBoolean(prefs::kArcEnabled, true); | 251 prefs->SetBoolean(prefs::kArcEnabled, true); |
| 249 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, | 252 token_service()->IssueTokenForAllPendingRequests(kManagedAuthToken, |
| 250 base::Time::Max()); | 253 base::Time::Max()); |
| 251 ArcAuthServiceShutdownObserver observer; | 254 ArcAuthServiceShutdownObserver observer; |
| 252 observer.Wait(); | 255 observer.Wait(); |
| 253 ASSERT_EQ(ArcAuthService::State::STOPPED, ArcAuthService::Get()->state()); | 256 ASSERT_EQ(ArcAuthService::State::STOPPED, ArcAuthService::Get()->state()); |
| 254 } | 257 } |
| 255 | 258 |
| 256 } // namespace arc | 259 } // namespace arc |
| OLD | NEW |