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

Unified Diff: chrome/renderer/chrome_content_renderer_client_browsertest.cc

Issue 649873006: Enable shadow DOM-based "missing plugin" placeholder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test for allowed plugin Created 6 years, 2 months 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
Index: chrome/renderer/chrome_content_renderer_client_browsertest.cc
diff --git a/chrome/renderer/chrome_content_renderer_client_browsertest.cc b/chrome/renderer/chrome_content_renderer_client_browsertest.cc
index 603d78e8f4c489d97f854dc53514a67c204d3139..93b4d41fe27d11725dbca4b3ca212e9bcdee1dc5 100644
--- a/chrome/renderer/chrome_content_renderer_client_browsertest.cc
+++ b/chrome/renderer/chrome_content_renderer_client_browsertest.cc
@@ -4,16 +4,31 @@
#include "chrome/renderer/chrome_content_renderer_client.h"
+#include <string>
#include <vector>
#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/render_messages.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
+#include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h"
#include "chrome/test/base/chrome_render_view_test.h"
+#include "content/public/renderer/render_frame.h"
+#include "content/public/renderer/render_frame_observer.h"
+#include "content/public/renderer/render_view.h"
+#include "content/public/test/mock_render_thread.h"
+#include "ipc/ipc_listener.h"
+#include "ipc/ipc_sender.h"
+#include "ipc/ipc_test_sink.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
+#include "third_party/WebKit/public/web/WebPluginParams.h"
#include "url/gurl.h"
+using testing::_;
+using testing::SetArgPointee;
+
typedef ChromeRenderViewTest InstantProcessNavigationTest;
// Tests that renderer-initiated navigations from an Instant render process get
@@ -52,3 +67,102 @@ TEST_F(InstantProcessNavigationTest, ForkForNavigationsToSearchURLs) {
GetMainFrame(), GURL("http://example.com/"), "GET", false, false,
&unused));
}
+
+namespace {
+
+// Intercepts plugin info IPCs for a mock render thread within its scope,
+// and allows tests to mock the response to each request.
+class ScopedMockPluginInfoFilter : public IPC::Listener, public IPC::Sender {
+ public:
+ explicit ScopedMockPluginInfoFilter(
+ content::MockRenderThread* mock_render_thread)
+ : sink_(mock_render_thread->sink()), sender_(mock_render_thread) {
+ sink_.AddFilter(this);
+ }
+ ~ScopedMockPluginInfoFilter() { sink_.RemoveFilter(this); }
Bernhard Bauer 2014/10/29 09:53:05 I think this should be override?
jbroman 2014/10/29 17:14:43 Done.
+
+ bool OnMessageReceived(const IPC::Message& message) override {
+ IPC_BEGIN_MESSAGE_MAP(ScopedMockPluginInfoFilter, message)
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetPluginInfo, OnGetPluginInfo)
+ IPC_MESSAGE_UNHANDLED(return false)
+ IPC_END_MESSAGE_MAP()
+ return true;
+ }
+
+ bool Send(IPC::Message* message) override { return sender_->Send(message); }
+
+ MOCK_METHOD5(OnGetPluginInfo,
+ void(int render_frame_id,
+ const GURL& url,
+ const GURL& top_origin_url,
+ const std::string& mime_type,
+ ChromeViewHostMsg_GetPluginInfo_Output* output));
+
+ private:
+ IPC::TestSink& sink_;
+ IPC::Sender* sender_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedMockPluginInfoFilter);
+};
+
+} // namespace
+
+class OverrideCreatePluginPlaceholderTest : public ChromeRenderViewTest {
+ protected:
+ void SetUp() override {
+ ChromeRenderViewTest::SetUp();
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnablePluginPlaceholderShadowDom);
+ }
+
+ content::RenderFrame* GetMainRenderFrame() const {
+ return view_->GetMainRenderFrame();
+ }
+
+ int GetRoutingID() const { return GetMainRenderFrame()->GetRoutingID(); }
+};
+
+TEST_F(OverrideCreatePluginPlaceholderTest, MissingPlugin) {
+ GURL url("http://www.example.com/example.swf");
+ std::string mime_type("application/x-shockwave-flash");
+
+ blink::WebPluginParams params;
+ params.url = url;
+ params.mimeType = base::ASCIIToUTF16(mime_type);
+
+ ChromeViewHostMsg_GetPluginInfo_Output output;
+ output.status.value = ChromeViewHostMsg_GetPluginInfo_Status::kNotFound;
+
+ ScopedMockPluginInfoFilter filter(render_thread_.get());
+#if defined(ENABLE_PLUGINS)
+ EXPECT_CALL(filter, OnGetPluginInfo(GetRoutingID(), url, _, mime_type, _))
+ .WillOnce(SetArgPointee<4>(output));
+#endif
+
+ blink::WebPluginPlaceholder* placeholder =
+ content_renderer_client_->OverrideCreatePluginPlaceholder(
+ GetMainRenderFrame(), GetMainFrame(), params);
+ EXPECT_TRUE(IsShadowDOMPlaceholderForMissingPlugin(placeholder));
+}
+
+TEST_F(OverrideCreatePluginPlaceholderTest, PluginFound) {
+ GURL url("http://www.example.com/example.swf");
+ std::string mime_type("application/x-shockwave-flash");
+
+ blink::WebPluginParams params;
+ params.url = url;
+ params.mimeType = base::ASCIIToUTF16(mime_type);
+
+ ChromeViewHostMsg_GetPluginInfo_Output output;
+ output.status.value = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed;
+
+ ScopedMockPluginInfoFilter filter(render_thread_.get());
+#if defined(ENABLE_PLUGINS)
+ EXPECT_CALL(filter, OnGetPluginInfo(GetRoutingID(), url, _, mime_type, _))
+ .WillOnce(SetArgPointee<4>(output));
+#endif
+
+ blink::WebPluginPlaceholder* placeholder =
+ content_renderer_client_->OverrideCreatePluginPlaceholder(
+ GetMainRenderFrame(), GetMainFrame(), params);
+ EXPECT_TRUE(placeholder == nullptr);
+}

Powered by Google App Engine
This is Rietveld 408576698