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 11 matching lines...) Expand all Loading... |
22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/renderer/safe_browsing/features.h" | 23 #include "chrome/renderer/safe_browsing/features.h" |
24 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" | 24 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" |
25 #include "chrome/renderer/safe_browsing/test_utils.h" | 25 #include "chrome/renderer/safe_browsing/test_utils.h" |
26 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
27 #include "chrome/test/base/ui_test_utils.h" | 27 #include "chrome/test/base/ui_test_utils.h" |
28 #include "content/public/browser/interstitial_page.h" | 28 #include "content/public/browser/interstitial_page.h" |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "content/public/renderer/render_view.h" | 30 #include "content/public/renderer/render_view.h" |
31 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
| 32 #include "content/public/test/routing_id_mangling_disabler.h" |
32 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
33 #include "net/dns/mock_host_resolver.h" | 34 #include "net/dns/mock_host_resolver.h" |
34 #include "net/test/embedded_test_server/embedded_test_server.h" | 35 #include "net/test/embedded_test_server/embedded_test_server.h" |
35 #include "net/test/embedded_test_server/http_request.h" | 36 #include "net/test/embedded_test_server/http_request.h" |
36 #include "net/test/embedded_test_server/http_response.h" | 37 #include "net/test/embedded_test_server/http_response.h" |
37 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
38 #include "third_party/WebKit/public/platform/WebString.h" | 39 #include "third_party/WebKit/public/platform/WebString.h" |
39 #include "third_party/WebKit/public/web/WebFrame.h" | 40 #include "third_party/WebKit/public/web/WebFrame.h" |
40 #include "third_party/WebKit/public/web/WebScriptSource.h" | 41 #include "third_party/WebKit/public/web/WebScriptSource.h" |
41 #include "third_party/WebKit/public/web/WebView.h" | 42 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 GURL url(GetURL(host, "")); | 173 GURL url(GetURL(host, "")); |
173 responses_[url.spec()] = content; | 174 responses_[url.spec()] = content; |
174 ui_test_utils::NavigateToURL(browser(), url); | 175 ui_test_utils::NavigateToURL(browser(), url); |
175 return url; | 176 return url; |
176 } | 177 } |
177 | 178 |
178 // Map of url -> response body for network requests from the renderer. | 179 // Map of url -> response body for network requests from the renderer. |
179 // Any urls not in this map are served a 404 error. | 180 // Any urls not in this map are served a 404 error. |
180 std::map<std::string, std::string> responses_; | 181 std::map<std::string, std::string> responses_; |
181 | 182 |
| 183 content::RoutingIDManglingDisabler mangling_disabler_; |
182 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; | 184 scoped_ptr<net::test_server::EmbeddedTestServer> embedded_test_server_; |
183 MockFeatureExtractorClock clock_; | 185 MockFeatureExtractorClock clock_; |
184 scoped_ptr<PhishingDOMFeatureExtractor> extractor_; | 186 scoped_ptr<PhishingDOMFeatureExtractor> extractor_; |
185 bool success_; // holds the success value from ExtractFeatures | 187 bool success_; // holds the success value from ExtractFeatures |
186 base::WeakPtrFactory<PhishingDOMFeatureExtractorTest> weak_factory_; | 188 base::WeakPtrFactory<PhishingDOMFeatureExtractorTest> weak_factory_; |
187 }; | 189 }; |
188 | 190 |
189 IN_PROC_BROWSER_TEST_F(PhishingDOMFeatureExtractorTest, FormFeatures) { | 191 IN_PROC_BROWSER_TEST_F(PhishingDOMFeatureExtractorTest, FormFeatures) { |
190 // This test doesn't exercise the extraction timing. | 192 // This test doesn't exercise the extraction timing. |
191 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); | 193 EXPECT_CALL(clock_, Now()).WillRepeatedly(Return(base::TimeTicks::Now())); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 LoadHtml( | 514 LoadHtml( |
513 "host.com", | 515 "host.com", |
514 "<html><head></head><body>" | 516 "<html><head></head><body>" |
515 "<iframe src=\"frame.html\" id=\"frame1\"></iframe>" | 517 "<iframe src=\"frame.html\" id=\"frame1\"></iframe>" |
516 "<form></form></body></html>"); | 518 "<form></form></body></html>"); |
517 ASSERT_TRUE(ExtractFeatures(&features)); | 519 ASSERT_TRUE(ExtractFeatures(&features)); |
518 ExpectFeatureMapsAreEqual(features, expected_features); | 520 ExpectFeatureMapsAreEqual(features, expected_features); |
519 } | 521 } |
520 | 522 |
521 } // namespace safe_browsing | 523 } // namespace safe_browsing |
OLD | NEW |