1 // Copyright (c) 2012 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 "base/command_line.h" 6 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/common/chrome_switches.h" 9 #include "chrome/test/base/in_process_browser_test.h" 10 #include "chrome/test/base/ui_test_utils.h" 11 #include "content/public/browser/navigation_controller.h" 12 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/web_contents.h" 14 #include "content/public/common/content_switches.h" 15 #include "url/gurl.h" 16 17 namespace content { 18 19 class ChromeContentBrowserClientBrowserTest : public InProcessBrowserTest { 20 public: 21 // Returns the last committed navigation entry of the first tab. May be NULL 22 // if there is no such entry. 23 NavigationEntry* GetLastCommittedEntry() { 24 return browser()->tab_strip_model()->GetWebContentsAt(0)-> 25 GetController().GetLastCommittedEntry(); 26 } 27 }; 28 29 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 30 UberURLHandler_SettingsPage) { 31 const GURL url_short("chrome://settings/"); 32 const GURL url_long("chrome://chrome/settings/"); 33 34 ui_test_utils::NavigateToURL(browser(), url_short); 35 NavigationEntry* entry = GetLastCommittedEntry(); 36 37 ASSERT_TRUE(entry != NULL); 38 EXPECT_EQ(url_long, entry->GetURL()); 39 EXPECT_EQ(url_short, entry->GetVirtualURL()); 40 } 41 42 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 43 UberURLHandler_ContentSettingsPage) { 44 const GURL url_short("chrome://settings/content"); 45 const GURL url_long("chrome://chrome/settings/content"); 46 47 ui_test_utils::NavigateToURL(browser(), url_short); 48 NavigationEntry* entry = GetLastCommittedEntry(); 49 50 ASSERT_TRUE(entry != NULL); 51 EXPECT_EQ(url_long, entry->GetURL()); 52 EXPECT_EQ(url_short, entry->GetVirtualURL()); 53 } 54 55 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 56 UberURLHandler_AboutPage) { 57 const GURL url("chrome://chrome/"); 58 59 ui_test_utils::NavigateToURL(browser(), url); 60 NavigationEntry* entry = GetLastCommittedEntry(); 61 62 ASSERT_TRUE(entry != NULL); 63 EXPECT_EQ(url, entry->GetURL()); 64 EXPECT_EQ(url, entry->GetVirtualURL()); 65 } 66 67 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 68 UberURLHandler_EmptyHost) { 69 const GURL url("chrome://chrome//foo"); 70 71 ui_test_utils::NavigateToURL(browser(), url); 72 NavigationEntry* entry = GetLastCommittedEntry(); 73 74 ASSERT_TRUE(entry != NULL); 75 EXPECT_TRUE(entry->GetVirtualURL().is_valid()); 76 EXPECT_EQ(url, entry->GetVirtualURL()); 77 } 78 79 // Test that a basic navigation works in --site-per-process mode. This prevents 80 // regressions when that mode calls out into the ChromeContentBrowserClient, 81 // such as http://crbug.com/164223. 82 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, 83 SitePerProcessNavigation) { 84 CommandLine::ForCurrentProcess()->AppendSwitch( 85 switches::kSitePerProcess); 86 ASSERT_TRUE(test_server()->Start()); 87 const GURL url(test_server()->GetURL("files/title1.html")); 88 89 ui_test_utils::NavigateToURL(browser(), url); 90 NavigationEntry* entry = GetLastCommittedEntry(); 91 92 ASSERT_TRUE(entry != NULL); 93 EXPECT_EQ(url, entry->GetURL()); 94 EXPECT_EQ(url, entry->GetVirtualURL()); 95 } 96 97 } // namespace content 98