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