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

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: 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) {
mlamouri (slow - plz ping) 2016/07/30 17:46:06 style: - only one space before {public,protected,p
kdsilva 2016/08/01 12:42:44 Done.
89 // We're only interested in YouTube video embeds
90 if (request.headers.at("Host").find("youtube.com") == std::string::npos) {
mlamouri (slow - plz ping) 2016/07/30 17:46:06 style: this is missing indentation
kdsilva 2016/08/01 12:42:44 Done.
91 return;
92 }
mlamouri (slow - plz ping) 2016/07/30 17:46:06 style: remove the { }
kdsilva 2016/08/01 12:42:44 Done.
93
94 if (request.relative_url.find("/embed") != 0 ||
95 request.relative_url.find("?enablejsapi=1") != std::string::npos) {
mlamouri (slow - plz ping) 2016/07/30 17:46:06 style: `request` and `request` should be aligned
kdsilva 2016/08/01 12:42:44 Done.
96 return;
mlamouri (slow - plz ping) 2016/07/30 17:46:06 I think it would be fine to check for "/v" and "/e
kdsilva 2016/08/01 12:42:44 Done.
97 }
98
99 EXPECT_EQ(request.relative_url, expected_url_);
100 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
101 message_runner_->QuitClosure());
102 }
103
104 void WaitForYouTubeRequest() {
105 message_runner_ = new content::MessageLoopRunner();
106 message_runner_->Run();
107 }
108
109 void set_expected_url(std::string given) {
110 expected_url_ = given;
111 }
112
113 private:
114 std::string expected_url_;
115 scoped_refptr<content::MessageLoopRunner> message_runner_;
116 };
117
118 // These tests examine Youtube requests that use the Flash API and ensure that
119 // the requests have been modified to instead use HTML5.
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(base::Bind(
129 &ChromeContentRendererClientBrowserTest::MonitorRequestHandler, this));
130
131 GURL url(embedded_test_server()->GetURL("/flash_embeds.html"));
132
133 ui_test_utils::NavigateToURL(browser(), url);
134
135 content::WebContents* web_contents =
136 browser()->tab_strip_model()->GetActiveWebContents();
137 std::string port = std::to_string(embedded_test_server()->port());
138
139 // Valid URL, no parameters
140 std::string video_url = "http://www.youtube.com:" + port + "/v/deadbeef";
141 set_expected_url("/embed/deadbeef");
142 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
143 WaitForYouTubeRequest();
144
145 // Valid URL, enablejsapi=1
146 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?enablejsapi=1";
147 set_expected_url("/embed/deadbeef?enablejsapi=1");
148 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
149
150 // Valid URL, no parameters, subdomain
151 video_url = "http://www.foo.youtube.com:" + port + "/v/deadbeef";
152 set_expected_url("/embed/deadbeef");
153 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
154 WaitForYouTubeRequest();
155
156 // Valid URL, many parameters
157 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?start=4&fs=1";
158 set_expected_url("/embed/deadbeef?start=4&fs=1");
159 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
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(web_contents, "appendToDOM('" + video_url + "');"));
166 WaitForYouTubeRequest();
167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698