Skip to content

Commit

Permalink
Don't add brave url to history
Browse files Browse the repository at this point in the history
Added test for this change: HistoryUtilsTest.VariousURLTest
  • Loading branch information
simonhong committed Mar 3, 2019
1 parent 96a8582 commit 3721c79
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
15 changes: 15 additions & 0 deletions chromium_src/chrome/browser/history/history_utils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#define CanAddURLToHistory CanAddURLToHistory_ChromiumImpl
#include "../../../../../chrome/browser/history/history_utils.cc" // NOLINT
#undef CanAddURLToHistory

bool CanAddURLToHistory(const GURL& url) {
if (!CanAddURLToHistory_ChromiumImpl(url))
return false;

return !url.SchemeIs(content::kBraveUIScheme);
}
36 changes: 36 additions & 0 deletions chromium_src/chrome/browser/history/history_utils_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "chrome/browser/history/history_utils.h"
#include "components/previews/core/previews_experiments.h"
#include "net/base/url_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"

namespace {
// Refered IsLitePageRedirectPreviewDomain() to make sample lite page url.
GURL GetSampleLitePageUrl() {
return net::AppendQueryParameter(
previews::params::GetLitePagePreviewsDomainURL(),
"u", "1234");
}
} // namespace

// This test covers all cases that upstream and our version of
// CanAddURLToHistory().
TEST(HistoryUtilsTest, VariousURLTest) {
EXPECT_TRUE(CanAddURLToHistory(GURL("https://www.brave.com/")));
EXPECT_FALSE(CanAddURLToHistory(GURL("brave://sync/")));
EXPECT_FALSE(CanAddURLToHistory(GURL("javascript://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("about://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("content://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("chrome-devtools://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("chrome://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("view-source://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("chrome-native://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("chrome-search://test")));
EXPECT_FALSE(CanAddURLToHistory(GURL("chrome-distiller://test")));
EXPECT_FALSE(CanAddURLToHistory(GetSampleLitePageUrl()));
}
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ test("brave_unit_tests") {
"//brave/browser/resources/settings/reset_report_uploader_unittest.cc",
"//brave/browser/resources/settings/brandcode_config_fetcher_unittest.cc",
"//brave/chromium_src/chrome/browser/external_protocol/external_protocol_handler_unittest.cc",
"//brave/chromium_src/chrome/browser/history/history_utils_unittest.cc",
"//brave/chromium_src/chrome/browser/signin/account_consistency_disabled_unittest.cc",
"//brave/chromium_src/chrome/browser/ui/bookmarks/brave_bookmark_context_menu_controller_unittest.cc",
"//brave/chromium_src/components/search_engines/brave_template_url_prepopulate_data_unittest.cc",
Expand Down

0 comments on commit 3721c79

Please sign in to comment.