Home | History | Annotate | Download | only in browser
      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/search/search.h"
      7 #include "chrome/browser/ui/browser.h"
      8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
      9 #include "chrome/common/chrome_switches.h"
     10 #include "chrome/test/base/in_process_browser_test.h"
     11 #include "chrome/test/base/ui_test_utils.h"
     12 #include "content/public/browser/navigation_controller.h"
     13 #include "content/public/browser/navigation_entry.h"
     14 #include "content/public/browser/web_contents.h"
     15 #include "content/public/common/content_switches.h"
     16 #include "url/gurl.h"
     17 
     18 namespace content {
     19 
     20 class ChromeContentBrowserClientBrowserTest : public InProcessBrowserTest {
     21  public:
     22   // Returns the last committed navigation entry of the first tab. May be NULL
     23   // if there is no such entry.
     24   NavigationEntry* GetLastCommittedEntry() {
     25     return browser()->tab_strip_model()->GetWebContentsAt(0)->
     26         GetController().GetLastCommittedEntry();
     27   }
     28 };
     29 
     30 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
     31                        UberURLHandler_SettingsPage) {
     32   const GURL url_short("chrome://settings/");
     33   const GURL url_long("chrome://chrome/settings/");
     34 
     35   ui_test_utils::NavigateToURL(browser(), url_short);
     36   NavigationEntry* entry = GetLastCommittedEntry();
     37 
     38   ASSERT_TRUE(entry != NULL);
     39   EXPECT_EQ(url_long, entry->GetURL());
     40   EXPECT_EQ(url_short, entry->GetVirtualURL());
     41 }
     42 
     43 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
     44                        UberURLHandler_ContentSettingsPage) {
     45   const GURL url_short("chrome://settings/content");
     46   const GURL url_long("chrome://chrome/settings/content");
     47 
     48   ui_test_utils::NavigateToURL(browser(), url_short);
     49   NavigationEntry* entry = GetLastCommittedEntry();
     50 
     51   ASSERT_TRUE(entry != NULL);
     52   EXPECT_EQ(url_long, entry->GetURL());
     53   EXPECT_EQ(url_short, entry->GetVirtualURL());
     54 }
     55 
     56 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
     57                        UberURLHandler_AboutPage) {
     58   const GURL url("chrome://chrome/");
     59 
     60   ui_test_utils::NavigateToURL(browser(), url);
     61   NavigationEntry* entry = GetLastCommittedEntry();
     62 
     63   ASSERT_TRUE(entry != NULL);
     64   EXPECT_EQ(url, entry->GetURL());
     65   EXPECT_EQ(url, entry->GetVirtualURL());
     66 }
     67 
     68 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
     69                        UberURLHandler_EmptyHost) {
     70   const GURL url("chrome://chrome//foo");
     71 
     72   ui_test_utils::NavigateToURL(browser(), url);
     73   NavigationEntry* entry = GetLastCommittedEntry();
     74 
     75   ASSERT_TRUE(entry != NULL);
     76   EXPECT_TRUE(entry->GetVirtualURL().is_valid());
     77   EXPECT_EQ(url, entry->GetVirtualURL());
     78 }
     79 
     80 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
     81                        UberURLHandler_InstantExtendedNewTabPage) {
     82   const GURL url_original("chrome://newtab");
     83   const GURL url_rewritten("http://example.com/newtab");
     84   CommandLine::ForCurrentProcess()->AppendSwitchASCII(
     85       switches::kInstantNewTabURL, url_rewritten.spec());
     86   chrome::EnableInstantExtendedAPIForTesting();
     87 
     88   ui_test_utils::NavigateToURL(browser(), url_original);
     89   NavigationEntry* entry = GetLastCommittedEntry();
     90 
     91   ASSERT_TRUE(entry != NULL);
     92   EXPECT_EQ(url_rewritten, entry->GetURL());
     93   EXPECT_EQ(url_original, entry->GetVirtualURL());
     94 }
     95 
     96 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
     97                        UberURLHandler_InstantExtendedNewTabPageDisabled) {
     98   const GURL url_original("chrome://newtab");
     99   const GURL url_rewritten("http://example.com/newtab");
    100   CommandLine::ForCurrentProcess()->AppendSwitchASCII(
    101       switches::kInstantNewTabURL, url_rewritten.spec());
    102 
    103   ui_test_utils::NavigateToURL(browser(), url_original);
    104   NavigationEntry* entry = GetLastCommittedEntry();
    105 
    106   ASSERT_TRUE(entry != NULL);
    107   EXPECT_EQ(url_original, entry->GetURL());
    108   EXPECT_EQ(url_original, entry->GetVirtualURL());
    109 }
    110 
    111 // Test that a basic navigation works in --site-per-process mode.  This prevents
    112 // regressions when that mode calls out into the ChromeContentBrowserClient,
    113 // such as http://crbug.com/164223.
    114 IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest,
    115                        SitePerProcessNavigation) {
    116   CommandLine::ForCurrentProcess()->AppendSwitch(
    117       switches::kSitePerProcess);
    118   ASSERT_TRUE(test_server()->Start());
    119   const GURL url(test_server()->GetURL("files/title1.html"));
    120 
    121   ui_test_utils::NavigateToURL(browser(), url);
    122   NavigationEntry* entry = GetLastCommittedEntry();
    123 
    124   ASSERT_TRUE(entry != NULL);
    125   EXPECT_EQ(url, entry->GetURL());
    126   EXPECT_EQ(url, entry->GetVirtualURL());
    127 }
    128 
    129 }  // namespace content
    130