-
Notifications
You must be signed in to change notification settings - Fork 905
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
NTP / FTX fix group #9074
Merged
NTP / FTX fix group #9074
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
206b348
News: Do not show '0' on settings section when there are no publisher…
petemill ec13872
FTX: UI for summary view with no balances
petemill 3968d7a
NTP: Introduce new "all widgets off" pref and migrate previous style …
petemill d2f77e6
NTP: remove clickable background for branded wallpapers"
petemill 96cde5b
FTX: disconnect when hiding
petemill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// 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/search/ntp_utils.h" | ||
|
||
#include <memory> | ||
|
||
#include "brave/common/pref_names.h" | ||
#include "brave/components/crypto_dot_com/browser/buildflags/buildflags.h" | ||
#include "chrome/test/base/testing_profile.h" | ||
#include "components/prefs/pref_registry_simple.h" | ||
#include "components/prefs/testing_pref_service.h" | ||
#include "components/sync_preferences/testing_pref_service_syncable.h" | ||
#include "content/public/test/browser_task_environment.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
#if BUILDFLAG(CRYPTO_DOT_COM_ENABLED) | ||
#include "brave/components/crypto_dot_com/common/pref_names.h" | ||
#endif | ||
|
||
class NTPUtilsTest : public ::testing::Test { | ||
public: | ||
NTPUtilsTest() = default; | ||
|
||
void SetUp() override { | ||
profile_ = std::make_unique<TestingProfile>(); | ||
} | ||
|
||
Profile* profile() { return profile_.get(); } | ||
|
||
protected: | ||
// BrowserTaskEnvironment is needed before TestingProfile | ||
content::BrowserTaskEnvironment task_environment_; | ||
|
||
std::unique_ptr<TestingProfile> profile_; | ||
}; | ||
|
||
TEST_F(NTPUtilsTest, MigratesHideWidgetTrue) { | ||
// Manually turn all off | ||
auto* prefs = profile()->GetPrefs(); | ||
prefs->SetBoolean(kNewTabPageShowRewards, false); | ||
prefs->SetBoolean(kNewTabPageShowTogether, false); | ||
prefs->SetBoolean(kNewTabPageShowBinance, false); | ||
#if BUILDFLAG(CRYPTO_DOT_COM_ENABLED) | ||
prefs->SetBoolean(kCryptoDotComNewTabPageShowCryptoDotCom, false); | ||
#endif | ||
prefs->SetBoolean(kNewTabPageShowGemini, false); | ||
// Migrate | ||
new_tab_page::MigrateNewTabPagePrefs(profile()); | ||
// Expect migrated to off | ||
EXPECT_TRUE(prefs->GetBoolean(kNewTabPageHideAllWidgets)); | ||
} | ||
|
||
TEST_F(NTPUtilsTest, MigratesHideWidgetFalse) { | ||
// Manually turn some off | ||
auto* prefs = profile()->GetPrefs(); | ||
prefs->SetBoolean(kNewTabPageShowRewards, false); | ||
prefs->SetBoolean(kNewTabPageShowTogether, true); | ||
prefs->SetBoolean(kNewTabPageShowBinance, false); | ||
#if BUILDFLAG(CRYPTO_DOT_COM_ENABLED) | ||
prefs->SetBoolean(kCryptoDotComNewTabPageShowCryptoDotCom, false); | ||
#endif | ||
prefs->SetBoolean(kNewTabPageShowGemini, false); | ||
// Migrate | ||
new_tab_page::MigrateNewTabPagePrefs(profile()); | ||
// Expect not migrated | ||
EXPECT_FALSE(prefs->GetBoolean(kNewTabPageHideAllWidgets)); | ||
} | ||
|
||
TEST_F(NTPUtilsTest, MigratesHideWidgetFalseDefault) { | ||
// Don't manually change any settings | ||
// Migrate | ||
new_tab_page::MigrateNewTabPagePrefs(profile()); | ||
// Expect not migrated | ||
auto* prefs = profile()->GetPrefs(); | ||
EXPECT_FALSE(prefs->GetBoolean(kNewTabPageHideAllWidgets)); | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can use
std::all_of
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great tip, thanks!