Commit 9f8a9694 authored by Panos Astithas's avatar Panos Astithas Committed by Commit Bot

Complete removal of DictionaryValue from net/log

I also took this opportunity to silence a clang-tidy warning in values.h. Given that there is already a long comment about why the linter is wrong in this case, it seems only natural to let the linter know about it, too.

Bug: 646113
Change-Id: I59ae89f42731445789638c4c25840249263127fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285305
Commit-Queue: Panos Astithas <pastithas@google.com>
Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarEric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786620}
parent 4c833792
...@@ -121,7 +121,7 @@ class BASE_EXPORT Value { ...@@ -121,7 +121,7 @@ class BASE_EXPORT Value {
static const ListValue& AsListValue(const Value& val); static const ListValue& AsListValue(const Value& val);
Value(Value&& that) noexcept; Value(Value&& that) noexcept;
Value() noexcept {} // A null value Value() noexcept {} // A null value. NOLINT(modernize-use-equals-default)
// Fun fact: using '= default' above instead of '{}' does not work because // Fun fact: using '= default' above instead of '{}' does not work because
// the compiler complains that the default constructor was deleted since // the compiler complains that the default constructor was deleted since
// the inner union contains fields with non-default constructors. // the inner union contains fields with non-default constructors.
......
...@@ -481,8 +481,7 @@ FileNetLogObserver::FileNetLogObserver( ...@@ -481,8 +481,7 @@ FileNetLogObserver::FileNetLogObserver(
write_queue_(std::move(write_queue)), write_queue_(std::move(write_queue)),
file_writer_(std::move(file_writer)) { file_writer_(std::move(file_writer)) {
if (!constants) if (!constants)
constants = base::DictionaryValue::From( constants = base::Value::ToUniquePtrValue(GetNetConstants());
base::Value::ToUniquePtrValue(GetNetConstants()));
file_task_runner_->PostTask( file_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&FileNetLogObserver::FileWriter::Initialize, FROM_HERE, base::BindOnce(&FileNetLogObserver::FileWriter::Initialize,
base::Unretained(file_writer_.get()), base::Unretained(file_writer_.get()),
......
...@@ -98,23 +98,20 @@ void AddEntries(FileNetLogObserver* logger, ...@@ -98,23 +98,20 @@ void AddEntries(FileNetLogObserver* logger,
// and polled data). // and polled data).
struct ParsedNetLog { struct ParsedNetLog {
::testing::AssertionResult InitFromFileContents(const std::string& input); ::testing::AssertionResult InitFromFileContents(const std::string& input);
const base::DictionaryValue* GetEvent(size_t i) const; const base::Value* GetEvent(size_t i) const;
// Initializes the ParsedNetLog by parsing a JSON file. // Initializes the ParsedNetLog by parsing a JSON file.
// Owner for the Value tree. // Owner for the Value tree and a dictionary for the entire netlog.
base::Value container; base::Value root;
// A dictionary for the entire netlog.
const base::DictionaryValue* root = nullptr;
// The constants dictionary. // The constants dictionary.
const base::DictionaryValue* constants = nullptr; const base::Value* constants = nullptr;
// The events list. // The events list.
const base::ListValue* events = nullptr; const base::Value* events = nullptr;
// The optional polled data (may be nullptr). // The optional polled data (may be nullptr).
const base::DictionaryValue* polled_data = nullptr; const base::Value* polled_data = nullptr;
}; };
::testing::AssertionResult ParsedNetLog::InitFromFileContents( ::testing::AssertionResult ParsedNetLog::InitFromFileContents(
...@@ -128,40 +125,38 @@ struct ParsedNetLog { ...@@ -128,40 +125,38 @@ struct ParsedNetLog {
if (!parsed_json.value) { if (!parsed_json.value) {
return ::testing::AssertionFailure() << parsed_json.error_message; return ::testing::AssertionFailure() << parsed_json.error_message;
} }
container = std::move(*parsed_json.value); root = std::move(*parsed_json.value);
if (!container.GetAsDictionary(&root)) { if (!root.is_dict()) {
return ::testing::AssertionFailure() << "Not a dictionary"; return ::testing::AssertionFailure() << "Not a dictionary";
} }
if (!root->GetList("events", &events)) { events = root.FindPath("events");
if (!events || !events->is_list()) {
return ::testing::AssertionFailure() << "No events list"; return ::testing::AssertionFailure() << "No events list";
} }
if (!root->GetDictionary("constants", &constants)) { constants = root.FindDictPath("constants");
if (!constants) {
return ::testing::AssertionFailure() << "No constants dictionary"; return ::testing::AssertionFailure() << "No constants dictionary";
} }
// Polled data is optional (ignore success). // Polled data is optional (ignore success).
root->GetDictionary("polledData", &polled_data); polled_data = root.FindDictPath("polledData");
return ::testing::AssertionSuccess(); return ::testing::AssertionSuccess();
} }
// Returns the event at index |i|, or nullptr if there is none. // Returns the event at index |i|, or nullptr if there is none.
const base::DictionaryValue* ParsedNetLog::GetEvent(size_t i) const { const base::Value* ParsedNetLog::GetEvent(size_t i) const {
if (!events || i >= events->GetSize()) if (!events || i >= events->GetList().size())
return nullptr;
const base::Value* value;
if (!events->Get(i, &value))
return nullptr; return nullptr;
const base::DictionaryValue* dict; const base::Value& value = events->GetList()[i];
if (!value->GetAsDictionary(&dict)) if (!value.is_dict())
return nullptr; return nullptr;
return dict; return &value;
} }
// Creates a ParsedNetLog by reading a NetLog from a file. Returns nullptr on // Creates a ParsedNetLog by reading a NetLog from a file. Returns nullptr on
...@@ -193,33 +188,32 @@ void VerifyEventsInLog(const ParsedNetLog* log, ...@@ -193,33 +188,32 @@ void VerifyEventsInLog(const ParsedNetLog* log,
size_t num_events_saved) { size_t num_events_saved) {
ASSERT_TRUE(log); ASSERT_TRUE(log);
ASSERT_LE(num_events_saved, num_events_emitted); ASSERT_LE(num_events_saved, num_events_emitted);
ASSERT_EQ(num_events_saved, log->events->GetSize()); ASSERT_EQ(num_events_saved, log->events->GetList().size());
// The last |num_events_saved| should all be sequential, with the last one // The last |num_events_saved| should all be sequential, with the last one
// being numbered |num_events_emitted - 1|. // being numbered |num_events_emitted - 1|.
for (size_t i = 0; i < num_events_saved; ++i) { for (size_t i = 0; i < num_events_saved; ++i) {
const base::DictionaryValue* event = log->GetEvent(i); const base::Value* event = log->GetEvent(i);
ASSERT_TRUE(event); ASSERT_TRUE(event);
size_t expected_source_id = num_events_emitted - num_events_saved + i; size_t expected_source_id = num_events_emitted - num_events_saved + i;
const base::Value* id_value = nullptr; const base::Value* id_value = event->FindPath("source.id");
ASSERT_TRUE(event->Get("source.id", &id_value)); ASSERT_TRUE(id_value);
int actual_id; int actual_id = id_value->GetInt();
ASSERT_TRUE(id_value->GetAsInteger(&actual_id));
ASSERT_EQ(static_cast<int>(expected_source_id), actual_id); ASSERT_EQ(static_cast<int>(expected_source_id), actual_id);
} }
} }
// Helper that checks whether |dict| has a string property at |key| having // Helper that checks whether |dict| has a string property at |key| having
// |value|. // |value|.
void ExpectDictionaryContainsProperty(const base::DictionaryValue* dict, void ExpectDictionaryContainsProperty(const base::Value* dict,
const std::string& key, const std::string& key,
const std::string& value) { const std::string& value) {
ASSERT_TRUE(dict); ASSERT_TRUE(dict);
std::string actual_value; ASSERT_TRUE(dict->is_dict());
ASSERT_TRUE(dict->GetString(key, &actual_value)); const std::string* actual_value = dict->FindStringPath(key);
ASSERT_EQ(value, actual_value); ASSERT_EQ(value, *actual_value);
} }
// Used for tests that are common to both bounded and unbounded modes of the // Used for tests that are common to both bounded and unbounded modes of the
...@@ -445,7 +439,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithNoEvents) { ...@@ -445,7 +439,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithNoEvents) {
// Verify the written log. // Verify the written log.
std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_); std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_);
ASSERT_TRUE(log); ASSERT_TRUE(log);
ASSERT_EQ(0u, log->events->GetSize()); ASSERT_EQ(0u, log->events->GetList().size());
} }
TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEvent) { TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEvent) {
...@@ -463,7 +457,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEvent) { ...@@ -463,7 +457,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEvent) {
// Verify the written log. // Verify the written log.
std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_); std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_);
ASSERT_TRUE(log); ASSERT_TRUE(log);
ASSERT_EQ(1u, log->events->GetSize()); ASSERT_EQ(1u, log->events->GetList().size());
} }
TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEventPreExisting) { TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEventPreExisting) {
...@@ -481,7 +475,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEventPreExisting) { ...@@ -481,7 +475,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithOneEventPreExisting) {
// Verify the written log. // Verify the written log.
std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_); std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_);
ASSERT_TRUE(log); ASSERT_TRUE(log);
ASSERT_EQ(1u, log->events->GetSize()); ASSERT_EQ(1u, log->events->GetList().size());
} }
TEST_P(FileNetLogObserverTest, PreExistingFileBroken) { TEST_P(FileNetLogObserverTest, PreExistingFileBroken) {
...@@ -510,8 +504,9 @@ TEST_P(FileNetLogObserverTest, CustomConstants) { ...@@ -510,8 +504,9 @@ TEST_P(FileNetLogObserverTest, CustomConstants) {
const char kConstantKey[] = "magic"; const char kConstantKey[] = "magic";
const char kConstantString[] = "poney"; const char kConstantString[] = "poney";
std::unique_ptr<base::DictionaryValue> constants(new base::DictionaryValue()); std::unique_ptr<base::Value> constants(
constants->SetString(kConstantKey, kConstantString); new base::Value(base::Value::Type::DICTIONARY));
constants->SetStringPath(kConstantKey, kConstantString);
CreateAndStartObserving(std::move(constants)); CreateAndStartObserving(std::move(constants));
...@@ -536,9 +531,10 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) { ...@@ -536,9 +531,10 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) {
// Create dummy polled data // Create dummy polled data
const char kDummyPolledDataPath[] = "dummy_path"; const char kDummyPolledDataPath[] = "dummy_path";
const char kDummyPolledDataString[] = "dummy_info"; const char kDummyPolledDataString[] = "dummy_info";
std::unique_ptr<base::DictionaryValue> dummy_polled_data = std::unique_ptr<base::Value> dummy_polled_data(
std::make_unique<base::DictionaryValue>(); new base::Value(base::Value::Type::DICTIONARY));
dummy_polled_data->SetString(kDummyPolledDataPath, kDummyPolledDataString); dummy_polled_data->SetStringPath(kDummyPolledDataPath,
kDummyPolledDataString);
logger_->StopObserving(std::move(dummy_polled_data), closure.closure()); logger_->StopObserving(std::move(dummy_polled_data), closure.closure());
...@@ -547,7 +543,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) { ...@@ -547,7 +543,7 @@ TEST_P(FileNetLogObserverTest, GeneratesValidJSONWithPolledData) {
// Verify the written log. // Verify the written log.
std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_); std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_);
ASSERT_TRUE(log); ASSERT_TRUE(log);
ASSERT_EQ(0u, log->events->GetSize()); ASSERT_EQ(0u, log->events->GetList().size());
// Make sure additional information is present and validate it. // Make sure additional information is present and validate it.
ASSERT_TRUE(log->polled_data); ASSERT_TRUE(log->polled_data);
...@@ -619,7 +615,8 @@ TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreads) { ...@@ -619,7 +615,8 @@ TEST_P(FileNetLogObserverTest, AddEventsFromMultipleThreads) {
std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_); std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_);
ASSERT_TRUE(log); ASSERT_TRUE(log);
// Check that the expected number of events were written to disk. // Check that the expected number of events were written to disk.
EXPECT_EQ(kNumEventsAddedPerThread * kNumThreads, log->events->GetSize()); EXPECT_EQ(kNumEventsAddedPerThread * kNumThreads,
log->events->GetList().size());
#if defined(OS_FUCHSIA) #if defined(OS_FUCHSIA)
LOG(ERROR) << "Teardown."; LOG(ERROR) << "Teardown.";
...@@ -933,7 +930,7 @@ TEST_F(FileNetLogObserverBoundedTest, BlockEventsFile0) { ...@@ -933,7 +930,7 @@ TEST_F(FileNetLogObserverBoundedTest, BlockEventsFile0) {
// Verify the written log. // Verify the written log.
std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_); std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_);
ASSERT_TRUE(log); ASSERT_TRUE(log);
ASSERT_EQ(0u, log->events->GetSize()); ASSERT_EQ(0u, log->events->GetList().size());
} }
// Make sure that when using bounded mode with a pre-existing output file, // Make sure that when using bounded mode with a pre-existing output file,
...@@ -992,7 +989,7 @@ TEST_F(FileNetLogObserverBoundedTest, LargeWriteQueueSize) { ...@@ -992,7 +989,7 @@ TEST_F(FileNetLogObserverBoundedTest, LargeWriteQueueSize) {
// Verify the written log. // Verify the written log.
std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_); std::unique_ptr<ParsedNetLog> log = ReadNetLogFromDisk(log_path_);
ASSERT_TRUE(log); ASSERT_TRUE(log);
ASSERT_EQ(3u, log->events->GetSize()); ASSERT_EQ(3u, log->events->GetList().size());
} }
void AddEntriesViaNetLog(NetLog* net_log, int num_entries) { void AddEntriesViaNetLog(NetLog* net_log, int num_entries) {
......
...@@ -60,17 +60,31 @@ base::Value NetLogSource::ToEventParameters() const { ...@@ -60,17 +60,31 @@ base::Value NetLogSource::ToEventParameters() const {
// static // static
bool NetLogSource::FromEventParameters(const base::Value* event_params, bool NetLogSource::FromEventParameters(const base::Value* event_params,
NetLogSource* source) { NetLogSource* source) {
const base::DictionaryValue* dict = nullptr; const base::Value* source_dict = nullptr;
const base::DictionaryValue* source_dict = nullptr;
int source_id = -1; int source_id = -1;
int source_type = static_cast<int>(NetLogSourceType::COUNT); int source_type = static_cast<int>(NetLogSourceType::COUNT);
if (!event_params || !event_params->GetAsDictionary(&dict) || if (!event_params) {
!dict->GetDictionary("source_dependency", &source_dict) ||
!source_dict->GetInteger("id", &source_id) ||
!source_dict->GetInteger("type", &source_type)) {
*source = NetLogSource(); *source = NetLogSource();
return false; 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_GE(source_id, 0);
DCHECK_LT(source_type, static_cast<int>(NetLogSourceType::COUNT)); DCHECK_LT(source_type, static_cast<int>(NetLogSourceType::COUNT));
......
...@@ -31,9 +31,9 @@ base::Value CaptureModeToValue(NetLogCaptureMode capture_mode) { ...@@ -31,9 +31,9 @@ base::Value CaptureModeToValue(NetLogCaptureMode capture_mode) {
} }
base::Value NetCaptureModeParams(NetLogCaptureMode capture_mode) { base::Value NetCaptureModeParams(NetLogCaptureMode capture_mode) {
base::DictionaryValue dict; base::Value dict(base::Value::Type::DICTIONARY);
dict.SetKey("capture_mode", CaptureModeToValue(capture_mode)); dict.SetKey("capture_mode", CaptureModeToValue(capture_mode));
return std::move(dict); return dict;
} }
TEST(NetLogTest, BasicGlobalEvents) { TEST(NetLogTest, BasicGlobalEvents) {
...@@ -212,19 +212,17 @@ class LoggingObserver : public NetLog::ThreadSafeObserver { ...@@ -212,19 +212,17 @@ class LoggingObserver : public NetLog::ThreadSafeObserver {
} }
void OnAddEntry(const NetLogEntry& entry) override { void OnAddEntry(const NetLogEntry& entry) override {
std::unique_ptr<base::DictionaryValue> dict = base::DictionaryValue::From( std::unique_ptr<base::Value> dict =
base::Value::ToUniquePtrValue(entry.ToValue())); base::Value::ToUniquePtrValue(entry.ToValue());
ASSERT_TRUE(dict); ASSERT_TRUE(dict);
values_.push_back(std::move(dict)); values_.push_back(std::move(dict));
} }
size_t GetNumValues() const { return values_.size(); } size_t GetNumValues() const { return values_.size(); }
base::DictionaryValue* GetValue(size_t index) const { base::Value* GetValue(size_t index) const { return values_[index].get(); }
return values_[index].get();
}
private: private:
std::vector<std::unique_ptr<base::DictionaryValue>> values_; std::vector<std::unique_ptr<base::Value>> values_;
}; };
void AddEvent(NetLog* net_log) { void AddEvent(NetLog* net_log) {
...@@ -416,14 +414,16 @@ TEST(NetLogTest, NetLogTwoObservers) { ...@@ -416,14 +414,16 @@ TEST(NetLogTest, NetLogTwoObservers) {
// Add event and make sure both observers receive it at their respective log // Add event and make sure both observers receive it at their respective log
// levels. // levels.
int param; base::Optional<int> param;
AddEvent(&net_log); AddEvent(&net_log);
ASSERT_EQ(1U, observer[0].GetNumValues()); ASSERT_EQ(1U, observer[0].GetNumValues());
ASSERT_TRUE(observer[0].GetValue(0)->GetInteger("params", &param)); param = observer[0].GetValue(0)->FindIntKey("params");
EXPECT_EQ(CaptureModeToInt(observer[0].capture_mode()), param); ASSERT_TRUE(param);
EXPECT_EQ(CaptureModeToInt(observer[0].capture_mode()), param.value());
ASSERT_EQ(1U, observer[1].GetNumValues()); ASSERT_EQ(1U, observer[1].GetNumValues());
ASSERT_TRUE(observer[1].GetValue(0)->GetInteger("params", &param)); param = observer[1].GetValue(0)->FindIntKey("params");
EXPECT_EQ(CaptureModeToInt(observer[1].capture_mode()), param); ASSERT_TRUE(param);
EXPECT_EQ(CaptureModeToInt(observer[1].capture_mode()), param.value());
// Remove second observer. // Remove second observer.
net_log.RemoveObserver(&observer[1]); net_log.RemoveObserver(&observer[1]);
......
...@@ -45,13 +45,33 @@ struct TraceEntryInfo { ...@@ -45,13 +45,33 @@ struct TraceEntryInfo {
std::string source_type; std::string source_type;
}; };
TraceEntryInfo GetTraceEntryInfoFromValue(const base::DictionaryValue& value) { TraceEntryInfo GetTraceEntryInfoFromValue(const base::Value& value) {
TraceEntryInfo info; TraceEntryInfo info;
EXPECT_TRUE(value.GetString("cat", &info.category)); if (const std::string* cat = value.FindStringKey("cat")) {
EXPECT_TRUE(value.GetString("id", &info.id)); info.category = *cat;
EXPECT_TRUE(value.GetString("ph", &info.phase)); } else {
EXPECT_TRUE(value.GetString("name", &info.name)); ADD_FAILURE() << "Missing 'cat'";
EXPECT_TRUE(value.GetString("args.source_type", &info.source_type)); }
if (const std::string* id = value.FindStringKey("id")) {
info.id = *id;
} else {
ADD_FAILURE() << "Missing 'id'";
}
if (const std::string* ph = value.FindStringKey("ph")) {
info.phase = *ph;
} else {
ADD_FAILURE() << "Missing 'ph'";
}
if (const std::string* name = value.FindStringKey("name")) {
info.name = *name;
} else {
ADD_FAILURE() << "Missing 'name'";
}
if (const std::string* type = value.FindStringPath("args.source_type")) {
info.source_type = *type;
} else {
ADD_FAILURE() << "Missing 'args.source_type'";
}
return info; return info;
} }
...@@ -137,18 +157,18 @@ class TraceNetLogObserverTest : public TestWithTaskEnvironment { ...@@ -137,18 +157,18 @@ class TraceNetLogObserverTest : public TestWithTaskEnvironment {
std::unique_ptr<base::ListValue> filtered_trace_events( std::unique_ptr<base::ListValue> filtered_trace_events(
new base::ListValue()); new base::ListValue());
for (size_t i = 0; i < trace_events.GetSize(); i++) { for (size_t i = 0; i < trace_events.GetSize(); i++) {
const base::DictionaryValue* dict = nullptr; const base::Value* dict = &trace_events.GetList()[i];
if (!trace_events.GetDictionary(i, &dict)) { if (!dict->is_dict()) {
ADD_FAILURE() << "Unexpected non-dictionary event in trace_events"; ADD_FAILURE() << "Unexpected non-dictionary event in trace_events";
continue; continue;
} }
std::string category; const std::string* category = dict->FindStringPath("cat");
if (!dict->GetString("cat", &category)) { if (!category) {
ADD_FAILURE() ADD_FAILURE()
<< "Unexpected item without a category field in trace_events"; << "Unexpected item without a category field in trace_events";
continue; continue;
} }
if (category != kNetLogTracingCategory) if (*category != kNetLogTracingCategory)
continue; continue;
filtered_trace_events->Append(dict->CreateDeepCopy()); filtered_trace_events->Append(dict->CreateDeepCopy());
} }
...@@ -219,12 +239,14 @@ TEST_F(TraceNetLogObserverTest, TraceEventCaptured) { ...@@ -219,12 +239,14 @@ TEST_F(TraceNetLogObserverTest, TraceEventCaptured) {
EndTraceAndFlush(); EndTraceAndFlush();
trace_net_log_observer()->StopWatchForTraceStart(); trace_net_log_observer()->StopWatchForTraceStart();
EXPECT_EQ(3u, trace_events()->GetSize()); EXPECT_EQ(3u, trace_events()->GetSize());
const base::DictionaryValue* item1 = nullptr; const base::Value* item1 = &trace_events()->GetList()[0];
ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); ASSERT_TRUE(item1->is_dict());
const base::DictionaryValue* item2 = nullptr; const base::Value* item2 = &trace_events()->GetList()[1];
ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); ;
const base::DictionaryValue* item3 = nullptr; ASSERT_TRUE(item2->is_dict());
ASSERT_TRUE(trace_events()->GetDictionary(2, &item3)); const base::Value* item3 = &trace_events()->GetList()[2];
;
ASSERT_TRUE(item3->is_dict());
TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
...@@ -272,10 +294,10 @@ TEST_F(TraceNetLogObserverTest, EnableAndDisableTracing) { ...@@ -272,10 +294,10 @@ TEST_F(TraceNetLogObserverTest, EnableAndDisableTracing) {
auto entries = net_log()->GetEntries(); auto entries = net_log()->GetEntries();
EXPECT_EQ(3u, entries.size()); EXPECT_EQ(3u, entries.size());
EXPECT_EQ(2u, trace_events()->GetSize()); EXPECT_EQ(2u, trace_events()->GetSize());
const base::DictionaryValue* item1 = nullptr; const base::Value* item1 = &trace_events()->GetList()[0];
ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); ASSERT_TRUE(item1->is_dict());
const base::DictionaryValue* item2 = nullptr; const base::Value* item2 = &trace_events()->GetList()[1];
ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); ASSERT_TRUE(item2->is_dict());
TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
...@@ -312,8 +334,8 @@ TEST_F(TraceNetLogObserverTest, DestroyObserverWhileTracing) { ...@@ -312,8 +334,8 @@ TEST_F(TraceNetLogObserverTest, DestroyObserverWhileTracing) {
EXPECT_EQ(2u, entries.size()); EXPECT_EQ(2u, entries.size());
EXPECT_EQ(1u, trace_events()->GetSize()); EXPECT_EQ(1u, trace_events()->GetSize());
const base::DictionaryValue* item1 = nullptr; const base::Value* item1 = &trace_events()->GetList()[0];
ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); ASSERT_TRUE(item1->is_dict());
TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
EXPECT_EQ(kNetLogTracingCategory, actual_item1.category); EXPECT_EQ(kNetLogTracingCategory, actual_item1.category);
...@@ -392,10 +414,10 @@ TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { ...@@ -392,10 +414,10 @@ TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) {
auto entries = net_log()->GetEntries(); auto entries = net_log()->GetEntries();
EXPECT_EQ(2u, entries.size()); EXPECT_EQ(2u, entries.size());
EXPECT_EQ(2u, trace_events()->GetSize()); EXPECT_EQ(2u, trace_events()->GetSize());
const base::DictionaryValue* item1 = nullptr; const base::Value* item1 = &trace_events()->GetList()[0];
ASSERT_TRUE(trace_events()->GetDictionary(0, &item1)); ASSERT_TRUE(item1->is_dict());
const base::DictionaryValue* item2 = nullptr; const base::Value* item2 = &trace_events()->GetList()[1];
ASSERT_TRUE(trace_events()->GetDictionary(1, &item2)); ASSERT_TRUE(item2->is_dict());
TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1); TraceEntryInfo actual_item1 = GetTraceEntryInfoFromValue(*item1);
TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2); TraceEntryInfo actual_item2 = GetTraceEntryInfoFromValue(*item2);
...@@ -417,13 +439,13 @@ TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) { ...@@ -417,13 +439,13 @@ TEST_F(TraceNetLogObserverTest, EventsWithAndWithoutParameters) {
EXPECT_EQ(NetLog::SourceTypeToString(entries[1].source.type), EXPECT_EQ(NetLog::SourceTypeToString(entries[1].source.type),
actual_item2.source_type); actual_item2.source_type);
std::string item1_params; const std::string* item1_params = item1->FindStringPath("args.params.foo");
const base::DictionaryValue* item2_params; ASSERT_TRUE(item1_params);
EXPECT_TRUE(item1->GetString("args.params.foo", &item1_params)); EXPECT_EQ("bar", *item1_params);
EXPECT_EQ("bar", item1_params);
EXPECT_TRUE(item2->GetDictionary("args.params", &item2_params)); const base::Value* item2_params = item2->FindDictPath("args.params");
EXPECT_TRUE(item2_params->empty()); ASSERT_TRUE(item2_params);
EXPECT_TRUE(item2_params->DictEmpty());
} }
TEST(TraceNetLogObserverCategoryTest, DisabledCategory) { TEST(TraceNetLogObserverCategoryTest, DisabledCategory) {
......
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