Commit 6196b626 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

Port EasyUnlockService unittest to IdentityTestEnvironment

This is possible now that there is //chrome-level infrastructure for
glueing an IdentityTestEnvironment instance to a Profile.

Note that this particular test is somewhat unusual in that it builds
multiple Profiles but does not require IdentityTestEnvironment to
interact with those Profiles beyond doing initial configuration. For
simplicity, we use local variables for the IdentityTestEnvironment
associated with each Profile; otherwise, we would need to introduce
distinct instance variables for the two.

This CL also modifies the relevant
IdentityTestEnvironmentProfileAdaptor APIs to return the
TestingProfiles that they create as TestingProfiles; this avoids a
cast that this test would otherwise require and clarifies the APIs.

TBR=droger@chcromium.org

Bug: 896180
Change-Id: Icba8cdc67c1667949636a96078f05e15fd79649c
Reviewed-on: https://chromium-review.googlesource.com/c/1283038
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarJames Hawkins <jhawkins@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600767}
parent 6057fc83
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
#include "chrome/browser/chromeos/login/users/mock_user_manager.h" #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -41,8 +40,6 @@ ...@@ -41,8 +40,6 @@
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "device/bluetooth/bluetooth_adapter_factory.h" #include "device/bluetooth/bluetooth_adapter_factory.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h" #include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "services/identity/public/cpp/identity_manager.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
using device::MockBluetoothAdapter; using device::MockBluetoothAdapter;
...@@ -312,15 +309,20 @@ class EasyUnlockServiceTest : public testing::Test { ...@@ -312,15 +309,20 @@ class EasyUnlockServiceTest : public testing::Test {
// gaia id and output to |gaia_id|. Returns the created TestingProfile. // gaia id and output to |gaia_id|. Returns the created TestingProfile.
std::unique_ptr<TestingProfile> SetUpProfile(const std::string& email, std::unique_ptr<TestingProfile> SetUpProfile(const std::string& email,
std::string* gaia_id) { std::string* gaia_id) {
TestingProfile::Builder builder; std::unique_ptr<TestingProfile> profile =
builder.AddTestingFactory( IdentityTestEnvironmentProfileAdaptor::
EasyUnlockServiceFactory::GetInstance(), CreateProfileForIdentityTestEnvironment(
base::BindRepeating(&CreateEasyUnlockServiceForTest)); {{EasyUnlockServiceFactory::GetInstance(),
std::unique_ptr<TestingProfile> profile = builder.Build(); base::BindRepeating(&CreateEasyUnlockServiceForTest)}});
AccountInfo account_info = identity::SetPrimaryAccount( // Note: This can simply be a local variable as the test does not need to
SigninManagerFactory::GetForProfile(profile.get()), // interact with IdentityTestEnvironment outside of this method. If that
IdentityManagerFactory::GetForProfile(profile.get()), email); // ever changes, there will need to be distinct instance variables for the
// environments associated with |profile_| and |secondary_profile_|.
IdentityTestEnvironmentProfileAdaptor identity_test_env_adaptor(
profile.get());
AccountInfo account_info =
identity_test_env_adaptor.identity_test_env()->SetPrimaryAccount(email);
*gaia_id = account_info.gaia; *gaia_id = account_info.gaia;
......
...@@ -27,14 +27,14 @@ TestingProfile::TestingFactories GetIdentityTestEnvironmentFactories() { ...@@ -27,14 +27,14 @@ TestingProfile::TestingFactories GetIdentityTestEnvironmentFactories() {
} // namespace } // namespace
// static // static
std::unique_ptr<content::BrowserContext> IdentityTestEnvironmentProfileAdaptor:: std::unique_ptr<TestingProfile> IdentityTestEnvironmentProfileAdaptor::
CreateProfileForIdentityTestEnvironment() { CreateProfileForIdentityTestEnvironment() {
return CreateProfileForIdentityTestEnvironment( return CreateProfileForIdentityTestEnvironment(
TestingProfile::TestingFactories()); TestingProfile::TestingFactories());
} }
// static // static
std::unique_ptr<content::BrowserContext> std::unique_ptr<TestingProfile>
IdentityTestEnvironmentProfileAdaptor::CreateProfileForIdentityTestEnvironment( IdentityTestEnvironmentProfileAdaptor::CreateProfileForIdentityTestEnvironment(
const TestingProfile::TestingFactories& input_factories) { const TestingProfile::TestingFactories& input_factories) {
TestingProfile::Builder builder; TestingProfile::Builder builder;
......
...@@ -20,12 +20,12 @@ class IdentityTestEnvironmentProfileAdaptor { ...@@ -20,12 +20,12 @@ class IdentityTestEnvironmentProfileAdaptor {
public: public:
// Creates and returns a TestingProfile that has been configured with the set // Creates and returns a TestingProfile that has been configured with the set
// of testing factories that IdentityTestEnvironment requires. // of testing factories that IdentityTestEnvironment requires.
static std::unique_ptr<content::BrowserContext> static std::unique_ptr<TestingProfile>
CreateProfileForIdentityTestEnvironment(); CreateProfileForIdentityTestEnvironment();
// Like the above, but additionally configures the returned Profile with // Like the above, but additionally configures the returned Profile with
// |input_factories|. // |input_factories|.
static std::unique_ptr<content::BrowserContext> static std::unique_ptr<TestingProfile>
CreateProfileForIdentityTestEnvironment( CreateProfileForIdentityTestEnvironment(
const TestingProfile::TestingFactories& input_factories); const TestingProfile::TestingFactories& input_factories);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment