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

Unified Diff: net/nqe/event_creator_unittest.cc

Issue 2724403004: NQE: Add net log event if the metric changes substantially (Closed)
Patch Set: ryansturm comments Created 3 years, 10 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/nqe/event_creator.cc ('k') | net/nqe/network_quality_estimator.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/nqe/event_creator_unittest.cc
diff --git a/net/nqe/event_creator_unittest.cc b/net/nqe/event_creator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bc9acfb062316ad62e0ac5c57631603cebc92a55
--- /dev/null
+++ b/net/nqe/event_creator_unittest.cc
@@ -0,0 +1,127 @@
+// 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/event_creator.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/time/time.h"
+#include "net/log/net_log_with_source.h"
+#include "net/log/test_net_log.h"
+#include "net/log/test_net_log_entry.h"
+#include "net/nqe/effective_connection_type.h"
+#include "net/nqe/network_quality.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+namespace nqe {
+
+namespace internal {
+
+namespace {
+
+// Returns the number of entries in |net_log| that have type set to
+// |NetLogEventType::NETWORK_QUALITY_CHANGED|.
+int GetNetworkQualityChangedEntriesCount(BoundTestNetLog* net_log) {
+ TestNetLogEntry::List entries;
+ net_log->GetEntries(&entries);
+
+ int count = 0;
+ for (const auto& entry : entries) {
+ if (entry.type == NetLogEventType::NETWORK_QUALITY_CHANGED)
+ ++count;
+ }
+ return count;
+}
+
+// Verify that the net log events are recorded correctly.
+TEST(NetworkQualityEstimatorEventCreatorTest, Notified) {
+ // std::unique_ptr<BoundTestNetLog>
+ // net_log(base::MakeUnique<BoundTestNetLog>());
+ BoundTestNetLog net_log;
+
+ EventCreator event_creator(net_log.bound());
+
+ NetworkQuality network_quality_100(base::TimeDelta::FromMilliseconds(100),
+ base::TimeDelta::FromMilliseconds(100),
+ 100);
+
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_2G, network_quality_100);
+ EXPECT_EQ(1, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // No new entry should be created since the network quality has not changed.
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_2G, network_quality_100);
+ EXPECT_EQ(1, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should be created since effective connection type has changed.
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_100);
+ EXPECT_EQ(2, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should not be created since HTTP RTT has not changed
+ // meaningfully.
+ NetworkQuality network_quality_http_rtt_110(
+ base::TimeDelta::FromMilliseconds(110),
+ base::TimeDelta::FromMilliseconds(100), 100);
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_http_rtt_110);
+ EXPECT_EQ(2, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should be created since HTTP RTT has changed meaningfully.
+ NetworkQuality network_quality_http_rtt_300(
+ base::TimeDelta::FromMilliseconds(300),
+ base::TimeDelta::FromMilliseconds(100), 100);
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_http_rtt_300);
+ EXPECT_EQ(3, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should be created since transport RTT has changed meaningfully.
+ NetworkQuality network_quality_transport_rtt_300(
+ base::TimeDelta::FromMilliseconds(300),
+ base::TimeDelta::FromMilliseconds(300), 100);
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_transport_rtt_300);
+ EXPECT_EQ(4, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should be created since bandwidth has changed meaningfully.
+ NetworkQuality network_quality_kbps_300(
+ base::TimeDelta::FromMilliseconds(300),
+ base::TimeDelta::FromMilliseconds(300), 300);
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_300);
+ EXPECT_EQ(5, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should not be created since network quality has not changed
+ // meaningfully.
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_300);
+ EXPECT_EQ(5, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should be created since bandwidth has changed meaningfully.
+ NetworkQuality network_quality_kbps_2000(
+ base::TimeDelta::FromMilliseconds(300),
+ base::TimeDelta::FromMilliseconds(300), 2000);
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_2000);
+ EXPECT_EQ(6, GetNetworkQualityChangedEntriesCount(&net_log));
+
+ // A new entry should not be created since bandwidth has not changed by more
+ // than 20%.
+ NetworkQuality network_quality_kbps_2200(
+ base::TimeDelta::FromMilliseconds(300),
+ base::TimeDelta::FromMilliseconds(300), 2200);
+ event_creator.MaybeAddNetworkQualityChangedEventToNetLog(
+ EFFECTIVE_CONNECTION_TYPE_3G, network_quality_kbps_2200);
+ EXPECT_EQ(6, GetNetworkQualityChangedEntriesCount(&net_log));
+}
+
+} // namespace
+
+} // namespace internal
+
+} // namespace nqe
+
+} // namespace net
« no previous file with comments | « net/nqe/event_creator.cc ('k') | net/nqe/network_quality_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698