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

Side by Side Diff: chrome/browser/extensions/api/gcd_private/gcd_private_apitest.cc

Issue 356613002: Add queryForNewLocalDevices to gcdPrivate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" 9 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h"
10 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0xc0, 0x0c, 131 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0xc0, 0x0c,
132 0x00, 0x21, // Type is SRV 132 0x00, 0x21, // Type is SRV
133 0x00, 0x01, // CLASS is IN 133 0x00, 0x01, // CLASS is IN
134 0x00, 0x00, // TTL (4 bytes) is 0 seconds. 134 0x00, 0x00, // TTL (4 bytes) is 0 seconds.
135 0x00, 0x00, 0x00, 0x17, // RDLENGTH is 23 135 0x00, 0x00, 0x00, 0x17, // RDLENGTH is 23
136 0x00, 0x00, 0x00, 0x00, 0x22, 0xb8, // port 8888 136 0x00, 0x00, 0x00, 0x00, 0x22, 0xb8, // port 8888
137 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0x05, 'l', 137 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0x05, 'l',
138 'o', 'c', 'a', 'l', 0x00, 138 'o', 'c', 'a', 'l', 0x00,
139 }; 139 };
140 140
141 const uint8 kQueryPacket[] = {
142 // Header
143 0x00, 0x00, // ID is zeroed out
144 0x00, 0x00, // No flags.
145 0x00, 0x01, // One question.
146 0x00, 0x00, // 0 RRs (answers)
147 0x00, 0x00, // 0 authority RRs
148 0x00, 0x00, // 0 additional RRs
149
150 // Question
151 // This part is echoed back from the respective query.
152 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c',
153 'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR.
154 0x00, 0x01, // CLASS is IN.
155 };
156
141 #endif // ENABLE_MDNS 157 #endif // ENABLE_MDNS
142 158
143 // Sentinel value to signify the request should fail. 159 // Sentinel value to signify the request should fail.
144 const char kResponseValueFailure[] = "FAILURE"; 160 const char kResponseValueFailure[] = "FAILURE";
145 161
146 class FakeGCDApiFlowFactory 162 class FakeGCDApiFlowFactory
147 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { 163 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests {
148 public: 164 public:
149 FakeGCDApiFlowFactory() { 165 FakeGCDApiFlowFactory() {
150 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); 166 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 FROM_HERE, 317 FROM_HERE,
302 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, 318 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive,
303 test_service_discovery_client_, 319 test_service_discovery_client_,
304 kGoodbyePacket, 320 kGoodbyePacket,
305 sizeof(kGoodbyePacket)), 321 sizeof(kGoodbyePacket)),
306 base::TimeDelta::FromSeconds(1)); 322 base::TimeDelta::FromSeconds(1));
307 323
308 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); 324 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html"));
309 } 325 }
310 326
327 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, SendQuery) {
328 EXPECT_CALL(*test_service_discovery_client_,
329 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket),
330 sizeof(kQueryPacket)))).Times(2);
331
332 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html"));
333 }
334
311 #endif // ENABLE_MDNS 335 #endif // ENABLE_MDNS
312 336
313 #if defined(ENABLE_WIFI_BOOTSTRAPPING) 337 #if defined(ENABLE_WIFI_BOOTSTRAPPING)
314 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiAdd) { 338 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiAdd) {
315 response_callback_ = base::Bind(&GcdPrivateAPITest::RespondWithFilledList, 339 response_callback_ = base::Bind(&GcdPrivateAPITest::RespondWithFilledList,
316 base::Unretained(this)); 340 base::Unretained(this));
317 341
318 EXPECT_CALL(wifi_manager_factory_, OnWifiManagerCreated(_)).WillOnce( 342 EXPECT_CALL(wifi_manager_factory_, OnWifiManagerCreated(_)).WillOnce(
319 Invoke(this, &GcdPrivateAPITest::RespondToSSIDListWithCallback)); 343 Invoke(this, &GcdPrivateAPITest::RespondToSSIDListWithCallback));
320 344
321 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "add_wifi_device.html")); 345 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "add_wifi_device.html"));
322 } 346 }
323 347
324 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiAddRemove) { 348 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, WifiAddRemove) {
325 response_callback_ = base::Bind(&GcdPrivateAPITest::RespondWithAddRemove, 349 response_callback_ = base::Bind(&GcdPrivateAPITest::RespondWithAddRemove,
326 base::Unretained(this)); 350 base::Unretained(this));
327 351
328 EXPECT_CALL(wifi_manager_factory_, OnWifiManagerCreated(_)).WillOnce( 352 EXPECT_CALL(wifi_manager_factory_, OnWifiManagerCreated(_)).WillOnce(
329 Invoke(this, &GcdPrivateAPITest::RespondToSSIDListWithCallback)); 353 Invoke(this, &GcdPrivateAPITest::RespondToSSIDListWithCallback));
330 354
331 EXPECT_TRUE( 355 EXPECT_TRUE(
332 RunExtensionSubtest("gcd_private/api", "remove_wifi_device.html")); 356 RunExtensionSubtest("gcd_private/api", "remove_wifi_device.html"));
333 } 357 }
358
334 #endif 359 #endif
335 360
336 } // namespace 361 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698