Chromium Code Reviews| Index: chrome/browser/signin/easy_unlock_service_browsertest_chromeos.cc |
| diff --git a/chrome/browser/signin/easy_unlock_service_browsertest_chromeos.cc b/chrome/browser/signin/easy_unlock_service_browsertest_chromeos.cc |
| index 577120de3258f350dfd276748e057dd0c05b20ae..0c1069bf057cb20497b56d20d5fe6e8c7a30f094 100644 |
| --- a/chrome/browser/signin/easy_unlock_service_browsertest_chromeos.cc |
| +++ b/chrome/browser/signin/easy_unlock_service_browsertest_chromeos.cc |
| @@ -22,6 +22,8 @@ |
| #include "components/policy/core/common/policy_map.h" |
| #include "components/policy/core/common/policy_types.h" |
| #include "content/public/common/content_switches.h" |
| +#include "device/bluetooth/bluetooth_adapter_factory.h" |
| +#include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| #include "extensions/browser/extension_system.h" |
| #include "policy/policy_constants.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -31,6 +33,7 @@ using chromeos::LoginManagerTest; |
| using chromeos::StartupUtils; |
| using chromeos::UserAddingScreen; |
| using chromeos::UserManager; |
| +using device::MockBluetoothAdapter; |
| using testing::_; |
| using testing::Return; |
| @@ -49,11 +52,11 @@ bool HasEasyUnlockAppForProfile(Profile* profile) { |
| } |
| #endif |
| -} //namespace |
| +} // namespace |
| class EasyUnlockServiceTest : public InProcessBrowserTest { |
| public: |
| - EasyUnlockServiceTest() {} |
| + EasyUnlockServiceTest() : is_bluetooth_adapter_present_(true) {} |
| virtual ~EasyUnlockServiceTest() {} |
| void SetEasyUnlockAllowedPolicy(bool allowed) { |
| @@ -67,6 +70,18 @@ class EasyUnlockServiceTest : public InProcessBrowserTest { |
| base::RunLoop().RunUntilIdle(); |
| } |
| + void SetupBluetoothMock(bool is_present) { |
|
Ilya Sherman
2014/08/14 21:38:28
nit: "Setup" -> "SetUp"
xiyuan
2014/08/14 22:56:46
Done.
|
| + mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |
| + device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); |
| + |
| + EXPECT_CALL(*mock_adapter_, AddObserver(_)) |
| + .WillRepeatedly(testing::Return()); |
| + EXPECT_CALL(*mock_adapter_, RemoveObserver(_)) |
| + .WillRepeatedly(testing::Return()); |
|
Ilya Sherman
2014/08/14 21:38:28
Hmm, why are these four lines needed?
xiyuan
2014/08/14 22:56:46
It was because I was desperately trying to figure
|
| + EXPECT_CALL(*mock_adapter_, IsPresent()) |
| + .WillRepeatedly(testing::Return(is_present)); |
| + } |
| + |
| #if defined(GOOGLE_CHROME_BUILD) |
| bool HasEasyUnlockApp() const { |
| return HasEasyUnlockAppForProfile(profile()); |
| @@ -78,6 +93,7 @@ class EasyUnlockServiceTest : public InProcessBrowserTest { |
| EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| .WillRepeatedly(Return(true)); |
| policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| + SetupBluetoothMock(is_bluetooth_adapter_present_); |
| } |
| Profile* profile() const { return browser()->profile(); } |
| @@ -86,8 +102,14 @@ class EasyUnlockServiceTest : public InProcessBrowserTest { |
| return EasyUnlockService::Get(profile()); |
| } |
| + void set_is_bluetooth_adapter_present(bool is_present) { |
| + is_bluetooth_adapter_present_ = is_present; |
| + } |
| + |
| private: |
| policy::MockConfigurationPolicyProvider provider_; |
| + scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
|
Ilya Sherman
2014/08/14 21:38:28
nit: Does this really need to be a class member, o
xiyuan
2014/08/14 22:56:46
It turns out that we have to do this. Otherwise, i
|
| + bool is_bluetooth_adapter_present_; |
| DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); |
| }; |
| @@ -100,6 +122,28 @@ IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { |
| #endif |
| } |
| +class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { |
| + public: |
| + EasyUnlockServiceNoBluetoothTest() {} |
| + virtual ~EasyUnlockServiceNoBluetoothTest() {} |
| + |
| + // InProcessBrowserTest: |
| + virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| + set_is_bluetooth_adapter_present(false); |
| + EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceNoBluetoothTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(EasyUnlockServiceNoBluetoothTest, NoService) { |
| + EXPECT_FALSE(service()->IsAllowed()); |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + EXPECT_FALSE(HasEasyUnlockApp()); |
| +#endif |
| +} |
| + |
| class EasyUnlockServiceFinchEnabledTest : public EasyUnlockServiceTest { |
| public: |
| EasyUnlockServiceFinchEnabledTest() {} |
| @@ -172,7 +216,18 @@ class EasyUnlockServiceMultiProfileTest : public LoginManagerTest { |
| EasyUnlockServiceMultiProfileTest() : LoginManagerTest(false) {} |
| virtual ~EasyUnlockServiceMultiProfileTest() {} |
| + // InProcessBrowserTest: |
| + virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| + LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
| + |
| + mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |
| + device::BluetoothAdapterFactory::SetAdapterForTesting(mock_adapter_); |
| + EXPECT_CALL(*mock_adapter_, IsPresent()) |
| + .WillRepeatedly(testing::Return(true)); |
| + } |
| + |
| private: |
| + scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
|
Ilya Sherman
2014/08/14 21:38:28
nit: Does this really need to be a class member, o
xiyuan
2014/08/14 22:56:46
ditto.
|
| DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceMultiProfileTest); |
| }; |