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

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

Powered by Google App Engine
This is Rietveld 408576698