[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 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 | |
[email protected] | 2ee3da9d6 | 2012-12-05 20:17:19 | [diff] [blame] | 5 | #include "base/command_line.h" |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 6 | #include "chrome/browser/ui/browser.h" |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 7 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 8 | #include "chrome/common/chrome_switches.h" |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 9 | #include "chrome/test/base/in_process_browser_test.h" |
| 10 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 11 | #include "content/public/browser/navigation_controller.h" |
| 12 | #include "content/public/browser/navigation_entry.h" |
| 13 | #include "content/public/browser/web_contents.h" |
[email protected] | 2ee3da9d6 | 2012-12-05 20:17:19 | [diff] [blame] | 14 | #include "content/public/common/content_switches.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 15 | #include "url/gurl.h" |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 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() { |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 24 | return browser()->tab_strip_model()->GetWebContentsAt(0)-> |
| 25 | GetController().GetLastCommittedEntry(); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 26 | } |
| 27 | }; |
| 28 | |
| 29 | IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, |
| 30 | UberURLHandler_SettingsPage) { |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 31 | const GURL url_short("chrome://settings/"); |
| 32 | const GURL url_long("chrome://chrome/settings/"); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 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) { |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 44 | const GURL url_short("chrome://settings/content"); |
| 45 | const GURL url_long("chrome://chrome/settings/content"); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 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 | |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 55 | IN_PROC_BROWSER_TEST_F(ChromeContentBrowserClientBrowserTest, |
| 56 | UberURLHandler_AboutPage) { |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 57 | const GURL url("chrome://chrome/"); |
[email protected] | 045bf7c | 2012-09-28 20:27:36 | [diff] [blame] | 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 | |
[email protected] | 44e8add | 2013-06-13 17:29:15 | [diff] [blame] | 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 | |
[email protected] | 2ee3da9d6 | 2012-12-05 20:17:19 | [diff] [blame] | 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); |
[email protected] | bbdd1b20b | 2012-12-11 21:24:13 | [diff] [blame] | 86 | ASSERT_TRUE(test_server()->Start()); |
| 87 | const GURL url(test_server()->GetURL("files/title1.html")); |
[email protected] | 2ee3da9d6 | 2012-12-05 20:17:19 | [diff] [blame] | 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 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 97 | } // namespace content |