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

Side by Side 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: missed deleting this in the previous patch set Created 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include <string>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/render_messages.h" 13 #include "chrome/common/render_messages.h"
14 #include "chrome/grit/generated_resources.h"
12 #include "chrome/renderer/chrome_content_renderer_client.h" 15 #include "chrome/renderer/chrome_content_renderer_client.h"
16 #include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h"
13 #include "chrome/test/base/chrome_render_view_test.h" 17 #include "chrome/test/base/chrome_render_view_test.h"
18 #include "content/public/renderer/render_frame.h"
19 #include "content/public/renderer/render_frame_observer.h"
20 #include "content/public/renderer/render_view.h"
21 #include "content/public/test/mock_render_thread.h"
22 #include "ipc/ipc_listener.h"
23 #include "ipc/ipc_sender.h"
24 #include "ipc/ipc_test_sink.h"
25 #include "testing/gmock/include/gmock/gmock.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h" 26 #include "third_party/WebKit/public/web/WebLocalFrame.h"
27 #include "third_party/WebKit/public/web/WebPluginParams.h"
28 #include "ui/base/l10n/l10n_util.h"
15 #include "url/gurl.h" 29 #include "url/gurl.h"
16 30
31 using testing::_;
32 using testing::SetArgPointee;
33
17 typedef ChromeRenderViewTest InstantProcessNavigationTest; 34 typedef ChromeRenderViewTest InstantProcessNavigationTest;
18 35
19 // Tests that renderer-initiated navigations from an Instant render process get 36 // Tests that renderer-initiated navigations from an Instant render process get
20 // bounced back to the browser to be rebucketed into a non-Instant renderer if 37 // bounced back to the browser to be rebucketed into a non-Instant renderer if
21 // necessary. 38 // necessary.
22 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { 39 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) {
23 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kInstantProcess); 40 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kInstantProcess);
24 bool unused; 41 bool unused;
25 ChromeContentRendererClient* client = 42 ChromeContentRendererClient* client =
26 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); 43 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get());
(...skipping 18 matching lines...) Expand all
45 EXPECT_TRUE(client->ShouldFork( 62 EXPECT_TRUE(client->ShouldFork(
46 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, 63 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false,
47 &unused)); 64 &unused));
48 EXPECT_TRUE(client->ShouldFork( 65 EXPECT_TRUE(client->ShouldFork(
49 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, 66 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false,
50 false, &unused)); 67 false, &unused));
51 EXPECT_FALSE(client->ShouldFork( 68 EXPECT_FALSE(client->ShouldFork(
52 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, 69 GetMainFrame(), GURL("http://example.com/"), "GET", false, false,
53 &unused)); 70 &unused));
54 } 71 }
72
73 namespace {
74
75 // Intercepts plugin info IPCs for a mock render thread within its scope,
76 // and allows tests to mock the response to each request.
77 class ScopedMockPluginInfoFilter : public IPC::Listener, public IPC::Sender {
78 public:
79 explicit ScopedMockPluginInfoFilter(
80 content::MockRenderThread* mock_render_thread)
81 : sink_(mock_render_thread->sink()), sender_(mock_render_thread) {
82 sink_.AddFilter(this);
83 }
84 ~ScopedMockPluginInfoFilter() override { sink_.RemoveFilter(this); }
85
86 bool OnMessageReceived(const IPC::Message& message) override {
87 IPC_BEGIN_MESSAGE_MAP(ScopedMockPluginInfoFilter, message)
88 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetPluginInfo, OnGetPluginInfo)
89 IPC_MESSAGE_UNHANDLED(return false)
90 IPC_END_MESSAGE_MAP()
91 return true;
92 }
93
94 bool Send(IPC::Message* message) override { return sender_->Send(message); }
95
96 MOCK_METHOD5(OnGetPluginInfo,
97 void(int render_frame_id,
98 const GURL& url,
99 const GURL& top_origin_url,
100 const std::string& mime_type,
101 ChromeViewHostMsg_GetPluginInfo_Output* output));
102
103 private:
104 IPC::TestSink& sink_;
105 IPC::Sender* sender_;
106 DISALLOW_COPY_AND_ASSIGN(ScopedMockPluginInfoFilter);
107 };
108
109 } // namespace
110
111 class CreatePluginPlaceholderTest : public ChromeRenderViewTest {
112 protected:
113 void SetUp() override {
114 ChromeRenderViewTest::SetUp();
115 CommandLine::ForCurrentProcess()->AppendSwitch(
116 switches::kEnablePluginPlaceholderShadowDom);
117 }
118
119 content::RenderFrame* GetMainRenderFrame() const {
120 return view_->GetMainRenderFrame();
121 }
122
123 int GetRoutingID() const { return GetMainRenderFrame()->GetRoutingID(); }
124 };
125
126 TEST_F(CreatePluginPlaceholderTest, MissingPlugin) {
127 GURL url("http://www.example.com/example.swf");
128 std::string mime_type("application/x-shockwave-flash");
129
130 blink::WebPluginParams params;
131 params.url = url;
132 params.mimeType = base::ASCIIToUTF16(mime_type);
133
134 ChromeViewHostMsg_GetPluginInfo_Output output;
135 output.status.value = ChromeViewHostMsg_GetPluginInfo_Status::kNotFound;
136
137 ScopedMockPluginInfoFilter filter(render_thread_.get());
138 #if defined(ENABLE_PLUGINS)
139 EXPECT_CALL(filter, OnGetPluginInfo(GetRoutingID(), url, _, mime_type, _))
140 .WillOnce(SetArgPointee<4>(output));
141 #endif
142
143 scoped_ptr<blink::WebPluginPlaceholder> placeholder =
144 content_renderer_client_->CreatePluginPlaceholder(
145 GetMainRenderFrame(), GetMainFrame(), params);
146 ASSERT_TRUE(placeholder != nullptr);
147 EXPECT_TRUE(placeholder->message() ==
Bernhard Bauer 2014/10/29 17:45:54 EXPECT_EQ should work here, right? It will give be
jbroman 2014/10/29 18:14:40 Erm, yes, of course. This was previously one EXPEC
148 l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED));
149 }
150
151 TEST_F(CreatePluginPlaceholderTest, PluginFound) {
152 GURL url("http://www.example.com/example.swf");
153 std::string mime_type("application/x-shockwave-flash");
154
155 blink::WebPluginParams params;
156 params.url = url;
157 params.mimeType = base::ASCIIToUTF16(mime_type);
158
159 ChromeViewHostMsg_GetPluginInfo_Output output;
160 output.status.value = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed;
161
162 ScopedMockPluginInfoFilter filter(render_thread_.get());
163 #if defined(ENABLE_PLUGINS)
164 EXPECT_CALL(filter, OnGetPluginInfo(GetRoutingID(), url, _, mime_type, _))
165 .WillOnce(SetArgPointee<4>(output));
166 #endif
167
168 scoped_ptr<blink::WebPluginPlaceholder> placeholder =
169 content_renderer_client_->CreatePluginPlaceholder(
170 GetMainRenderFrame(), GetMainFrame(), params);
171 EXPECT_TRUE(placeholder == nullptr);
172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698