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

Unified Diff: net/quic/port_suggester_unittest.cc

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « net/quic/port_suggester.cc ('k') | net/quic/quic_ack_notifier.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/port_suggester_unittest.cc
diff --git a/net/quic/port_suggester_unittest.cc b/net/quic/port_suggester_unittest.cc
deleted file mode 100644
index add5258450933b9e25929929cf19b2d9efaa1eda..0000000000000000000000000000000000000000
--- a/net/quic/port_suggester_unittest.cc
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2013 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/quic/port_suggester.h"
-
-#include <set>
-
-#include "base/basictypes.h"
-#include "net/base/host_port_pair.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace net {
-namespace test {
-
-class PortSuggesterTest : public ::testing::Test {
- protected:
- PortSuggesterTest()
- : entropy_(1345689),
- min_ephemeral_port_(1025),
- max_ephemeral_port_(65535) {
- }
-
- uint64 entropy_;
- int min_ephemeral_port_;
- int max_ephemeral_port_;
-};
-
-TEST_F(PortSuggesterTest, SmallRangeTest) {
- // When the range is small (one wide), we always get that as our answer.
- scoped_refptr<PortSuggester> port_suggester =
- new PortSuggester(HostPortPair("www.example.com", 443), entropy_);
- // Test this for a few different (small) ranges.
- for (int port = 2000; port < 2010; ++port) {
- // Use |port| for both |min| and |max| delimiting the suggestion range.
- EXPECT_EQ(port, port_suggester->SuggestPort(port, port));
- EXPECT_EQ(port, port_suggester->previous_suggestion());
- }
-}
-
-TEST_F(PortSuggesterTest, SuggestAllPorts) {
- // We should eventually fill out any range, but we'll just ensure that we
- // fill out a small range of ports.
- scoped_refptr<PortSuggester> port_suggester =
- new PortSuggester(HostPortPair("www.example.com", 443), entropy_);
- std::set<int> ports;
- const uint32 port_range = 20;
- const int insertion_limit = 200; // We should be done by then.
- for (int i = 0; i < insertion_limit; ++i) {
- ports.insert(port_suggester->SuggestPort(min_ephemeral_port_,
- min_ephemeral_port_ + port_range - 1));
- if (ports.size() == port_range) {
- break;
- }
- }
- EXPECT_EQ(port_range, ports.size());
-}
-
-TEST_F(PortSuggesterTest, AvoidDuplication) {
- // When the range is large, duplicates are rare, but we'll ask for a few
- // suggestions and make sure they are unique.
- scoped_refptr<PortSuggester> port_suggester =
- new PortSuggester(HostPortPair("www.example.com", 80), entropy_);
- std::set<int> ports;
- const size_t port_count = 200;
- for (size_t i = 0; i < port_count; ++i) {
- ports.insert(port_suggester->SuggestPort(min_ephemeral_port_,
- max_ephemeral_port_));
- }
- EXPECT_EQ(port_suggester->call_count(), port_count);
- EXPECT_EQ(port_count, ports.size());
-}
-
-TEST_F(PortSuggesterTest, ConsistentPorts) {
- // For given hostname, port, and entropy, we should always get the same
- // suggestions.
- scoped_refptr<PortSuggester> port_suggester1 =
- new PortSuggester(HostPortPair("www.example.com", 443), entropy_);
- scoped_refptr<PortSuggester> port_suggester2 =
- new PortSuggester(HostPortPair("www.example.com", 443), entropy_);
- for (int test_count = 20; test_count > 0; --test_count) {
- EXPECT_EQ(port_suggester1->SuggestPort(min_ephemeral_port_,
- min_ephemeral_port_),
- port_suggester2->SuggestPort(min_ephemeral_port_,
- min_ephemeral_port_));
- }
-}
-
-TEST_F(PortSuggesterTest, DifferentHostPortEntropy) {
- // When we have different hosts, port, or entropy, we probably won't collide.
- scoped_refptr<PortSuggester> port_suggester[] = {
- new PortSuggester(HostPortPair("www.example.com", 80), entropy_),
- new PortSuggester(HostPortPair("www.example.ORG", 80), entropy_),
- new PortSuggester(HostPortPair("www.example.com", 443), entropy_),
- new PortSuggester(HostPortPair("www.example.com", 80), entropy_ + 123456),
- };
-
- std::set<int> ports;
- const int port_count = 40;
- size_t insertion_count = 0;
- for (size_t j = 0; j < arraysize(port_suggester); ++j) {
- for (int i = 0; i < port_count; ++i) {
- ports.insert(port_suggester[j]->SuggestPort(min_ephemeral_port_,
- max_ephemeral_port_));
- ++insertion_count;
- }
- }
- EXPECT_EQ(insertion_count, ports.size());
-}
-
-} // namespace test
-} // namespace net
« no previous file with comments | « net/quic/port_suggester.cc ('k') | net/quic/quic_ack_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698