[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 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/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 6 | #include "base/memory/scoped_ptr.h" |
[email protected] | 3fc40c14 | 2011-12-01 13:09:04 | [diff] [blame] | 7 | #include "base/message_loop.h" |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 8 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | 3e0f7d52 | 2010-06-18 04:09:14 | [diff] [blame] | 9 | #include "chrome/common/about_handler.h" |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 10 | #include "chrome/common/url_constants.h" |
[email protected] | a4ff9eae | 2011-08-01 19:58:16 | [diff] [blame] | 11 | #include "chrome/test/base/testing_profile.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 12 | #include "content/test/test_browser_thread.h" |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 13 | #include "googleurl/src/gurl.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 16 | using content::BrowserThread; |
| 17 | |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 18 | typedef testing::Test BrowserAboutHandlerTest; |
[email protected] | bcd98a5 | 2011-02-25 07:50:19 | [diff] [blame] | 19 | |
| 20 | TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 21 | std::string chrome_prefix(chrome::kChromeUIScheme); |
| 22 | chrome_prefix.append(chrome::kStandardSchemeSeparator); |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 23 | struct AboutURLTestData { |
| 24 | GURL test_url; |
| 25 | GURL result_url; |
| 26 | bool about_handled; |
| 27 | bool browser_handled; |
| 28 | } test_data[] = { |
| 29 | { |
| 30 | GURL("http://google.com"), |
| 31 | GURL("http://google.com"), |
| 32 | false, |
| 33 | false |
| 34 | }, |
| 35 | { |
| 36 | GURL(chrome::kAboutBlankURL), |
| 37 | GURL(chrome::kAboutBlankURL), |
| 38 | false, |
| 39 | false |
| 40 | }, |
| 41 | { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 42 | GURL(chrome_prefix + chrome::kChromeUICrashHost), |
| 43 | GURL(chrome_prefix + chrome::kChromeUICrashHost), |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 44 | true, |
| 45 | false |
| 46 | }, |
| 47 | { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 48 | GURL(chrome_prefix + chrome::kChromeUIKillHost), |
| 49 | GURL(chrome_prefix + chrome::kChromeUIKillHost), |
[email protected] | a8f02439 | 2011-01-13 21:50:16 | [diff] [blame] | 50 | true, |
| 51 | false |
| 52 | }, |
| 53 | { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 54 | GURL(chrome_prefix + chrome::kChromeUIHangHost), |
| 55 | GURL(chrome_prefix + chrome::kChromeUIHangHost), |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 56 | true, |
| 57 | false |
| 58 | }, |
| 59 | { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 60 | GURL(chrome_prefix + chrome::kChromeUIShorthangHost), |
| 61 | GURL(chrome_prefix + chrome::kChromeUIShorthangHost), |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 62 | true, |
| 63 | false |
| 64 | }, |
| 65 | { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 66 | GURL(chrome_prefix + chrome::kChromeUIMemoryHost), |
| 67 | GURL(chrome_prefix + chrome::kChromeUIMemoryHost), |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 68 | false, |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 69 | false |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 70 | }, |
| 71 | { |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 72 | GURL(chrome_prefix + chrome::kChromeUIDefaultHost), |
| 73 | GURL(chrome_prefix + chrome::kChromeUIVersionHost), |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 74 | false, |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 75 | false |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 76 | }, |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 77 | { |
| 78 | GURL(chrome_prefix + chrome::kChromeUIAboutHost), |
| 79 | GURL(chrome_prefix + chrome::kChromeUIChromeURLsHost), |
| 80 | false, |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 81 | false |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 82 | }, |
| 83 | { |
| 84 | GURL(chrome_prefix + chrome::kChromeUICacheHost), |
| 85 | GURL(chrome_prefix + chrome::kChromeUINetworkViewCacheHost), |
| 86 | false, |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 87 | false |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 88 | }, |
| 89 | { |
| 90 | GURL(chrome_prefix + chrome::kChromeUIGpuHost), |
| 91 | GURL(chrome_prefix + chrome::kChromeUIGpuInternalsHost), |
| 92 | false, |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 93 | false |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 94 | }, |
| 95 | { |
| 96 | GURL(chrome_prefix + chrome::kChromeUISyncHost), |
| 97 | GURL(chrome_prefix + chrome::kChromeUISyncInternalsHost), |
| 98 | false, |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 99 | false |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 100 | }, |
| 101 | { |
| 102 | GURL(chrome_prefix + "host/path?query#ref"), |
| 103 | GURL(chrome_prefix + "host/path?query#ref"), |
| 104 | false, |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 105 | false |
[email protected] | 89f550b | 2011-06-08 18:34:03 | [diff] [blame] | 106 | } |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 107 | }; |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 108 | MessageLoopForUI message_loop; |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 109 | content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 110 | TestingProfile profile; |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 111 | |
| 112 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 113 | GURL url(test_data[i].test_url); |
[email protected] | 3e0f7d52 | 2010-06-18 04:09:14 | [diff] [blame] | 114 | EXPECT_EQ(test_data[i].about_handled, |
| 115 | chrome_about_handler::WillHandle(url)); |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 116 | EXPECT_EQ(test_data[i].browser_handled, |
[email protected] | 248ce19 | 2011-02-10 15:26:34 | [diff] [blame] | 117 | WillHandleBrowserAboutURL(&url, &profile)); |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 118 | EXPECT_EQ(test_data[i].result_url, url); |
| 119 | } |
| 120 | |
[email protected] | 37ae3f2 | 2011-07-12 03:56:14 | [diff] [blame] | 121 | // Crash the browser process for chrome://inducebrowsercrashforrealz. |
| 122 | GURL url(chrome_prefix + chrome::kChromeUIBrowserCrashHost); |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 123 | EXPECT_DEATH(HandleNonNavigationAboutURL(url), ""); |
[email protected] | 9d1a9e2 | 2010-06-11 20:27:04 | [diff] [blame] | 124 | } |