Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 std::unique_ptr<net::test_server::HttpResponse> HandleRequest( | |
| 89 const net::test_server::HttpRequest& request) { | |
| 90 // We're only interested in YouTube video embeds | |
| 91 if (request.relative_url.find("embed") != std::string::npos) { | |
| 92 EXPECT_EQ(request.relative_url, expected_url_); | |
| 93 content::BrowserThread::PostTask( | |
| 94 content::BrowserThread::UI, | |
| 95 FROM_HERE, | |
| 96 base::Bind(&ChromeContentRendererClientBrowserTest::QuitMessageRunne r, | |
| 97 base::Unretained(this))); | |
| 98 } | |
| 99 | |
| 100 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( | |
| 101 new net::test_server::BasicHttpResponse()); | |
| 102 http_response->set_code(net::HTTP_OK); | |
| 103 return std::move(http_response); | |
| 104 } | |
| 105 | |
| 106 void QuitMessageRunner() { | |
| 107 message_runner_->Quit(); | |
| 108 } | |
| 109 | |
| 110 void RunMessageRunner() { | |
|
mlamouri (slow - plz ping)
2016/07/28 13:05:13
nit: maybe rename "WaitForYouTubeRequest()"? It wi
kdsilva
2016/07/28 15:17:17
Done.
| |
| 111 message_runner_ = new content::MessageLoopRunner(); | |
| 112 message_runner_->Run(); | |
| 113 } | |
| 114 | |
| 115 void SetExpectedURL(std::string given) { | |
|
mlamouri (slow - plz ping)
2016/07/28 13:05:12
style: set_expected_url()
kdsilva
2016/07/28 15:17:17
Done.
| |
| 116 expected_url_ = given; | |
| 117 } | |
| 118 | |
| 119 private: | |
| 120 std::string expected_url_; | |
| 121 scoped_refptr<content::MessageLoopRunner> message_runner_; | |
| 122 }; | |
| 123 | |
| 124 // These tests examine Youtube requests that use the Flash API and ensure that | |
| 125 // the requests have been modified to instead use HTML5. | |
| 126 IN_PROC_BROWSER_TEST_F(ChromeContentRendererClientBrowserTest, RewriteYouTubeFla shEmbedTest) { | |
|
mlamouri (slow - plz ping)
2016/07/28 13:05:13
No need to suffix with Test.
kdsilva
2016/07/28 15:17:17
Done.
| |
| 127 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTP); | |
|
mlamouri (slow - plz ping)
2016/07/28 13:05:12
Can you simply use embedded_test_server() ?
kdsilva
2016/07/28 15:17:17
Done.
| |
| 128 ASSERT_TRUE(https_server.Start()); | |
| 129 | |
| 130 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 131 | |
| 132 https_server.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); | |
| 133 https_server.RegisterRequestHandler(base::Bind( | |
|
mlamouri (slow - plz ping)
2016/07/28 13:05:12
Can you try to use the monitor function? We don't
kdsilva
2016/07/28 15:17:17
Done.
| |
| 134 &ChromeContentRendererClientBrowserTest::HandleRequest, this)); | |
| 135 | |
| 136 GURL url(https_server.GetURL("/flash_embeds.html")); | |
| 137 | |
| 138 ui_test_utils::NavigateToURL(browser(), url); | |
| 139 | |
| 140 content::WebContents* web_contents = browser()->tab_strip_model()->GetActiveWe bContents(); | |
| 141 std::string port = std::to_string(https_server.port()); | |
| 142 | |
| 143 // Valid URL, no parameters | |
| 144 std::string video_url = "http://www.youtube.com:" + port + "/v/cW44BpXpjYw"; | |
| 145 SetExpectedURL("/embed/cW44BpXpjYw"); | |
| 146 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); | |
| 147 RunMessageRunner(); | |
| 148 | |
| 149 // Valid URL, no parameters, subdomain | |
| 150 video_url = "http://www.foo.youtube.com:" + port + "/v/cW44BpXpjYw"; | |
| 151 SetExpectedURL("/embed/cW44BpXpjYw"); | |
| 152 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); | |
| 153 RunMessageRunner(); | |
| 154 | |
| 155 // Valid URL, one parameter | |
| 156 video_url = "http://www.youtube.com:" + port + "/v/cW44BpXpjYw?start=4"; | |
| 157 SetExpectedURL("/embed/cW44BpXpjYw?start=4"); | |
| 158 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); | |
| 159 RunMessageRunner(); | |
| 160 | |
| 161 // Valid URL, many parameters | |
| 162 video_url = "http://www.youtube.com:" + port + "/v/cW44BpXpjYw?start=4&fs=1"; | |
| 163 SetExpectedURL("/embed/cW44BpXpjYw?start=4&fs=1"); | |
| 164 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); | |
| 165 RunMessageRunner(); | |
| 166 | |
| 167 // Invalid URL, one parameter | |
| 168 video_url = "http://www.youtube.com:" + port + "/v/cW44BpXpjYw&foo=4"; | |
| 169 SetExpectedURL("/embed/cW44BpXpjYw?foo=4"); | |
| 170 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); | |
| 171 RunMessageRunner(); | |
| 172 | |
| 173 // Invalid URL, many parameters | |
| 174 video_url = "http://www.youtube.com:" + port + "/v/cW44BpXpjYw&bar=4&foo=6"; | |
| 175 SetExpectedURL("/embed/cW44BpXpjYw?bar=4&foo=6"); | |
| 176 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); | |
| 177 RunMessageRunner(); | |
| 178 | |
| 179 // Invalid URL, many parameters | |
|
mlamouri (slow - plz ping)
2016/07/28 13:05:12
I think you have too many tests here. Browsertests
kdsilva
2016/07/28 15:17:17
Done.
| |
| 180 video_url = "http://www.youtube.com:" + port + "/v/cW44BpXpjYw&bar=4&foo=6?baz =1"; | |
| 181 SetExpectedURL("/embed/cW44BpXpjYw?bar=4&foo=6&baz=1"); | |
| 182 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); | |
| 183 RunMessageRunner(); | |
| 184 } | |
| OLD | NEW |