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 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" | 5 #include "chrome/renderer/safe_browsing/phishing_dom_feature_extractor.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "chrome/renderer/chrome_content_renderer_client.h" | 12 #include "chrome/renderer/chrome_content_renderer_client.h" |
13 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" | 13 #include "chrome/renderer/extensions/chrome_extensions_dispatcher_delegate.h" |
14 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h" | 14 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h" |
15 #include "chrome/renderer/safe_browsing/features.h" | 15 #include "chrome/renderer/safe_browsing/features.h" |
16 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" | 16 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" |
17 #include "chrome/renderer/safe_browsing/test_utils.h" | 17 #include "chrome/renderer/safe_browsing/test_utils.h" |
18 #include "chrome/renderer/spellchecker/spellcheck.h" | 18 #include "chrome/renderer/spellchecker/spellcheck.h" |
19 #include "chrome/test/base/chrome_render_view_test.h" | 19 #include "chrome/test/base/chrome_render_view_test.h" |
20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
21 #include "content/public/renderer/render_frame.h" | 21 #include "content/public/renderer/render_frame.h" |
22 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
23 #include "extensions/renderer/dispatcher.h" | 23 #include "extensions/renderer/dispatcher.h" |
24 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
25 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 25 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "third_party/WebKit/public/platform/URLConversion.h" |
27 #include "third_party/WebKit/public/platform/WebString.h" | 28 #include "third_party/WebKit/public/platform/WebString.h" |
28 #include "third_party/WebKit/public/web/WebFrame.h" | 29 #include "third_party/WebKit/public/web/WebFrame.h" |
29 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
30 #include "third_party/WebKit/public/web/WebScriptSource.h" | 31 #include "third_party/WebKit/public/web/WebScriptSource.h" |
31 | 32 |
32 using ::testing::DoAll; | 33 using ::testing::DoAll; |
33 using ::testing::Invoke; | 34 using ::testing::Invoke; |
34 using ::testing::Return; | 35 using ::testing::Return; |
35 | 36 |
36 namespace safe_browsing { | 37 namespace safe_browsing { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 88 |
88 // For similar reason as above, PhishingDOMFeatureExtractor::CompeteURL(..) | 89 // For similar reason as above, PhishingDOMFeatureExtractor::CompeteURL(..) |
89 // always returns empty WebURL. Overriding this CompeteURL(..) to work around | 90 // always returns empty WebURL. Overriding this CompeteURL(..) to work around |
90 // this issue. | 91 // this issue. |
91 blink::WebURL CompleteURL(const blink::WebElement& element, | 92 blink::WebURL CompleteURL(const blink::WebElement& element, |
92 const blink::WebString& partial_url) override { | 93 const blink::WebString& partial_url) override { |
93 GURL parsed_url(GURL(partial_url.utf8())); | 94 GURL parsed_url(GURL(partial_url.utf8())); |
94 GURL full_url; | 95 GURL full_url; |
95 if (parsed_url.has_scheme()) { | 96 if (parsed_url.has_scheme()) { |
96 // This is already a complete URL. | 97 // This is already a complete URL. |
97 full_url = GURL(partial_url); | 98 full_url = GURL(blink::WebStringToGURL(partial_url)); |
98 } else if (!base_domain_.empty()) { | 99 } else if (!base_domain_.empty()) { |
99 // This is a partial URL and only one frame in testing html. | 100 // This is a partial URL and only one frame in testing html. |
100 full_url = GURL("http://" + base_domain_).Resolve(partial_url); | 101 full_url = GURL("http://" + base_domain_).Resolve(partial_url); |
101 } else { | 102 } else { |
102 auto it = url_to_frame_domain_map_.find(partial_url.utf8()); | 103 auto it = url_to_frame_domain_map_.find(partial_url.utf8()); |
103 if (it != url_to_frame_domain_map_.end()) { | 104 if (it != url_to_frame_domain_map_.end()) { |
104 const std::string frame_domain = it->second; | 105 const std::string frame_domain = it->second; |
105 full_url = GURL("http://" + it->second).Resolve(partial_url.utf8()); | 106 full_url = GURL("http://" + it->second).Resolve(partial_url.utf8()); |
106 url_to_frame_domain_map_[full_url.spec()] = it->second; | 107 url_to_frame_domain_map_[full_url.spec()] = it->second; |
107 } else { | 108 } else { |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 "<html><head></head><body>" | 575 "<html><head></head><body>" |
575 "<iframe src=\"" + | 576 "<iframe src=\"" + |
576 net::EscapeForHTML(iframe1_url.spec()) + | 577 net::EscapeForHTML(iframe1_url.spec()) + |
577 "\" id=\"frame1\"></iframe>" | 578 "\" id=\"frame1\"></iframe>" |
578 "<form></form></body></html>"); | 579 "<form></form></body></html>"); |
579 ExtractFeatures("host.com", html, &features); | 580 ExtractFeatures("host.com", html, &features); |
580 ExpectFeatureMapsAreEqual(features, expected_features); | 581 ExpectFeatureMapsAreEqual(features, expected_features); |
581 } | 582 } |
582 | 583 |
583 } // namespace safe_browsing | 584 } // namespace safe_browsing |
OLD | NEW |