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

Unified Diff: net/base/net_log_util_unittest.cc

Issue 848006: Generalize the net module's LoadLog facility from a passive container, to an event stream (NetLog). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up RequestTracker into ConnectJobTracker+RequestTracker+RequestTrackerBase, address comments Created 10 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/base/net_log_util.cc ('k') | net/ftp/ftp_network_transaction.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/net_log_util_unittest.cc
===================================================================
--- net/base/net_log_util_unittest.cc (revision 40318)
+++ net/base/net_log_util_unittest.cc (working copy)
@@ -2,61 +2,78 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/base/load_log_unittest.h"
-#include "net/base/load_log_util.h"
+#include "net/base/net_log_unittest.h"
+#include "net/base/net_log_util.h"
#include "net/base/net_errors.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace {
-TEST(LoadLogUtilTest, Basic) {
- scoped_refptr<LoadLog> log(new LoadLog(10));
+NetLog::Entry MakeEventEntry(int t,
+ NetLog::EventType event_type,
+ NetLog::EventPhase event_phase) {
+ NetLog::Entry entry;
+ entry.type = NetLog::Entry::TYPE_EVENT;
+ entry.time = MakeTime(t);
+ entry.event = NetLog::Event(event_type, event_phase);
+ return entry;
+}
- log->Add(LoadLog::Entry(MakeTime(1),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL,
- LoadLog::PHASE_BEGIN)));
- log->Add(
- LoadLog::Entry(
- MakeTime(5),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- LoadLog::PHASE_BEGIN)));
- log->Add(
- LoadLog::Entry(
- MakeTime(8),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- LoadLog::PHASE_END)));
+NetLog::Entry MakeStringEntry(int t, const std::string& string) {
+ NetLog::Entry entry;
+ entry.type = NetLog::Entry::TYPE_STRING;
+ entry.time = MakeTime(t);
+ entry.string = string;
+ return entry;
+}
- log->Add(LoadLog::Entry(MakeTime(12),
- LoadLog::Event(LoadLog::TYPE_CANCELLED,
- LoadLog::PHASE_NONE)));
+NetLog::Entry MakeErrorCodeEntry(int t, int error_code) {
+ NetLog::Entry entry;
+ entry.type = NetLog::Entry::TYPE_ERROR_CODE;
+ entry.time = MakeTime(t);
+ entry.error_code = error_code;
+ return entry;
+}
- log->Add(LoadLog::Entry(MakeTime(131),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL,
- LoadLog::PHASE_END)));
+TEST(NetLogUtilTest, Basic) {
+ std::vector<NetLog::Entry> log;
+ log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL,
+ NetLog::PHASE_BEGIN));
+ log.push_back(
+ MakeEventEntry(5, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
+ NetLog::PHASE_BEGIN));
+ log.push_back(
+ MakeEventEntry(8, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
+ NetLog::PHASE_END));
+
+ log.push_back(MakeEventEntry(12, NetLog::TYPE_CANCELLED,
+ NetLog::PHASE_NONE));
+
+ log.push_back(MakeEventEntry(131, NetLog::TYPE_HOST_RESOLVER_IMPL,
+ NetLog::PHASE_END));
+
EXPECT_EQ(
"t= 1: +HOST_RESOLVER_IMPL [dt=130]\n"
"t= 5: HOST_RESOLVER_IMPL_OBSERVER_ONSTART [dt= 3]\n"
"t= 12: CANCELLED\n"
"t=131: -HOST_RESOLVER_IMPL",
- LoadLogUtil::PrettyPrintAsEventTree(log));
+ NetLogUtil::PrettyPrintAsEventTree(log, 0));
}
-TEST(LoadLogUtilTest, Basic2) {
- scoped_refptr<LoadLog> log(new LoadLog(10));
+TEST(NetLogUtilTest, Basic2) {
+ std::vector<NetLog::Entry> log;
- log->Add(LoadLog::Entry(MakeTime(1),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL,
- LoadLog::PHASE_BEGIN)));
+ log.push_back(MakeEventEntry(1, NetLog::TYPE_HOST_RESOLVER_IMPL,
+ NetLog::PHASE_BEGIN));
- log->Add(LoadLog::Entry(MakeTime(12), "Sup foo"));
- log->Add(LoadLog::Entry(MakeTime(12), ERR_UNEXPECTED));
- log->Add(LoadLog::Entry(MakeTime(14), "Multiline\nString"));
+ log.push_back(MakeStringEntry(12, "Sup foo"));
+ log.push_back(MakeErrorCodeEntry(12, ERR_UNEXPECTED));
+ log.push_back(MakeStringEntry(14, "Multiline\nString"));
- log->Add(LoadLog::Entry(MakeTime(131),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL,
- LoadLog::PHASE_END)));
+ log.push_back(MakeEventEntry(131, NetLog::TYPE_HOST_RESOLVER_IMPL,
+ NetLog::PHASE_END));
EXPECT_EQ(
"t= 1: +HOST_RESOLVER_IMPL [dt=130]\n"
@@ -65,37 +82,29 @@
"t= 14: \"Multiline\n"
"String\"\n"
"t=131: -HOST_RESOLVER_IMPL",
- LoadLogUtil::PrettyPrintAsEventTree(log));
+ NetLogUtil::PrettyPrintAsEventTree(log, 0));
}
-TEST(LoadLogUtilTest, UnmatchedOpen) {
- scoped_refptr<LoadLog> log(new LoadLog(10));
+TEST(NetLogUtilTest, UnmatchedOpen) {
+ std::vector<NetLog::Entry> log;
- log->Add(LoadLog::Entry(MakeTime(3),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL,
- LoadLog::PHASE_BEGIN)));
+ log.push_back(MakeEventEntry(3, NetLog::TYPE_HOST_RESOLVER_IMPL,
+ NetLog::PHASE_BEGIN));
// Note that there is no matching call to PHASE_END for all of the following.
- log->Add(
- LoadLog::Entry(
- MakeTime(6),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- LoadLog::PHASE_BEGIN)));
- log->Add(
- LoadLog::Entry(
- MakeTime(7),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- LoadLog::PHASE_BEGIN)));
- log->Add(
- LoadLog::Entry(
- MakeTime(8),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
- LoadLog::PHASE_BEGIN)));
- log->Add(LoadLog::Entry(MakeTime(10),
- LoadLog::Event(LoadLog::TYPE_CANCELLED,
- LoadLog::PHASE_NONE)));
- log->Add(LoadLog::Entry(MakeTime(16),
- LoadLog::Event(LoadLog::TYPE_HOST_RESOLVER_IMPL,
- LoadLog::PHASE_END)));
+ log.push_back(
+ MakeEventEntry(
+ 6, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
+ NetLog::PHASE_BEGIN));
+ log.push_back(
+ MakeEventEntry(7, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
+ NetLog::PHASE_BEGIN));
+ log.push_back(
+ MakeEventEntry(8, NetLog::TYPE_HOST_RESOLVER_IMPL_OBSERVER_ONSTART,
+ NetLog::PHASE_BEGIN));
+ log.push_back(MakeEventEntry(10, NetLog::TYPE_CANCELLED,
+ NetLog::PHASE_NONE));
+ log.push_back(MakeEventEntry(16, NetLog::TYPE_HOST_RESOLVER_IMPL,
+ NetLog::PHASE_END));
EXPECT_EQ(
"t= 3: +HOST_RESOLVER_IMPL [dt=13]\n"
@@ -104,25 +113,23 @@
"t= 8: +HOST_RESOLVER_IMPL_OBSERVER_ONSTART [dt= 8]\n"
"t=10: CANCELLED\n"
"t=16: -HOST_RESOLVER_IMPL",
- LoadLogUtil::PrettyPrintAsEventTree(log));
+ NetLogUtil::PrettyPrintAsEventTree(log, 0));
}
-TEST(LoadLogUtilTest, DisplayOfTruncated) {
- size_t kMaxNumEntries = 5;
- scoped_refptr<LoadLog> log(new LoadLog(kMaxNumEntries));
+TEST(NetLogUtilTest, DisplayOfTruncated) {
+ std::vector<NetLog::Entry> log;
- // Add a total of 10 events. This means that 5 will be truncated.
- log->Add(LoadLog::Entry(MakeTime(0),
- LoadLog::Event(LoadLog::TYPE_TCP_CONNECT,
- LoadLog::PHASE_BEGIN)));
- for (size_t i = 1; i < 8; ++i) {
- log->Add(LoadLog::Entry(MakeTime(i),
- LoadLog::Event(LoadLog::TYPE_CANCELLED,
- LoadLog::PHASE_NONE)));
+ log.push_back(MakeEventEntry(0,
+ NetLog::TYPE_TCP_CONNECT,
+ NetLog::PHASE_BEGIN));
+ for (size_t i = 1; i <= 3; ++i) {
+ log.push_back(MakeEventEntry(i,
+ NetLog::TYPE_CANCELLED,
+ NetLog::PHASE_NONE));
}
- log->Add(LoadLog::Entry(MakeTime(9),
- LoadLog::Event(LoadLog::TYPE_TCP_CONNECT,
- LoadLog::PHASE_END)));
+ log.push_back(MakeEventEntry(9,
+ NetLog::TYPE_TCP_CONNECT,
+ NetLog::PHASE_END));
EXPECT_EQ(
"t=0: +TCP_CONNECT [dt=9]\n"
@@ -131,7 +138,7 @@
"t=3: CANCELLED\n"
" ... Truncated 4 entries ...\n"
"t=9: -TCP_CONNECT",
- LoadLogUtil::PrettyPrintAsEventTree(log));
+ NetLogUtil::PrettyPrintAsEventTree(log, 4));
}
} // namespace
« no previous file with comments | « net/base/net_log_util.cc ('k') | net/ftp/ftp_network_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698