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

Side by Side Diff: chrome/browser/extensions/api/bluetooth/bluetooth_apitest_chromeos.cc

Issue 10899037: Refactoring bluetooth API code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: A Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h> 5 #include <string.h>
6 6
7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h" 7 #include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" 8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h"
9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" 9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h"
10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" 10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_function_test_utils.h" 13 #include "chrome/browser/extensions/extension_function_test_utils.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_test_message_listener.h" 15 #include "chrome/browser/extensions/extension_test_message_listener.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chromeos/dbus/bluetooth_out_of_band_client.h" 17 #include "chromeos/dbus/bluetooth_out_of_band_client.h"
18 #include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
18 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 21
21 using extensions::Extension; 22 using extensions::Extension;
22 23
23 namespace utils = extension_function_test_utils; 24 namespace utils = extension_function_test_utils;
24 namespace api = extensions::api; 25 namespace api = extensions::api;
25 26
26 namespace { 27 namespace {
27 28
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 chromeos::kBluetoothOutOfBandPairingDataSize); 102 chromeos::kBluetoothOutOfBandPairingDataSize);
102 return data; 103 return data;
103 } 104 }
104 105
105 static bool CallClosure(const base::Closure& callback) { 106 static bool CallClosure(const base::Closure& callback) {
106 callback.Run(); 107 callback.Run();
107 return true; 108 return true;
108 } 109 }
109 110
110 static void CallOutOfBandPairingDataCallback( 111 static void CallOutOfBandPairingDataCallback(
111 const chromeos::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& 112 const chromeos::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
112 callback, 113 callback,
113 const chromeos::BluetoothAdapter::ErrorCallback& error_callback) { 114 const chromeos::BluetoothAdapter::ErrorCallback& error_callback) {
114 callback.Run(GetOutOfBandPairingData()); 115 callback.Run(GetOutOfBandPairingData());
115 } 116 }
116 117
117 template <bool Value> 118 template <bool Value>
118 static void CallProvidesServiceCallback( 119 static void CallProvidesServiceCallback(
119 const std::string& name, 120 const std::string& name,
120 const chromeos::BluetoothDevice::ProvidesServiceCallback& callback) { 121 const chromeos::BluetoothDevice::ProvidesServiceCallback& callback) {
121 callback.Run(Value); 122 callback.Run(Value);
122 } 123 }
123 124
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(testing::_)) 388 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(testing::_))
388 .WillOnce(testing::Return(false)); 389 .WillOnce(testing::Return(false));
389 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) 390 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_))
390 .WillOnce(testing::Invoke(CallProvidesServiceCallback<true>)); 391 .WillOnce(testing::Invoke(CallProvidesServiceCallback<true>));
391 392
392 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(testing::_)) 393 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(testing::_))
393 .WillOnce(testing::Return(true)); 394 .WillOnce(testing::Return(true));
394 EXPECT_CALL(*device2_, ProvidesServiceWithName(testing::_, testing::_)) 395 EXPECT_CALL(*device2_, ProvidesServiceWithName(testing::_, testing::_))
395 .WillOnce(testing::Invoke(CallProvidesServiceCallback<false>)); 396 .WillOnce(testing::Invoke(CallProvidesServiceCallback<false>));
396 397
397 EXPECT_CALL(*mock_adapter_, GetDevices()) 398 EXPECT_CALL(testing::Const(*mock_adapter_), GetDevices())
398 .Times(3) 399 .Times(3)
399 .WillRepeatedly(testing::Return(devices)); 400 .WillRepeatedly(testing::Return(devices));
400 401
401 // Load and wait for setup 402 // Load and wait for setup
402 ExtensionTestMessageListener listener("ready", true); 403 ExtensionTestMessageListener listener("ready", true);
403 const extensions::Extension* extension = 404 const extensions::Extension* extension =
404 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); 405 LoadExtension(test_data_dir_.AppendASCII("bluetooth"));
405 GURL page_url = extension->GetResourceURL("test_getdevices.html"); 406 GURL page_url = extension->GetResourceURL("test_getdevices.html");
406 ui_test_utils::NavigateToURL(browser(), page_url); 407 ui_test_utils::NavigateToURL(browser(), page_url);
407 EXPECT_TRUE(listener.WaitUntilSatisfied()); 408 EXPECT_TRUE(listener.WaitUntilSatisfied());
408 409
409 listener.Reply("go"); 410 listener.Reply("go");
410 411
411 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 412 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
412 } 413 }
413 414
414 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) { 415 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) {
415 ResultCatcher catcher; 416 ResultCatcher catcher;
416 catcher.RestrictToProfile(browser()->profile()); 417 catcher.RestrictToProfile(browser()->profile());
417 418
418 chromeos::BluetoothAdapter::ConstDeviceList devices; 419 chromeos::BluetoothAdapter::ConstDeviceList devices;
419 devices.push_back(device1_.get()); 420 devices.push_back(device1_.get());
420 421
421 // Save the callback to delay execution so that we can force the calls to 422 // Save the callback to delay execution so that we can force the calls to
422 // happen concurrently. This will be called after the listener is satisfied. 423 // happen concurrently. This will be called after the listener is satisfied.
423 chromeos::BluetoothDevice::ProvidesServiceCallback callback; 424 chromeos::BluetoothDevice::ProvidesServiceCallback callback;
424 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) 425 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_))
425 .WillOnce(testing::SaveArg<1>(&callback)); 426 .WillOnce(testing::SaveArg<1>(&callback));
426 427
427 EXPECT_CALL(*mock_adapter_, GetDevices()) 428 EXPECT_CALL(testing::Const(*mock_adapter_), GetDevices())
428 .WillOnce(testing::Return(devices)); 429 .WillOnce(testing::Return(devices));
429 430
430 // Load and wait for setup 431 // Load and wait for setup
431 ExtensionTestMessageListener listener("ready", true); 432 ExtensionTestMessageListener listener("ready", true);
432 const extensions::Extension* extension = 433 const extensions::Extension* extension =
433 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); 434 LoadExtension(test_data_dir_.AppendASCII("bluetooth"));
434 GURL page_url = 435 GURL page_url =
435 extension->GetResourceURL("test_getdevices_concurrently.html"); 436 extension->GetResourceURL("test_getdevices_concurrently.html");
436 ui_test_utils::NavigateToURL(browser(), page_url); 437 ui_test_utils::NavigateToURL(browser(), page_url);
437 EXPECT_TRUE(listener.WaitUntilSatisfied()); 438 EXPECT_TRUE(listener.WaitUntilSatisfied());
438 439
439 callback.Run(false); 440 callback.Run(false);
440 listener.Reply("go"); 441 listener.Reply("go");
441 442
442 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 443 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
443 } 444 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698