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

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

Issue 2424293002: Fix <object data=> YouTube Flash rewrites. (Closed)
Patch Set: Changed the setup method to the one running on the main thread? 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, 73 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false,
74 &unused)); 74 &unused));
75 EXPECT_TRUE(client->ShouldFork( 75 EXPECT_TRUE(client->ShouldFork(
76 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, 76 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false,
77 false, &unused)); 77 false, &unused));
78 EXPECT_FALSE(client->ShouldFork( 78 EXPECT_FALSE(client->ShouldFork(
79 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, 79 GetMainFrame(), GURL("http://example.com/"), "GET", false, false,
80 &unused)); 80 &unused));
81 } 81 }
82 82
83 class ChromeContentRendererClientBrowserTest : public InProcessBrowserTest { 83 // The tests below examine Youtube requests that use the Flash API and ensure
84 // that the requests have been modified to instead use HTML5. The tests also
85 // check the MIME type of the request to ensure that it is "text/html".
86 namespace {
87
88 struct FlashEmbedsTestData {
89 std::string name;
90 std::string host;
91 std::string path;
92 std::string type;
93 std::string expected_url;
94 };
95
96 const FlashEmbedsTestData kFlashEmbedsTestData[] = {
97 {
98 "Valid URL, no parameters",
99 "www.youtube.com",
100 "/v/deadbeef",
101 "application/x-shockwave-flash",
102 "/embed/deadbeef"
103 },
104 {
105 "Valid URL, no parameters, subdomain",
106 "www.foo.youtube.com",
107 "/v/deadbeef",
108 "application/x-shockwave-flash",
109 "/embed/deadbeef"
110 },
111 {
112 "Valid URL, many parameters",
113 "www.youtube.com",
114 "/v/deadbeef?start=4&fs=1",
115 "application/x-shockwave-flash",
116 "/embed/deadbeef?start=4&fs=1"
117 },
118 {
119 "Invalid parameter construct, many parameters",
120 "www.youtube.com",
121 "/v/deadbeef&bar=4&foo=6",
122 "application/x-shockwave-flash",
123 "/embed/deadbeef?bar=4&foo=6"
124 },
125 {
126 "Valid URL, enablejsapi=1",
127 "www.youtube.com",
128 "/v/deadbeef?enablejsapi=1",
129 "",
130 "/v/deadbeef?enablejsapi=1"
131 }
132 };
133
134 } // namespace
135
136 class ChromeContentRendererClientBrowserTest :
137 public InProcessBrowserTest,
138 public ::testing::WithParamInterface<FlashEmbedsTestData> {
84 public: 139 public:
85 void MonitorRequestHandler(const net::test_server::HttpRequest& request) { 140 void MonitorRequestHandler(const net::test_server::HttpRequest& request) {
86 // We're only interested in YouTube video embeds 141 // We're only interested in YouTube video embeds
87 if (request.headers.at("Host").find("youtube.com") == std::string::npos) 142 if (request.headers.at("Host").find("youtube.com") == std::string::npos)
88 return; 143 return;
89 144
90 if (request.relative_url.find("/embed") != 0 && 145 if (request.relative_url.find("/embed") != 0 &&
91 request.relative_url.find("/v") != 0) 146 request.relative_url.find("/v") != 0)
92 return; 147 return;
93 148
94 auto type = request.headers.find("Accept"); 149 auto type = request.headers.find("Accept");
95 EXPECT_NE(std::string::npos, type->second.find("text/html")); 150 EXPECT_NE(std::string::npos, type->second.find("text/html"))
151 << "Type is not text/html for test " << GetParam().name;
96 152
97 EXPECT_EQ(request.relative_url, expected_url_); 153 EXPECT_EQ(request.relative_url, GetParam().expected_url)
154 << "URL is wrong for test " << GetParam().name;
98 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 155 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
99 message_runner_->QuitClosure()); 156 message_runner_->QuitClosure());
100 } 157 }
101 158
102 void WaitForYouTubeRequest() { 159 void WaitForYouTubeRequest() {
103 message_runner_ = new content::MessageLoopRunner();
104 message_runner_->Run(); 160 message_runner_->Run();
105 } 161 }
106 162
107 void set_expected_url(std::string given) { expected_url_ = given; } 163 void SetUpOnMainThread() override {
164 ASSERT_TRUE(embedded_test_server()->Start());
165
166 host_resolver()->AddRule("*", "127.0.0.1");
167
168 embedded_test_server()->ServeFilesFromSourceDirectory(
169 base::FilePath(kDocRoot));
170 embedded_test_server()->RegisterRequestMonitor(base::Bind(
171 &ChromeContentRendererClientBrowserTest::MonitorRequestHandler,
172 base::Unretained(this)));
173 message_runner_ = new content::MessageLoopRunner();
174 }
108 175
109 private: 176 private:
110 std::string expected_url_;
111 scoped_refptr<content::MessageLoopRunner> message_runner_; 177 scoped_refptr<content::MessageLoopRunner> message_runner_;
112 }; 178 };
113 179
114 // These tests examine Youtube requests that use the Flash API and ensure that 180 IN_PROC_BROWSER_TEST_P(ChromeContentRendererClientBrowserTest,
115 // 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".
117 IN_PROC_BROWSER_TEST_F(ChromeContentRendererClientBrowserTest,
118 RewriteYouTubeFlashEmbed) { 181 RewriteYouTubeFlashEmbed) {
119 ASSERT_TRUE(embedded_test_server()->Start());
120
121 host_resolver()->AddRule("*", "127.0.0.1");
122
123 embedded_test_server()->ServeFilesFromSourceDirectory(
124 base::FilePath(kDocRoot));
125 embedded_test_server()->RegisterRequestMonitor(
126 base::Bind(&ChromeContentRendererClientBrowserTest::MonitorRequestHandler,
127 base::Unretained(this)));
128
129 GURL url(embedded_test_server()->GetURL("/flash_embeds.html")); 182 GURL url(embedded_test_server()->GetURL("/flash_embeds.html"));
130
131 ui_test_utils::NavigateToURL(browser(), url); 183 ui_test_utils::NavigateToURL(browser(), url);
132
133 content::WebContents* web_contents = 184 content::WebContents* web_contents =
134 browser()->tab_strip_model()->GetActiveWebContents(); 185 browser()->tab_strip_model()->GetActiveWebContents();
135 std::string port = std::to_string(embedded_test_server()->port()); 186 std::string port = std::to_string(embedded_test_server()->port());
136 187
137 // Valid URL, no parameters 188 std::string video_url =
138 std::string video_url = "http://www.youtube.com:" + port + "/v/deadbeef"; 189 "http://" + GetParam().host + ":" + port + GetParam().path;
139 std::string mime_type = "application/x-shockwave-flash"; 190 EXPECT_TRUE(ExecuteScript(web_contents,
140 set_expected_url("/embed/deadbeef"); 191 "appendEmbedToDOM('" + video_url + "','" + GetParam().type + "');"));
141 EXPECT_TRUE(ExecuteScript(
142 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
143 WaitForYouTubeRequest();
144
145 // Valid URL, no parameters, subdomain
146 video_url = "http://www.foo.youtube.com:" + port + "/v/deadbeef";
147 set_expected_url("/embed/deadbeef");
148 EXPECT_TRUE(ExecuteScript(
149 web_contents, "appendToDOM('" + video_url + "','" + mime_type + "');"));
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(); 192 WaitForYouTubeRequest();
173 } 193 }
194
195 IN_PROC_BROWSER_TEST_P(ChromeContentRendererClientBrowserTest,
196 RewriteYouTubeFlashEmbedObject) {
197 GURL url(embedded_test_server()->GetURL("/flash_embeds.html"));
198 ui_test_utils::NavigateToURL(browser(), url);
199 content::WebContents* web_contents =
200 browser()->tab_strip_model()->GetActiveWebContents();
201 std::string port = std::to_string(embedded_test_server()->port());
202
203 std::string video_url =
204 "http://" + GetParam().host + ":" + port + GetParam().path;
205 EXPECT_TRUE(ExecuteScript(web_contents,
206 "appendDataEmbedToDOM('" + video_url + "','" + GetParam().type + "');"));
207 WaitForYouTubeRequest();
208 }
209
210 INSTANTIATE_TEST_CASE_P(
211 FlashEmbeds,
212 ChromeContentRendererClientBrowserTest,
213 ::testing::ValuesIn(kFlashEmbedsTestData));
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