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