OLD | NEW |
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 <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/render_messages.h" | 14 #include "chrome/common/render_messages.h" |
15 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
16 #include "chrome/renderer/chrome_content_renderer_client.h" | 16 #include "chrome/renderer/chrome_content_renderer_client.h" |
17 #include "chrome/renderer/plugins/shadow_dom_plugin_placeholder.h" | |
18 #include "chrome/test/base/chrome_render_view_test.h" | 17 #include "chrome/test/base/chrome_render_view_test.h" |
19 #include "content/public/common/content_constants.h" | 18 #include "content/public/common/content_constants.h" |
20 #include "content/public/renderer/render_frame.h" | 19 #include "content/public/renderer/render_frame.h" |
21 #include "content/public/renderer/render_view.h" | 20 #include "content/public/renderer/render_view.h" |
22 #include "content/public/test/mock_render_thread.h" | 21 #include "content/public/test/mock_render_thread.h" |
23 #include "ipc/ipc_listener.h" | 22 #include "ipc/ipc_listener.h" |
24 #include "ipc/ipc_sender.h" | 23 #include "ipc/ipc_sender.h" |
25 #include "ipc/ipc_test_sink.h" | 24 #include "ipc/ipc_test_sink.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 EXPECT_TRUE(client->ShouldFork( | 63 EXPECT_TRUE(client->ShouldFork( |
65 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, | 64 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, |
66 &unused)); | 65 &unused)); |
67 EXPECT_TRUE(client->ShouldFork( | 66 EXPECT_TRUE(client->ShouldFork( |
68 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, | 67 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, |
69 false, &unused)); | 68 false, &unused)); |
70 EXPECT_FALSE(client->ShouldFork( | 69 EXPECT_FALSE(client->ShouldFork( |
71 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, | 70 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, |
72 &unused)); | 71 &unused)); |
73 } | 72 } |
74 | |
75 namespace { | |
76 | |
77 // Intercepts plugin info IPCs for a mock render thread within its scope, | |
78 // and allows tests to mock the response to each request. | |
79 class ScopedMockPluginInfoFilter : public IPC::Listener, public IPC::Sender { | |
80 public: | |
81 explicit ScopedMockPluginInfoFilter( | |
82 content::MockRenderThread* mock_render_thread) | |
83 : sink_(mock_render_thread->sink()), sender_(mock_render_thread) { | |
84 sink_.AddFilter(this); | |
85 } | |
86 ~ScopedMockPluginInfoFilter() override { sink_.RemoveFilter(this); } | |
87 | |
88 bool OnMessageReceived(const IPC::Message& message) override { | |
89 IPC_BEGIN_MESSAGE_MAP(ScopedMockPluginInfoFilter, message) | |
90 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_GetPluginInfo, OnGetPluginInfo) | |
91 IPC_MESSAGE_UNHANDLED(return false) | |
92 IPC_END_MESSAGE_MAP() | |
93 return true; | |
94 } | |
95 | |
96 bool Send(IPC::Message* message) override { return sender_->Send(message); } | |
97 | |
98 MOCK_METHOD5(OnGetPluginInfo, | |
99 void(int render_frame_id, | |
100 const GURL& url, | |
101 const GURL& top_origin_url, | |
102 const std::string& mime_type, | |
103 ChromeViewHostMsg_GetPluginInfo_Output* output)); | |
104 | |
105 private: | |
106 IPC::TestSink& sink_; | |
107 IPC::Sender* sender_; | |
108 DISALLOW_COPY_AND_ASSIGN(ScopedMockPluginInfoFilter); | |
109 }; | |
110 | |
111 } // namespace | |
112 | |
113 class CreatePluginPlaceholderTest : public ChromeRenderViewTest { | |
114 protected: | |
115 void SetUp() override { | |
116 ChromeRenderViewTest::SetUp(); | |
117 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
118 switches::kEnablePluginPlaceholderShadowDom); | |
119 } | |
120 | |
121 content::RenderFrame* GetMainRenderFrame() const { | |
122 return view_->GetMainRenderFrame(); | |
123 } | |
124 | |
125 int GetRoutingID() const { return GetMainRenderFrame()->GetRoutingID(); } | |
126 }; | |
127 | |
128 TEST_F(CreatePluginPlaceholderTest, MissingPlugin) { | |
129 GURL url("http://www.example.com/example.swf"); | |
130 std::string mime_type("application/x-shockwave-flash"); | |
131 | |
132 blink::WebPluginParams params; | |
133 params.url = url; | |
134 params.mimeType = base::ASCIIToUTF16(mime_type); | |
135 | |
136 ChromeViewHostMsg_GetPluginInfo_Output output; | |
137 output.status = ChromeViewHostMsg_GetPluginInfo_Status::kNotFound; | |
138 | |
139 ScopedMockPluginInfoFilter filter(render_thread_.get()); | |
140 #if defined(ENABLE_PLUGINS) | |
141 EXPECT_CALL(filter, OnGetPluginInfo(GetRoutingID(), url, _, mime_type, _)) | |
142 .WillOnce(SetArgPointee<4>(output)); | |
143 #endif | |
144 | |
145 scoped_ptr<blink::WebPluginPlaceholder> placeholder = | |
146 content_renderer_client_->CreatePluginPlaceholder( | |
147 GetMainRenderFrame(), GetMainFrame(), params); | |
148 ASSERT_NE(nullptr, placeholder); | |
149 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PLUGIN_NOT_SUPPORTED), | |
150 placeholder->message()); | |
151 } | |
152 | |
153 TEST_F(CreatePluginPlaceholderTest, PluginFound) { | |
154 GURL url("http://www.example.com/example.swf"); | |
155 std::string mime_type(content::kFlashPluginSwfMimeType); | |
156 | |
157 blink::WebPluginParams params; | |
158 params.url = url; | |
159 params.mimeType = base::ASCIIToUTF16(mime_type); | |
160 | |
161 ChromeViewHostMsg_GetPluginInfo_Output output; | |
162 output.status = ChromeViewHostMsg_GetPluginInfo_Status::kAllowed; | |
163 | |
164 ScopedMockPluginInfoFilter filter(render_thread_.get()); | |
165 #if defined(ENABLE_PLUGINS) | |
166 EXPECT_CALL(filter, OnGetPluginInfo(GetRoutingID(), url, _, mime_type, _)) | |
167 .WillOnce(SetArgPointee<4>(output)); | |
168 #endif | |
169 | |
170 scoped_ptr<blink::WebPluginPlaceholder> placeholder = | |
171 content_renderer_client_->CreatePluginPlaceholder( | |
172 GetMainRenderFrame(), GetMainFrame(), params); | |
173 EXPECT_EQ(nullptr, placeholder); | |
174 } | |
OLD | NEW |