browser_about_handler_unittest.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2010 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/basictypes.h" 6#include "base/scoped_ptr.h" 7#include "chrome/browser/browser_about_handler.h" 8#include "chrome/browser/browser_thread.h" 9#include "chrome/common/about_handler.h" 10#include "chrome/common/url_constants.h" 11#include "chrome/test/testing_profile.h" 12#include "googleurl/src/gurl.h" 13#include "testing/gtest/include/gtest/gtest.h" 14 15TEST(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) { 16 struct AboutURLTestData { 17 GURL test_url; 18 GURL result_url; 19 bool about_handled; 20 bool browser_handled; 21 } test_data[] = { 22 { 23 GURL("http://google.com"), 24 GURL("http://google.com"), 25 false, 26 false 27 }, 28 { 29 GURL(chrome::kAboutBlankURL), 30 GURL(chrome::kAboutBlankURL), 31 false, 32 false 33 }, 34 { 35 GURL(std::string(chrome::kAboutCacheURL) + "/mercury"), 36 GURL(std::string(chrome::kNetworkViewCacheURL) + "mercury"), 37 false, 38 true 39 }, 40 { 41 GURL(std::string(chrome::kAboutNetInternalsURL) + "/venus"), 42 GURL(std::string(chrome::kNetworkViewInternalsURL) + "venus"), 43 false, 44 true 45 }, 46 { 47 GURL(std::string(chrome::kAboutGpuURL) + "/jupiter"), 48 GURL(std::string(chrome::kGpuInternalsURL) + "jupiter"), 49 false, 50 true 51 }, 52 { 53 GURL(std::string(chrome::kAboutAppCacheInternalsURL) + "/earth"), 54 GURL(std::string(chrome::kAppCacheViewInternalsURL) + "earth"), 55 false, 56 true 57 }, 58 { 59 GURL(chrome::kAboutPluginsURL), 60 GURL(chrome::kChromeUIPluginsURL), 61 false, 62 true 63 }, 64 { 65 GURL(chrome::kAboutCrashURL), 66 GURL(chrome::kAboutCrashURL), 67 true, 68 false 69 }, 70 { 71 GURL(chrome::kAboutKillURL), 72 GURL(chrome::kAboutKillURL), 73 true, 74 false 75 }, 76 { 77 GURL(chrome::kAboutHangURL), 78 GURL(chrome::kAboutHangURL), 79 true, 80 false 81 }, 82 { 83 GURL(chrome::kAboutShorthangURL), 84 GURL(chrome::kAboutShorthangURL), 85 true, 86 false 87 }, 88 { 89 GURL("about:memory"), 90 GURL("chrome://about/memory-redirect"), 91 false, 92 true 93 }, 94 { 95 GURL("about:mars"), 96 GURL("chrome://about/mars"), 97 false, 98 true 99 }, 100 }; 101 MessageLoopForUI message_loop; 102 BrowserThread ui_thread(BrowserThread::UI, &message_loop); 103 TestingProfile profile; 104 105 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 106 GURL url(test_data[i].test_url); 107 EXPECT_EQ(test_data[i].about_handled, 108 chrome_about_handler::WillHandle(url)); 109 EXPECT_EQ(test_data[i].browser_handled, 110 WillHandleBrowserAboutURL(&url, &profile)); 111 EXPECT_EQ(test_data[i].result_url, url); 112 } 113 114 // Crash the browser process for about:inducebrowsercrashforrealz. 115 GURL url(chrome::kAboutBrowserCrash); 116 EXPECT_DEATH(WillHandleBrowserAboutURL(&url, NULL), ""); 117} 118