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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_api.h" | 9 #include "chrome/browser/extensions/api/bluetooth_socket/bluetooth_socket_api.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // Run the test. | 125 // Run the test. |
126 ExtensionTestMessageListener listener("ready", true); | 126 ExtensionTestMessageListener listener("ready", true); |
127 scoped_refptr<const Extension> extension( | 127 scoped_refptr<const Extension> extension( |
128 LoadExtension(test_data_dir_.AppendASCII("bluetooth_socket/connect"))); | 128 LoadExtension(test_data_dir_.AppendASCII("bluetooth_socket/connect"))); |
129 ASSERT_TRUE(extension.get()); | 129 ASSERT_TRUE(extension.get()); |
130 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 130 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
131 | 131 |
132 listener.Reply("go"); | 132 listener.Reply("go"); |
133 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 133 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
134 } | 134 } |
| 135 |
| 136 IN_PROC_BROWSER_TEST_F(BluetoothSocketApiTest, Listen) { |
| 137 ResultCatcher catcher; |
| 138 catcher.RestrictToProfile(browser()->profile()); |
| 139 |
| 140 // Return a mock socket object as a successful result to the create service |
| 141 // call. |
| 142 BluetoothUUID service_uuid("2de497f9-ab28-49db-b6d2-066ea69f1737"); |
| 143 scoped_refptr<testing::StrictMock<MockBluetoothSocket> > mock_server_socket |
| 144 = new testing::StrictMock<MockBluetoothSocket>(); |
| 145 EXPECT_CALL(*mock_adapter_, |
| 146 CreateRfcommService(service_uuid, |
| 147 BluetoothAdapter::kPsmAuto, |
| 148 false, |
| 149 testing::_, testing::_)) |
| 150 .WillOnce(InvokeCallbackArgument<3>(mock_server_socket)); |
| 151 |
| 152 // Since the socket is unpaused, expect a call to Accept() from the socket |
| 153 // dispatcher. We'll immediately send back another mock socket to represent |
| 154 // the client API. Further calls will return no data and behave as if |
| 155 // pending. |
| 156 scoped_refptr<testing::StrictMock<MockBluetoothSocket> > mock_client_socket |
| 157 = new testing::StrictMock<MockBluetoothSocket>(); |
| 158 EXPECT_CALL(*mock_server_socket, Accept(testing::_, testing::_)) |
| 159 .Times(2) |
| 160 .WillOnce(InvokeCallbackArgument<0>(mock_device1_.get(), |
| 161 mock_client_socket)) |
| 162 .WillOnce(testing::Return()); |
| 163 |
| 164 // Run the test, it sends a ready signal once it's ready for us to dispatch |
| 165 // a client connection to it. |
| 166 ExtensionTestMessageListener socket_listening("ready", true); |
| 167 scoped_refptr<const Extension> extension( |
| 168 LoadExtension(test_data_dir_.AppendASCII("bluetooth_socket/listen"))); |
| 169 ASSERT_TRUE(extension.get()); |
| 170 EXPECT_TRUE(socket_listening.WaitUntilSatisfied()); |
| 171 |
| 172 // Connection events are dispatched using a couple of PostTask to the UI |
| 173 // thread. Waiting until idle ensures the event is dispatched to the |
| 174 // receiver(s). |
| 175 base::RunLoop().RunUntilIdle(); |
| 176 ExtensionTestMessageListener listener("ready", true); |
| 177 socket_listening.Reply("go"); |
| 178 |
| 179 // Second stage of tests checks for error conditions, and will clean up |
| 180 // the existing server and client sockets. |
| 181 EXPECT_CALL(*mock_server_socket, Disconnect(testing::_)) |
| 182 .WillOnce(InvokeCallbackArgument<0>()); |
| 183 EXPECT_CALL(*mock_server_socket, Close()); |
| 184 |
| 185 EXPECT_CALL(*mock_client_socket, Disconnect(testing::_)) |
| 186 .WillOnce(InvokeCallbackArgument<0>()); |
| 187 EXPECT_CALL(*mock_client_socket, Close()); |
| 188 |
| 189 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 190 listener.Reply("go"); |
| 191 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 192 } |
OLD | NEW |