Commit 3dddb889 authored by Eric Roman's avatar Eric Roman Committed by Commit Bot

Move some test-only code out of NetLog.

Change-Id: If23d2017ad8d15b38ffe22e0f51e5ed070def161
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332584
Commit-Queue: Eric Roman <eroman@chromium.org>
Commit-Queue: Matt Mueller <mattm@chromium.org>
Auto-Submit: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#793767}
parent 228b0f38
......@@ -57,39 +57,4 @@ base::Value NetLogSource::ToEventParameters() const {
return SourceEventParametersCallback(*this);
}
// static
bool NetLogSource::FromEventParameters(const base::Value* event_params,
NetLogSource* source) {
const base::Value* source_dict = nullptr;
int source_id = -1;
int source_type = static_cast<int>(NetLogSourceType::COUNT);
if (!event_params) {
*source = NetLogSource();
return false;
}
source_dict = event_params->FindDictKey("source_dependency");
if (!source_dict) {
*source = NetLogSource();
return false;
}
base::Optional<int> opt_int;
opt_int = source_dict->FindIntKey("id");
if (!opt_int) {
*source = NetLogSource();
return false;
}
source_id = opt_int.value();
opt_int = source_dict->FindIntKey("type");
if (!opt_int) {
*source = NetLogSource();
return false;
}
source_type = opt_int.value();
DCHECK_GE(source_id, 0);
DCHECK_LT(source_type, static_cast<int>(NetLogSourceType::COUNT));
*source = NetLogSource(static_cast<NetLogSourceType>(source_type), source_id);
return true;
}
} // namespace net
......@@ -36,13 +36,6 @@ struct NET_EXPORT NetLogSource {
// describes |this|.
base::Value ToEventParameters() const;
// Attempts to extract a NetLogSource from a set of event parameters. Returns
// true and writes the result to |source| on success. Returns false and
// makes |source| an invalid source on failure.
// TODO(mmenke): Long term, we want to remove this.
static bool FromEventParameters(const base::Value* event_params,
NetLogSource* source);
NetLogSourceType type;
uint32_t id;
base::TimeTicks start_time;
......
......@@ -2130,6 +2130,43 @@ TEST_F(SpdySessionTest, ChangeStreamRequestPriority) {
ASSERT_EQ(HIGHEST, stream1->priority());
}
// Attempts to extract a NetLogSource from a set of event parameters. Returns
// true and writes the result to |source| on success. Returns false and
// makes |source| an invalid source on failure.
bool NetLogSourceFromEventParameters(const base::Value* event_params,
NetLogSource* source) {
const base::Value* source_dict = nullptr;
int source_id = -1;
int source_type = static_cast<int>(NetLogSourceType::COUNT);
if (!event_params) {
*source = NetLogSource();
return false;
}
source_dict = event_params->FindDictKey("source_dependency");
if (!source_dict) {
*source = NetLogSource();
return false;
}
base::Optional<int> opt_int;
opt_int = source_dict->FindIntKey("id");
if (!opt_int) {
*source = NetLogSource();
return false;
}
source_id = opt_int.value();
opt_int = source_dict->FindIntKey("type");
if (!opt_int) {
*source = NetLogSource();
return false;
}
source_type = opt_int.value();
DCHECK_GE(source_id, 0);
DCHECK_LT(source_type, static_cast<int>(NetLogSourceType::COUNT));
*source = NetLogSource(static_cast<NetLogSourceType>(source_type), source_id);
return true;
}
TEST_F(SpdySessionTest, Initialize) {
MockRead reads[] = {
MockRead(ASYNC, 0, 0) // EOF
......@@ -2158,7 +2195,7 @@ TEST_F(SpdySessionTest, Initialize) {
NetLogSource socket_source;
EXPECT_TRUE(
NetLogSource::FromEventParameters(&entries[pos].params, &socket_source));
NetLogSourceFromEventParameters(&entries[pos].params, &socket_source));
EXPECT_TRUE(socket_source.IsValid());
EXPECT_NE(log_.bound().source().id, socket_source.id);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment