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/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
| 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 48 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 49 extensions::switches::kWhitelistedExtensionID, kTestExtensionId); | 49 extensions::switches::kWhitelistedExtensionID, kTestExtensionId); |
| 50 mock_adapter_ = new NiceMock<MockBluetoothAdapter>(); | 50 mock_adapter_ = new NiceMock<MockBluetoothAdapter>(); |
| 51 event_router()->SetAdapterForTest(mock_adapter_.get()); | 51 event_router()->SetAdapterForTest(mock_adapter_.get()); |
| 52 mock_device_.reset(new NiceMock<MockBluetoothDevice>(mock_adapter_.get(), | 52 mock_device_.reset(new NiceMock<MockBluetoothDevice>(mock_adapter_.get(), |
| 53 0, | 53 0, |
| 54 kDeviceName, | 54 kDeviceName, |
| 55 "11:12:13:14:15:16", | 55 "11:12:13:14:15:16", |
| 56 false, | 56 false, |
| 57 false)); | 57 false)); |
| 58 ON_CALL(*mock_adapter_, GetDevice(mock_device_->GetAddress())) | 58 ON_CALL(*mock_adapter_.get(), GetDevice(mock_device_->GetAddress())) |
|
Jeffrey Yasskin
2014/08/26 01:14:16
Adding .get() shouldn't affect how this works, sin
dcheng
2014/08/26 01:26:00
Before anything else, I'd like to say that I reall
| |
| 59 .WillByDefault(Return(mock_device_.get())); | 59 .WillByDefault(Return(mock_device_.get())); |
| 60 ON_CALL(*mock_adapter_, IsPresent()) | 60 ON_CALL(*mock_adapter_.get(), IsPresent()).WillByDefault(Return(true)); |
| 61 .WillByDefault(Return(true)); | |
| 62 } | 61 } |
| 63 | 62 |
| 64 virtual void TearDownOnMainThread() OVERRIDE {} | 63 virtual void TearDownOnMainThread() OVERRIDE {} |
| 65 | 64 |
| 66 extensions::BluetoothEventRouter* event_router() { | 65 extensions::BluetoothEventRouter* event_router() { |
| 67 return extensions::BluetoothAPI::Get(browser()->profile()) | 66 return extensions::BluetoothAPI::Get(browser()->profile()) |
| 68 ->event_router(); | 67 ->event_router(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 void SetName(const std::string& name, const base::Closure& callback) { | 70 void SetName(const std::string& name, const base::Closure& callback) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 protected: | 113 protected: |
| 115 std::string adapter_name_; | 114 std::string adapter_name_; |
| 116 bool adapter_powered_; | 115 bool adapter_powered_; |
| 117 bool adapter_discoverable_; | 116 bool adapter_discoverable_; |
| 118 | 117 |
| 119 scoped_refptr<NiceMock<MockBluetoothAdapter> > mock_adapter_; | 118 scoped_refptr<NiceMock<MockBluetoothAdapter> > mock_adapter_; |
| 120 scoped_ptr<NiceMock<MockBluetoothDevice> > mock_device_; | 119 scoped_ptr<NiceMock<MockBluetoothDevice> > mock_device_; |
| 121 }; | 120 }; |
| 122 | 121 |
| 123 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, SetAdapterState) { | 122 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, SetAdapterState) { |
| 124 ON_CALL(*mock_adapter_, GetName()) | 123 ON_CALL(*mock_adapter_.get(), GetName()) |
| 125 .WillByDefault(ReturnPointee(&adapter_name_)); | 124 .WillByDefault(ReturnPointee(&adapter_name_)); |
| 126 ON_CALL(*mock_adapter_, IsPowered()) | 125 ON_CALL(*mock_adapter_.get(), IsPowered()) |
| 127 .WillByDefault(ReturnPointee(&adapter_powered_)); | 126 .WillByDefault(ReturnPointee(&adapter_powered_)); |
| 128 ON_CALL(*mock_adapter_, IsDiscoverable()) | 127 ON_CALL(*mock_adapter_.get(), IsDiscoverable()) |
| 129 .WillByDefault(ReturnPointee(&adapter_discoverable_)); | 128 .WillByDefault(ReturnPointee(&adapter_discoverable_)); |
| 130 | 129 |
| 131 EXPECT_CALL(*mock_adapter_, SetName("Dome", _, _)).WillOnce( | 130 EXPECT_CALL(*mock_adapter_.get(), SetName("Dome", _, _)).WillOnce( |
| 132 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetName))); | 131 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetName))); |
| 133 EXPECT_CALL(*mock_adapter_, SetPowered(true, _, _)).WillOnce( | 132 EXPECT_CALL(*mock_adapter_.get(), SetPowered(true, _, _)).WillOnce( |
| 134 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetPowered))); | 133 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetPowered))); |
| 135 EXPECT_CALL(*mock_adapter_, SetDiscoverable(true, _, _)).WillOnce( | 134 EXPECT_CALL(*mock_adapter_.get(), SetDiscoverable(true, _, _)).WillOnce( |
| 136 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetDiscoverable))); | 135 WithArgs<0, 1>(Invoke(this, &BluetoothPrivateApiTest::SetDiscoverable))); |
| 137 | 136 |
| 138 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/adapter_state")) | 137 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/adapter_state")) |
| 139 << message_; | 138 << message_; |
| 140 } | 139 } |
| 141 | 140 |
| 142 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, NoBluetoothAdapter) { | 141 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, NoBluetoothAdapter) { |
| 143 ON_CALL(*mock_adapter_, IsPresent()) | 142 ON_CALL(*mock_adapter_.get(), IsPresent()).WillByDefault(Return(false)); |
| 144 .WillByDefault(Return(false)); | |
| 145 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/no_adapter")) | 143 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/no_adapter")) |
| 146 << message_; | 144 << message_; |
| 147 } | 145 } |
| 148 | 146 |
| 149 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, CancelPairing) { | 147 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, CancelPairing) { |
| 150 InSequence s; | 148 InSequence s; |
| 151 EXPECT_CALL(*mock_adapter_, | 149 EXPECT_CALL(*mock_adapter_.get(), |
| 152 AddPairingDelegate( | 150 AddPairingDelegate( |
| 153 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) | 151 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) |
| 154 .WillOnce(WithoutArgs(Invoke( | 152 .WillOnce(WithoutArgs(Invoke( |
| 155 this, &BluetoothPrivateApiTest::DispatchAuthorizePairingEvent))); | 153 this, &BluetoothPrivateApiTest::DispatchAuthorizePairingEvent))); |
| 156 EXPECT_CALL(*mock_device_, ExpectingConfirmation()) | 154 EXPECT_CALL(*mock_device_, ExpectingConfirmation()) |
| 157 .WillRepeatedly(Return(true)); | 155 .WillRepeatedly(Return(true)); |
| 158 EXPECT_CALL(*mock_device_, CancelPairing()); | 156 EXPECT_CALL(*mock_device_, CancelPairing()); |
| 159 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/cancel_pairing")) | 157 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/cancel_pairing")) |
| 160 << message_; | 158 << message_; |
| 161 } | 159 } |
| 162 | 160 |
| 163 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PincodePairing) { | 161 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PincodePairing) { |
| 164 EXPECT_CALL(*mock_adapter_, | 162 EXPECT_CALL(*mock_adapter_.get(), |
| 165 AddPairingDelegate( | 163 AddPairingDelegate( |
| 166 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) | 164 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) |
| 167 .WillOnce(WithoutArgs( | 165 .WillOnce(WithoutArgs( |
| 168 Invoke(this, &BluetoothPrivateApiTest::DispatchPincodePairingEvent))); | 166 Invoke(this, &BluetoothPrivateApiTest::DispatchPincodePairingEvent))); |
| 169 EXPECT_CALL(*mock_device_, ExpectingPinCode()).WillRepeatedly(Return(true)); | 167 EXPECT_CALL(*mock_device_, ExpectingPinCode()).WillRepeatedly(Return(true)); |
| 170 EXPECT_CALL(*mock_device_, SetPinCode("abbbbbbk")); | 168 EXPECT_CALL(*mock_device_, SetPinCode("abbbbbbk")); |
| 171 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/pincode_pairing")) | 169 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/pincode_pairing")) |
| 172 << message_; | 170 << message_; |
| 173 } | 171 } |
| 174 | 172 |
| 175 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PasskeyPairing) { | 173 IN_PROC_BROWSER_TEST_F(BluetoothPrivateApiTest, PasskeyPairing) { |
| 176 EXPECT_CALL(*mock_adapter_, | 174 EXPECT_CALL(*mock_adapter_.get(), |
| 177 AddPairingDelegate( | 175 AddPairingDelegate( |
| 178 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) | 176 _, device::BluetoothAdapter::PAIRING_DELEGATE_PRIORITY_HIGH)) |
| 179 .WillOnce(WithoutArgs( | 177 .WillOnce(WithoutArgs( |
| 180 Invoke(this, &BluetoothPrivateApiTest::DispatchPasskeyPairingEvent))); | 178 Invoke(this, &BluetoothPrivateApiTest::DispatchPasskeyPairingEvent))); |
| 181 EXPECT_CALL(*mock_device_, ExpectingPasskey()).WillRepeatedly(Return(true)); | 179 EXPECT_CALL(*mock_device_, ExpectingPasskey()).WillRepeatedly(Return(true)); |
| 182 EXPECT_CALL(*mock_device_, SetPasskey(900531)); | 180 EXPECT_CALL(*mock_device_, SetPasskey(900531)); |
| 183 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/passkey_pairing")) | 181 ASSERT_TRUE(RunComponentExtensionTest("bluetooth_private/passkey_pairing")) |
| 184 << message_; | 182 << message_; |
| 185 } | 183 } |
| OLD | NEW |