Chromium Code Reviews| 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/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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 #include "content/public/browser/navigation_controller.h" | 46 #include "content/public/browser/navigation_controller.h" |
| 47 #include "content/public/browser/navigation_entry.h" | 47 #include "content/public/browser/navigation_entry.h" |
| 48 #include "content/public/browser/notification_service.h" | 48 #include "content/public/browser/notification_service.h" |
| 49 #include "content/public/browser/render_process_host.h" | 49 #include "content/public/browser/render_process_host.h" |
| 50 #include "content/public/browser/render_view_host.h" | 50 #include "content/public/browser/render_view_host.h" |
| 51 #include "content/public/browser/site_instance.h" | 51 #include "content/public/browser/site_instance.h" |
| 52 #include "content/public/browser/url_data_source.h" | 52 #include "content/public/browser/url_data_source.h" |
| 53 #include "content/public/browser/web_contents.h" | 53 #include "content/public/browser/web_contents.h" |
| 54 #include "content/public/browser/web_contents_view.h" | 54 #include "content/public/browser/web_contents_view.h" |
| 55 #include "content/public/common/bindings_policy.h" | 55 #include "content/public/common/bindings_policy.h" |
| 56 #include "content/public/common/renderer_preferences.h" | |
| 56 #include "content/public/test/browser_test_utils.h" | 57 #include "content/public/test/browser_test_utils.h" |
| 57 #include "content/public/test/test_utils.h" | 58 #include "content/public/test/test_utils.h" |
| 58 #include "third_party/skia/include/core/SkBitmap.h" | 59 #include "third_party/skia/include/core/SkBitmap.h" |
| 59 | 60 |
| 60 namespace { | 61 namespace { |
| 61 | 62 |
| 62 // Creates a bitmap of the specified color. Caller takes ownership. | 63 // Creates a bitmap of the specified color. Caller takes ownership. |
| 63 gfx::Image CreateBitmap(SkColor color) { | 64 gfx::Image CreateBitmap(SkColor color) { |
| 64 SkBitmap thumbnail; | 65 SkBitmap thumbnail; |
| 65 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); | 66 thumbnail.setConfig(SkBitmap::kARGB_8888_Config, 4, 4); |
| (...skipping 1788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1854 | 1855 |
| 1855 SendDownArrow(); | 1856 SendDownArrow(); |
| 1856 EXPECT_EQ("result 1", GetOmniboxText()); | 1857 EXPECT_EQ("result 1", GetOmniboxText()); |
| 1857 | 1858 |
| 1858 // Press Enter. | 1859 // Press Enter. |
| 1859 browser()->window()->GetLocationBar()->AcceptInput(); | 1860 browser()->window()->GetLocationBar()->AcceptInput(); |
| 1860 | 1861 |
| 1861 // Confirm that the Instant overlay was NOT committed. | 1862 // Confirm that the Instant overlay was NOT committed. |
| 1862 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); | 1863 EXPECT_NE(overlay, browser()->tab_strip_model()->GetActiveWebContents()); |
| 1863 } | 1864 } |
| 1865 | |
| 1866 // Test that renderer initiated navigations to an instant URL from a non | |
| 1867 // Instant page do not end up in an Instant process if they are bounced to the | |
| 1868 // browser. | |
| 1869 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | |
| 1870 RendererInitiatedNavigationNotInInstantProcess) { | |
| 1871 InstantService* instant_service = | |
| 1872 InstantServiceFactory::GetForProfile(browser()->profile()); | |
| 1873 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | |
| 1874 | |
| 1875 // Setup Instant. | |
| 1876 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 1877 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
| 1878 | |
| 1879 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 1880 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 1881 | |
| 1882 // Dont use https server for the non instant URL so that the browser uses | |
|
Charlie Reis
2013/05/01 01:17:54
nit: Don't
Shishir
2013/05/01 07:56:14
Done.
| |
| 1883 // differnt RenderViews. | |
|
Charlie Reis
2013/05/01 01:17:54
nit: different
Shishir
2013/05/01 07:56:14
Done.
| |
| 1884 GURL non_instant_url = test_server()->GetURL("files/simple.html"); | |
| 1885 ui_test_utils::NavigateToURLWithDisposition( | |
| 1886 browser(), | |
| 1887 non_instant_url, | |
| 1888 CURRENT_TAB, | |
| 1889 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 1890 content::WebContents* contents = | |
| 1891 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1892 EXPECT_FALSE(instant_service->IsInstantProcess( | |
| 1893 contents->GetRenderProcessHost()->GetID())); | |
| 1894 EXPECT_EQ(non_instant_url, contents->GetURL()); | |
| 1895 | |
| 1896 int old_render_view_id = contents->GetRenderViewHost()->GetRoutingID(); | |
| 1897 int old_render_process_id = contents->GetRenderProcessHost()->GetID(); | |
| 1898 | |
| 1899 std::string instant_url_with_query = instant_url().spec() + "q=3"; | |
| 1900 std::string add_link_script = base::StringPrintf( | |
| 1901 "var a = document.createElement('a');" | |
| 1902 "a.id = 'toClick';" | |
| 1903 "a.href = '%s';" | |
| 1904 "document.body.appendChild(a);", | |
| 1905 instant_url_with_query.c_str()); | |
| 1906 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script)); | |
| 1907 | |
| 1908 // Ensure that navigations are bounced to the browser. | |
| 1909 contents->GetMutableRendererPrefs()->browser_handles_all_top_level_requests | |
| 1910 = true; | |
|
Charlie Reis
2013/05/01 01:17:54
nit: Move = to previous line (should fit, and more
Shishir
2013/05/01 07:56:14
Done.
| |
| 1911 contents->GetRenderViewHost()->SyncRendererPrefs(); | |
| 1912 | |
| 1913 content::WindowedNotificationObserver observer( | |
| 1914 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 1915 content::NotificationService::AllSources()); | |
| 1916 EXPECT_TRUE(content::ExecuteScript( | |
| 1917 contents, "document.getElementById('toClick').click();")); | |
| 1918 observer.Wait(); | |
| 1919 | |
| 1920 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 1921 contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1922 EXPECT_FALSE(instant_service->IsInstantProcess( | |
| 1923 contents->GetRenderProcessHost()->GetID())); | |
| 1924 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); | |
| 1925 int new_render_view_id = contents->GetRenderViewHost()->GetRoutingID(); | |
| 1926 int new_render_process_id = contents->GetRenderProcessHost()->GetID(); | |
| 1927 | |
| 1928 EXPECT_TRUE(old_render_process_id != new_render_process_id || | |
| 1929 old_render_view_id != new_render_view_id); | |
| 1930 } | |
| 1931 | |
| 1932 // Test that renderer initiated navigations to an instant URL from a | |
| 1933 // Instant page end up in an Instant process. | |
|
Charlie Reis
2013/05/01 01:17:54
nit: // Instant process
Shishir
2013/05/01 07:56:14
Done.
| |
| 1934 IN_PROC_BROWSER_TEST_F(InstantExtendedTest, | |
| 1935 RendererInitiatedNavigationInInstantProcess) { | |
| 1936 InstantService* instant_service = | |
| 1937 InstantServiceFactory::GetForProfile(browser()->profile()); | |
| 1938 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | |
| 1939 | |
| 1940 // Setup Instant. | |
| 1941 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 1942 FocusOmniboxAndWaitForInstantOverlayAndNTPSupport(); | |
| 1943 | |
| 1944 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 1945 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 1946 | |
| 1947 ui_test_utils::NavigateToURLWithDisposition( | |
| 1948 browser(), | |
| 1949 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_TRUE(instant_service->IsInstantProcess( | |
| 1955 contents->GetRenderProcessHost()->GetID())); | |
| 1956 | |
| 1957 std::string instant_url_with_query = instant_url().spec() + "q=3"; | |
| 1958 std::string add_link_script = base::StringPrintf( | |
| 1959 "var a = document.createElement('a');" | |
| 1960 "a.id = 'toClick';" | |
| 1961 "a.href = '%s';" | |
| 1962 "document.body.appendChild(a);", | |
| 1963 instant_url_with_query.c_str()); | |
| 1964 EXPECT_TRUE(content::ExecuteScript(contents, add_link_script)); | |
| 1965 | |
| 1966 content::WindowedNotificationObserver observer( | |
| 1967 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 1968 content::NotificationService::AllSources()); | |
| 1969 EXPECT_TRUE(content::ExecuteScript( | |
| 1970 contents, "document.getElementById('toClick').click();")); | |
| 1971 observer.Wait(); | |
| 1972 | |
| 1973 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | |
| 1974 contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
| 1975 EXPECT_TRUE(instant_service->IsInstantProcess( | |
| 1976 contents->GetRenderProcessHost()->GetID())); | |
| 1977 EXPECT_EQ(GURL(instant_url_with_query), contents->GetURL()); | |
| 1978 } | |
| OLD | NEW |