Commit 8aed8cc1 authored by David Van Cleve's avatar David Van Cleve Committed by Commit Bot

NetLog: Allow extracting a nested dictionary in the test util getter

This change updates net_log_test_util's methods that retrieve strings
from NetLogEvent dictionaries to allow fetching a string from a nested
dictionary using the base::Value::GetStringPath syntax (for instance,
"inner.item" will fetch { "inner": { "item": "value" } }).

(This allows writing some slightly more concise test code in the child
CL crrev.com/c/2315641.)

R=eroman

Bug: None
Change-Id: Ie8552b9347e9bb147f12e1a57ca98a43b9216f88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2354293
Commit-Queue: David Van Cleve <davidvc@chromium.org>
Commit-Queue: Eric Roman <eroman@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Auto-Submit: David Van Cleve <davidvc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798224}
parent 9adf9254
......@@ -125,11 +125,11 @@ size_t ExpectLogContainsSomewhereAfter(const std::vector<NetLogEntry>& entries,
base::Optional<std::string> GetOptionalStringValueFromParams(
const NetLogEntry& entry,
base::StringPiece name) {
base::StringPiece path) {
if (!entry.params.is_dict())
return base::nullopt;
const std::string* result = entry.params.FindStringKey(name);
const std::string* result = entry.params.FindStringPath(path);
if (!result)
return base::nullopt;
......@@ -137,17 +137,17 @@ base::Optional<std::string> GetOptionalStringValueFromParams(
}
base::Optional<bool> GetOptionalBooleanValueFromParams(const NetLogEntry& entry,
base::StringPiece name) {
base::StringPiece path) {
if (!entry.params.is_dict())
return base::nullopt;
return entry.params.FindBoolKey(name);
return entry.params.FindBoolPath(path);
}
base::Optional<int> GetOptionalIntegerValueFromParams(const NetLogEntry& entry,
base::StringPiece name) {
base::StringPiece path) {
if (!entry.params.is_dict())
return base::nullopt;
return entry.params.FindIntKey(name);
return entry.params.FindIntPath(path);
}
base::Optional<int> GetOptionalNetErrorCodeFromParams(
......@@ -156,30 +156,30 @@ base::Optional<int> GetOptionalNetErrorCodeFromParams(
}
std::string GetStringValueFromParams(const NetLogEntry& entry,
base::StringPiece name) {
auto result = GetOptionalStringValueFromParams(entry, name);
base::StringPiece path) {
auto result = GetOptionalStringValueFromParams(entry, path);
if (!result) {
ADD_FAILURE() << "No string parameter " << name;
ADD_FAILURE() << "No string parameter " << path;
return "";
}
return *result;
}
int GetIntegerValueFromParams(const NetLogEntry& entry,
base::StringPiece name) {
auto result = GetOptionalIntegerValueFromParams(entry, name);
base::StringPiece path) {
auto result = GetOptionalIntegerValueFromParams(entry, path);
if (!result) {
ADD_FAILURE() << "No int parameter " << name;
ADD_FAILURE() << "No int parameter " << path;
return -1;
}
return *result;
}
bool GetBooleanValueFromParams(const NetLogEntry& entry,
base::StringPiece name) {
auto result = GetOptionalBooleanValueFromParams(entry, name);
base::StringPiece path) {
auto result = GetOptionalBooleanValueFromParams(entry, path);
if (!result) {
ADD_FAILURE() << "No bool parameter " << name;
ADD_FAILURE() << "No bool parameter " << path;
return -1;
}
return *result;
......@@ -195,12 +195,12 @@ int GetNetErrorCodeFromParams(const NetLogEntry& entry) {
}
bool GetListValueFromParams(const NetLogEntry& entry,
base::StringPiece name,
base::StringPiece path,
const base::ListValue** value) {
if (!entry.params.is_dict())
return false;
const base::Value* list = entry.params.FindListKey(name);
const base::Value* list = entry.params.FindListPath(path);
if (!list)
return false;
......
......@@ -73,29 +73,29 @@ size_t ExpectLogContainsSomewhereAfter(const std::vector<NetLogEntry>& entries,
NetLogEventType expected_event,
NetLogEventPhase expected_phase);
// The following methods return a parameter of the given name and type, or
// nullopt if there is none.
// The following methods return a parameter of the given type at the given path,
// or nullopt if there is none.
base::Optional<std::string> GetOptionalStringValueFromParams(
const NetLogEntry& entry,
base::StringPiece name);
base::StringPiece path);
base::Optional<bool> GetOptionalBooleanValueFromParams(const NetLogEntry& entry,
base::StringPiece name);
base::StringPiece path);
base::Optional<int> GetOptionalIntegerValueFromParams(const NetLogEntry& entry,
base::StringPiece name);
base::StringPiece path);
base::Optional<int> GetOptionalNetErrorCodeFromParams(const NetLogEntry& entry);
// Same as the *Optional* versions above, except will add a Gtest failure if the
// value was not present, and then return some default.
std::string GetStringValueFromParams(const NetLogEntry& entry,
base::StringPiece name);
int GetIntegerValueFromParams(const NetLogEntry& entry, base::StringPiece name);
base::StringPiece path);
int GetIntegerValueFromParams(const NetLogEntry& entry, base::StringPiece path);
bool GetBooleanValueFromParams(const NetLogEntry& entry,
base::StringPiece name);
base::StringPiece path);
int GetNetErrorCodeFromParams(const NetLogEntry& entry);
// TODO(eroman): Remove use of base::ListValue.
bool GetListValueFromParams(const NetLogEntry& entry,
base::StringPiece name,
base::StringPiece path,
const base::ListValue** value);
} // namespace net
......
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