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 "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 BluetoothHostPairingTestNoInput : public OobeBaseTest { | |
|
achuithb
2016/10/05 22:24:10
Isn't BluetoothHostPairingNoInputTest better? I th
xdai1
2016/10/05 23:57:29
Done.
| |
| 49 public: | 52 public: |
| 50 using InputDeviceInfo = device::InputServiceLinux::InputDeviceInfo; | 53 using InputDeviceInfo = device::InputServiceLinux::InputDeviceInfo; |
| 51 | 54 |
| 52 BluetoothHostPairingTest() { | 55 BluetoothHostPairingTestNoInput() { |
| 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 ~BluetoothHostPairingTestNoInput() 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 WizardController* wizard_controller = |
|
achuithb
2016/10/05 22:24:10
You could just get rid of this and inlign below.
xdai1
2016/10/05 23:57:29
Done.
| |
| 72 WizardController::default_controller(); | 74 WizardController::default_controller(); |
| 73 return wizard_controller->GetSharkConnectionListenerForTesting() | 75 pairing_chromeos::SharkConnectionListener* shark_listener = |
| 74 ->GetControllerForTesting(); | 76 wizard_controller->GetSharkConnectionListenerForTesting(); |
| 77 return shark_listener ? shark_listener->GetControllerForTesting() : nullptr; | |
| 75 } | 78 } |
| 76 | 79 |
| 77 device::BluetoothAdapter* bluetooth_adapter() { | 80 device::BluetoothAdapter* bluetooth_adapter() { |
| 78 return bluetooth_adapter_.get(); | 81 return bluetooth_adapter_.get(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 TestDelegate* delegate() { return delegate_.get(); } | 84 TestDelegate* delegate() { return delegate_.get(); } |
| 82 | 85 |
| 83 void AddUsbMouse() { | 86 void AddUsbMouse() { |
| 84 InputDeviceInfo mouse; | 87 InputDeviceInfo mouse; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 105 mouse.type = InputDeviceInfo::TYPE_BLUETOOTH; | 108 mouse.type = InputDeviceInfo::TYPE_BLUETOOTH; |
| 106 mouse.is_mouse = true; | 109 mouse.is_mouse = true; |
| 107 input_service_linux_->AddDeviceForTesting(mouse); | 110 input_service_linux_->AddDeviceForTesting(mouse); |
| 108 } | 111 } |
| 109 | 112 |
| 110 private: | 113 private: |
| 111 std::unique_ptr<device::FakeInputServiceLinux> input_service_linux_; | 114 std::unique_ptr<device::FakeInputServiceLinux> input_service_linux_; |
| 112 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; | 115 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; |
| 113 std::unique_ptr<TestDelegate> delegate_; | 116 std::unique_ptr<TestDelegate> delegate_; |
| 114 | 117 |
| 115 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingTest); | 118 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingTestNoInput); |
| 116 }; | 119 }; |
| 117 | 120 |
| 118 // Test that in normal user OOBE login flow, if there is no Bluetooth device | 121 // 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 | 122 // if there is no Bluetooth device connected, the Bluetooth adapter should be |
| 120 // screen (which means OOBE has been completed). | 123 // disabled when OOBE reaches login screen (which means OOBE has been completed) |
| 121 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingTest, NoBluetoothDeviceConnected) { | 124 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingTestNoInput, |
| 122 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); | 125 NoBluetoothDeviceConnected) { |
| 126 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_HID_DETECTION).Wait(); | |
| 123 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); | 127 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); |
| 124 WizardController::default_controller()->SkipToLoginForTesting( | 128 WizardController::default_controller()->SkipToLoginForTesting( |
| 125 LoginScreenContext()); | 129 LoginScreenContext()); |
| 126 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); | 130 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); |
| 127 delegate()->WaitUntilAdapterReset(); | 131 delegate()->WaitUntilAdapterReset(); |
| 128 EXPECT_EQ(bluetooth_adapter()->IsPowered(), false); | 132 EXPECT_EQ(bluetooth_adapter()->IsPowered(), false); |
| 129 } | 133 } |
| 130 | 134 |
| 131 // Test that in normal user OOBE login flow, if there is any Bluetooth device | 135 // 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. | 136 // if there is any Bluetooth device connected, the Bluetooth adapter should not |
| 133 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingTest, BluetoothDeviceConnected) { | 137 // be disabled after OOBE completes. |
| 134 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_NETWORK).Wait(); | 138 IN_PROC_BROWSER_TEST_F(BluetoothHostPairingTestNoInput, |
| 139 BluetoothDeviceConnected) { | |
| 140 OobeScreenWaiter(OobeScreen::SCREEN_OOBE_HID_DETECTION).Wait(); | |
| 135 AddBluetoothMouse(); | 141 AddBluetoothMouse(); |
| 136 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); | 142 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); |
| 137 WizardController::default_controller()->SkipToLoginForTesting( | 143 WizardController::default_controller()->SkipToLoginForTesting( |
| 138 LoginScreenContext()); | 144 LoginScreenContext()); |
| 139 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); | 145 OobeScreenWaiter(OobeScreen::SCREEN_GAIA_SIGNIN).Wait(); |
| 140 delegate()->WaitUntilAdapterReset(); | 146 delegate()->WaitUntilAdapterReset(); |
| 141 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); | 147 EXPECT_EQ(bluetooth_adapter()->IsPowered(), true); |
| 142 } | 148 } |
| 143 | 149 |
| 150 // This is the class to simulate the OOBE process for devices that have | |
| 151 // sufficient input, i.e., the first screen of OOBE is the network screen. | |
| 152 // The device will not put itself in Bluetooth discoverable mode until the user | |
| 153 // manually trigger it using the proper accelerator. | |
| 154 class BluetoothHostPairingTestWithInput | |
|
achuithb
2016/10/05 22:24:10
Test last
xdai1
2016/10/05 23:57:29
Done.
| |
| 155 : public BluetoothHostPairingTestNoInput { | |
| 156 public: | |
| 157 BluetoothHostPairingTestWithInput() { | |
| 158 AddUsbMouse(); | |
| 159 AddUsbKeyboard(); | |
| 160 } | |
| 161 ~BluetoothHostPairingTestWithInput() override {} | |
| 162 | |
| 163 DISALLOW_COPY_AND_ASSIGN(BluetoothHostPairingTestWithInput); | |
|
achuithb
2016/10/05 22:24:10
This must be private
xdai1
2016/10/05 23:57:29
Done.
| |
| 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(BluetoothHostPairingTestWithInput, | |
| 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 |