Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / renderer / chrome_content_renderer_client_browsertest.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/chrome_content_renderer_client.h"
6
7 #include <vector>
8
9 #include "base/command_line.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/render_messages.h"
12 #include "chrome/renderer/chrome_content_renderer_client.h"
13 #include "chrome/test/base/chrome_render_view_test.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "url/gurl.h"
16
17 typedef ChromeRenderViewTest InstantProcessNavigationTest;
18
19 // Tests that renderer-initiated navigations from an Instant render process get
20 // bounced back to the browser to be rebucketed into a non-Instant renderer if
21 // necessary.
22 TEST_F(InstantProcessNavigationTest, ForkForNavigationsFromInstantProcess) {
23   CommandLine::ForCurrentProcess()->AppendSwitch(switches::kInstantProcess);
24   bool unused;
25   ChromeContentRendererClient* client =
26       static_cast<ChromeContentRendererClient*>(content_renderer_client_.get());
27   EXPECT_TRUE(client->ShouldFork(
28       GetMainFrame(), GURL("http://foo"), "GET", false, false, &unused));
29 }
30
31 // Tests that renderer-initiated navigations from a non-Instant render process
32 // to potentially Instant URLs get bounced back to the browser to be rebucketed
33 // into an Instant renderer if necessary.
34 TEST_F(InstantProcessNavigationTest, ForkForNavigationsToSearchURLs) {
35   ChromeContentRendererClient* client =
36       static_cast<ChromeContentRendererClient*>(content_renderer_client_.get());
37   chrome_render_thread_->set_io_message_loop_proxy(
38       base::MessageLoopProxy::current());
39   client->RenderThreadStarted();
40   std::vector<GURL> search_urls;
41   search_urls.push_back(GURL("http://example.com/search"));
42   chrome_render_thread_->Send(new ChromeViewMsg_SetSearchURLs(
43       search_urls, GURL("http://example.com/newtab")));
44   bool unused;
45   EXPECT_TRUE(client->ShouldFork(
46       GetMainFrame(), GURL("http://example.com/newtab"), "GET", false, false,
47       &unused));
48   EXPECT_TRUE(client->ShouldFork(
49       GetMainFrame(), GURL("http://example.com/search?q=foo"), "GET", false,
50       false, &unused));
51   EXPECT_FALSE(client->ShouldFork(
52       GetMainFrame(), GURL("http://example.com/"), "GET", false, false,
53       &unused));
54 }