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

Unified Diff: net/nqe/network_quality_estimator_util_unittest.cc

Issue 2936823002: NQE: Exclude network observations from private networks (Closed)
Patch Set: bengr, mmenke comments Created 3 years, 6 months 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 side-by-side diff with in-line comments
Download patch
Index: net/nqe/network_quality_estimator_util_unittest.cc
diff --git a/net/nqe/network_quality_estimator_util_unittest.cc b/net/nqe/network_quality_estimator_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4776579a567c1a9e08821ea698f5a177ececa62a
--- /dev/null
+++ b/net/nqe/network_quality_estimator_util_unittest.cc
@@ -0,0 +1,108 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/nqe/network_quality_estimator_util.h"
+
+#include <memory>
+
+#include "base/memory/ptr_util.h"
+#include "net/base/net_errors.h"
+#include "net/base/test_completion_callback.h"
+#include "net/dns/mock_host_resolver.h"
+#include "net/log/test_net_log.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace net {
+
+namespace nqe {
+
+namespace internal {
+
+namespace {
+
+// Verify that the cached network qualities from the prefs are not used if the
+// reading of the network quality prefs is not enabled..
+TEST(NetworkQualityEstimatorUtilTest, ReservedHost) {
+ std::unique_ptr<BoundTestNetLog> net_log =
+ base::MakeUnique<BoundTestNetLog>();
+ BoundTestNetLog* net_log_ptr = net_log.get();
+
+ MockCachingHostResolver mock_host_resolver;
+
+ scoped_refptr<net::RuleBasedHostResolverProc> rules(
+ new net::RuleBasedHostResolverProc(nullptr));
+
+ // example1.com resolves to a private IP address.
+ rules->AddRule("example1.com", "127.0.0.3");
+
+ // example2.com resolves to a public IP address.
+ rules->AddRule("example2.com", "27.0.0.3");
+
+ mock_host_resolver.set_rules(rules.get());
+
+ {
+ // Resolve example1.com so that the resolution entry is cached.
+ TestCompletionCallback callback;
+ std::unique_ptr<HostResolver::Request> request;
+ AddressList ignored;
+ int rv = mock_host_resolver.Resolve(
+ HostResolver::RequestInfo(HostPortPair("example1.com", 443)),
+ DEFAULT_PRIORITY, &ignored, callback.callback(), &request,
+ NetLogWithSource());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+ }
+
+ {
+ // Resolve example2.com so that the resolution entry is cached.
+ TestCompletionCallback callback;
+ std::unique_ptr<HostResolver::Request> request;
+ AddressList ignored;
+ int rv = mock_host_resolver.Resolve(
+ HostResolver::RequestInfo(HostPortPair("example2.com", 443)),
+ DEFAULT_PRIORITY, &ignored, callback.callback(), &request,
+ NetLogWithSource());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+ }
+
+ EXPECT_EQ(2u, mock_host_resolver.num_resolve());
+
+ EXPECT_TRUE(IsPrivateHost(&mock_host_resolver, HostPortPair("localhost", 443),
+ net_log_ptr->bound()));
mmenke 2017/06/16 15:03:58 Also check localhost6?
tbansal1 2017/06/17 01:54:01 Done.
+ EXPECT_TRUE(IsPrivateHost(&mock_host_resolver, HostPortPair("127.0.0.1", 80),
+ net_log_ptr->bound()));
mmenke 2017/06/16 15:03:58 Also suggest 0.0.0.0 (It's used as an alias for 12
tbansal1 2017/06/17 01:54:01 Done.
+
+ EXPECT_TRUE(IsPrivateHost(&mock_host_resolver,
+ HostPortPair("192.168.0.1", 443),
+ net_log_ptr->bound()));
+ EXPECT_EQ(0u, mock_host_resolver.num_resolve_from_cache());
+
+ EXPECT_FALSE(IsPrivateHost(&mock_host_resolver,
+ HostPortPair("92.168.0.1", 443),
+ net_log_ptr->bound()));
+ EXPECT_EQ(1u, mock_host_resolver.num_resolve_from_cache());
mmenke 2017/06/16 15:03:58 Suggest checking some IPv6 hosts (::1, sure there
tbansal1 2017/06/17 01:54:01 Done.
+
+ EXPECT_TRUE(IsPrivateHost(&mock_host_resolver,
+ HostPortPair("example1.com", 443),
+ net_log_ptr->bound()));
+ EXPECT_EQ(2u, mock_host_resolver.num_resolve_from_cache());
+
+ EXPECT_FALSE(IsPrivateHost(&mock_host_resolver,
+ HostPortPair("example2.com", 443),
+ net_log_ptr->bound()));
mmenke 2017/06/16 15:03:58 Test with a hostname that's not cached, so Resolve
tbansal1 2017/06/17 01:54:01 Done.
+ EXPECT_EQ(3u, mock_host_resolver.num_resolve_from_cache());
+
+ // IsPrivateHost() should have queried only the resolver's cache.
+ EXPECT_EQ(2u, mock_host_resolver.num_resolve());
+}
+
+} // namespace
+
+} // namespace internal
+
+} // namespace nqe
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698