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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client_browsertest.cc

Issue 2154233003: Rewrite YouTube Flash embeds (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 4 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 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 <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/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/render_messages.h" 16 #include "chrome/common/render_messages.h"
15 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
16 #include "chrome/renderer/chrome_content_renderer_client.h" 18 #include "chrome/renderer/chrome_content_renderer_client.h"
17 #include "chrome/test/base/chrome_render_view_test.h" 19 #include "chrome/test/base/chrome_render_view_test.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/common/content_constants.h" 22 #include "content/public/common/content_constants.h"
19 #include "content/public/renderer/render_frame.h" 23 #include "content/public/renderer/render_frame.h"
20 #include "content/public/renderer/render_view.h" 24 #include "content/public/renderer/render_view.h"
25 #include "content/public/test/browser_test_utils.h"
21 #include "content/public/test/mock_render_thread.h" 26 #include "content/public/test/mock_render_thread.h"
27 #include "content/public/test/test_utils.h"
22 #include "ipc/ipc_listener.h" 28 #include "ipc/ipc_listener.h"
23 #include "ipc/ipc_sender.h" 29 #include "ipc/ipc_sender.h"
24 #include "ipc/ipc_test_sink.h" 30 #include "ipc/ipc_test_sink.h"
31 #include "net/dns/mock_host_resolver.h"
32 #include "net/test/embedded_test_server/http_request.h"
33 #include "net/test/embedded_test_server/http_response.h"
25 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
26 #include "third_party/WebKit/public/web/WebLocalFrame.h" 35 #include "third_party/WebKit/public/web/WebLocalFrame.h"
27 #include "third_party/WebKit/public/web/WebPluginParams.h" 36 #include "third_party/WebKit/public/web/WebPluginParams.h"
28 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
29 #include "url/gurl.h" 38 #include "url/gurl.h"
30 39
31 using testing::_; 40 using testing::_;
32 using testing::SetArgPointee; 41 using testing::SetArgPointee;
33 42
34 typedef ChromeRenderViewTest InstantProcessNavigationTest; 43 typedef ChromeRenderViewTest InstantProcessNavigationTest;
35 44
45 const base::FilePath::CharType kDocRoot[] =
46 FILE_PATH_LITERAL("chrome/test/data");
47
36 // Tests that renderer-initiated navigations from an Instant render process get 48 // Tests that renderer-initiated navigations from an Instant render process get
37 // bounced back to the browser to be rebucketed into a non-Instant renderer if 49 // bounced back to the browser to be rebucketed into a non-Instant renderer if
38 // necessary. 50 // necessary.
39 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { 51 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) {
40 base::CommandLine::ForCurrentProcess()->AppendSwitch( 52 base::CommandLine::ForCurrentProcess()->AppendSwitch(
41 switches::kInstantProcess); 53 switches::kInstantProcess);
42 bool unused; 54 bool unused;
43 ChromeContentRendererClient* client = 55 ChromeContentRendererClient* client =
44 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); 56 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get());
45 EXPECT_TRUE(client->ShouldFork( 57 EXPECT_TRUE(client->ShouldFork(
(...skipping 17 matching lines...) Expand all
63 EXPECT_TRUE(client->ShouldFork( 75 EXPECT_TRUE(client->ShouldFork(
64 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, 76 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false,
65 &unused)); 77 &unused));
66 EXPECT_TRUE(client->ShouldFork( 78 EXPECT_TRUE(client->ShouldFork(
67 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, 79 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false,
68 false, &unused)); 80 false, &unused));
69 EXPECT_FALSE(client->ShouldFork( 81 EXPECT_FALSE(client->ShouldFork(
70 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, 82 GetMainFrame(), GURL("http://example.com/"), "GET", false, false,
71 &unused)); 83 &unused));
72 } 84 }
85
86 class ChromeContentRendererClientBrowserTest : public InProcessBrowserTest {
87 public:
88 void MonitorRequestHandler(const net::test_server::HttpRequest& request) {
89 // We're only interested in YouTube video embeds
90 if (request.headers.at("Host").find("youtube.com") == std::string::npos)
91 return;
92
93 if (request.relative_url.find("/embed") != 0 &&
94 request.relative_url.find("/v") != 0)
95 return;
96
97 auto type = request.headers.find("Accept");
98 EXPECT_NE(std::string::npos, type->second.find("text/html"));
99
100 EXPECT_EQ(request.relative_url, expected_url_);
101 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
102 message_runner_->QuitClosure());
103 }
104
105 void WaitForYouTubeRequest() {
106 message_runner_ = new content::MessageLoopRunner();
107 message_runner_->Run();
108 }
109
110 void set_expected_url(std::string given) { expected_url_ = given; }
111
112 private:
113 std::string expected_url_;
114 scoped_refptr<content::MessageLoopRunner> message_runner_;
115 };
116
117 // These tests examine Youtube requests that use the Flash API and ensure that
118 // the requests have been modified to instead use HTML5. The tests also check
119 // the MIME type of the request to ensure that it is "text/html".
120 IN_PROC_BROWSER_TEST_F(ChromeContentRendererClientBrowserTest,
121 RewriteYouTubeFlashEmbed) {
122 ASSERT_TRUE(embedded_test_server()->Start());
123
124 host_resolver()->AddRule("*", "127.0.0.1");
125
126 embedded_test_server()->ServeFilesFromSourceDirectory(
127 base::FilePath(kDocRoot));
128 embedded_test_server()->RegisterRequestMonitor(
129 base::Bind(&ChromeContentRendererClientBrowserTest::MonitorRequestHandler,
130 base::Unretained(this)));
131
132 GURL url(embedded_test_server()->GetURL("/flash_embeds.html"));
133
134 ui_test_utils::NavigateToURL(browser(), url);
135
136 content::WebContents* web_contents =
137 browser()->tab_strip_model()->GetActiveWebContents();
138 std::string port = std::to_string(embedded_test_server()->port());
139
140 // Valid URL, no parameters
141 std::string video_url = "http://www.youtube.com:" + port + "/v/deadbeef";
142 std::string mime_type = "application/x-shockwave-flash";
143 set_expected_url("/embed/deadbeef");
144 EXPECT_TRUE(ExecuteScript(
145 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
146 WaitForYouTubeRequest();
147
148 // Valid URL, no parameters, subdomain
149 video_url = "http://www.foo.youtube.com:" + port + "/v/deadbeef";
150 set_expected_url("/embed/deadbeef");
151 EXPECT_TRUE(ExecuteScript(
152 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
153 WaitForYouTubeRequest();
154
155 // Valid URL, many parameters
156 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?start=4&fs=1";
157 set_expected_url("/embed/deadbeef?start=4&fs=1");
158 EXPECT_TRUE(ExecuteScript(
159 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
160 WaitForYouTubeRequest();
161
162 // Invalid parameter construct, many parameters
163 video_url = "http://www.youtube.com:" + port + "/v/deadbeef&bar=4&foo=6";
164 set_expected_url("/embed/deadbeef?bar=4&foo=6");
165 EXPECT_TRUE(ExecuteScript(
166 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
167 WaitForYouTubeRequest();
168
169 // Valid URL, enablejsapi=1
170 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?enablejsapi=1";
171 mime_type = "";
172 set_expected_url("/v/deadbeef?enablejsapi=1");
173 EXPECT_TRUE(ExecuteScript(
174 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
175 WaitForYouTubeRequest();
176 }
OLDNEW
« no previous file with comments | « chrome/renderer/chrome_content_renderer_client.cc ('k') | chrome/renderer/chrome_content_renderer_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698