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

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

Issue 2416253002: Fix <object data=> YouTube Flash rewrites. (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/flash_embeds.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void MonitorRequestHandler(const net::test_server::HttpRequest& request) { 85 void MonitorRequestHandler(const net::test_server::HttpRequest& request) {
86 // We're only interested in YouTube video embeds 86 // We're only interested in YouTube video embeds
87 if (request.headers.at("Host").find("youtube.com") == std::string::npos) 87 if (request.headers.at("Host").find("youtube.com") == std::string::npos)
88 return; 88 return;
89 89
90 if (request.relative_url.find("/embed") != 0 && 90 if (request.relative_url.find("/embed") != 0 &&
91 request.relative_url.find("/v") != 0) 91 request.relative_url.find("/v") != 0)
92 return; 92 return;
93 93
94 auto type = request.headers.find("Accept"); 94 auto type = request.headers.find("Accept");
95 EXPECT_NE(std::string::npos, type->second.find("text/html")); 95 EXPECT_NE(std::string::npos, type->second.find("text/html"))
96 << "Type is not text/html for test " << test_name_;
96 97
97 EXPECT_EQ(request.relative_url, expected_url_); 98 EXPECT_EQ(request.relative_url, expected_url_)
99 << "URL is wrong for test " << test_name_;
98 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 100 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
99 message_runner_->QuitClosure()); 101 message_runner_->QuitClosure());
100 } 102 }
101 103
102 void WaitForYouTubeRequest() { 104 void WaitForYouTubeRequest() {
103 message_runner_ = new content::MessageLoopRunner(); 105 message_runner_ = new content::MessageLoopRunner();
104 message_runner_->Run(); 106 message_runner_->Run();
105 } 107 }
106 108
107 void set_expected_url(std::string given) { expected_url_ = given; } 109 void set_expected_url(const std::string& expected_url) {
110 expected_url_ = expected_url;
111 }
112
113 void set_test_name(const std::string& test_name) {
114 test_name_ = test_name;
115 }
108 116
109 private: 117 private:
118 std::string test_name_;
110 std::string expected_url_; 119 std::string expected_url_;
111 scoped_refptr<content::MessageLoopRunner> message_runner_; 120 scoped_refptr<content::MessageLoopRunner> message_runner_;
112 }; 121 };
113 122
114 // These tests examine Youtube requests that use the Flash API and ensure that 123 // These tests examine Youtube requests that use the Flash API and ensure that
115 // the requests have been modified to instead use HTML5. The tests also check 124 // the requests have been modified to instead use HTML5. The tests also check
116 // the MIME type of the request to ensure that it is "text/html". 125 // the MIME type of the request to ensure that it is "text/html".
117 IN_PROC_BROWSER_TEST_F(ChromeContentRendererClientBrowserTest, 126 IN_PROC_BROWSER_TEST_F(ChromeContentRendererClientBrowserTest,
118 RewriteYouTubeFlashEmbed) { 127 RewriteYouTubeFlashEmbed) {
128 struct TestData {
129 std::string name;
130 std::string host;
131 std::string path;
132 std::string type;
133 std::string expected_url;
134 } test_data[] = {
135 {
136 "Valid URL, no parameters",
137 "www.youtube.com",
138 "/v/deadbeef",
139 "application/x-shockwave-flash",
140 "/embed/deadbeef"
141 },
142 {
143 "Valid URL, no parameters, subdomain",
144 "www.foo.youtube.com",
145 "/v/deadbeef",
146 "application/x-shockwave-flash",
147 "/embed/deadbeef"
148 },
149 {
150 "Valid URL, many parameters",
151 "www.youtube.com",
152 "/v/deadbeef?start=4&fs=1",
153 "application/x-shockwave-flash",
154 "/embed/deadbeef?start=4&fs=1"
155 },
156 {
157 "Invalid parameter construct, many parameters",
158 "www.youtube.com",
159 "/v/deadbeef&bar=4&foo=6",
160 "application/x-shockwave-flash",
161 "/embed/deadbeef?bar=4&foo=6"
162 },
163 {
164 "Valid URL, enablejsapi=1",
165 "www.youtube.com",
166 "/v/deadbeef?enablejsapi=1",
167 "",
168 "/v/deadbeef?enablejsapi=1"
169 }
170 };
171
119 ASSERT_TRUE(embedded_test_server()->Start()); 172 ASSERT_TRUE(embedded_test_server()->Start());
120 173
121 host_resolver()->AddRule("*", "127.0.0.1"); 174 host_resolver()->AddRule("*", "127.0.0.1");
122 175
123 embedded_test_server()->ServeFilesFromSourceDirectory( 176 embedded_test_server()->ServeFilesFromSourceDirectory(
124 base::FilePath(kDocRoot)); 177 base::FilePath(kDocRoot));
125 embedded_test_server()->RegisterRequestMonitor( 178 embedded_test_server()->RegisterRequestMonitor(
126 base::Bind(&ChromeContentRendererClientBrowserTest::MonitorRequestHandler, 179 base::Bind(&ChromeContentRendererClientBrowserTest::MonitorRequestHandler,
127 base::Unretained(this))); 180 base::Unretained(this)));
128 181
129 GURL url(embedded_test_server()->GetURL("/flash_embeds.html")); 182 GURL url(embedded_test_server()->GetURL("/flash_embeds.html"));
130 183
131 ui_test_utils::NavigateToURL(browser(), url); 184 ui_test_utils::NavigateToURL(browser(), url);
132 185
133 content::WebContents* web_contents = 186 content::WebContents* web_contents =
134 browser()->tab_strip_model()->GetActiveWebContents(); 187 browser()->tab_strip_model()->GetActiveWebContents();
135 std::string port = std::to_string(embedded_test_server()->port()); 188 std::string port = std::to_string(embedded_test_server()->port());
136 189
137 // Valid URL, no parameters 190 for (auto data : test_data) {
138 std::string video_url = "http://www.youtube.com:" + port + "/v/deadbeef"; 191 std::string video_url = "http://" + data.host + ":" + port + data.path;
139 std::string mime_type = "application/x-shockwave-flash"; 192 set_expected_url(data.expected_url);
140 set_expected_url("/embed/deadbeef"); 193 set_test_name("<embed src= > " + data.name);
141 EXPECT_TRUE(ExecuteScript( 194 EXPECT_TRUE(ExecuteScript(web_contents,
142 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');")); 195 "appendEmbedToDOM('" + video_url + "','" + data.type + "');"));
143 WaitForYouTubeRequest(); 196 WaitForYouTubeRequest();
144 197
145 // Valid URL, no parameters, subdomain 198 set_test_name("<embed data= > " + data.name);
146 video_url = "http://www.foo.youtube.com:" + port + "/v/deadbeef"; 199 EXPECT_TRUE(ExecuteScript(web_contents,
147 set_expected_url("/embed/deadbeef"); 200 "appendDataEmbedToDOM('" + video_url + "','" + data.type + "');"));
148 EXPECT_TRUE(ExecuteScript( 201 WaitForYouTubeRequest();
149 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');")); 202 }
150 WaitForYouTubeRequest();
151
152 // Valid URL, many parameters
153 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?start=4&fs=1";
154 set_expected_url("/embed/deadbeef?start=4&fs=1");
155 EXPECT_TRUE(ExecuteScript(
156 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
157 WaitForYouTubeRequest();
158
159 // Invalid parameter construct, many parameters
160 video_url = "http://www.youtube.com:" + port + "/v/deadbeef&bar=4&foo=6";
161 set_expected_url("/embed/deadbeef?bar=4&foo=6");
162 EXPECT_TRUE(ExecuteScript(
163 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
164 WaitForYouTubeRequest();
165
166 // Valid URL, enablejsapi=1
167 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?enablejsapi=1";
168 mime_type = "";
169 set_expected_url("/v/deadbeef?enablejsapi=1");
170 EXPECT_TRUE(ExecuteScript(
171 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
172 WaitForYouTubeRequest();
173 } 203 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/flash_embeds.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698