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

Side by Side Diff: components/dom_distiller/core/page_features_unittest.cc

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/dom_distiller/core/page_features.h" 5 #include "components/dom_distiller/core/page_features.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 labels.push_back(label); 63 labels.push_back(label);
64 } 64 }
65 65
66 for (size_t i = 0; i < input_entries->GetSize(); ++i) { 66 for (size_t i = 0; i < input_entries->GetSize(); ++i) {
67 base::DictionaryValue* core_features; 67 base::DictionaryValue* core_features;
68 ASSERT_TRUE(input_entries->GetDictionary(i, &entry)); 68 ASSERT_TRUE(input_entries->GetDictionary(i, &entry));
69 ASSERT_TRUE(entry->GetDictionary("features", &core_features)); 69 ASSERT_TRUE(entry->GetDictionary("features", &core_features));
70 // CalculateDerivedFeaturesFromJSON expects a base::Value of the stringified 70 // CalculateDerivedFeaturesFromJSON expects a base::Value of the stringified
71 // JSON (and not a base::Value of the JSON itself) 71 // JSON (and not a base::Value of the JSON itself)
72 std::string stringified_json; 72 std::string stringified_json;
73 ASSERT_TRUE(base::JSONWriter::Write(core_features, &stringified_json)); 73 ASSERT_TRUE(base::JSONWriter::Write(*core_features, &stringified_json));
74 scoped_ptr<base::Value> stringified_value( 74 scoped_ptr<base::Value> stringified_value(
75 new base::StringValue(stringified_json)); 75 new base::StringValue(stringified_json));
76 std::vector<double> derived( 76 std::vector<double> derived(
77 CalculateDerivedFeaturesFromJSON(stringified_value.get())); 77 CalculateDerivedFeaturesFromJSON(stringified_value.get()));
78 78
79 ASSERT_EQ(labels.size(), derived.size()); 79 ASSERT_EQ(labels.size(), derived.size());
80 ASSERT_TRUE(expected_output_entries->GetDictionary(i, &entry)); 80 ASSERT_TRUE(expected_output_entries->GetDictionary(i, &entry));
81 ASSERT_TRUE(entry->GetList("features", &derived_features)); 81 ASSERT_TRUE(entry->GetList("features", &derived_features));
82 std::string entry_url; 82 std::string entry_url;
83 ASSERT_TRUE(entry->GetString("url", &entry_url)); 83 ASSERT_TRUE(entry->GetString("url", &entry_url));
84 for (size_t j = 0, value_index = 1; j < derived.size(); 84 for (size_t j = 0, value_index = 1; j < derived.size();
85 ++j, value_index += 2) { 85 ++j, value_index += 2) {
86 double expected_value; 86 double expected_value;
87 if (!derived_features->GetDouble(value_index, &expected_value)) { 87 if (!derived_features->GetDouble(value_index, &expected_value)) {
88 bool bool_value; 88 bool bool_value;
89 ASSERT_TRUE(derived_features->GetBoolean(value_index, &bool_value)); 89 ASSERT_TRUE(derived_features->GetBoolean(value_index, &bool_value));
90 expected_value = bool_value ? 1.0 : 0.0; 90 expected_value = bool_value ? 1.0 : 0.0;
91 } 91 }
92 EXPECT_DOUBLE_EQ(derived[j], expected_value) 92 EXPECT_DOUBLE_EQ(derived[j], expected_value)
93 << "incorrect value for entry with url " << entry_url 93 << "incorrect value for entry with url " << entry_url
94 << " for derived feature " << labels[j]; 94 << " for derived feature " << labels[j];
95 } 95 }
96 } 96 }
97 } 97 }
98 } 98 }
OLDNEW
« no previous file with comments | « components/dom_distiller/core/distiller_page.cc ('k') | components/dom_distiller/core/viewer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698