| 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/extensions/chrome_extensions_dispatcher_delegate.h" | |
| 17 #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h" | |
| 18 #include "chrome/renderer/safe_browsing/features.h" | 16 #include "chrome/renderer/safe_browsing/features.h" |
| 19 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" | 17 #include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h" |
| 20 #include "chrome/renderer/safe_browsing/test_utils.h" | 18 #include "chrome/renderer/safe_browsing/test_utils.h" |
| 21 #include "chrome/renderer/spellchecker/spellcheck.h" | |
| 22 #include "chrome/test/base/chrome_render_view_test.h" | 19 #include "chrome/test/base/chrome_render_view_test.h" |
| 23 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/renderer/render_frame.h" | 21 #include "content/public/renderer/render_frame.h" |
| 25 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
| 26 #include "extensions/renderer/dispatcher.h" | |
| 27 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
| 28 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 24 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "third_party/WebKit/public/platform/URLConversion.h" | 26 #include "third_party/WebKit/public/platform/URLConversion.h" |
| 31 #include "third_party/WebKit/public/platform/WebString.h" | 27 #include "third_party/WebKit/public/platform/WebString.h" |
| 32 #include "third_party/WebKit/public/web/WebFrame.h" | 28 #include "third_party/WebKit/public/web/WebFrame.h" |
| 33 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 29 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 34 #include "third_party/WebKit/public/web/WebScriptSource.h" | 30 #include "third_party/WebKit/public/web/WebScriptSource.h" |
| 35 | 31 |
| 36 using ::testing::DoAll; | 32 using ::testing::DoAll; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 extractor_.reset(new TestPhishingDOMFeatureExtractor(&clock_)); | 189 extractor_.reset(new TestPhishingDOMFeatureExtractor(&clock_)); |
| 194 } | 190 } |
| 195 | 191 |
| 196 void TearDown() override { | 192 void TearDown() override { |
| 197 extractor_.reset(nullptr); | 193 extractor_.reset(nullptr); |
| 198 ChromeRenderViewTest::TearDown(); | 194 ChromeRenderViewTest::TearDown(); |
| 199 } | 195 } |
| 200 | 196 |
| 201 content::ContentRendererClient* CreateContentRendererClient() override { | 197 content::ContentRendererClient* CreateContentRendererClient() override { |
| 202 ChromeContentRendererClient* client = new TestChromeContentRendererClient(); | 198 ChromeContentRendererClient* client = new TestChromeContentRendererClient(); |
| 203 #if defined(ENABLE_EXTENSIONS) | 199 InitChromeContentRendererClient(client); |
| 204 extension_dispatcher_delegate_.reset( | |
| 205 new ChromeExtensionsDispatcherDelegate()); | |
| 206 ChromeExtensionsRendererClient* ext_client = | |
| 207 ChromeExtensionsRendererClient::GetInstance(); | |
| 208 ext_client->SetExtensionDispatcherForTest(base::WrapUnique( | |
| 209 new extensions::Dispatcher(extension_dispatcher_delegate_.get()))); | |
| 210 #endif | |
| 211 #if defined(ENABLE_SPELLCHECK) | |
| 212 client->SetSpellcheck(new SpellCheck()); | |
| 213 #endif | |
| 214 return client; | 200 return client; |
| 215 } | 201 } |
| 216 | 202 |
| 217 void AnotherExtractionDone(bool success) { | 203 void AnotherExtractionDone(bool success) { |
| 218 success_ = success; | 204 success_ = success; |
| 219 message_loop_->QuitClosure().Run(); | 205 message_loop_->QuitClosure().Run(); |
| 220 } | 206 } |
| 221 | 207 |
| 222 // Does the actual work of removing the iframe "frame1" from the document. | 208 // Does the actual work of removing the iframe "frame1" from the document. |
| 223 void RemoveIframe() { | 209 void RemoveIframe() { |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 "<html><head></head><body>" | 564 "<html><head></head><body>" |
| 579 "<iframe src=\"" + | 565 "<iframe src=\"" + |
| 580 net::EscapeForHTML(iframe1_url.spec()) + | 566 net::EscapeForHTML(iframe1_url.spec()) + |
| 581 "\" id=\"frame1\"></iframe>" | 567 "\" id=\"frame1\"></iframe>" |
| 582 "<form></form></body></html>"); | 568 "<form></form></body></html>"); |
| 583 ExtractFeatures("host.com", html, &features); | 569 ExtractFeatures("host.com", html, &features); |
| 584 ExpectFeatureMapsAreEqual(features, expected_features); | 570 ExpectFeatureMapsAreEqual(features, expected_features); |
| 585 } | 571 } |
| 586 | 572 |
| 587 } // namespace safe_browsing | 573 } // namespace safe_browsing |
| OLD | NEW |