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

Disable password sign in promo disregarding sync status #3566

Merged
merged 1 commit into from
Oct 2, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* 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/. */

class PrefService;
namespace syncer {
class SyncService;
} // namespace syncer

namespace password_bubble_experiment {

bool ShouldShowChromeSignInPasswordPromo(
PrefService* prefs,
const syncer::SyncService* sync_service) {
return false;
}

} // namespace password_bubble_experiment

#define ShouldShowChromeSignInPasswordPromo \
ShouldShowChromeSignInPasswordPromo_ChromiumImpl
#include "../../../../../../components/password_manager/core/browser/password_bubble_experiment.cc" // NOLINT
#undef ShouldShowChromeSignInPasswordPromo
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* 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 "components/password_manager/core/browser/password_bubble_experiment.h"

#include <ostream>

#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "components/sync/driver/test_sync_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace password_bubble_experiment {

class PasswordManagerPasswordBubbleExperimentTest : public testing::Test {
public:
PasswordManagerPasswordBubbleExperimentTest() {
RegisterPrefs(pref_service_.registry());
}

PrefService* prefs() { return &pref_service_; }

syncer::TestSyncService* sync_service() { return &fake_sync_service_; }

private:
syncer::TestSyncService fake_sync_service_;
TestingPrefServiceSimple pref_service_;
};

TEST_F(PasswordManagerPasswordBubbleExperimentTest,
ShouldShowChromeSignInPasswordPromo) {
// By default the promo is off.
EXPECT_FALSE(ShouldShowChromeSignInPasswordPromo(prefs(), nullptr));
constexpr struct {
bool was_already_clicked;
bool is_sync_allowed;
bool is_first_setup_complete;
int current_shown_count;
bool result;
} kTestData[] = {
{false, true, false, 0, false}, {false, true, false, 5, false},
{true, true, false, 0, false}, {true, true, false, 10, false},
{false, false, false, 0, false}, {false, true, true, 0, false},
};
for (const auto& test_case : kTestData) {
SCOPED_TRACE(testing::Message("#test_case = ") << (&test_case - kTestData));
prefs()->SetBoolean(password_manager::prefs::kWasSignInPasswordPromoClicked,
test_case.was_already_clicked);
prefs()->SetInteger(
password_manager::prefs::kNumberSignInPasswordPromoShown,
test_case.current_shown_count);
sync_service()->SetDisableReasons(
test_case.is_sync_allowed
? syncer::SyncService::DISABLE_REASON_NONE
: syncer::SyncService::DISABLE_REASON_ENTERPRISE_POLICY);
sync_service()->SetFirstSetupComplete(test_case.is_first_setup_complete);
sync_service()->SetTransportState(
test_case.is_first_setup_complete
? syncer::SyncService::TransportState::ACTIVE
: syncer::SyncService::TransportState::
PENDING_DESIRED_CONFIGURATION);

EXPECT_EQ(test_case.result,
ShouldShowChromeSignInPasswordPromo(prefs(), sync_service()));
}
}

} // namespace password_bubble_experiment
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ test("brave_unit_tests") {
"//brave/chromium_src/chrome/browser/ui/bookmarks/brave_bookmark_context_menu_controller_unittest.cc",
"//brave/chromium_src/components/autofill/core/browser/autofill_experiments_unittest.cc",
"//brave/chromium_src/components/metrics/enabled_state_provider_unittest.cc",
"//brave/chromium_src/components/password_manager/core/browser/password_bubble_experiment_unittest.cc",
"//brave/chromium_src/components/search_engines/brave_template_url_prepopulate_data_unittest.cc",
"//brave/chromium_src/components/search_engines/brave_template_url_service_util_unittest.cc",
"//brave/chromium_src/components/variations/service/field_trial_unittest.cc",
Expand Down