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