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

Side by Side Diff: chrome/browser/local_discovery/service_discovery_client_mac_unittest.mm

Issue 1534583002: Migrate Local Discovery from net::IPAddressNumber to net::IPAddress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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
OLDNEW
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 6
7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 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/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/local_discovery/service_discovery_client_mac.h" 11 #include "chrome/browser/local_discovery/service_discovery_client_mac.h"
12 #include "chrome/common/local_discovery/service_discovery_client.h" 12 #include "chrome/common/local_discovery/service_discovery_client.h"
13 #include "content/public/test/test_browser_thread_bundle.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "net/base/ip_address.h"
14 #include "net/base/ip_endpoint.h" 15 #include "net/base/ip_endpoint.h"
15 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
16 #include "testing/gtest_mac.h" 17 #include "testing/gtest_mac.h"
17 18
18 @interface TestNSNetService : NSNetService { 19 @interface TestNSNetService : NSNetService {
19 @private 20 @private
20 NSData* data_; 21 NSData* data_;
21 NSArray* addresses_; 22 NSArray* addresses_;
22 } 23 }
23 - (id)initWithData:(NSData*)data; 24 - (id)initWithData:(NSData*)data;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 base::Bind(&ServiceDiscoveryClientMacTest::OnResolveComplete, 119 base::Bind(&ServiceDiscoveryClientMacTest::OnResolveComplete,
119 base::Unretained(this))); 120 base::Unretained(this)));
120 121
121 const uint8 record_bytes[] = { 2, 'a', 'b', 3, 'd', '=', 'e' }; 122 const uint8 record_bytes[] = { 2, 'a', 'b', 3, 'd', '=', 'e' };
122 base::scoped_nsobject<TestNSNetService> test_service([[TestNSNetService alloc] 123 base::scoped_nsobject<TestNSNetService> test_service([[TestNSNetService alloc]
123 initWithData:[[NSData alloc] initWithBytes:record_bytes 124 initWithData:[[NSData alloc] initWithBytes:record_bytes
124 length:arraysize(record_bytes)]]); 125 length:arraysize(record_bytes)]]);
125 126
126 const std::string kIp = "2001:4860:4860::8844"; 127 const std::string kIp = "2001:4860:4860::8844";
127 const uint16_t kPort = 4321; 128 const uint16_t kPort = 4321;
128 net::IPAddressNumber ip_address; 129 net::IPAddress ip_address;
129 ASSERT_TRUE(net::ParseIPLiteralToNumber(kIp, &ip_address)); 130 ASSERT_TRUE(net::IPAddress::FromIPLiteral(kIp, &ip_address));
130 net::IPEndPoint endpoint(ip_address, kPort); 131 net::IPEndPoint endpoint(ip_address, kPort);
131 net::SockaddrStorage storage; 132 net::SockaddrStorage storage;
132 ASSERT_TRUE(endpoint.ToSockAddr(storage.addr, &storage.addr_len)); 133 ASSERT_TRUE(endpoint.ToSockAddr(storage.addr, &storage.addr_len));
133 NSData* discoveryHost = 134 NSData* discoveryHost =
134 [NSData dataWithBytes:storage.addr length:storage.addr_len]; 135 [NSData dataWithBytes:storage.addr length:storage.addr_len];
135 NSArray* addresses = @[ discoveryHost ]; 136 NSArray* addresses = @[ discoveryHost ];
136 [test_service setAddresses:addresses]; 137 [test_service setAddresses:addresses];
137 138
138 ServiceResolverImplMac* resolver_impl = 139 ServiceResolverImplMac* resolver_impl =
139 static_cast<ServiceResolverImplMac*>(resolver.get()); 140 static_cast<ServiceResolverImplMac*>(resolver.get());
140 resolver_impl->GetContainerForTesting()->SetServiceForTesting(test_service); 141 resolver_impl->GetContainerForTesting()->SetServiceForTesting(test_service);
141 resolver->StartResolving(); 142 resolver->StartResolving();
142 143
143 resolver_impl->GetContainerForTesting()->OnResolveUpdate( 144 resolver_impl->GetContainerForTesting()->OnResolveUpdate(
144 ServiceResolver::STATUS_SUCCESS); 145 ServiceResolver::STATUS_SUCCESS);
145 146
146 base::MessageLoop::current()->RunUntilIdle(); 147 base::MessageLoop::current()->RunUntilIdle();
147 148
148 EXPECT_EQ(1, num_resolves_); 149 EXPECT_EQ(1, num_resolves_);
149 EXPECT_EQ(2u, last_service_description_.metadata.size()); 150 EXPECT_EQ(2u, last_service_description_.metadata.size());
150 EXPECT_EQ(ip_address, last_service_description_.ip_address); 151 EXPECT_EQ(ip_address, last_service_description_.ip_address);
151 EXPECT_EQ(kPort, last_service_description_.address.port()); 152 EXPECT_EQ(kPort, last_service_description_.address.port());
152 EXPECT_EQ(kIp, last_service_description_.address.host()); 153 EXPECT_EQ(kIp, last_service_description_.address.host());
153 } 154 }
154 155
155 } // namespace local_discovery 156 } // namespace local_discovery
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698