Commit 1ea87880 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Don't rewrite the about NTP url twice.

Rewrite chrome://newtab to about://newtab, but don't rewrite
about://newtab twice.

Also adds unit tests.

Change-Id: I4744e84d0855c39b50076a9550aefe75812c4bf9
Reviewed-on: https://chromium-review.googlesource.com/c/1490959
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Auto-Submit: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636183}
parent 97fe92a0
......@@ -244,6 +244,7 @@ source_set("unit_tests") {
testonly = true
sources = [
"app_startup_parameters_unittest.mm",
"browser_about_rewriter_unittest.cc",
"chrome_browser_provider_observer_bridge_unittest.mm",
"chrome_url_util_unittest.mm",
"crash_loop_detection_util_unittest.mm",
......
......@@ -27,6 +27,8 @@ const struct HostReplacement {
} // namespace
bool WillHandleWebBrowserAboutURL(GURL* url, web::BrowserState* browser_state) {
GURL original_url = *url;
// Ensure that any cleanup done by FixupURL happens before the rewriting
// phase that determines the virtual URL, by including it in an initial
// URLHandler. This prevents minor changes from producing a virtual URL,
......@@ -48,7 +50,7 @@ bool WillHandleWebBrowserAboutURL(GURL* url, web::BrowserState* browser_state) {
GURL::Replacements replacements;
replacements.SetSchemeStr(url::kAboutScheme);
*url = url->ReplaceComponents(replacements);
return true;
return *url != original_url;
}
}
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/chrome/browser/browser_about_rewriter.h"
#include "base/test/gtest_util.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#include "testing/platform_test.h"
#include "url/gurl.h"
using BrowserAboutRewriterTest = PlatformTest;
// Test that chrome://newtab is re-written to about://newtab,
// but that about://newtab is not re-written twice.
TEST_F(BrowserAboutRewriterTest, NtpTest) {
GURL url = GURL(kChromeUINewTabURL);
EXPECT_TRUE(WillHandleWebBrowserAboutURL(&url, /*browser_state=*/nullptr));
EXPECT_EQ(url, GURL(kChromeUIAboutNewTabURL));
EXPECT_FALSE(WillHandleWebBrowserAboutURL(&url, nil));
}
// Test that about|chrome://about is rewritten to chrome-urls.
TEST_F(BrowserAboutRewriterTest, AboutTest) {
GURL url = GURL("about:about");
EXPECT_FALSE(WillHandleWebBrowserAboutURL(&url, /*browser_state=*/nullptr));
EXPECT_EQ(url, GURL("chrome://chrome-urls/"));
url = GURL("chrome://about/");
EXPECT_FALSE(WillHandleWebBrowserAboutURL(&url, /*browser_state=*/nullptr));
EXPECT_EQ(url, GURL("chrome://chrome-urls/"));
}
// Test that about|chrome://sync is rewritten to sync-internals.
TEST_F(BrowserAboutRewriterTest, SyncTest) {
GURL url = GURL("about:sync");
EXPECT_FALSE(WillHandleWebBrowserAboutURL(&url, /*browser_state=*/nullptr));
EXPECT_EQ(url, GURL("chrome://sync-internals/"));
url = GURL("chrome://sync/");
EXPECT_FALSE(WillHandleWebBrowserAboutURL(&url, /*browser_state=*/nullptr));
EXPECT_EQ(url, GURL("chrome://sync-internals/"));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment