| 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" | 7 #include "chrome/browser/chromeos/login/test/oobe_base_test.h" |
| 8 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" | 8 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" |
| 9 #include "chrome/browser/chromeos/login/wizard_controller.h" | 9 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 10 #include "components/pairing/bluetooth_host_pairing_controller.h" | 10 #include "components/pairing/bluetooth_host_pairing_controller.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 bool finished_ = false; | 40 bool finished_ = false; |
| 41 std::unique_ptr<base::RunLoop> run_loop_; | 41 std::unique_ptr<base::RunLoop> run_loop_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | 43 DISALLOW_COPY_AND_ASSIGN(TestDelegate); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 } // namespace | 46 } // namespace |
| 47 | 47 |
| 48 class BluetoothHostPairingTest : public OobeBaseTest { | 48 // This is the class to simulate the OOBE process for devices that don't have |
| 49 // sufficient input, i.e., the first screen of OOBE is the HID detection screen. |
| 50 // The device will put itself in Bluetooth discoverable mode. |
| 51 class BluetoothHostPairingNoInputTest : public OobeBaseTest { |
| 49 public: | 52 public: |
| 50 using InputDeviceInfo = device::InputServiceLinux::InputDeviceInfo; | 53 using InputDeviceInfo = device::InputServiceLinux::InputDeviceInfo; |
| 51 | 54 |
| 52 BluetoothHostPairingTest() { | 55 BluetoothHostPairingNoInputTest() { |
| 53 InputServiceProxy::SetThreadIdForTesting(content::BrowserThread::UI); | 56 InputServiceProxy::SetThreadIdForTesting(content::BrowserThread::UI); |
| 54 input_service_linux_.reset(new device::FakeInputServiceLinux); | 57 input_service_linux_.reset(new device::FakeInputServiceLinux); |
| 55 device::InputServiceLinux::SetForTesting(input_service_linux_.get()); | 58 device::InputServiceLinux::SetForTesting(input_service_linux_.get()); |
| 56 | |
| 57 AddUsbMouse(); | |
| 58 AddUsbKeyboard(); | |
| 59 } | 59 } |
| 60 ~BluetoothHostPairingTest() override {} | 60 ~BluetoothHostPairingNoInputTest() override {} |
| 61 | 61 |
| 62 // OobeBaseTest override: | 62 // OobeBaseTest override: |
| 63 void SetUpOnMainThread() override { | 63 void SetUpOnMainThread() override { |
| 64 OobeBaseTest::SetUpOnMainThread(); | 64 OobeBaseTest::SetUpOnMainThread(); |
| 65 delegate_.reset(new TestDelegate); | 65 delegate_.reset(new TestDelegate); |
| 66 controller()->SetDelegateForTesting(delegate_.get()); | 66 if (controller()) { |
| 67 bluetooth_adapter_ = controller()->GetAdapterForTesting(); | 67 controller()->SetDelegateForTesting(delegate_.get()); |
| 68 bluetooth_adapter_ = controller()->GetAdapterForTesting(); |
| 69 } |
| 68 } | 70 } |
| 69 | 71 |
| 70 pairing_chromeos::BluetoothHostPairingController* controller() { | 72 pairing_chromeos::BluetoothHostPairingController* controller() { |
| 71 WizardController* wizard_controller = | 73 pairing_chromeos::SharkConnectionListener* shark_listener = |
| 72 WizardController::default_controller(); | 74 WizardController::default_controller() |
| 73 return wizard_controller->GetSharkConnectionListenerForTesting() | 75 ->GetSharkConnectionListenerForTesting(); |
| 74 ->GetControllerForTesting(); | 76 return shark_listener ? shark_listener->GetControllerForTesting() : nullptr; |
| 75 } | 77 } |
| 76 | 78 |
| 77 device::BluetoothAdapter* bluetooth_adapter() { | 79 device::BluetoothAdapter* bluetooth_adapter() { |
| 78 return bluetooth_adapter_.get(); | 80 return bluetooth_adapter_.get(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 TestDelegate* delegate() { return delegate_.get(); } | 83 TestDelegate* delegate() { return delegate_.get(); } |
| 82 | 84 |
| 83 void AddUsbMouse() { | 85 void AddUsbMouse() { |
| 84 InputDeviceInfo mouse; | 86 InputDeviceInfo mouse; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 105 mouse.type = InputDeviceInfo::TYPE_BLUETOOTH; | 107 mouse.type = InputDeviceInfo::TYPE_BLUETOOTH; |
| 106 mouse.is_mouse = true; | 108 mouse.is_mouse = true; |
| 107 input_service_linux_->AddDeviceForTesting(mouse); | 109 input_service_linux_->AddDeviceForTesting(mouse); |
| 108 } | 110 } |
| 109 | 111 |
| 110 private: | 112 private: |
| 111 std::unique_ptr<device::FakeInputServiceLinux> input_service_linux_; | 113 std::unique_ptr<device::FakeInputServiceLinux> input_service_linux_; |
| 112 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; | 114 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; |
| 113 std::unique_ptr<TestDelegate> delegate_; | 115 std::unique_ptr<TestDelegate> delegate_; |
| 114 | 116 |
| 115 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingTest); | 117 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingNoInputTest); |
| 116 }; | 118 }; |
| 117 | 119 |
| 118 // Test that in normal user OOBE login flow, if there is no Bluetooth device | 120 // Test that in normal user OOBE login flow for devices lacking input devices, |
| 119 // connected, the Bluetooth adapter should be disabled when OOBE reaches login | 121 // if there is no Bluetooth device connected, the Bluetooth adapter should be |
| 120 // screen (which means OOBE has been completed). | 122 // disabled when OOBE reaches login screen (which means OOBE has been completed) |
| 121 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingTest, NoBluetoothDeviceConnected) { | 123 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingNoInputTest, |
| 122 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); | 124 NoBluetoothDeviceConnected) { |
| 125 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_HID_DETECTION).Wait(); |
| 123 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); | 126 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); |
| 124 WizardController::default_controller()->SkipToLoginForTesting( | 127 WizardController::default_controller()->SkipToLoginForTesting( |
| 125 LoginScreenContext()); | 128 LoginScreenContext()); |
| 126 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); | 129 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); |
| 127 delegate()->WaitUntilAdapterReset(); | 130 delegate()->WaitUntilAdapterReset(); |
| 128 EXPECT_EQ(bluetooth_adapter()->IsPowered(), false); | 131 EXPECT_EQ(bluetooth_adapter()->IsPowered(), false); |
| 129 } | 132 } |
| 130 | 133 |
| 131 // Test that in normal user OOBE login flow, if there is any Bluetooth device | 134 // Test that in normal user OOBE login flow for devices lacking input devices, |
| 132 // connected, the Bluetooth adapter should not be disabled after OOBE completes. | 135 // if there is any Bluetooth device connected, the Bluetooth adapter should not |
| 133 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingTest, BluetoothDeviceConnected) { | 136 // be disabled after OOBE completes. |
| 134 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); | 137 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingNoInputTest, |
| 138 BluetoothDeviceConnected) { |
| 139 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_HID_DETECTION).Wait(); |
| 135 AddBluetoothMouse(); | 140 AddBluetoothMouse(); |
| 136 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); | 141 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); |
| 137 WizardController::default_controller()->SkipToLoginForTesting( | 142 WizardController::default_controller()->SkipToLoginForTesting( |
| 138 LoginScreenContext()); | 143 LoginScreenContext()); |
| 139 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); | 144 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); |
| 140 delegate()->WaitUntilAdapterReset(); | 145 delegate()->WaitUntilAdapterReset(); |
| 141 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); | 146 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); |
| 142 } | 147 } |
| 143 | 148 |
| 149 // This is the class to simulate the OOBE process for devices that have |
| 150 // sufficient input, i.e., the first screen of OOBE is the network screen. |
| 151 // The device will not put itself in Bluetooth discoverable mode until the user |
| 152 // manually trigger it using the proper accelerator. |
| 153 class BluetoothHostPairingWithInputTest |
| 154 : public BluetoothHostPairingNoInputTest { |
| 155 public: |
| 156 BluetoothHostPairingWithInputTest() { |
| 157 AddUsbMouse(); |
| 158 AddUsbKeyboard(); |
| 159 } |
| 160 ~BluetoothHostPairingWithInputTest() override {} |
| 161 |
| 162 private: |
| 163 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingWithInputTest); |
| 164 }; |
| 165 |
| 166 // Test that in normal user OOBE login flow for devices that have input devices, |
| 167 // the Bluetooth is disabled by default. |
| 168 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingWithInputTest, |
| 169 BluetoothDisableByDefault) { |
| 170 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); |
| 171 EXPECT_FALSE(controller()); |
| 172 EXPECT_FALSE(bluetooth_adapter()); |
| 173 } |
| 174 |
| 144 } // namespace chromeos | 175 } // namespace chromeos |
| OLD | NEW |