blob: 120e152eadc67c86d2455e555bd1acf5817eea71 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]9d1a9e22010-06-11 20:27:042// 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]3b63f8f42011-03-28 01:54:156#include "base/memory/scoped_ptr.h"
[email protected]3fc40c142011-12-01 13:09:047#include "base/message_loop.h"
[email protected]9d1a9e22010-06-11 20:27:048#include "chrome/browser/browser_about_handler.h"
[email protected]3e0f7d522010-06-18 04:09:149#include "chrome/common/about_handler.h"
[email protected]9d1a9e22010-06-11 20:27:0410#include "chrome/common/url_constants.h"
[email protected]a4ff9eae2011-08-01 19:58:1611#include "chrome/test/base/testing_profile.h"
[email protected]c38831a12011-10-28 12:44:4912#include "content/test/test_browser_thread.h"
[email protected]9d1a9e22010-06-11 20:27:0413#include "googleurl/src/gurl.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
[email protected]631bb742011-11-02 11:29:3916using content::BrowserThread;
17
[email protected]583844c2011-08-27 00:38:3518typedef testing::Test BrowserAboutHandlerTest;
[email protected]bcd98a52011-02-25 07:50:1919
20TEST_F(BrowserAboutHandlerTest, WillHandleBrowserAboutURL) {
[email protected]89f550b2011-06-08 18:34:0321 std::string chrome_prefix(chrome::kChromeUIScheme);
22 chrome_prefix.append(chrome::kStandardSchemeSeparator);
[email protected]9d1a9e22010-06-11 20:27:0423 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]89f550b2011-06-08 18:34:0342 GURL(chrome_prefix + chrome::kChromeUICrashHost),
43 GURL(chrome_prefix + chrome::kChromeUICrashHost),
[email protected]9d1a9e22010-06-11 20:27:0444 true,
45 false
46 },
47 {
[email protected]89f550b2011-06-08 18:34:0348 GURL(chrome_prefix + chrome::kChromeUIKillHost),
49 GURL(chrome_prefix + chrome::kChromeUIKillHost),
[email protected]a8f024392011-01-13 21:50:1650 true,
51 false
52 },
53 {
[email protected]89f550b2011-06-08 18:34:0354 GURL(chrome_prefix + chrome::kChromeUIHangHost),
55 GURL(chrome_prefix + chrome::kChromeUIHangHost),
[email protected]9d1a9e22010-06-11 20:27:0456 true,
57 false
58 },
59 {
[email protected]89f550b2011-06-08 18:34:0360 GURL(chrome_prefix + chrome::kChromeUIShorthangHost),
61 GURL(chrome_prefix + chrome::kChromeUIShorthangHost),
[email protected]9d1a9e22010-06-11 20:27:0462 true,
63 false
64 },
65 {
[email protected]89f550b2011-06-08 18:34:0366 GURL(chrome_prefix + chrome::kChromeUIMemoryHost),
67 GURL(chrome_prefix + chrome::kChromeUIMemoryHost),
[email protected]9d1a9e22010-06-11 20:27:0468 false,
[email protected]b3adbd02011-11-30 22:23:2769 false
[email protected]9d1a9e22010-06-11 20:27:0470 },
71 {
[email protected]89f550b2011-06-08 18:34:0372 GURL(chrome_prefix + chrome::kChromeUIDefaultHost),
73 GURL(chrome_prefix + chrome::kChromeUIVersionHost),
[email protected]9d1a9e22010-06-11 20:27:0474 false,
[email protected]b3adbd02011-11-30 22:23:2775 false
[email protected]9d1a9e22010-06-11 20:27:0476 },
[email protected]89f550b2011-06-08 18:34:0377 {
78 GURL(chrome_prefix + chrome::kChromeUIAboutHost),
79 GURL(chrome_prefix + chrome::kChromeUIChromeURLsHost),
80 false,
[email protected]b3adbd02011-11-30 22:23:2781 false
[email protected]89f550b2011-06-08 18:34:0382 },
83 {
84 GURL(chrome_prefix + chrome::kChromeUICacheHost),
85 GURL(chrome_prefix + chrome::kChromeUINetworkViewCacheHost),
86 false,
[email protected]b3adbd02011-11-30 22:23:2787 false
[email protected]89f550b2011-06-08 18:34:0388 },
89 {
90 GURL(chrome_prefix + chrome::kChromeUIGpuHost),
91 GURL(chrome_prefix + chrome::kChromeUIGpuInternalsHost),
92 false,
[email protected]b3adbd02011-11-30 22:23:2793 false
[email protected]89f550b2011-06-08 18:34:0394 },
95 {
96 GURL(chrome_prefix + chrome::kChromeUISyncHost),
97 GURL(chrome_prefix + chrome::kChromeUISyncInternalsHost),
98 false,
[email protected]b3adbd02011-11-30 22:23:2799 false
[email protected]89f550b2011-06-08 18:34:03100 },
101 {
102 GURL(chrome_prefix + "host/path?query#ref"),
103 GURL(chrome_prefix + "host/path?query#ref"),
104 false,
[email protected]b3adbd02011-11-30 22:23:27105 false
[email protected]89f550b2011-06-08 18:34:03106 }
[email protected]9d1a9e22010-06-11 20:27:04107 };
[email protected]248ce192011-02-10 15:26:34108 MessageLoopForUI message_loop;
[email protected]c38831a12011-10-28 12:44:49109 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
[email protected]248ce192011-02-10 15:26:34110 TestingProfile profile;
[email protected]9d1a9e22010-06-11 20:27:04111
112 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
113 GURL url(test_data[i].test_url);
[email protected]3e0f7d522010-06-18 04:09:14114 EXPECT_EQ(test_data[i].about_handled,
115 chrome_about_handler::WillHandle(url));
[email protected]9d1a9e22010-06-11 20:27:04116 EXPECT_EQ(test_data[i].browser_handled,
[email protected]248ce192011-02-10 15:26:34117 WillHandleBrowserAboutURL(&url, &profile));
[email protected]9d1a9e22010-06-11 20:27:04118 EXPECT_EQ(test_data[i].result_url, url);
119 }
120
[email protected]37ae3f22011-07-12 03:56:14121 // Crash the browser process for chrome://inducebrowsercrashforrealz.
122 GURL url(chrome_prefix + chrome::kChromeUIBrowserCrashHost);
[email protected]b3adbd02011-11-30 22:23:27123 EXPECT_DEATH(HandleNonNavigationAboutURL(url), "");
[email protected]9d1a9e22010-06-11 20:27:04124}