Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4297)

Unified Diff: chrome/renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc

Issue 2470413004: PlzNavigate: Fix for the PhishingDOMFeatureExtractorTest.SubFrames and SubframeRemoval tests (Closed)
Patch Set: Address review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/safe_browsing/DEPS ('k') | chrome/test/base/chrome_render_view_test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc
diff --git a/chrome/renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc b/chrome/renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc
index 7a22fa7688cde92f45e28693472050bc977ce973..f8f0924c5b584a2f30548481d6f74c3f79c4f620 100644
--- a/chrome/renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc
+++ b/chrome/renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc
@@ -7,6 +7,7 @@
#include <memory>
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
@@ -17,9 +18,13 @@
#include "chrome/renderer/safe_browsing/mock_feature_extractor_clock.h"
#include "chrome/renderer/safe_browsing/test_utils.h"
#include "chrome/test/base/chrome_render_view_test.h"
+#include "content/common/frame_messages.h"
+#include "content/common/navigation_params.h"
#include "content/public/common/content_switches.h"
+#include "content/public/common/resource_response.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/test/test_utils.h"
+#include "ipc/ipc_message_macros.h"
#include "net/base/escape.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -184,6 +189,48 @@ class PhishingDOMFeatureExtractorTest : public ChromeRenderViewTest {
}
protected:
+ // Subclasses the ChromeMockRenderThread class for providing functionality
+ // to mock IPCs being sent to the browser from RenderViewTests.
+ class PhishingMockRenderThread : public ChromeMockRenderThread {
+ public:
+ PhishingMockRenderThread()
+ : current_message_routing_id_(-1) {
+ }
+
+ protected:
+ bool OnMessageReceived(const IPC::Message& msg) override {
+ current_message_routing_id_ = msg.routing_id();
+
+ IPC_BEGIN_MESSAGE_MAP(PhishingMockRenderThread, msg)
+ IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, OnBeginNavigation)
+ IPC_END_MESSAGE_MAP()
+
+ current_message_routing_id_ = -1;
+ return ChromeMockRenderThread::OnMessageReceived(msg);
+ }
+
+ void OnBeginNavigation(
+ const content::CommonNavigationParams& common_params,
+ const content::BeginNavigationParams& begin_params) {
+ std::unique_ptr<IPC::Message> message;
+
+ message.reset(new FrameMsg_CommitNavigation(
+ current_message_routing_id_, content::ResourceResponseHead(),
+ common_params.url, common_params,
+ content::RequestNavigationParams()));
+ content::RenderFrame* frame = content::RenderFrame::FromRoutingID(
+ current_message_routing_id_);
+
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE,
+ base::Bind(
+ base::IgnoreResult(&content::RenderFrame::OnMessageReceived),
+ base::Unretained(frame), *message));
+ }
+
+ int current_message_routing_id_;
+ };
+
void SetUp() override {
ChromeRenderViewTest::SetUp();
extractor_.reset(new TestPhishingDOMFeatureExtractor(&clock_));
@@ -213,6 +260,11 @@ class PhishingDOMFeatureExtractorTest : public ChromeRenderViewTest {
"document.body.removeChild(document.getElementById('frame1'));"));
}
+ // ChromeMockRenderThread overrides.
+ ChromeMockRenderThread* CreateMockRenderThread() override {
+ return new PhishingMockRenderThread();
+ }
+
MockFeatureExtractorClock clock_;
bool success_;
std::unique_ptr<TestPhishingDOMFeatureExtractor> extractor_;
« no previous file with comments | « chrome/renderer/safe_browsing/DEPS ('k') | chrome/test/base/chrome_render_view_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698