| 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" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/render_messages.h" | 16 #include "chrome/common/render_messages.h" |
| 17 #include "chrome/renderer/searchbox/searchbox.h" |
| 17 #include "chrome/test/base/chrome_render_view_test.h" | 18 #include "chrome/test/base/chrome_render_view_test.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/public/common/content_constants.h" | 21 #include "content/public/common/content_constants.h" |
| 21 #include "content/public/renderer/render_frame.h" | 22 #include "content/public/renderer/render_frame.h" |
| 22 #include "content/public/renderer/render_view.h" | 23 #include "content/public/renderer/render_view.h" |
| 23 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
| 24 #include "content/public/test/mock_render_thread.h" | 25 #include "content/public/test/mock_render_thread.h" |
| 25 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 26 #include "ipc/ipc_listener.h" | 27 #include "ipc/ipc_listener.h" |
| 27 #include "ipc/ipc_sender.h" | 28 #include "ipc/ipc_sender.h" |
| 28 #include "ipc/ipc_test_sink.h" | 29 #include "ipc/ipc_test_sink.h" |
| 29 #include "net/dns/mock_host_resolver.h" | 30 #include "net/dns/mock_host_resolver.h" |
| 30 #include "net/test/embedded_test_server/http_request.h" | 31 #include "net/test/embedded_test_server/http_request.h" |
| 31 #include "net/test/embedded_test_server/http_response.h" | 32 #include "net/test/embedded_test_server/http_response.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 33 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 34 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 34 #include "third_party/WebKit/public/web/WebPluginParams.h" | 35 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
| 36 | 37 |
| 37 using testing::_; | 38 using InstantProcessNavigationTest = ChromeRenderViewTest; |
| 38 using testing::SetArgPointee; | 39 using ChromeContentRendererClientSearchBoxTest = ChromeRenderViewTest; |
| 39 | |
| 40 typedef ChromeRenderViewTest InstantProcessNavigationTest; | |
| 41 | 40 |
| 42 const base::FilePath::CharType kDocRoot[] = | 41 const base::FilePath::CharType kDocRoot[] = |
| 43 FILE_PATH_LITERAL("chrome/test/data"); | 42 FILE_PATH_LITERAL("chrome/test/data"); |
| 44 | 43 |
| 44 const char kHtmlWithIframe[] ="<iframe srcdoc=\"Nothing here\"></iframe>"; |
| 45 |
| 45 // Tests that renderer-initiated navigations from an Instant render process get | 46 // Tests that renderer-initiated navigations from an Instant render process get |
| 46 // bounced back to the browser to be rebucketed into a non-Instant renderer if | 47 // bounced back to the browser to be rebucketed into a non-Instant renderer if |
| 47 // necessary. | 48 // necessary. |
| 48 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { | 49 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { |
| 49 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 50 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 50 switches::kInstantProcess); | 51 switches::kInstantProcess); |
| 51 bool unused; | 52 bool unused; |
| 52 ChromeContentRendererClient* client = | 53 ChromeContentRendererClient* client = |
| 53 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); | 54 static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); |
| 54 EXPECT_TRUE(client->ShouldFork( | 55 EXPECT_TRUE(client->ShouldFork( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 73 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, | 74 GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, |
| 74 &unused)); | 75 &unused)); |
| 75 EXPECT_TRUE(client->ShouldFork( | 76 EXPECT_TRUE(client->ShouldFork( |
| 76 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, | 77 GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, |
| 77 false, &unused)); | 78 false, &unused)); |
| 78 EXPECT_FALSE(client->ShouldFork( | 79 EXPECT_FALSE(client->ShouldFork( |
| 79 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, | 80 GetMainFrame(), GURL("http://example.com/"), "GET", false, false, |
| 80 &unused)); | 81 &unused)); |
| 81 } | 82 } |
| 82 | 83 |
| 84 TEST_F(ChromeContentRendererClientSearchBoxTest, RewriteThumbnailURL) { |
| 85 // Instantiate a SearchBox for the main render frame. |
| 86 content::RenderFrame* render_frame = |
| 87 content::RenderFrame::FromWebFrame(GetMainFrame()); |
| 88 new SearchBox(render_frame); |
| 89 |
| 90 // Load a page that contains an iframe. |
| 91 LoadHTML(kHtmlWithIframe); |
| 92 |
| 93 ChromeContentRendererClient client; |
| 94 |
| 95 // Create a thumbnail URL containing the correct render view ID and an |
| 96 // arbitrary instant restricted ID. |
| 97 GURL thumbnail_url(base::StringPrintf( |
| 98 "chrome-search:/thumb/%i/1", |
| 99 render_frame->GetRenderView()->GetRoutingID())); |
| 100 |
| 101 GURL result; |
| 102 // Make sure the SearchBox rewrites a thumbnail request from the main frame. |
| 103 EXPECT_TRUE(client.WillSendRequest(GetMainFrame(), ui::PAGE_TRANSITION_LINK, |
| 104 blink::WebURL(thumbnail_url), &result)); |
| 105 |
| 106 // Make sure the SearchBox rewrites a thumbnail request from the iframe. |
| 107 blink::WebFrame* child_frame = GetMainFrame()->firstChild(); |
| 108 ASSERT_TRUE(child_frame); |
| 109 ASSERT_TRUE(child_frame->isWebLocalFrame()); |
| 110 blink::WebLocalFrame* local_child = |
| 111 static_cast<blink::WebLocalFrame*>(child_frame); |
| 112 EXPECT_TRUE(client.WillSendRequest(local_child, ui::PAGE_TRANSITION_LINK, |
| 113 blink::WebURL(thumbnail_url), &result)); |
| 114 } |
| 115 |
| 83 // The tests below examine Youtube requests that use the Flash API and ensure | 116 // 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 | 117 // 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". | 118 // check the MIME type of the request to ensure that it is "text/html". |
| 86 namespace { | 119 namespace { |
| 87 | 120 |
| 88 struct FlashEmbedsTestData { | 121 struct FlashEmbedsTestData { |
| 89 std::string name; | 122 std::string name; |
| 90 std::string host; | 123 std::string host; |
| 91 std::string path; | 124 std::string path; |
| 92 std::string type; | 125 std::string type; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 "http://" + GetParam().host + ":" + port + GetParam().path; | 236 "http://" + GetParam().host + ":" + port + GetParam().path; |
| 204 EXPECT_TRUE(ExecuteScript(web_contents, | 237 EXPECT_TRUE(ExecuteScript(web_contents, |
| 205 "appendDataEmbedToDOM('" + video_url + "','" + GetParam().type + "');")); | 238 "appendDataEmbedToDOM('" + video_url + "','" + GetParam().type + "');")); |
| 206 WaitForYouTubeRequest(); | 239 WaitForYouTubeRequest(); |
| 207 } | 240 } |
| 208 | 241 |
| 209 INSTANTIATE_TEST_CASE_P( | 242 INSTANTIATE_TEST_CASE_P( |
| 210 FlashEmbeds, | 243 FlashEmbeds, |
| 211 ChromeContentRendererClientBrowserTest, | 244 ChromeContentRendererClientBrowserTest, |
| 212 ::testing::ValuesIn(kFlashEmbedsTestData)); | 245 ::testing::ValuesIn(kFlashEmbedsTestData)); |
| OLD | NEW |