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 | 7 |
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
11 #include "chrome/browser/local_discovery/service_discovery_client_mac.h" | 12 #include "chrome/browser/local_discovery/service_discovery_client_mac.h" |
| 13 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
12 #include "chrome/common/local_discovery/service_discovery_client.h" | 14 #include "chrome/common/local_discovery/service_discovery_client.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "net/base/ip_endpoint.h" | 16 #include "net/base/ip_endpoint.h" |
15 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
16 #include "testing/gtest_mac.h" | 18 #include "testing/gtest_mac.h" |
17 | 19 |
18 @interface TestNSNetService : NSNetService { | 20 @interface TestNSNetService : NSNetService { |
19 @private | 21 @private |
20 NSData* data_; | 22 NSData* data_; |
21 NSArray* addresses_; | 23 NSArray* addresses_; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 EXPECT_EQ(num_updates_, 3); | 113 EXPECT_EQ(num_updates_, 3); |
112 } | 114 } |
113 | 115 |
114 TEST_F(ServiceDiscoveryClientMacTest, ServiceResolver) { | 116 TEST_F(ServiceDiscoveryClientMacTest, ServiceResolver) { |
115 const std::string test_service_name = "Test.123._testing._tcp.local"; | 117 const std::string test_service_name = "Test.123._testing._tcp.local"; |
116 scoped_ptr<ServiceResolver> resolver = client_->CreateServiceResolver( | 118 scoped_ptr<ServiceResolver> resolver = client_->CreateServiceResolver( |
117 test_service_name, | 119 test_service_name, |
118 base::Bind(&ServiceDiscoveryClientMacTest::OnResolveComplete, | 120 base::Bind(&ServiceDiscoveryClientMacTest::OnResolveComplete, |
119 base::Unretained(this))); | 121 base::Unretained(this))); |
120 | 122 |
121 const uint8 record_bytes[] = { 2, 'a', 'b', 3, 'd', '=', 'e' }; | 123 const uint8_t record_bytes[] = {2, 'a', 'b', 3, 'd', '=', 'e'}; |
122 base::scoped_nsobject<TestNSNetService> test_service([[TestNSNetService alloc] | 124 base::scoped_nsobject<TestNSNetService> test_service([[TestNSNetService alloc] |
123 initWithData:[[NSData alloc] initWithBytes:record_bytes | 125 initWithData:[[NSData alloc] initWithBytes:record_bytes |
124 length:arraysize(record_bytes)]]); | 126 length:arraysize(record_bytes)]]); |
125 | 127 |
126 const std::string kIp = "2001:4860:4860::8844"; | 128 const std::string kIp = "2001:4860:4860::8844"; |
127 const uint16_t kPort = 4321; | 129 const uint16_t kPort = 4321; |
128 net::IPAddressNumber ip_address; | 130 net::IPAddressNumber ip_address; |
129 ASSERT_TRUE(net::ParseIPLiteralToNumber(kIp, &ip_address)); | 131 ASSERT_TRUE(net::ParseIPLiteralToNumber(kIp, &ip_address)); |
130 net::IPEndPoint endpoint(ip_address, kPort); | 132 net::IPEndPoint endpoint(ip_address, kPort); |
131 net::SockaddrStorage storage; | 133 net::SockaddrStorage storage; |
(...skipping 14 matching lines...) Expand all Loading... |
146 base::MessageLoop::current()->RunUntilIdle(); | 148 base::MessageLoop::current()->RunUntilIdle(); |
147 | 149 |
148 EXPECT_EQ(1, num_resolves_); | 150 EXPECT_EQ(1, num_resolves_); |
149 EXPECT_EQ(2u, last_service_description_.metadata.size()); | 151 EXPECT_EQ(2u, last_service_description_.metadata.size()); |
150 EXPECT_EQ(ip_address, last_service_description_.ip_address); | 152 EXPECT_EQ(ip_address, last_service_description_.ip_address); |
151 EXPECT_EQ(kPort, last_service_description_.address.port()); | 153 EXPECT_EQ(kPort, last_service_description_.address.port()); |
152 EXPECT_EQ(kIp, last_service_description_.address.host()); | 154 EXPECT_EQ(kIp, last_service_description_.address.host()); |
153 } | 155 } |
154 | 156 |
155 } // namespace local_discovery | 157 } // namespace local_discovery |
OLD | NEW |