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

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.relative_url.find("/embed") != std::string::npos) {
mlamouri (slow - plz ping) 2016/07/28 19:46:54 Can you check that the host contains "youtube.com"
kdsilva 2016/07/29 17:59:06 Done.
91 EXPECT_EQ(request.relative_url, expected_url_);
92 content::BrowserThread::PostTask(
93 content::BrowserThread::UI,
94 FROM_HERE,
95 base::Bind(&ChromeContentRendererClientBrowserTest::QuitMessageRunne r,
96 base::Unretained(this)));
mlamouri (slow - plz ping) 2016/07/28 19:46:54 Looking at MessageLoopRunner class, it sounds like
kdsilva 2016/07/29 17:59:06 Done.
97 }
98 }
99
100 void QuitMessageRunner() {
101 message_runner_->Quit();
102 }
mlamouri (slow - plz ping) 2016/07/28 19:46:54 If you do the change above, I think you can remove
kdsilva 2016/07/29 17:59:06 Done.
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, RewriteYouTubeFla shEmbed) {
121 ASSERT_TRUE(embedded_test_server()->Start());
122
123 host_resolver()->AddRule("*", "127.0.0.1");
124
125 embedded_test_server()->ServeFilesFromSourceDirectory(base::FilePath(kDocRoot) );
126 embedded_test_server()->RegisterRequestMonitor(base::Bind(
127 &ChromeContentRendererClientBrowserTest::MonitorRequestHandler, this));
128
129 GURL url(embedded_test_server()->GetURL("/flash_embeds.html"));
130
131 ui_test_utils::NavigateToURL(browser(), url);
132
133 content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWe bContents();
134 std::string port = std::to_string(embedded_test_server()->port());
135
136 // Valid URL, no parameters
137 std::string video_url = "http://www.youtube.com:" + port + "/v/deadbeef";
138 set_expected_url("/embed/deadbeef");
139 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
140 WaitForYouTubeRequest();
141
142 // Valid URL, enablejsapi=1
143 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?enablejsapi=1";
144 set_expected_url("/embed/deadbeef?enablejsapi=1");
145 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
146
147 // Valid URL, no parameters, subdomain
148 video_url = "http://www.foo.youtube.com:" + port + "/v/deadbeef";
149 set_expected_url("/embed/deadbeef");
150 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
151 WaitForYouTubeRequest();
152
153 // Valid URL, many parameters
154 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?start=4&fs=1";
155 set_expected_url("/embed/deadbeef?start=4&fs=1");
156 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
157 WaitForYouTubeRequest();
158
159 // Invalid URL, many parameters
mlamouri (slow - plz ping) 2016/07/28 19:46:54 Can you rephrase to "invalid parameters construct"
kdsilva 2016/07/29 17:59:06 Done.
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(web_contents, "appendToDOM('" + video_url + "');"));
163 WaitForYouTubeRequest();
164
165 // Invalid URL, many parameters
mlamouri (slow - plz ping) 2016/07/28 19:46:54 Maybe you can drop this one?
kdsilva 2016/07/29 17:59:06 Done.
166 video_url = "http://www.youtube.com:" + port + "/v/deadbeef&bar=4&foo=6?baz=1" ;
167 set_expected_url("/embed/deadbeef?bar=4&foo=6&baz=1");
168 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');"));
169 WaitForYouTubeRequest();
170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698