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