| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "content/public/browser/navigation_controller.h" | 49 #include "content/public/browser/navigation_controller.h" |
| 50 #include "content/public/browser/navigation_entry.h" | 50 #include "content/public/browser/navigation_entry.h" |
| 51 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
| 52 #include "content/public/browser/render_process_host.h" | 52 #include "content/public/browser/render_process_host.h" |
| 53 #include "content/public/browser/render_view_host.h" | 53 #include "content/public/browser/render_view_host.h" |
| 54 #include "content/public/browser/site_instance.h" | 54 #include "content/public/browser/site_instance.h" |
| 55 #include "content/public/browser/url_data_source.h" | 55 #include "content/public/browser/url_data_source.h" |
| 56 #include "content/public/browser/web_contents.h" | 56 #include "content/public/browser/web_contents.h" |
| 57 #include "content/public/browser/web_contents_view.h" | 57 #include "content/public/browser/web_contents_view.h" |
| 58 #include "content/public/common/bindings_policy.h" | 58 #include "content/public/common/bindings_policy.h" |
| 59 #include "content/public/common/renderer_preferences.h" |
| 59 #include "content/public/test/browser_test_utils.h" | 60 #include "content/public/test/browser_test_utils.h" |
| 60 #include "content/public/test/test_utils.h" | 61 #include "content/public/test/test_utils.h" |
| 61 #include "third_party/skia/include/core/SkBitmap.h" | 62 #include "third_party/skia/include/core/SkBitmap.h" |
| 62 | 63 |
| 63 namespace { | 64 namespace { |
| 64 | 65 |
| 65 // Creates a bitmap of the specified color. Caller takes ownership. | 66 // Creates a bitmap of the specified color. Caller takes ownership. |
| 66 gfx::Image CreateBitmap(SkColor color) { | 67 gfx::Image CreateBitmap(SkColor color) { |
| 67 SkBitmap thumbnail; | 68 SkBitmap thumbnail; |
| 68 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); | 69 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); |
| (...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 | 2043 |
| 2043 SendDownArrow(); | 2044 SendDownArrow(); |
| 2044 EXPECT_EQ("result 1", GetOmniboxText()); | 2045 EXPECT_EQ("result 1", GetOmniboxText()); |
| 2045 | 2046 |
| 2046 // Press Enter. | 2047 // Press Enter. |
| 2047 browser()->window()->GetLocationBar()->AcceptInput(); | 2048 browser()->window()->GetLocationBar()->AcceptInput(); |
| 2048 | 2049 |
| 2049 // Confirm that the Instant overlay was NOT committed. | 2050 // Confirm that the Instant overlay was NOT committed. |
| 2050 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); | 2051 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
| 2051 } | 2052 } |
| 2053 |
| 2054 // Test that renderer initiated navigations to an instant URL from a non |
| 2055 // Instant page do not end up in an Instant process if they are bounced to the |
| 2056 // browser. |
| 2057 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 2058 RendererInitiatedNavigationNotInInstantProcess) { |
| 2059 InstantService* instant_service = |
| 2060 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 2061 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
| 2062 |
| 2063 // Setup Instant. |
| 2064 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2065 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2066 |
| 2067 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 2068 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2069 |
| 2070 // Don't use https server for the non instant URL so that the browser uses |
| 2071 // different RenderViews. |
| 2072 GURL non_instant_url = test_server()->GetURL("files/simple.html"); |
| 2073 ui_test_utils::NavigateToURLWithDisposition( |
| 2074 browser(), |
| 2075 non_instant_url, |
| 2076 CURRENT_TAB, |
| 2077 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 2078 content::WebContents* contents = |
| 2079 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2080 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 2081 contents->GetRenderProcessHost()->GetID())); |
| 2082 EXPECT_EQ(non_instant_url, contents->GetURL()); |
| 2083 |
| 2084 int old_render_view_id = contents->GetRenderViewHost()->GetRoutingID(); |
| 2085 int old_render_process_id = contents->GetRenderProcessHost()->GetID(); |
| 2086 |
| 2087 std::string instant_url_with_query = instant_url().spec() + "q=3"; |
| 2088 std::string add_link_script = base::StringPrintf( |
| 2089 "var a = document.createElement('a');" |
| 2090 "a.id = 'toClick';" |
| 2091 "a.href = '%s';" |
| 2092 "document.body.appendChild(a);", |
| 2093 instant_url_with_query.c_str()); |
| 2094 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script)); |
| 2095 |
| 2096 // Ensure that navigations are bounced to the browser. |
| 2097 contents->GetMutableRendererPrefs()->browser_handles_all_top_level_requests = |
| 2098 true; |
| 2099 contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 2100 |
| 2101 content::WindowedNotificationObserver observer( |
| 2102 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 2103 content::NotificationService::AllSources()); |
| 2104 EXPECT_TRUE(content::ExecuteScript( |
| 2105 contents, "document.getElementById('toClick').click();")); |
| 2106 observer.Wait(); |
| 2107 |
| 2108 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2109 contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2110 EXPECT_FALSE(instant_service->IsInstantProcess( |
| 2111 contents->GetRenderProcessHost()->GetID())); |
| 2112 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); |
| 2113 int new_render_view_id = contents->GetRenderViewHost()->GetRoutingID(); |
| 2114 int new_render_process_id = contents->GetRenderProcessHost()->GetID(); |
| 2115 |
| 2116 EXPECT_TRUE(old_render_process_id != new_render_process_id || |
| 2117 old_render_view_id != new_render_view_id); |
| 2118 } |
| 2119 |
| 2120 // Test that renderer initiated navigations to an Instant URL from an |
| 2121 // Instant process end up in an Instant process. |
| 2122 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, |
| 2123 RendererInitiatedNavigationInInstantProcess) { |
| 2124 InstantService* instant_service = |
| 2125 InstantServiceFactory::GetForProfile(browser()->profile()); |
| 2126 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
| 2127 |
| 2128 // Setup Instant. |
| 2129 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 2130 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); |
| 2131 |
| 2132 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 2133 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2134 |
| 2135 ui_test_utils::NavigateToURLWithDisposition( |
| 2136 browser(), |
| 2137 instant_url(), |
| 2138 CURRENT_TAB, |
| 2139 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 2140 content::WebContents* contents = |
| 2141 browser()->tab_strip_model()->GetActiveWebContents(); |
| 2142 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 2143 contents->GetRenderProcessHost()->GetID())); |
| 2144 |
| 2145 std::string instant_url_with_query = instant_url().spec() + "q=3"; |
| 2146 std::string add_link_script = base::StringPrintf( |
| 2147 "var a = document.createElement('a');" |
| 2148 "a.id = 'toClick';" |
| 2149 "a.href = '%s';" |
| 2150 "document.body.appendChild(a);", |
| 2151 instant_url_with_query.c_str()); |
| 2152 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script)); |
| 2153 |
| 2154 content::WindowedNotificationObserver observer( |
| 2155 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 2156 content::NotificationService::AllSources()); |
| 2157 EXPECT_TRUE(content::ExecuteScript( |
| 2158 contents, "document.getElementById('toClick').click();")); |
| 2159 observer.Wait(); |
| 2160 |
| 2161 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 2162 contents = browser()->tab_strip_model()->GetActiveWebContents(); |
| 2163 EXPECT_TRUE(instant_service->IsInstantProcess( |
| 2164 contents->GetRenderProcessHost()->GetID())); |
| 2165 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); |
| 2166 } |
| OLD | NEW |