-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7859 from brave/topsite_edit
Improve topsite tiles in NTP
- Loading branch information
Showing
56 changed files
with
1,454 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) 2021 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/. | ||
|
||
source_set("unit_tests") { | ||
testonly = true | ||
|
||
if (!is_android) { | ||
sources = [ "brave_new_tab_ui_unittest.cc" ] | ||
|
||
deps = [ | ||
"//brave/browser/ui", | ||
"//components/history/core/browser", | ||
"//components/ntp_tiles", | ||
"//testing/gtest", | ||
] | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
browser/ui/webui/new_tab_page/brave_new_tab_ui_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* Copyright (c) 2021 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 "brave/browser/ui/webui/new_tab_page/brave_new_tab_ui_utils.h" | ||
#include "components/history/core/browser/top_sites_impl.h" | ||
#include "components/ntp_tiles/constants.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
TEST(BraveNewTabUITest, ConstantsTest) { | ||
// Make sure history/ntp_tiles module has proper constants for our NTP | ||
// requirements. | ||
constexpr size_t kBraveMaxTopSitesNumber = 12; | ||
constexpr size_t kTopSitesNumber = history::TopSitesImpl::kTopSitesNumber; | ||
|
||
EXPECT_EQ(kBraveMaxTopSitesNumber, kTopSitesNumber); | ||
EXPECT_EQ(kBraveMaxTopSitesNumber, ntp_tiles::kMaxNumCustomLinks); | ||
EXPECT_EQ(kBraveMaxTopSitesNumber, ntp_tiles::kMaxNumMostVisited); | ||
EXPECT_EQ(static_cast<int>(kBraveMaxTopSitesNumber), ntp_tiles::kMaxNumTiles); | ||
} | ||
|
||
TEST(BraveNewTabUITest, TopSiteURLValidation) { | ||
std::string url = "a"; | ||
EXPECT_TRUE(GetValidURLStringForTopSite(&url)); | ||
EXPECT_EQ("https://a", url); | ||
|
||
url = "http://a"; | ||
EXPECT_TRUE(GetValidURLStringForTopSite(&url)); | ||
EXPECT_EQ("http://a", url); | ||
|
||
url = "https://a"; | ||
EXPECT_TRUE(GetValidURLStringForTopSite(&url)); | ||
EXPECT_EQ("https://a", url); | ||
|
||
url = "https://www.a.com"; | ||
EXPECT_TRUE(GetValidURLStringForTopSite(&url)); | ||
EXPECT_EQ("https://www.a.com", url); | ||
|
||
// Check failed to make vaile url. | ||
url = "!@"; | ||
EXPECT_FALSE(GetValidURLStringForTopSite(&url)); | ||
|
||
url = ""; | ||
EXPECT_FALSE(GetValidURLStringForTopSite(&url)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2021 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 "brave/browser/ui/webui/new_tab_page/brave_new_tab_ui_utils.h" | ||
|
||
#include "url/gurl.h" | ||
|
||
bool GetValidURLStringForTopSite(std::string* url) { | ||
if (GURL(*url).is_valid()) | ||
return true; | ||
|
||
// fixup if passed |url| is not valid. | ||
const std::string new_url = "https://" + *url; | ||
if (GURL(new_url).is_valid()) { | ||
*url = new_url; | ||
return true; | ||
} | ||
|
||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) 2021 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/. | ||
|
||
#ifndef BRAVE_BROWSER_UI_WEBUI_NEW_TAB_PAGE_BRAVE_NEW_TAB_UI_UTILS_H_ | ||
#define BRAVE_BROWSER_UI_WEBUI_NEW_TAB_PAGE_BRAVE_NEW_TAB_UI_UTILS_H_ | ||
|
||
#include <string> | ||
|
||
// Simply append `https://` scheme to |url| if |url| is not valid. | ||
// Retruns true if |url| is valid or fixed |url| is valid. | ||
// Fixed url is passed via |url|. | ||
bool GetValidURLStringForTopSite(std::string* url); | ||
|
||
#endif // BRAVE_BROWSER_UI_WEBUI_NEW_TAB_PAGE_BRAVE_NEW_TAB_UI_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include_rules = [ | ||
"+../../../../../../components/history/core/browser", | ||
] |
18 changes: 18 additions & 0 deletions
18
chromium_src/components/history/core/browser/top_sites_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2021 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/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_IMPL_H_ | ||
#define BRAVE_CHROMIUM_SRC_COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_IMPL_H_ | ||
|
||
// Needs 12 items for our NTP top site tiles. | ||
#define kTopSitesNumber \ | ||
kTopSitesNumber = 12; \ | ||
static constexpr size_t kTopSitesNumber_Unused | ||
|
||
#include "../../../../../../components/history/core/browser/top_sites_impl.h" | ||
|
||
#undef kTopSitesNumber | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_HISTORY_CORE_BROWSER_TOP_SITES_IMPL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include_rules = [ | ||
"+../../../../components/ntp_tiles", | ||
"+components/ntp_tiles", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* Copyright (c) 2021 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 "components/ntp_tiles/constants.h" | ||
|
||
namespace ntp_tiles { | ||
|
||
const size_t kMaxNumCustomLinks = 12; | ||
const size_t kMaxNumMostVisited = 12; | ||
|
||
} // namespace ntp_tiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* Copyright (c) 2021 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/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_NTP_TILES_CONSTANTS_H_ | ||
#define BRAVE_CHROMIUM_SRC_COMPONENTS_NTP_TILES_CONSTANTS_H_ | ||
|
||
// Needs 12 items for our NTP top site tiles. | ||
#define kMaxNumTiles \ | ||
kMaxNumTiles = 12; \ | ||
const int kMaxNumTiles_Unused | ||
|
||
#include "../../../../components/ntp_tiles/constants.h" | ||
|
||
#undef kMaxNumTiles | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_NTP_TILES_CONSTANTS_H_ |
Oops, something went wrong.