Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: extensions/browser/api/bluetooth_socket/bluetooth_socket_apitest.cc

Issue 555633003: Use extensions::ResultCatcher; delete ExtensionApiTest::ResultCatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h" 10 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_test_message_listener.h" 12 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "device/bluetooth/bluetooth_adapter_factory.h" 15 #include "device/bluetooth/bluetooth_adapter_factory.h"
16 #include "device/bluetooth/bluetooth_uuid.h" 16 #include "device/bluetooth/bluetooth_uuid.h"
17 #include "device/bluetooth/test/mock_bluetooth_adapter.h" 17 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
18 #include "device/bluetooth/test/mock_bluetooth_device.h" 18 #include "device/bluetooth/test/mock_bluetooth_device.h"
19 #include "device/bluetooth/test/mock_bluetooth_socket.h" 19 #include "device/bluetooth/test/mock_bluetooth_socket.h"
20 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h" 20 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h"
21 #include "extensions/test/result_catcher.h"
21 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
22 23
23 using device::BluetoothAdapter; 24 using device::BluetoothAdapter;
24 using device::BluetoothAdapterFactory; 25 using device::BluetoothAdapterFactory;
25 using device::BluetoothDevice; 26 using device::BluetoothDevice;
26 using device::BluetoothSocket; 27 using device::BluetoothSocket;
27 using device::BluetoothUUID; 28 using device::BluetoothUUID;
28 using device::MockBluetoothAdapter; 29 using device::MockBluetoothAdapter;
29 using device::MockBluetoothDevice; 30 using device::MockBluetoothDevice;
30 using device::MockBluetoothSocket; 31 using device::MockBluetoothSocket;
31 using extensions::Extension; 32 using extensions::Extension;
33 using extensions::ResultCatcher;
32 34
33 namespace utils = extension_function_test_utils; 35 namespace utils = extension_function_test_utils;
34 namespace api = extensions::core_api; 36 namespace api = extensions::core_api;
35 37
36 namespace { 38 namespace {
37 39
38 class BluetoothSocketApiTest : public ExtensionApiTest { 40 class BluetoothSocketApiTest : public ExtensionApiTest {
39 public: 41 public:
40 BluetoothSocketApiTest() {} 42 BluetoothSocketApiTest() {}
41 43
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 ACTION_TEMPLATE(InvokeCallbackArgument, 95 ACTION_TEMPLATE(InvokeCallbackArgument,
94 HAS_1_TEMPLATE_PARAMS(int, k), 96 HAS_1_TEMPLATE_PARAMS(int, k),
95 AND_2_VALUE_PARAMS(p0, p1)) { 97 AND_2_VALUE_PARAMS(p0, p1)) {
96 ::std::tr1::get<k>(args).Run(p0, p1); 98 ::std::tr1::get<k>(args).Run(p0, p1);
97 } 99 }
98 100
99 } // namespace 101 } // namespace
100 102
101 IN_PROC_BROWSER_TEST_F(BluetoothSocketApiTest, Connect) { 103 IN_PROC_BROWSER_TEST_F(BluetoothSocketApiTest, Connect) {
102 ResultCatcher catcher; 104 ResultCatcher catcher;
103 catcher.RestrictToProfile(browser()->profile()); 105 catcher.RestrictToBrowserContext(browser()->profile());
104 106
105 // Return the right mock device object for the address used by the test, 107 // Return the right mock device object for the address used by the test,
106 // return NULL for the "Device not found" test. 108 // return NULL for the "Device not found" test.
107 EXPECT_CALL(*mock_adapter_.get(), GetDevice(mock_device1_->GetAddress())) 109 EXPECT_CALL(*mock_adapter_.get(), GetDevice(mock_device1_->GetAddress()))
108 .WillRepeatedly(testing::Return(mock_device1_.get())); 110 .WillRepeatedly(testing::Return(mock_device1_.get()));
109 EXPECT_CALL(*mock_adapter_.get(), GetDevice(std::string("aa:aa:aa:aa:aa:aa"))) 111 EXPECT_CALL(*mock_adapter_.get(), GetDevice(std::string("aa:aa:aa:aa:aa:aa")))
110 .WillOnce(testing::Return(static_cast<BluetoothDevice*>(NULL))); 112 .WillOnce(testing::Return(static_cast<BluetoothDevice*>(NULL)));
111 113
112 // Return a mock socket object as a successful result to the connect() call. 114 // Return a mock socket object as a successful result to the connect() call.
113 BluetoothUUID service_uuid("8e3ad063-db38-4289-aa8f-b30e4223cf40"); 115 BluetoothUUID service_uuid("8e3ad063-db38-4289-aa8f-b30e4223cf40");
(...skipping 24 matching lines...) Expand all
138 } 140 }
139 141
140 #if defined(_LIBCPP_VERSION) 142 #if defined(_LIBCPP_VERSION)
141 // This test fails in libc++ builds, see http://crbug.com/392205. 143 // This test fails in libc++ builds, see http://crbug.com/392205.
142 #define MAYBE_Listen DISABLED_Listen 144 #define MAYBE_Listen DISABLED_Listen
143 #else 145 #else
144 #define MAYBE_Listen Listen 146 #define MAYBE_Listen Listen
145 #endif 147 #endif
146 IN_PROC_BROWSER_TEST_F(BluetoothSocketApiTest, MAYBE_Listen) { 148 IN_PROC_BROWSER_TEST_F(BluetoothSocketApiTest, MAYBE_Listen) {
147 ResultCatcher catcher; 149 ResultCatcher catcher;
148 catcher.RestrictToProfile(browser()->profile()); 150 catcher.RestrictToBrowserContext(browser()->profile());
149 151
150 // Return a mock socket object as a successful result to the create service 152 // Return a mock socket object as a successful result to the create service
151 // call. 153 // call.
152 BluetoothUUID service_uuid("2de497f9-ab28-49db-b6d2-066ea69f1737"); 154 BluetoothUUID service_uuid("2de497f9-ab28-49db-b6d2-066ea69f1737");
153 scoped_refptr<testing::StrictMock<MockBluetoothSocket> > mock_server_socket 155 scoped_refptr<testing::StrictMock<MockBluetoothSocket> > mock_server_socket
154 = new testing::StrictMock<MockBluetoothSocket>(); 156 = new testing::StrictMock<MockBluetoothSocket>();
155 BluetoothAdapter::ServiceOptions service_options; 157 BluetoothAdapter::ServiceOptions service_options;
156 service_options.name.reset(new std::string("MyServiceName")); 158 service_options.name.reset(new std::string("MyServiceName"));
157 EXPECT_CALL( 159 EXPECT_CALL(
158 *mock_adapter_.get(), 160 *mock_adapter_.get(),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 .WillOnce(InvokeCallbackArgument<0>()); 202 .WillOnce(InvokeCallbackArgument<0>());
201 EXPECT_CALL(*mock_client_socket.get(), Close()); 203 EXPECT_CALL(*mock_client_socket.get(), Close());
202 204
203 EXPECT_TRUE(listener.WaitUntilSatisfied()); 205 EXPECT_TRUE(listener.WaitUntilSatisfied());
204 listener.Reply("go"); 206 listener.Reply("go");
205 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 207 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
206 } 208 }
207 209
208 IN_PROC_BROWSER_TEST_F(BluetoothSocketApiTest, PermissionDenied) { 210 IN_PROC_BROWSER_TEST_F(BluetoothSocketApiTest, PermissionDenied) {
209 ResultCatcher catcher; 211 ResultCatcher catcher;
210 catcher.RestrictToProfile(browser()->profile()); 212 catcher.RestrictToBrowserContext(browser()->profile());
211 213
212 // Run the test. 214 // Run the test.
213 scoped_refptr<const Extension> extension( 215 scoped_refptr<const Extension> extension(
214 LoadExtension(test_data_dir_.AppendASCII( 216 LoadExtension(test_data_dir_.AppendASCII(
215 "bluetooth_socket/permission_denied"))); 217 "bluetooth_socket/permission_denied")));
216 ASSERT_TRUE(extension.get()); 218 ASSERT_TRUE(extension.get());
217 219
218 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 220 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
219 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698