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

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

Issue 11075006: Moved bluetooth adapter files to device/bluetooth/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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"
8 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h"
9 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h"
10 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" 7 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" 8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 9 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_function_test_utils.h" 10 #include "chrome/browser/extensions/extension_function_test_utils.h"
14 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_test_message_listener.h" 12 #include "chrome/browser/extensions/extension_test_message_listener.h"
16 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
17 #include "chromeos/dbus/bluetooth_out_of_band_client.h" 14 #include "chromeos/dbus/bluetooth_out_of_band_client.h"
18 #include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
19 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "device/bluetooth/bluetooth_adapter.h"
17 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
18 #include "device/bluetooth/test/mock_bluetooth_adapter.h"
19 #include "device/bluetooth/test/mock_bluetooth_device.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 21
22 using device_bluetooth::BluetoothAdapter;
23 using device_bluetooth::BluetoothDevice;
24 using device_bluetooth::BluetoothOutOfBandPairingData;
22 using extensions::Extension; 25 using extensions::Extension;
23 26
24 namespace utils = extension_function_test_utils; 27 namespace utils = extension_function_test_utils;
25 namespace api = extensions::api; 28 namespace api = extensions::api;
26 29
27 namespace { 30 namespace {
28 31
29 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6"; 32 static const char* kAdapterAddress = "A1:A2:A3:A4:A5:A6";
30 static const char* kName = "whatsinaname"; 33 static const char* kName = "whatsinaname";
31 34
32 class BluetoothApiTest : public PlatformAppApiTest { 35 class BluetoothApiTest : public PlatformAppApiTest {
33 public: 36 public:
34 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} 37 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {}
35 38
36 virtual void SetUpOnMainThread() OVERRIDE { 39 virtual void SetUpOnMainThread() OVERRIDE {
37 // The browser will clean this up when it is torn down 40 // The browser will clean this up when it is torn down
38 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>( 41 mock_adapter_ =
39 kAdapterAddress, kName); 42 new testing::StrictMock<device_bluetooth::MockBluetoothAdapter>(
43 kAdapterAddress, kName);
40 event_router()->SetAdapterForTest(mock_adapter_); 44 event_router()->SetAdapterForTest(mock_adapter_);
41 45
42 device1_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( 46 device1_.reset(new testing::NiceMock<device_bluetooth::MockBluetoothDevice>(
43 mock_adapter_, "d1", "11:12:13:14:15:16", 47 mock_adapter_, "d1", "11:12:13:14:15:16",
44 true /* paired */, false /* bonded */, true /* connected */)); 48 true /* paired */, false /* bonded */, true /* connected */));
45 device2_.reset(new testing::NiceMock<chromeos::MockBluetoothDevice>( 49 device2_.reset(new testing::NiceMock<device_bluetooth::MockBluetoothDevice>(
46 mock_adapter_, "d2", "21:22:23:24:25:26", 50 mock_adapter_, "d2", "21:22:23:24:25:26",
47 false /* paired */, true /* bonded */, false /* connected */)); 51 false /* paired */, true /* bonded */, false /* connected */));
48 } 52 }
49 53
50 virtual void CleanUpOnMainThread() OVERRIDE { 54 virtual void CleanUpOnMainThread() OVERRIDE {
51 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_)); 55 EXPECT_CALL(*mock_adapter_, RemoveObserver(testing::_));
52 } 56 }
53 57
54 void expectBooleanResult(bool expected, 58 void expectBooleanResult(bool expected,
55 UIThreadExtensionFunction* function) { 59 UIThreadExtensionFunction* function) {
(...skipping 18 matching lines...) Expand all
74 } 78 }
75 79
76 template <class T> 80 template <class T>
77 T* setupFunction(T* function) { 81 T* setupFunction(T* function) {
78 function->set_extension(empty_extension_.get()); 82 function->set_extension(empty_extension_.get());
79 function->set_has_callback(true); 83 function->set_has_callback(true);
80 return function; 84 return function;
81 } 85 }
82 86
83 protected: 87 protected:
84 testing::StrictMock<chromeos::MockBluetoothAdapter>* mock_adapter_; 88 testing::StrictMock<device_bluetooth::MockBluetoothAdapter>* mock_adapter_;
85 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device1_; 89 scoped_ptr<testing::NiceMock<device_bluetooth::MockBluetoothDevice> >
86 scoped_ptr<testing::NiceMock<chromeos::MockBluetoothDevice> > device2_; 90 device1_;
91 scoped_ptr<testing::NiceMock<device_bluetooth::MockBluetoothDevice> >
92 device2_;
87 93
88 chromeos::ExtensionBluetoothEventRouter* event_router() { 94 chromeos::ExtensionBluetoothEventRouter* event_router() {
89 return browser()->profile()->GetExtensionService()-> 95 return browser()->profile()->GetExtensionService()->
90 bluetooth_event_router(); 96 bluetooth_event_router();
91 } 97 }
92 98
93 private: 99 private:
94 scoped_refptr<Extension> empty_extension_; 100 scoped_refptr<Extension> empty_extension_;
95 }; 101 };
96 102
97 // This is the canonical UUID for the short UUID 0010. 103 // This is the canonical UUID for the short UUID 0010.
98 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh"; 104 static const char kOutOfBandPairingDataHash[] = "0123456789ABCDEh";
99 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr"; 105 static const char kOutOfBandPairingDataRandomizer[] = "0123456789ABCDEr";
100 106
101 static chromeos::BluetoothOutOfBandPairingData GetOutOfBandPairingData() { 107 static BluetoothOutOfBandPairingData GetOutOfBandPairingData() {
102 chromeos::BluetoothOutOfBandPairingData data; 108 BluetoothOutOfBandPairingData data;
103 memcpy(&(data.hash), kOutOfBandPairingDataHash, 109 memcpy(&(data.hash), kOutOfBandPairingDataHash,
104 chromeos::kBluetoothOutOfBandPairingDataSize); 110 device_bluetooth::kBluetoothOutOfBandPairingDataSize);
105 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer, 111 memcpy(&(data.randomizer), kOutOfBandPairingDataRandomizer,
106 chromeos::kBluetoothOutOfBandPairingDataSize); 112 device_bluetooth::kBluetoothOutOfBandPairingDataSize);
107 return data; 113 return data;
108 } 114 }
109 115
110 static bool CallClosure(const base::Closure& callback) { 116 static bool CallClosure(const base::Closure& callback) {
111 callback.Run(); 117 callback.Run();
112 return true; 118 return true;
113 } 119 }
114 120
115 static void CallOutOfBandPairingDataCallback( 121 static void CallOutOfBandPairingDataCallback(
116 const chromeos::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& 122 const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback,
117 callback, 123 const device_bluetooth::BluetoothAdapter::ErrorCallback& error_callback) {
118 const chromeos::BluetoothAdapter::ErrorCallback& error_callback) {
119 callback.Run(GetOutOfBandPairingData()); 124 callback.Run(GetOutOfBandPairingData());
120 } 125 }
121 126
122 template <bool Value> 127 template <bool Value>
123 static void CallProvidesServiceCallback( 128 static void CallProvidesServiceCallback(
124 const std::string& name, 129 const std::string& name,
125 const chromeos::BluetoothDevice::ProvidesServiceCallback& callback) { 130 const BluetoothDevice::ProvidesServiceCallback& callback) {
126 callback.Run(Value); 131 callback.Run(Value);
127 } 132 }
128 133
129 } // namespace 134 } // namespace
130 135
131 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, IsAvailable) { 136 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, IsAvailable) {
132 EXPECT_CALL(*mock_adapter_, IsPresent()) 137 EXPECT_CALL(*mock_adapter_, IsPresent())
133 .WillOnce(testing::Return(false)); 138 .WillOnce(testing::Return(false));
134 139
135 scoped_refptr<api::BluetoothIsAvailableFunction> is_available; 140 scoped_refptr<api::BluetoothIsAvailableFunction> is_available;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 383
379 listener.Reply("go"); 384 listener.Reply("go");
380 385
381 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 386 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
382 } 387 }
383 388
384 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) { 389 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevices) {
385 ResultCatcher catcher; 390 ResultCatcher catcher;
386 catcher.RestrictToProfile(browser()->profile()); 391 catcher.RestrictToProfile(browser()->profile());
387 392
388 chromeos::BluetoothAdapter::ConstDeviceList devices; 393 device_bluetooth::BluetoothAdapter::ConstDeviceList devices;
389 devices.push_back(device1_.get()); 394 devices.push_back(device1_.get());
390 devices.push_back(device2_.get()); 395 devices.push_back(device2_.get());
391 396
392 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(testing::_)) 397 EXPECT_CALL(*device1_, ProvidesServiceWithUUID(testing::_))
393 .WillOnce(testing::Return(false)); 398 .WillOnce(testing::Return(false));
394 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) 399 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_))
395 .WillOnce(testing::Invoke(CallProvidesServiceCallback<true>)); 400 .WillOnce(testing::Invoke(CallProvidesServiceCallback<true>));
396 401
397 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(testing::_)) 402 EXPECT_CALL(*device2_, ProvidesServiceWithUUID(testing::_))
398 .WillOnce(testing::Return(true)); 403 .WillOnce(testing::Return(true));
(...skipping 14 matching lines...) Expand all
413 418
414 listener.Reply("go"); 419 listener.Reply("go");
415 420
416 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 421 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
417 } 422 }
418 423
419 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) { 424 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, GetDevicesConcurrently) {
420 ResultCatcher catcher; 425 ResultCatcher catcher;
421 catcher.RestrictToProfile(browser()->profile()); 426 catcher.RestrictToProfile(browser()->profile());
422 427
423 chromeos::BluetoothAdapter::ConstDeviceList devices; 428 device_bluetooth::BluetoothAdapter::ConstDeviceList devices;
424 devices.push_back(device1_.get()); 429 devices.push_back(device1_.get());
425 430
426 // Save the callback to delay execution so that we can force the calls to 431 // Save the callback to delay execution so that we can force the calls to
427 // happen concurrently. This will be called after the listener is satisfied. 432 // happen concurrently. This will be called after the listener is satisfied.
428 chromeos::BluetoothDevice::ProvidesServiceCallback callback; 433 BluetoothDevice::ProvidesServiceCallback callback;
429 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_)) 434 EXPECT_CALL(*device1_, ProvidesServiceWithName(testing::_, testing::_))
430 .WillOnce(testing::SaveArg<1>(&callback)); 435 .WillOnce(testing::SaveArg<1>(&callback));
431 436
432 EXPECT_CALL(*mock_adapter_, GetDevices()) 437 EXPECT_CALL(*mock_adapter_, GetDevices())
433 .WillOnce(testing::Return(devices)); 438 .WillOnce(testing::Return(devices));
434 439
435 // Load and wait for setup 440 // Load and wait for setup
436 ExtensionTestMessageListener listener("ready", true); 441 ExtensionTestMessageListener listener("ready", true);
437 const extensions::Extension* extension = 442 const extensions::Extension* extension =
438 LoadExtension(test_data_dir_.AppendASCII("bluetooth")); 443 LoadExtension(test_data_dir_.AppendASCII("bluetooth"));
439 GURL page_url = 444 GURL page_url =
440 extension->GetResourceURL("test_getdevices_concurrently.html"); 445 extension->GetResourceURL("test_getdevices_concurrently.html");
441 ui_test_utils::NavigateToURL(browser(), page_url); 446 ui_test_utils::NavigateToURL(browser(), page_url);
442 EXPECT_TRUE(listener.WaitUntilSatisfied()); 447 EXPECT_TRUE(listener.WaitUntilSatisfied());
443 448
444 callback.Run(false); 449 callback.Run(false);
445 listener.Reply("go"); 450 listener.Reply("go");
446 451
447 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 452 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
448 } 453 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698