Commit ceaa6613 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Disallow about://newtab url in history.

Bug: 905721
Change-Id: I6218a61cdd74b93257cb44580351c9c666092c0c
Reviewed-on: https://chromium-review.googlesource.com/c/1338964
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608927}
parent 0ca8bd3c
......@@ -71,6 +71,7 @@ source_set("unit_tests") {
"//base/test:test_support",
"//components/history/core/browser",
"//components/keyed_service/core",
"//ios/chrome/browser/",
"//ios/chrome/browser/browser_state:test_support",
"//ios/web",
"//ios/web/public/test/fakes",
......
......@@ -11,6 +11,7 @@
#include "components/history/core/browser/history_service.h"
#include "components/keyed_service/core/service_access_type.h"
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/history/history_service_factory.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/test/fakes/test_web_state.h"
......@@ -184,3 +185,23 @@ TEST_F(HistoryTabHelperTest, EmptyTitleOverwritesPreviousTitle) {
QueryURL(test_url);
EXPECT_NE(base::UTF8ToUTF16(test_title), latest_row_result_.title());
}
// Tests that the ntp is not saved to history.
TEST_F(HistoryTabHelperTest, TestNTPNotAdded) {
HistoryTabHelper* helper = HistoryTabHelper::FromWebState(&web_state_);
ASSERT_TRUE(helper);
std::unique_ptr<web::NavigationItem> item = web::NavigationItem::Create();
GURL test_url("https://www.google.com/");
item->SetVirtualURL(test_url);
AddVisitForURL(test_url);
QueryURL(test_url);
EXPECT_EQ(test_url, latest_row_result_.url());
item = web::NavigationItem::Create();
GURL ntp_url(kChromeUIAboutNewTabURL);
item->SetVirtualURL(ntp_url);
AddVisitForURL(ntp_url);
QueryURL(ntp_url);
EXPECT_NE(ntp_url, latest_row_result_.url());
}
......@@ -25,9 +25,9 @@ bool CanAddURLToHistory(const GURL& url) {
url.SchemeIs(kChromeUIScheme))
return false;
// Allow all about: and chrome: URLs except about:blank, since the user may
// like to see "chrome://version", etc. in their history and autocomplete.
if (url == url::kAboutBlankURL)
// Allow all about: and chrome: URLs except about:blank|newtab, since the user
// may like to see "chrome://version", etc. in their history and autocomplete.
if (url == url::kAboutBlankURL || url == kChromeUIAboutNewTabURL)
return false;
return true;
......
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