Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/chromeos/login/login_manager_test.h" | 9 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 10 #include "chrome/browser/chromeos/login/startup_utils.h" | 10 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 11 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 11 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 12 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 12 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/signin/easy_unlock_service.h" | 15 #include "chrome/browser/signin/easy_unlock_service.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 20 #include "chromeos/dbus/fake_power_manager_client.h" | |
| 19 #include "components/policy/core/browser/browser_policy_connector.h" | 21 #include "components/policy/core/browser/browser_policy_connector.h" |
| 20 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 22 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 21 #include "components/policy/core/common/policy_map.h" | 23 #include "components/policy/core/common/policy_map.h" |
| 22 #include "components/policy/core/common/policy_types.h" | 24 #include "components/policy/core/common/policy_types.h" |
| 23 #include "components/user_manager/user_manager.h" | 25 #include "components/user_manager/user_manager.h" |
| 24 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 25 #include "device/bluetooth/bluetooth_adapter_factory.h" | 27 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 26 #include "device/bluetooth/test/mock_bluetooth_adapter.h" | 28 #include "device/bluetooth/test/mock_bluetooth_adapter.h" |
| 27 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
| 28 #include "policy/policy_constants.h" | 30 #include "policy/policy_constants.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 30 | 32 |
| 33 using chromeos::DBusThreadManagerSetter; | |
| 34 using chromeos::FakePowerManagerClient; | |
| 35 using chromeos::PowerManagerClient; | |
| 31 using chromeos::ProfileHelper; | 36 using chromeos::ProfileHelper; |
| 32 using chromeos::LoginManagerTest; | 37 using chromeos::LoginManagerTest; |
| 33 using chromeos::StartupUtils; | 38 using chromeos::StartupUtils; |
| 34 using chromeos::UserAddingScreen; | 39 using chromeos::UserAddingScreen; |
| 35 using user_manager::UserManager; | 40 using user_manager::UserManager; |
| 36 using device::MockBluetoothAdapter; | 41 using device::MockBluetoothAdapter; |
| 37 using testing::_; | 42 using testing::_; |
| 38 using testing::Return; | 43 using testing::Return; |
| 39 | 44 |
| 40 namespace { | 45 namespace { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 #endif | 98 #endif |
| 94 | 99 |
| 95 // InProcessBrowserTest: | 100 // InProcessBrowserTest: |
| 96 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 101 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 97 EXPECT_CALL(provider_, IsInitializationComplete(_)) | 102 EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| 98 .WillRepeatedly(Return(true)); | 103 .WillRepeatedly(Return(true)); |
| 99 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); | 104 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| 100 | 105 |
| 101 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); | 106 mock_adapter_ = new testing::NiceMock<MockBluetoothAdapter>(); |
| 102 SetUpBluetoothMock(mock_adapter_, is_bluetooth_adapter_present_); | 107 SetUpBluetoothMock(mock_adapter_, is_bluetooth_adapter_present_); |
| 108 | |
| 109 scoped_ptr<DBusThreadManagerSetter> dbus_setter = | |
| 110 chromeos::DBusThreadManager::GetSetterForTesting(); | |
| 111 power_manager_client_ = new FakePowerManagerClient; | |
| 112 dbus_setter->SetPowerManagerClient( | |
| 113 scoped_ptr<PowerManagerClient>(power_manager_client_)); | |
| 103 } | 114 } |
| 104 | 115 |
| 105 Profile* profile() const { return browser()->profile(); } | 116 Profile* profile() const { return browser()->profile(); } |
| 106 | 117 |
| 107 EasyUnlockService* service() const { | 118 EasyUnlockService* service() const { |
| 108 return EasyUnlockService::Get(profile()); | 119 return EasyUnlockService::Get(profile()); |
| 109 } | 120 } |
| 110 | 121 |
| 111 void set_is_bluetooth_adapter_present(bool is_present) { | 122 void set_is_bluetooth_adapter_present(bool is_present) { |
| 112 is_bluetooth_adapter_present_ = is_present; | 123 is_bluetooth_adapter_present_ = is_present; |
| 113 } | 124 } |
| 114 | 125 |
| 126 FakePowerManagerClient* power_manager_client() { | |
| 127 return power_manager_client_; | |
| 128 } | |
| 129 | |
| 115 private: | 130 private: |
| 116 policy::MockConfigurationPolicyProvider provider_; | 131 policy::MockConfigurationPolicyProvider provider_; |
| 117 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; | 132 scoped_refptr<testing::NiceMock<MockBluetoothAdapter> > mock_adapter_; |
| 118 bool is_bluetooth_adapter_present_; | 133 bool is_bluetooth_adapter_present_; |
| 134 FakePowerManagerClient* power_manager_client_; | |
| 119 | 135 |
| 120 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); | 136 DISALLOW_COPY_AND_ASSIGN(EasyUnlockServiceTest); |
| 121 }; | 137 }; |
| 122 | 138 |
| 123 // Tests that EasyUnlock is on by default. | 139 // Tests that EasyUnlock is on by default. |
| 124 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { | 140 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, DefaultOn) { |
| 125 EXPECT_TRUE(service()->IsAllowed()); | 141 EXPECT_TRUE(service()->IsAllowed()); |
| 126 #if defined(GOOGLE_CHROME_BUILD) | 142 #if defined(GOOGLE_CHROME_BUILD) |
| 127 EXPECT_TRUE(HasEasyUnlockApp()); | 143 EXPECT_TRUE(HasEasyUnlockApp()); |
| 128 #endif | 144 #endif |
| 129 } | 145 } |
| 130 | 146 |
| 147 IN_PROC_BROWSER_TEST_F(EasyUnlockServiceTest, UnloadsOnSuspend) { | |
| 148 #if defined(GOOGLE_CHROME_BUILD) | |
|
xiyuan
2014/09/03 21:36:13
nit: The test is essentially empty for chromium bu
Tim Song
2014/09/18 23:50:28
Done.
| |
| 149 EXPECT_TRUE(HasEasyUnlockApp()); | |
| 150 power_manager_client()->SendSuspendImminent(); | |
| 151 EXPECT_FALSE(HasEasyUnlockApp()); | |
| 152 power_manager_client()->SendSuspendDone(); | |
| 153 EXPECT_TRUE(HasEasyUnlockApp()); | |
| 154 #endif | |
| 155 } | |
| 156 | |
| 131 class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { | 157 class EasyUnlockServiceNoBluetoothTest : public EasyUnlockServiceTest { |
| 132 public: | 158 public: |
| 133 EasyUnlockServiceNoBluetoothTest() {} | 159 EasyUnlockServiceNoBluetoothTest() {} |
| 134 virtual ~EasyUnlockServiceNoBluetoothTest() {} | 160 virtual ~EasyUnlockServiceNoBluetoothTest() {} |
| 135 | 161 |
| 136 // InProcessBrowserTest: | 162 // InProcessBrowserTest: |
| 137 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 163 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 138 set_is_bluetooth_adapter_present(false); | 164 set_is_bluetooth_adapter_present(false); |
| 139 EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); | 165 EasyUnlockServiceTest::SetUpInProcessBrowserTestFixture(); |
| 140 } | 166 } |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( | 284 Profile* secondary_profile = ProfileHelper::Get()->GetProfileByUserIdHash( |
| 259 secondary_user->username_hash()); | 285 secondary_user->username_hash()); |
| 260 | 286 |
| 261 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); | 287 EXPECT_TRUE(EasyUnlockService::Get(primary_profile)->IsAllowed()); |
| 262 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); | 288 EXPECT_FALSE(EasyUnlockService::Get(secondary_profile)->IsAllowed()); |
| 263 #if defined(GOOGLE_CHROME_BUILD) | 289 #if defined(GOOGLE_CHROME_BUILD) |
| 264 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); | 290 EXPECT_TRUE(HasEasyUnlockAppForProfile(primary_profile)); |
| 265 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); | 291 EXPECT_FALSE(HasEasyUnlockAppForProfile(secondary_profile)); |
| 266 #endif | 292 #endif |
| 267 } | 293 } |
| OLD | NEW |