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

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

Issue 1409133007: Add a new set of page features for distillability testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webkit
Patch Set: Created 5 years, 1 month 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"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebDistillability.h"
17 #include "url/gurl.h"
16 18
17 namespace dom_distiller { 19 namespace dom_distiller {
18 20
19 // This test uses input data of core features and the output of the training 21 // This test uses input data of core features and the output of the training
20 // pipeline's derived feature extraction to ensure that the extraction that is 22 // pipeline's derived feature extraction to ensure that the extraction that is
21 // done in Chromium matches that in the training pipeline. 23 // done in Chromium matches that in the training pipeline.
22 TEST(DomDistillerPageFeaturesTest, TestCalculateDerivedFeatures) { 24 TEST(DomDistillerPageFeaturesTest, TestCalculateDerivedFeatures) {
23 base::FilePath dir_source_root; 25 base::FilePath dir_source_root;
24 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root)); 26 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &dir_source_root));
25 std::string input_data; 27 std::string input_data;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 bool bool_value; 90 bool bool_value;
89 ASSERT_TRUE(derived_features->GetBoolean(value_index, &bool_value)); 91 ASSERT_TRUE(derived_features->GetBoolean(value_index, &bool_value));
90 expected_value = bool_value ? 1.0 : 0.0; 92 expected_value = bool_value ? 1.0 : 0.0;
91 } 93 }
92 EXPECT_DOUBLE_EQ(derived[j], expected_value) 94 EXPECT_DOUBLE_EQ(derived[j], expected_value)
93 << "incorrect value for entry with url " << entry_url 95 << "incorrect value for entry with url " << entry_url
94 << " for derived feature " << labels[j]; 96 << " for derived feature " << labels[j];
95 } 97 }
96 } 98 }
97 } 99 }
100
101 TEST(DomDistillerPageFeaturesTest, TestPath) {
102 blink::WebDistillabilityFeatures f = blink::WebDistillabilityFeatures();
103
104 GURL url("http://example.com/search/view/index/the-title-of-archive.php");
105
106 std::vector<double> derived(CalculateDerivedFeatures(f, url));
107 EXPECT_EQ(0, lround(derived[1]));
108 EXPECT_EQ(1, lround(derived[2]));
109 EXPECT_EQ(1, lround(derived[3]));
110 EXPECT_EQ(1, lround(derived[4]));
111 EXPECT_EQ(1, lround(derived[5]));
112 EXPECT_EQ(0, lround(derived[6]));
113 EXPECT_EQ(0, lround(derived[7]));
114 EXPECT_EQ(1, lround(derived[8]));
115 EXPECT_EQ(43, lround(derived[9]));
116 EXPECT_EQ(0, lround(derived[10]));
117 EXPECT_EQ(4, lround(derived[11]));
118 EXPECT_EQ(4, lround(derived[12]));
119 EXPECT_EQ(0, lround(derived[13]));
120 EXPECT_EQ(24, lround(derived[14]));
98 } 121 }
122
123 TEST(DomDistillerPageFeaturesTest, TestPath2) {
124 blink::WebDistillabilityFeatures f = blink::WebDistillabilityFeatures();
125
126 GURL url("http://example.com/phpbb/forum123/456.asp");
127
128 std::vector<double> derived(CalculateDerivedFeatures(f, url));
129 EXPECT_EQ(1, lround(derived[1]));
130 EXPECT_EQ(0, lround(derived[2]));
131 EXPECT_EQ(0, lround(derived[3]));
132 EXPECT_EQ(0, lround(derived[4]));
133 EXPECT_EQ(0, lround(derived[5]));
134 EXPECT_EQ(1, lround(derived[6]));
135 EXPECT_EQ(1, lround(derived[7]));
136 EXPECT_EQ(0, lround(derived[8]));
137 EXPECT_EQ(23, lround(derived[9]));
138 EXPECT_EQ(0, lround(derived[10]));
139 EXPECT_EQ(3, lround(derived[11]));
140 EXPECT_EQ(1, lround(derived[12]));
141 EXPECT_EQ(2, lround(derived[13]));
142 EXPECT_EQ(7, lround(derived[14]));
143 }
144
145 TEST(DomDistillerPageFeaturesTest, TestPath3) {
146 blink::WebDistillabilityFeatures f = blink::WebDistillabilityFeatures();
147
148 GURL url("https://example.com/");
149
150 std::vector<double> derived(CalculateDerivedFeatures(f, url));
151 EXPECT_EQ(0, lround(derived[1]));
152 EXPECT_EQ(0, lround(derived[2]));
153 EXPECT_EQ(0, lround(derived[3]));
154 EXPECT_EQ(0, lround(derived[4]));
155 EXPECT_EQ(0, lround(derived[5]));
156 EXPECT_EQ(0, lround(derived[6]));
157 EXPECT_EQ(0, lround(derived[7]));
158 EXPECT_EQ(0, lround(derived[8]));
159 EXPECT_EQ(1, lround(derived[9]));
160 EXPECT_EQ(1, lround(derived[10]));
161 EXPECT_EQ(0, lround(derived[11]));
162 EXPECT_EQ(0, lround(derived[12]));
163 EXPECT_EQ(0, lround(derived[13]));
164 EXPECT_EQ(0, lround(derived[14]));
165 }
166 }
OLDNEW
« components/dom_distiller/DEPS ('K') | « components/dom_distiller/core/page_features.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698