| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/renderer/chrome_content_renderer_client.h" | 15 #include "chrome/renderer/chrome_content_renderer_client.h" |
| 16 #include "chrome/renderer/safe_browsing/features.h" | 16 #include "chrome/renderer/safe_browsing/features.h" |
| 17 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" | 17 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" |
| 18 #include "chrome/renderer/safe_browsing/test_utils.h" | 18 #include "chrome/renderer/safe_browsing/test_utils.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 "net/base/escape.h" | 23 #include "net/base/escape.h" |
| 24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "third_party/WebKit/public/platform/URLConversion.h" | 26 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 27 #include "third_party/WebKit/public/platform/WebString.h" | 27 #include "third_party/WebKit/public/platform/WebString.h" |
| 28 #include "third_party/WebKit/public/web/WebFrame.h" | 28 #include "third_party/WebKit/public/web/WebFrame.h" |
| 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 30 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 30 #include "third_party/WebKit/public/web/WebScriptSource.h" | 31 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 32 #include "ui/native_theme/native_theme_switches.h" |
| 31 | 33 |
| 32 using ::testing::DoAll; | 34 using ::testing::DoAll; |
| 33 using ::testing::Invoke; | 35 using ::testing::Invoke; |
| 34 using ::testing::Return; | 36 using ::testing::Return; |
| 37 using blink::WebRuntimeFeatures; |
| 35 | 38 |
| 36 namespace safe_browsing { | 39 namespace safe_browsing { |
| 37 | 40 |
| 38 // TestPhishingDOMFeatureExtractor has nearly identical behavior as | 41 // TestPhishingDOMFeatureExtractor has nearly identical behavior as |
| 39 // PhishingDOMFeatureExtractor, except the IsExternalDomain() and | 42 // PhishingDOMFeatureExtractor, except the IsExternalDomain() and |
| 40 // CompleteURL() functions. This is to work around the fact that | 43 // CompleteURL() functions. This is to work around the fact that |
| 41 // ChromeRenderViewTest object does not know where the html content is hosted. | 44 // ChromeRenderViewTest object does not know where the html content is hosted. |
| 42 class TestPhishingDOMFeatureExtractor : public PhishingDOMFeatureExtractor { | 45 class TestPhishingDOMFeatureExtractor : public PhishingDOMFeatureExtractor { |
| 43 public: | 46 public: |
| 44 explicit TestPhishingDOMFeatureExtractor(FeatureExtractorClock* clock) | 47 explicit TestPhishingDOMFeatureExtractor(FeatureExtractorClock* clock) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // the iframe "frame1" from the document. | 182 // the iframe "frame1" from the document. |
| 180 void ScheduleRemoveIframe() { | 183 void ScheduleRemoveIframe() { |
| 181 base::ThreadTaskRunnerHandle::Get()->PostTask( | 184 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 182 FROM_HERE, base::Bind(&PhishingDOMFeatureExtractorTest::RemoveIframe, | 185 FROM_HERE, base::Bind(&PhishingDOMFeatureExtractorTest::RemoveIframe, |
| 183 weak_factory_.GetWeakPtr())); | 186 weak_factory_.GetWeakPtr())); |
| 184 } | 187 } |
| 185 | 188 |
| 186 protected: | 189 protected: |
| 187 void SetUp() override { | 190 void SetUp() override { |
| 188 ChromeRenderViewTest::SetUp(); | 191 ChromeRenderViewTest::SetUp(); |
| 192 WebRuntimeFeatures::enableOverlayScrollbars( |
| 193 ui::IsOverlayScrollbarEnabled()); |
| 189 extractor_.reset(new TestPhishingDOMFeatureExtractor(&clock_)); | 194 extractor_.reset(new TestPhishingDOMFeatureExtractor(&clock_)); |
| 190 } | 195 } |
| 191 | 196 |
| 192 void TearDown() override { | 197 void TearDown() override { |
| 193 extractor_.reset(nullptr); | 198 extractor_.reset(nullptr); |
| 194 ChromeRenderViewTest::TearDown(); | 199 ChromeRenderViewTest::TearDown(); |
| 195 } | 200 } |
| 196 | 201 |
| 197 content::ContentRendererClient* CreateContentRendererClient() override { | 202 content::ContentRendererClient* CreateContentRendererClient() override { |
| 198 ChromeContentRendererClient* client = new TestChromeContentRendererClient(); | 203 ChromeContentRendererClient* client = new TestChromeContentRendererClient(); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 "<html><head></head><body>" | 569 "<html><head></head><body>" |
| 565 "<iframe src=\"" + | 570 "<iframe src=\"" + |
| 566 net::EscapeForHTML(iframe1_url.spec()) + | 571 net::EscapeForHTML(iframe1_url.spec()) + |
| 567 "\" id=\"frame1\"></iframe>" | 572 "\" id=\"frame1\"></iframe>" |
| 568 "<form></form></body></html>"); | 573 "<form></form></body></html>"); |
| 569 ExtractFeatures("host.com", html, &features); | 574 ExtractFeatures("host.com", html, &features); |
| 570 ExpectFeatureMapsAreEqual(features, expected_features); | 575 ExpectFeatureMapsAreEqual(features, expected_features); |
| 571 } | 576 } |
| 572 | 577 |
| 573 } // namespace safe_browsing | 578 } // namespace safe_browsing |
| OLD | NEW |