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 void MonitorRequestHandler(const net::test_server::HttpRequest& request) { |
| 89 // We're only interested in YouTube video embeds |
| 90 if (request.headers.at("Host").find("youtube.com") == std::string::npos) |
| 91 return; |
| 92 |
| 93 if (request.relative_url.find("/embed") != 0 && |
| 94 request.relative_url.find("/v") != 0) |
| 95 return; |
| 96 |
| 97 EXPECT_EQ(request.relative_url, expected_url_); |
| 98 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, |
| 99 message_runner_->QuitClosure()); |
| 100 } |
| 101 |
| 102 void WaitForYouTubeRequest() { |
| 103 message_runner_ = new content::MessageLoopRunner(); |
| 104 message_runner_->Run(); |
| 105 } |
| 106 |
| 107 void set_expected_url(std::string given) { |
| 108 expected_url_ = given; |
| 109 } |
| 110 |
| 111 private: |
| 112 std::string expected_url_; |
| 113 scoped_refptr<content::MessageLoopRunner> message_runner_; |
| 114 }; |
| 115 |
| 116 // These tests examine Youtube requests that use the Flash API and ensure that |
| 117 // the requests have been modified to instead use HTML5. |
| 118 IN_PROC_BROWSER_TEST_F(ChromeContentRendererClientBrowserTest, |
| 119 RewriteYouTubeFlashEmbed) { |
| 120 ASSERT_TRUE(embedded_test_server()->Start()); |
| 121 |
| 122 host_resolver()->AddRule("*", "127.0.0.1"); |
| 123 |
| 124 embedded_test_server()->ServeFilesFromSourceDirectory( |
| 125 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 = |
| 134 browser()->tab_strip_model()->GetActiveWebContents(); |
| 135 std::string port = std::to_string(embedded_test_server()->port()); |
| 136 |
| 137 // Valid URL, no parameters |
| 138 std::string video_url = "http://www.youtube.com:" + port + "/v/deadbeef"; |
| 139 set_expected_url("/embed/deadbeef"); |
| 140 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); |
| 141 WaitForYouTubeRequest(); |
| 142 |
| 143 // Valid URL, enablejsapi=1 |
| 144 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?enablejsapi=1"; |
| 145 set_expected_url("/v/deadbeef?enablejsapi=1"); |
| 146 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); |
| 147 WaitForYouTubeRequest(); |
| 148 |
| 149 // Valid URL, no parameters, subdomain |
| 150 video_url = "http://www.foo.youtube.com:" + port + "/v/deadbeef"; |
| 151 set_expected_url("/embed/deadbeef"); |
| 152 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); |
| 153 WaitForYouTubeRequest(); |
| 154 |
| 155 // Valid URL, many parameters |
| 156 video_url = "http://www.youtube.com:" + port + "/v/deadbeef?start=4&fs=1"; |
| 157 set_expected_url("/embed/deadbeef?start=4&fs=1"); |
| 158 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); |
| 159 WaitForYouTubeRequest(); |
| 160 |
| 161 // Invalid parameter construct, many parameters |
| 162 video_url = "http://www.youtube.com:" + port + "/v/deadbeef&bar=4&foo=6"; |
| 163 set_expected_url("/embed/deadbeef?bar=4&foo=6"); |
| 164 EXPECT_TRUE(ExecuteScript(web_contents, "appendToDOM('" + video_url + "');")); |
| 165 WaitForYouTubeRequest(); |
| 166 } |
OLD | NEW |