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 | |
149 #endif // ENABLE_MDNS | 133 #endif // ENABLE_MDNS |
150 | 134 |
151 // Sentinel value to signify the request should fail. | 135 // Sentinel value to signify the request should fail. |
152 const char kResponseValueFailure[] = "FAILURE"; | 136 const char kResponseValueFailure[] = "FAILURE"; |
153 | 137 |
154 class FakeGCDApiFlowFactory | 138 class FakeGCDApiFlowFactory |
155 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { | 139 : public extensions::GcdPrivateAPI::GCDApiFlowFactoryForTests { |
156 public: | 140 public: |
157 FakeGCDApiFlowFactory() { | 141 FakeGCDApiFlowFactory() { |
158 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); | 142 extensions::GcdPrivateAPI::SetGCDApiFlowFactoryForTests(this); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 FROM_HERE, | 247 FROM_HERE, |
264 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, | 248 base::Bind(&local_discovery::TestServiceDiscoveryClient::SimulateReceive, |
265 test_service_discovery_client_, | 249 test_service_discovery_client_, |
266 kGoodbyePacket, | 250 kGoodbyePacket, |
267 sizeof(kGoodbyePacket)), | 251 sizeof(kGoodbyePacket)), |
268 base::TimeDelta::FromSeconds(1)); | 252 base::TimeDelta::FromSeconds(1)); |
269 | 253 |
270 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); | 254 EXPECT_TRUE(RunExtensionSubtest("gcd_private/api", "remove_device.html")); |
271 } | 255 } |
272 | 256 |
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 | |
281 #endif // ENABLE_MDNS | 257 #endif // ENABLE_MDNS |
282 | 258 |
283 } // namespace | 259 } // namespace |
OLD | NEW |