Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add brave url to history #1821

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/")));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some urls that should be added to history? Want to make sure that someone doesn't accidentally break this to return false for everything

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also some urls that should not be added based on the ChromiumImpl method?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to to check many urls because CanAddURLToHistory() just checks scheme.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see what you mean. will add more urls

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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