Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: chrome/browser/ui/search/instant_extended_interactive_uitest.cc

Issue 13877028: Renderer initiated navigations from non instant process should not fall into instant. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments & ensure InstantLoader pages start in the right SiteInstance. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <sstream> 5 #include <sstream>
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "content/public/browser/navigation_controller.h" 48 #include "content/public/browser/navigation_controller.h"
49 #include "content/public/browser/navigation_entry.h" 49 #include "content/public/browser/navigation_entry.h"
50 #include "content/public/browser/notification_service.h" 50 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/render_process_host.h" 51 #include "content/public/browser/render_process_host.h"
52 #include "content/public/browser/render_view_host.h" 52 #include "content/public/browser/render_view_host.h"
53 #include "content/public/browser/site_instance.h" 53 #include "content/public/browser/site_instance.h"
54 #include "content/public/browser/url_data_source.h" 54 #include "content/public/browser/url_data_source.h"
55 #include "content/public/browser/web_contents.h" 55 #include "content/public/browser/web_contents.h"
56 #include "content/public/browser/web_contents_view.h" 56 #include "content/public/browser/web_contents_view.h"
57 #include "content/public/common/bindings_policy.h" 57 #include "content/public/common/bindings_policy.h"
58 #include "content/public/common/renderer_preferences.h"
58 #include "content/public/test/browser_test_utils.h" 59 #include "content/public/test/browser_test_utils.h"
59 #include "content/public/test/test_utils.h" 60 #include "content/public/test/test_utils.h"
60 #include "third_party/skia/include/core/SkBitmap.h" 61 #include "third_party/skia/include/core/SkBitmap.h"
61 62
62 namespace { 63 namespace {
63 64
64 // Creates a bitmap of the specified color. Caller takes ownership. 65 // Creates a bitmap of the specified color. Caller takes ownership.
65 gfx::Image CreateBitmap(SkColor color) { 66 gfx::Image CreateBitmap(SkColor color) {
66 SkBitmap thumbnail; 67 SkBitmap thumbnail;
67 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); 68 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4);
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 1917
1917 SendDownArrow(); 1918 SendDownArrow();
1918 EXPECT_EQ("result 1", GetOmniboxText()); 1919 EXPECT_EQ("result 1", GetOmniboxText());
1919 1920
1920 // Press Enter. 1921 // Press Enter.
1921 browser()->window()->GetLocationBar()->AcceptInput(); 1922 browser()->window()->GetLocationBar()->AcceptInput();
1922 1923
1923 // Confirm that the Instant overlay was NOT committed. 1924 // Confirm that the Instant overlay was NOT committed.
1924 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); 1925 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents());
1925 } 1926 }
1927
1928 // Test that renderer initiated navigations to an instant URL from a non
1929 // Instant page do not end up in an Instant process if they are bounced to the
1930 // browser.
1931 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1932 RendererInitiatedNavigationNotInInstantProcess) {
1933 InstantService* instant_service =
1934 InstantServiceFactory::GetForProfile(browser()->profile());
1935 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
1936
1937 // Setup Instant.
1938 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
1939 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
1940
1941 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
1942 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1943
1944 // Don't use https server for the non instant URL so that the browser uses
1945 // different RenderViews.
1946 GURL non_instant_url = test_server()->GetURL("files/simple.html");
1947 ui_test_utils::NavigateToURLWithDisposition(
1948 browser(),
1949 non_instant_url,
1950 CURRENT_TAB,
1951 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1952 content::WebContents* contents =
1953 browser()->tab_strip_model()->GetActiveWebContents();
1954 EXPECT_FALSE(instant_service->IsInstantProcess(
1955 contents->GetRenderProcessHost()->GetID()));
1956 EXPECT_EQ(non_instant_url, contents->GetURL());
1957
1958 int old_render_view_id = contents->GetRenderViewHost()->GetRoutingID();
1959 int old_render_process_id = contents->GetRenderProcessHost()->GetID();
1960
1961 std::string instant_url_with_query = instant_url().spec() + "q=3";
1962 std::string add_link_script = base::StringPrintf(
1963 "var a = document.createElement('a');"
1964 "a.id = 'toClick';"
1965 "a.href = '%s';"
1966 "document.body.appendChild(a);",
1967 instant_url_with_query.c_str());
1968 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script));
1969
1970 // Ensure that navigations are bounced to the browser.
1971 contents->GetMutableRendererPrefs()->browser_handles_all_top_level_requests =
1972 true;
1973 contents->GetRenderViewHost()->SyncRendererPrefs();
1974
1975 content::WindowedNotificationObserver observer(
1976 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
1977 content::NotificationService::AllSources());
1978 EXPECT_TRUE(content::ExecuteScript(
1979 contents, "document.getElementById('toClick').click();"));
1980 observer.Wait();
1981
1982 EXPECT_EQ(1, browser()->tab_strip_model()->count());
1983 contents = browser()->tab_strip_model()->GetActiveWebContents();
1984 EXPECT_FALSE(instant_service->IsInstantProcess(
1985 contents->GetRenderProcessHost()->GetID()));
1986 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL());
1987 int new_render_view_id = contents->GetRenderViewHost()->GetRoutingID();
1988 int new_render_process_id = contents->GetRenderProcessHost()->GetID();
1989
1990 EXPECT_TRUE(old_render_process_id != new_render_process_id ||
1991 old_render_view_id != new_render_view_id);
1992 }
1993
1994 // Test that renderer initiated navigations to an Instant URL from an
1995 // Instant process end up in an Instant process.
1996 IN_PROC_BROWSER_TEST_F(InstantExtendedTest,
1997 RendererInitiatedNavigationInInstantProcess) {
1998 InstantService* instant_service =
1999 InstantServiceFactory::GetForProfile(browser()->profile());
2000 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
2001
2002 // Setup Instant.
2003 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
2004 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport();
2005
2006 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
2007 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2008
2009 ui_test_utils::NavigateToURLWithDisposition(
2010 browser(),
2011 instant_url(),
2012 CURRENT_TAB,
2013 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
2014 content::WebContents* contents =
2015 browser()->tab_strip_model()->GetActiveWebContents();
2016 EXPECT_TRUE(instant_service->IsInstantProcess(
2017 contents->GetRenderProcessHost()->GetID()));
2018
2019 std::string instant_url_with_query = instant_url().spec() + "q=3";
2020 std::string add_link_script = base::StringPrintf(
2021 "var a = document.createElement('a');"
2022 "a.id = 'toClick';"
2023 "a.href = '%s';"
2024 "document.body.appendChild(a);",
2025 instant_url_with_query.c_str());
2026 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script));
2027
2028 content::WindowedNotificationObserver observer(
2029 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
2030 content::NotificationService::AllSources());
2031 EXPECT_TRUE(content::ExecuteScript(
2032 contents, "document.getElementById('toClick').click();"));
2033 observer.Wait();
2034
2035 EXPECT_EQ(1, browser()->tab_strip_model()->count());
2036 contents = browser()->tab_strip_model()->GetActiveWebContents();
2037 EXPECT_TRUE(instant_service->IsInstantProcess(
2038 contents->GetRenderProcessHost()->GetID()));
2039 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL());
2040 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698