| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/stl_util.h" |
| 13 #include "chrome/browser/local_discovery/service_discovery_client.h" | 14 #include "chrome/browser/local_discovery/service_discovery_client.h" |
| 14 #include "chrome/browser/local_discovery/service_discovery_client_mac.h" | 15 #include "chrome/browser/local_discovery/service_discovery_client_mac.h" |
| 15 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" | 16 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" |
| 16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 17 #include "net/base/ip_endpoint.h" | 18 #include "net/base/ip_endpoint.h" |
| 18 #include "net/base/sockaddr_storage.h" | 19 #include "net/base/sockaddr_storage.h" |
| 19 #include "testing/gtest_mac.h" | 20 #include "testing/gtest_mac.h" |
| 20 | 21 |
| 21 @interface TestNSNetService : NSNetService { | 22 @interface TestNSNetService : NSNetService { |
| 22 @private | 23 @private |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 resolver_impl->GetContainerForTesting()->OnResolveUpdate( | 149 resolver_impl->GetContainerForTesting()->OnResolveUpdate( |
| 149 ServiceResolver::STATUS_SUCCESS); | 150 ServiceResolver::STATUS_SUCCESS); |
| 150 | 151 |
| 151 base::RunLoop().RunUntilIdle(); | 152 base::RunLoop().RunUntilIdle(); |
| 152 | 153 |
| 153 EXPECT_EQ(1, num_resolves_); | 154 EXPECT_EQ(1, num_resolves_); |
| 154 | 155 |
| 155 const std::vector<std::string>& metadata = | 156 const std::vector<std::string>& metadata = |
| 156 last_service_description_.metadata; | 157 last_service_description_.metadata; |
| 157 EXPECT_EQ(2u, metadata.size()); | 158 EXPECT_EQ(2u, metadata.size()); |
| 158 EXPECT_NE(metadata.end(), | 159 EXPECT_TRUE(base::ContainsValue(metadata, "ab")); |
| 159 std::find(metadata.begin(), metadata.end(), "ab")); | 160 EXPECT_TRUE(base::ContainsValue(metadata, "d=e")); |
| 160 EXPECT_NE(metadata.end(), | |
| 161 std::find(metadata.begin(), metadata.end(), "d=e")); | |
| 162 | 161 |
| 163 EXPECT_EQ(ip_address, last_service_description_.ip_address); | 162 EXPECT_EQ(ip_address, last_service_description_.ip_address); |
| 164 EXPECT_EQ(kPort, last_service_description_.address.port()); | 163 EXPECT_EQ(kPort, last_service_description_.address.port()); |
| 165 EXPECT_EQ(kIp, last_service_description_.address.host()); | 164 EXPECT_EQ(kIp, last_service_description_.address.host()); |
| 166 } | 165 } |
| 167 | 166 |
| 168 // https://crbug.com/586628 | 167 // https://crbug.com/586628 |
| 169 TEST_F(ServiceDiscoveryClientMacTest, ResolveInvalidUnicodeRecord) { | 168 TEST_F(ServiceDiscoveryClientMacTest, ResolveInvalidUnicodeRecord) { |
| 170 const std::string test_service_name = "Test.123._testing._tcp.local"; | 169 const std::string test_service_name = "Test.123._testing._tcp.local"; |
| 171 std::unique_ptr<ServiceResolver> resolver = client()->CreateServiceResolver( | 170 std::unique_ptr<ServiceResolver> resolver = client()->CreateServiceResolver( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 resolver_impl->GetContainerForTesting()->OnResolveUpdate( | 204 resolver_impl->GetContainerForTesting()->OnResolveUpdate( |
| 206 ServiceResolver::STATUS_SUCCESS); | 205 ServiceResolver::STATUS_SUCCESS); |
| 207 | 206 |
| 208 base::RunLoop().RunUntilIdle(); | 207 base::RunLoop().RunUntilIdle(); |
| 209 | 208 |
| 210 EXPECT_EQ(1, num_resolves_); | 209 EXPECT_EQ(1, num_resolves_); |
| 211 | 210 |
| 212 const std::vector<std::string>& metadata = | 211 const std::vector<std::string>& metadata = |
| 213 last_service_description_.metadata; | 212 last_service_description_.metadata; |
| 214 EXPECT_EQ(2u, metadata.size()); | 213 EXPECT_EQ(2u, metadata.size()); |
| 215 EXPECT_NE(metadata.end(), | 214 EXPECT_TRUE(base::ContainsValue(metadata, "a=b")); |
| 216 std::find(metadata.begin(), metadata.end(), "a=b")); | 215 EXPECT_TRUE(base::ContainsValue(metadata, "cd=e9")); |
| 217 EXPECT_NE(metadata.end(), | |
| 218 std::find(metadata.begin(), metadata.end(), "cd=e9")); | |
| 219 | 216 |
| 220 EXPECT_EQ(ip_address, last_service_description_.ip_address); | 217 EXPECT_EQ(ip_address, last_service_description_.ip_address); |
| 221 EXPECT_EQ(kPort, last_service_description_.address.port()); | 218 EXPECT_EQ(kPort, last_service_description_.address.port()); |
| 222 EXPECT_EQ(kIp, last_service_description_.address.host()); | 219 EXPECT_EQ(kIp, last_service_description_.address.host()); |
| 223 } | 220 } |
| 224 | 221 |
| 225 TEST_F(ServiceDiscoveryClientMacTest, ResolveInvalidServiceName) { | 222 TEST_F(ServiceDiscoveryClientMacTest, ResolveInvalidServiceName) { |
| 226 base::RunLoop run_loop; | 223 base::RunLoop run_loop; |
| 227 | 224 |
| 228 // This is the same invalid U+1F4A9 code unit sequence as in | 225 // This is the same invalid U+1F4A9 code unit sequence as in |
| (...skipping 13 matching lines...) Expand all Loading... |
| 242 base::Unretained(this), run_loop.QuitClosure())); | 239 base::Unretained(this), run_loop.QuitClosure())); |
| 243 resolver->StartResolving(); | 240 resolver->StartResolving(); |
| 244 | 241 |
| 245 run_loop.Run(); | 242 run_loop.Run(); |
| 246 | 243 |
| 247 EXPECT_EQ(1, num_resolves_); | 244 EXPECT_EQ(1, num_resolves_); |
| 248 EXPECT_EQ(ServiceResolver::STATUS_KNOWN_NONEXISTENT, last_status_); | 245 EXPECT_EQ(ServiceResolver::STATUS_KNOWN_NONEXISTENT, last_status_); |
| 249 } | 246 } |
| 250 | 247 |
| 251 } // namespace local_discovery | 248 } // namespace local_discovery |
| OLD | NEW |