[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / browser_about_handler_unittest.cc
1 // Copyright 2012 The Chromium Authors
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 "chrome/browser/browser_about_handler.h"
6
7 #include <stddef.h>
8
9 #include <memory>
10 #include <utility>
11 #include <vector>
12
13 #include "chrome/common/url_constants.h"
14 #include "chrome/test/base/testing_profile.h"
15 #include "content/public/browser/navigation_controller.h"
16 #include "content/public/browser/navigation_entry.h"
17 #include "content/public/common/referrer.h"
18 #include "content/public/test/browser_task_environment.h"
19 #include "services/network/public/cpp/shared_url_loader_factory.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "url/gurl.h"
22
23 using content::BrowserThread;
24 using content::NavigationController;
25 using content::NavigationEntry;
26 using content::Referrer;
27
28 namespace {
29 struct AboutURLTestCase {
30   GURL test_url;
31   GURL expected_url;
32 };
33 }
34
35 class BrowserAboutHandlerTest : public testing::Test {
36  protected:
37   void TestHandleChromeAboutAndChromeSyncRewrite(
38       const std::vector<AboutURLTestCase>& test_cases) {
39     TestingProfile profile;
40
41     for (const auto& test_case : test_cases) {
42       GURL url(test_case.test_url);
43       HandleChromeAboutAndChromeSyncRewrite(&url, &profile);
44       EXPECT_EQ(test_case.expected_url, url);
45     }
46   }
47
48  private:
49   content::BrowserTaskEnvironment task_environment_;
50 };
51
52 TEST_F(BrowserAboutHandlerTest, HandleChromeAboutAndChromeSyncRewrite) {
53   std::string chrome_prefix(content::kChromeUIScheme);
54   chrome_prefix.append(url::kStandardSchemeSeparator);
55   std::vector<AboutURLTestCase> test_cases(
56       {{GURL("http://google.com"), GURL("http://google.com")},
57        {GURL(url::kAboutBlankURL), GURL(url::kAboutBlankURL)},
58        {GURL(chrome_prefix + chrome::kChromeUIDefaultHost),
59         GURL(chrome_prefix + chrome::kChromeUIVersionHost)},
60        {GURL(chrome_prefix + chrome::kChromeUIAboutHost),
61         GURL(chrome_prefix + chrome::kChromeUIChromeURLsHost)},
62        {GURL(chrome_prefix + chrome::kChromeUISignInInternalsHost),
63         GURL(chrome_prefix + chrome::kChromeUISignInInternalsHost)},
64        {GURL(chrome_prefix + chrome::kChromeUISyncHost),
65         GURL(chrome_prefix + chrome::kChromeUISyncInternalsHost)},
66        {
67            GURL(chrome_prefix + "host/path?query#ref"),
68            GURL(chrome_prefix + "host/path?query#ref"),
69        }});
70   TestHandleChromeAboutAndChromeSyncRewrite(test_cases);
71 }
72
73 TEST_F(BrowserAboutHandlerTest,
74        HandleChromeAboutAndChromeSyncRewriteForMDSettings) {
75   std::string chrome_prefix(content::kChromeUIScheme);
76   chrome_prefix.append(url::kStandardSchemeSeparator);
77   std::vector<AboutURLTestCase> test_cases(
78       {{GURL(chrome_prefix + chrome::kChromeUISettingsHost),
79         GURL(chrome_prefix + chrome::kChromeUISettingsHost)}});
80   TestHandleChromeAboutAndChromeSyncRewrite(test_cases);
81 }
82
83 TEST_F(BrowserAboutHandlerTest,
84        HandleChromeAboutAndChromeSyncRewriteForHistory) {
85   GURL::Replacements replace_foo_query;
86   replace_foo_query.SetQueryStr("foo");
87   GURL history_foo_url(
88       GURL(chrome::kChromeUIHistoryURL).ReplaceComponents(replace_foo_query));
89   TestHandleChromeAboutAndChromeSyncRewrite(std::vector<AboutURLTestCase>({
90       {GURL("chrome:history"), GURL(chrome::kChromeUIHistoryURL)},
91       {GURL(chrome::kChromeUIHistoryURL), GURL(chrome::kChromeUIHistoryURL)},
92       {history_foo_url, history_foo_url},
93   }));
94 }
95
96 // Ensure that minor BrowserAboutHandler fixup to a URL does not cause us to
97 // keep a separate virtual URL, which would not be updated on redirects.
98 // See https://crbug.com/449829.
99 TEST_F(BrowserAboutHandlerTest, NoVirtualURLForFixup) {
100   GURL url("view-source:http://.foo");
101
102   // No "fixing" of the URL is expected at the content::NavigationEntry layer.
103   // We should only "fix" strings from the user (e.g. URLs from the Omnibox).
104   //
105   // Rewriters will remove the view-source prefix and expect it to stay in the
106   // virtual URL.
107   GURL expected_virtual_url = url;
108   GURL expected_url("http://.foo/");
109
110   TestingProfile profile;
111   std::unique_ptr<NavigationEntry> entry(
112       NavigationController::CreateNavigationEntry(
113           url, Referrer(), /* initiator_origin= */ absl::nullopt,
114           /* initiator_base_url= */ absl::nullopt, ui::PAGE_TRANSITION_RELOAD,
115           false, std::string(), &profile,
116           nullptr /* blob_url_loader_factory */));
117   EXPECT_EQ(expected_virtual_url, entry->GetVirtualURL());
118   EXPECT_EQ(expected_url, entry->GetURL());
119 }
120
121 TEST_F(BrowserAboutHandlerTest, HandleNonNavigationAboutURL_Invalid) {
122   GURL invalid_url("https:");
123   ASSERT_FALSE(invalid_url.is_valid());
124   EXPECT_FALSE(HandleNonNavigationAboutURL(invalid_url));
125 }