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

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

Issue 10536159: Bluetooth Extension API: Add a discovery API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove chromeos/bluetooth code Created 8 years, 6 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 "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
5 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h" 6 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_adapter.h"
6 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h" 7 #include "chrome/browser/chromeos/bluetooth/test/mock_bluetooth_device.h"
7 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h" 8 #include "chrome/browser/chromeos/extensions/bluetooth_event_router.h"
8 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" 9 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/extensions/extension_function_test_utils.h" 11 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/extension_test_message_listener.h" 13 #include "chrome/browser/extensions/extension_test_message_listener.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 16
16 using extensions::Extension; 17 using extensions::Extension;
17 18
18 namespace utils = extension_function_test_utils; 19 namespace utils = extension_function_test_utils;
19 namespace api = extensions::api; 20 namespace api = extensions::api;
20 21
21 namespace chromeos {
22
23 class BluetoothAdapater;
24
25 } // namespace chromeos
26
27
28 namespace { 22 namespace {
29 23
30 class BluetoothApiTest : public PlatformAppApiTest { 24 class BluetoothApiTest : public PlatformAppApiTest {
31 public: 25 public:
32 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {} 26 BluetoothApiTest() : empty_extension_(utils::CreateEmptyExtension()) {}
33 27
34 virtual void SetUpOnMainThread() OVERRIDE { 28 virtual void SetUpOnMainThread() OVERRIDE {
35 // The browser will clean this up when it is torn down 29 // The browser will clean this up when it is torn down
36 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>; 30 mock_adapter_ = new testing::StrictMock<chromeos::MockBluetoothAdapter>;
37 event_router()->SetAdapterForTest(mock_adapter_); 31 event_router()->SetAdapterForTest(mock_adapter_);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 base::Value* device_value; 130 base::Value* device_value;
137 EXPECT_TRUE(list->Get(0, &device_value)); 131 EXPECT_TRUE(list->Get(0, &device_value));
138 EXPECT_EQ(base::Value::TYPE_DICTIONARY, device_value->GetType()); 132 EXPECT_EQ(base::Value::TYPE_DICTIONARY, device_value->GetType());
139 base::DictionaryValue* device; 133 base::DictionaryValue* device;
140 ASSERT_TRUE(device_value->GetAsDictionary(&device)); 134 ASSERT_TRUE(device_value->GetAsDictionary(&device));
141 135
142 std::string name; 136 std::string name;
143 ASSERT_TRUE(device->GetString("name", &name)); 137 ASSERT_TRUE(device->GetString("name", &name));
144 EXPECT_EQ("d2", name); 138 EXPECT_EQ("d2", name);
145 } 139 }
140
141 IN_PROC_BROWSER_TEST_F(BluetoothApiTest, Discovery) {
142 testing::NiceMock<chromeos::MockBluetoothDevice> device1(
143 mock_adapter_, "d1", "11:12:13:14:15:16");
144 testing::NiceMock<chromeos::MockBluetoothDevice> device2(
145 mock_adapter_, "d2", "21:22:23:24:25:26");
146 chromeos::BluetoothAdapter::DeviceList devices;
147 devices.push_back(&device1);
148 devices.push_back(&device2);
149
150 scoped_refptr<api::BluetoothStartDiscoveryFunction> start_function;
151 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
152 std::string error(
153 utils::RunFunctionAndReturnError(start_function, "[]", browser()));
154 ASSERT_TRUE(!error.empty());
155
156 mock_adapter_->SetDiscoveringDevicesForTesting(devices);
157 start_function = setupFunction(new api::BluetoothStartDiscoveryFunction);
158 scoped_ptr<base::Value> result(
159 utils::RunFunctionAndReturnResult(start_function, "[]", browser()));
160
161 // TODO(bryeung): test the events as well (crbug.com/132616)
162
163 scoped_refptr<api::BluetoothStopDiscoveryFunction> stop_function;
164 stop_function = setupFunction(new api::BluetoothStopDiscoveryFunction);
165 result.reset(
166 utils::RunFunctionAndReturnResult(stop_function, "[]", browser()));
167
168 // TODO(bryeung): test that no events are sent now (crbug.com/132616)
169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698