OLD | NEW |
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0xc0, 0x0c, | 123 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0xc0, 0x0c, |
124 0x00, 0x21, // Type is SRV | 124 0x00, 0x21, // Type is SRV |
125 0x00, 0x01, // CLASS is IN | 125 0x00, 0x01, // CLASS is IN |
126 0x00, 0x00, // TTL (4 bytes) is 0 seconds. | 126 0x00, 0x00, // TTL (4 bytes) is 0 seconds. |
127 0x00, 0x00, 0x00, 0x17, // RDLENGTH is 23 | 127 0x00, 0x00, 0x00, 0x17, // RDLENGTH is 23 |
128 0x00, 0x00, 0x00, 0x00, 0x22, 0xb8, // port 8888 | 128 0x00, 0x00, 0x00, 0x00, 0x22, 0xb8, // port 8888 |
129 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0x05, 'l', | 129 0x09, 'm', 'y', 'S', 'e', 'r', 'v', 'i', 'c', 'e', 0x05, 'l', |
130 'o', 'c', 'a', 'l', 0x00, | 130 'o', 'c', 'a', 'l', 0x00, |
131 }; | 131 }; |
132 | 132 |
| 133 const uint8 kQueryPacket[] = { |
| 134 // Header |
| 135 0x00, 0x00, // ID is zeroed out |
| 136 0x00, 0x00, // No flags. |
| 137 0x00, 0x01, // One question. |
| 138 0x00, 0x00, // 0 RRs (answers) |
| 139 0x00, 0x00, // 0 authority RRs |
| 140 0x00, 0x00, // 0 additional RRs |
| 141 |
| 142 // Question |
| 143 // This part is echoed back from the respective query. |
| 144 0x07, '_', 'p', 'r', 'i', 'v', 'e', 't', 0x04, '_', 't', 'c', |
| 145 'p', 0x05, 'l', 'o', 'c', 'a', 'l', 0x00, 0x00, 0x0c, // TYPE is PTR. |
| 146 0x00, 0x01, // CLASS is IN. |
| 147 }; |
| 148 |
133 #endif // ENABLE_MDNS | 149 #endif // ENABLE_MDNS |
134 | 150 |
135 // Sentinel value to signify the request should fail. | 151 // Sentinel value to signify the request should fail. |
136 const char kResponseValueFailure[] = "FAILURE"; | 152 const char kResponseValueFailure[] = "FAILURE"; |
137 | 153 |
138 class FakeGCDApiFlowFactory | 154 class FakeGCDApiFlowFactory |
139 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { | 155 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { |
140 public: | 156 public: |
141 FakeGCDApiFlowFactory() { | 157 FakeGCDApiFlowFactory() { |
142 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); | 158 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 FROM_HERE, | 263 FROM_HERE, |
248 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, | 264 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, |
249 test_service_discovery_client_, | 265 test_service_discovery_client_, |
250 kGoodbyePacket, | 266 kGoodbyePacket, |
251 sizeof(kGoodbyePacket)), | 267 sizeof(kGoodbyePacket)), |
252 base::TimeDelta::FromSeconds(1)); | 268 base::TimeDelta::FromSeconds(1)); |
253 | 269 |
254 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); | 270 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); |
255 } | 271 } |
256 | 272 |
| 273 IN_PROC_BROWSER_TEST_F(GcdPrivateAPITest, SendQuery) { |
| 274 EXPECT_CALL(*test_service_discovery_client_, |
| 275 OnSendTo(std::string(reinterpret_cast<const char*>(kQueryPacket), |
| 276 sizeof(kQueryPacket)))).Times(2); |
| 277 |
| 278 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "send_query.html")); |
| 279 } |
| 280 |
257 #endif // ENABLE_MDNS | 281 #endif // ENABLE_MDNS |
258 | 282 |
259 } // namespace | 283 } // namespace |
OLD | NEW |