| // Copyright 2013 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "chrome/renderer/chrome_content_renderer_client.h" |
| |
| #include <string> |
| #include <vector> |
| |
| #include "base/command_line.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/thread_task_runner_handle.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/render_messages.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "chrome/renderer/chrome_content_renderer_client.h" |
| #include "chrome/test/base/chrome_render_view_test.h" |
| #include "content/public/common/content_constants.h" |
| #include "content/public/renderer/render_frame.h" |
| #include "content/public/renderer/render_view.h" |
| #include "content/public/test/mock_render_thread.h" |
| #include "ipc/ipc_listener.h" |
| #include "ipc/ipc_sender.h" |
| #include "ipc/ipc_test_sink.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| #include "third_party/WebKit/public/web/WebPluginParams.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "url/gurl.h" |
| |
| using testing::_; |
| using testing::SetArgPointee; |
| |
| typedef ChromeRenderViewTest InstantProcessNavigationTest; |
| |
| // Tests that renderer-initiated navigations from an Instant render process get |
| // bounced back to the browser to be rebucketed into a non-Instant renderer if |
| // necessary. |
| TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) { |
| base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| switches::kInstantProcess); |
| bool unused; |
| ChromeContentRendererClient* client = |
| static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); |
| EXPECT_TRUE(client->ShouldFork( |
| GetMainFrame(), GURL("http://foo"), "GET", false, false, &unused)); |
| } |
| |
| // Tests that renderer-initiated navigations from a non-Instant render process |
| // to potentially Instant URLs get bounced back to the browser to be rebucketed |
| // into an Instant renderer if necessary. |
| TEST_F(InstantProcessNavigationTest, ForkForNavigationsToSearchURLs) { |
| ChromeContentRendererClient* client = |
| static_cast<ChromeContentRendererClient*>(content_renderer_client_.get()); |
| chrome_render_thread_->set_io_message_loop_proxy( |
| base::ThreadTaskRunnerHandle::Get()); |
| client->RenderThreadStarted(); |
| std::vector<GURL> search_urls; |
| search_urls.push_back(GURL("http://example.com/search")); |
| chrome_render_thread_->Send(new ChromeViewMsg_SetSearchURLs( |
| search_urls, GURL("http://example.com/newtab"))); |
| bool unused; |
| EXPECT_TRUE(client->ShouldFork( |
| GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false, |
| &unused)); |
| EXPECT_TRUE(client->ShouldFork( |
| GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false, |
| false, &unused)); |
| EXPECT_FALSE(client->ShouldFork( |
| GetMainFrame(), GURL("http://example.com/"), "GET", false, false, |
| &unused)); |
| } |