OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Note that although this is not a "browser" test, it runs as part of | 5 // Note that although this is not a "browser" test, it runs as part of |
6 // browser_tests. This is because WebKit does not work properly if it is | 6 // browser_tests. This is because WebKit does not work properly if it is |
7 // shutdown and re-initialized. Since browser_tests runs each test in a | 7 // shutdown and re-initialized. Since browser_tests runs each test in a |
8 // new process, this avoids the problem. | 8 // new process, this avoids the problem. |
9 | 9 |
10 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" | 10 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 WebKit::WebString( | 85 WebKit::WebString( |
86 "document.body.removeChild(document.getElementById('frame1'));")); | 86 "document.body.removeChild(document.getElementById('frame1'));")); |
87 } | 87 } |
88 | 88 |
89 MockFeatureExtractorClock clock_; | 89 MockFeatureExtractorClock clock_; |
90 scoped_ptr<PhishingDOMFeatureExtractor> extractor_; | 90 scoped_ptr<PhishingDOMFeatureExtractor> extractor_; |
91 bool success_; // holds the success value from ExtractFeatures | 91 bool success_; // holds the success value from ExtractFeatures |
92 base::WeakPtrFactory<PhishingDOMFeatureExtractorTest> weak_factory_; | 92 base::WeakPtrFactory<PhishingDOMFeatureExtractorTest> weak_factory_; |
93 }; | 93 }; |
94 | 94 |
95 TEST_F(PhishingDOMFeatureExtractorTest, DISABLED_FormFeatures) { | 95 TEST_F(PhishingDOMFeatureExtractorTest, FormFeatures) { |
96 // This test doesn't exercise the extraction timing. | 96 // This test doesn't exercise the extraction timing. |
97 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); | 97 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); |
98 responses_["http://host.com/"] = | 98 responses_["http://host.com/"] = |
99 "<html><head><body>" | 99 "<html><head><body>" |
100 "<form action=\"query\"><input type=text><input type=checkbox></form>" | 100 "<form action=\"query\"><input type=text><input type=checkbox></form>" |
101 "<form action=\"http://cgi.host.com/submit\"></form>" | 101 "<form action=\"http://cgi.host.com/submit\"></form>" |
102 "<form action=\"http://other.com/\"></form>" | 102 "<form action=\"http://other.com/\"></form>" |
103 "<form action=\"query\"></form>" | 103 "<form action=\"query\"></form>" |
104 "<form></form></body></html>"; | 104 "<form></form></body></html>"; |
105 | 105 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 143 |
144 expected_features.Clear(); | 144 expected_features.Clear(); |
145 expected_features.AddBooleanFeature(features::kPageHasTextInputs); | 145 expected_features.AddBooleanFeature(features::kPageHasTextInputs); |
146 | 146 |
147 features.Clear(); | 147 features.Clear(); |
148 LoadURL("http://host.com/"); | 148 LoadURL("http://host.com/"); |
149 ASSERT_TRUE(ExtractFeatures(&features)); | 149 ASSERT_TRUE(ExtractFeatures(&features)); |
150 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); | 150 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); |
151 } | 151 } |
152 | 152 |
153 TEST_F(PhishingDOMFeatureExtractorTest, DISABLED_LinkFeatures) { | 153 TEST_F(PhishingDOMFeatureExtractorTest, LinkFeatures) { |
154 // This test doesn't exercise the extraction timing. | 154 // This test doesn't exercise the extraction timing. |
155 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); | 155 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); |
156 responses_["http://www.host.com/"] = | 156 responses_["http://www.host.com/"] = |
157 "<html><head><body>" | 157 "<html><head><body>" |
158 "<a href=\"http://www2.host.com/abc\">link</a>" | 158 "<a href=\"http://www2.host.com/abc\">link</a>" |
159 "<a name=page_anchor></a>" | 159 "<a name=page_anchor></a>" |
160 "<a href=\"http://www.chromium.org/\">chromium</a>" | 160 "<a href=\"http://www.chromium.org/\">chromium</a>" |
161 "</body></html"; | 161 "</body></html"; |
162 | 162 |
163 FeatureMap expected_features; | 163 FeatureMap expected_features; |
(...skipping 21 matching lines...) Expand all Loading... |
185 expected_features.AddRealFeature(features::kPageSecureLinksFreq, 0.5); | 185 expected_features.AddRealFeature(features::kPageSecureLinksFreq, 0.5); |
186 expected_features.AddBooleanFeature(features::kPageLinkDomain + | 186 expected_features.AddBooleanFeature(features::kPageLinkDomain + |
187 std::string("chromium.org")); | 187 std::string("chromium.org")); |
188 | 188 |
189 features.Clear(); | 189 features.Clear(); |
190 LoadURL("https://www.host.com/"); | 190 LoadURL("https://www.host.com/"); |
191 ASSERT_TRUE(ExtractFeatures(&features)); | 191 ASSERT_TRUE(ExtractFeatures(&features)); |
192 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); | 192 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); |
193 } | 193 } |
194 | 194 |
195 TEST_F(PhishingDOMFeatureExtractorTest, DISABLED_ScriptAndImageFeatures) { | 195 TEST_F(PhishingDOMFeatureExtractorTest, ScriptAndImageFeatures) { |
196 // This test doesn't exercise the extraction timing. | 196 // This test doesn't exercise the extraction timing. |
197 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); | 197 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); |
198 responses_["http://host.com/"] = | 198 responses_["http://host.com/"] = |
199 "<html><head><script></script><script></script></head></html>"; | 199 "<html><head><script></script><script></script></head></html>"; |
200 | 200 |
201 FeatureMap expected_features; | 201 FeatureMap expected_features; |
202 expected_features.AddBooleanFeature(features::kPageNumScriptTagsGTOne); | 202 expected_features.AddBooleanFeature(features::kPageNumScriptTagsGTOne); |
203 | 203 |
204 FeatureMap features; | 204 FeatureMap features; |
205 LoadURL("http://host.com/"); | 205 LoadURL("http://host.com/"); |
(...skipping 10 matching lines...) Expand all Loading... |
216 expected_features.AddBooleanFeature(features::kPageNumScriptTagsGTOne); | 216 expected_features.AddBooleanFeature(features::kPageNumScriptTagsGTOne); |
217 expected_features.AddBooleanFeature(features::kPageNumScriptTagsGTSix); | 217 expected_features.AddBooleanFeature(features::kPageNumScriptTagsGTSix); |
218 expected_features.AddRealFeature(features::kPageImgOtherDomainFreq, 0.5); | 218 expected_features.AddRealFeature(features::kPageImgOtherDomainFreq, 0.5); |
219 | 219 |
220 features.Clear(); | 220 features.Clear(); |
221 LoadURL("http://host.com/"); | 221 LoadURL("http://host.com/"); |
222 ASSERT_TRUE(ExtractFeatures(&features)); | 222 ASSERT_TRUE(ExtractFeatures(&features)); |
223 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); | 223 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); |
224 } | 224 } |
225 | 225 |
226 TEST_F(PhishingDOMFeatureExtractorTest, DISABLED_SubFrames) { | 226 TEST_F(PhishingDOMFeatureExtractorTest, SubFrames) { |
227 // This test doesn't exercise the extraction timing. | 227 // This test doesn't exercise the extraction timing. |
228 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); | 228 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); |
229 | 229 |
230 // Test that features are aggregated across all frames. | 230 // Test that features are aggregated across all frames. |
231 responses_["http://host.com/"] = | 231 responses_["http://host.com/"] = |
232 "<html><body><input type=text><a href=\"info.html\">link</a>" | 232 "<html><body><input type=text><a href=\"info.html\">link</a>" |
233 "<iframe src=\"http://host2.com/\"></iframe>" | 233 "<iframe src=\"http://host2.com/\"></iframe>" |
234 "<iframe src=\"http://host3.com/\"></iframe>" | 234 "<iframe src=\"http://host3.com/\"></iframe>" |
235 "</body></html>"; | 235 "</body></html>"; |
236 | 236 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(360))) | 351 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(360))) |
352 // Time check after the next 10 elements. This is over the limit. | 352 // Time check after the next 10 elements. This is over the limit. |
353 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(600))) | 353 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(600))) |
354 // A final time check for the histograms. | 354 // A final time check for the histograms. |
355 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(620))); | 355 .WillOnce(Return(now + base::TimeDelta::FromMilliseconds(620))); |
356 | 356 |
357 features.Clear(); | 357 features.Clear(); |
358 EXPECT_FALSE(ExtractFeatures(&features)); | 358 EXPECT_FALSE(ExtractFeatures(&features)); |
359 } | 359 } |
360 | 360 |
361 TEST_F(PhishingDOMFeatureExtractorTest, DISABLED_SubframeRemoval) { | 361 TEST_F(PhishingDOMFeatureExtractorTest, SubframeRemoval) { |
362 // In this test, we'll advance the feature extractor so that it is positioned | 362 // In this test, we'll advance the feature extractor so that it is positioned |
363 // inside an iframe, and have it pause due to exceeding the chunk time limit. | 363 // inside an iframe, and have it pause due to exceeding the chunk time limit. |
364 // Then, prior to continuation, the iframe is removed from the document. | 364 // Then, prior to continuation, the iframe is removed from the document. |
365 // As currently implemented, this should finish extraction from the removed | 365 // As currently implemented, this should finish extraction from the removed |
366 // iframe document. | 366 // iframe document. |
367 responses_["http://host.com/"] = | 367 responses_["http://host.com/"] = |
368 "<html><head></head><body>" | 368 "<html><head></head><body>" |
369 "<iframe src=\"frame.html\" id=\"frame1\"></iframe>" | 369 "<iframe src=\"frame.html\" id=\"frame1\"></iframe>" |
370 "<form></form></body></html>"; | 370 "<form></form></body></html>"; |
371 responses_["http://host.com/frame.html"] = | 371 responses_["http://host.com/frame.html"] = |
(...skipping 22 matching lines...) Expand all Loading... |
394 expected_features.AddBooleanFeature(features::kPageHasForms); | 394 expected_features.AddBooleanFeature(features::kPageHasForms); |
395 expected_features.AddBooleanFeature(features::kPageHasPswdInputs); | 395 expected_features.AddBooleanFeature(features::kPageHasPswdInputs); |
396 | 396 |
397 FeatureMap features; | 397 FeatureMap features; |
398 LoadURL("http://host.com/"); | 398 LoadURL("http://host.com/"); |
399 ASSERT_TRUE(ExtractFeatures(&features)); | 399 ASSERT_TRUE(ExtractFeatures(&features)); |
400 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); | 400 EXPECT_THAT(features.features(), ContainerEq(expected_features.features())); |
401 } | 401 } |
402 | 402 |
403 } // namespace safe_browsing | 403 } // namespace safe_browsing |
OLD | NEW |