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

Default shield advanced view to TRUE for existing users. #3154

Merged
merged 4 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
45 changes: 45 additions & 0 deletions browser/brave_first_run_browsertest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* 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 "brave/browser/brave_first_run_browsertest.h"

FirstRunMasterPrefsBrowserTestBase::FirstRunMasterPrefsBrowserTestBase() {}

FirstRunMasterPrefsBrowserTestBase::~FirstRunMasterPrefsBrowserTestBase() {}

void FirstRunMasterPrefsBrowserTestBase::SetUp() {
// All users of this test class need to call SetMasterPreferencesForTest()
// before this class' SetUp() is invoked.
ASSERT_TRUE(text_.get());

ASSERT_TRUE(base::CreateTemporaryFile(&prefs_file_));
EXPECT_EQ(static_cast<int>(text_->size()),
base::WriteFile(prefs_file_, text_->c_str(), text_->size()));
first_run::SetMasterPrefsPathForTesting(prefs_file_);

// This invokes BrowserMain, and does the import, so must be done last.
InProcessBrowserTest::SetUp();
}

void FirstRunMasterPrefsBrowserTestBase::TearDown() {
EXPECT_TRUE(base::DeleteFile(prefs_file_, false));
InProcessBrowserTest::TearDown();
}

void FirstRunMasterPrefsBrowserTestBase::SetUpCommandLine(
base::CommandLine* command_line) {
command_line->AppendSwitch(switches::kForceFirstRun);
EXPECT_EQ(first_run::AUTO_IMPORT_NONE, first_run::auto_import_state());

extensions::ComponentLoader::EnableBackgroundExtensionsForTesting();
}

#if defined(OS_MACOSX) || defined(OS_LINUX)
void FirstRunMasterPrefsBrowserTestBase::SetUpInProcessBrowserTestFixture() {
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
// Suppress first run dialog since it blocks test progress.
first_run::internal::ForceFirstRunDialogShownForTesting(false);
}
#endif
100 changes: 100 additions & 0 deletions browser/brave_first_run_browsertest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/* 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/. */

#ifndef BRAVE_BROWSER_BRAVE_FIRST_RUN_BROWSERTEST_H_
#define BRAVE_BROWSER_BRAVE_FIRST_RUN_BROWSERTEST_H_

// Copied from chrome/browser/first_run/first_run_browsertest.cc
// See browser/brave_profile_prefs_browsertest.cc for an example
// Useful for verifying first-run functionality.

#include <memory>
#include <string>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/first_run/first_run_internal.h"
#include "chrome/browser/importer/importer_list.h"
#include "chrome/browser/prefs/chrome_pref_service_factory.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "components/variations/metrics.h"
#include "components/variations/pref_names.h"
#include "components/variations/variations_switches.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_launcher.h"
#include "testing/gtest/include/gtest/gtest.h"

typedef InProcessBrowserTest FirstRunBrowserTest;

// A generic test class to be subclassed by test classes testing specific
// master_preferences. All subclasses must call SetMasterPreferencesForTest()
// from their SetUp() method before deferring the remainder of Setup() to this
// class.
class FirstRunMasterPrefsBrowserTestBase : public InProcessBrowserTest {
public:
FirstRunMasterPrefsBrowserTestBase();
~FirstRunMasterPrefsBrowserTestBase() override;

protected:
void SetUp() override;

void TearDown() override;

void SetUpCommandLine(base::CommandLine* command_line) override;

#if defined(OS_MACOSX) || defined(OS_LINUX)
void SetUpInProcessBrowserTestFixture() override;
#endif

void SetMasterPreferencesForTest(const char text[]) {
text_.reset(new std::string(text));
}

private:
base::FilePath prefs_file_;
std::unique_ptr<std::string> text_;

DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestBase);
};

template<const char Text[]>
class FirstRunMasterPrefsBrowserTestT
: public FirstRunMasterPrefsBrowserTestBase {
public:
FirstRunMasterPrefsBrowserTestT() {}

protected:
void SetUp() override {
SetMasterPreferencesForTest(Text);
FirstRunMasterPrefsBrowserTestBase::SetUp();
}

private:
DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestT);
};

#endif // BRAVE_BROWSER_BRAVE_FIRST_RUN_BROWSERTEST_H_
6 changes: 5 additions & 1 deletion browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "brave/common/pref_names.h"
#include "brave/components/brave_shields/browser/brave_shields_web_contents_observer.h"
#include "brave/components/brave_webtorrent/browser/buildflags/buildflags.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/common/pref_names.h"
Expand Down Expand Up @@ -50,7 +51,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
registry->RegisterBooleanPref(kNoScriptControlType, false);
registry->RegisterBooleanPref(kAdControlType, true);
registry->RegisterBooleanPref(kShieldsAdvancedViewEnabled, false);
// > advanced view is defaulted to true for EXISTING users; false for new
bool is_new_user = first_run::IsChromeFirstRun();
registry->RegisterBooleanPref(kShieldsAdvancedViewEnabled,
is_new_user == false);
registry->RegisterBooleanPref(kGoogleLoginControlType, true);
registry->RegisterBooleanPref(kFBEmbedControlType, true);
registry->RegisterBooleanPref(kTwitterEmbedControlType, true);
Expand Down
24 changes: 21 additions & 3 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "components/safe_browsing/common/safe_browsing_prefs.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/sync/base/pref_names.h"
#include "brave/browser/brave_first_run_browsertest.h"

using BraveProfilePrefsBrowserTest = InProcessBrowserTest;

Expand All @@ -29,9 +30,6 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
kHTTPSEVerywhereControlType));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(kNoScriptControlType));
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(
kShieldsAdvancedViewEnabled));
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(kAdControlType));
EXPECT_TRUE(
Expand All @@ -52,6 +50,26 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
browser()->profile()->GetPrefs()->GetBoolean(kIPFSCompanionEnabled));
}

// First run of Brave should default Shields to Simple view
const char kFirstRunEmptyPrefs[] = "{}";
typedef FirstRunMasterPrefsBrowserTestT<kFirstRunEmptyPrefs>
BraveProfilePrefsFirstRunBrowserTest;
IN_PROC_BROWSER_TEST_F(BraveProfilePrefsFirstRunBrowserTest,
AdvancedShieldsNewUserValue) {
EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(
kShieldsAdvancedViewEnabled));
}

// Existing Brave users should default shields to Advanced view
IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest,
AdvancedShieldsExistingUserValue) {
first_run::CreateSentinelIfNeeded();
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(
kShieldsAdvancedViewEnabled));
}

IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest,
DisableGoogleServicesByDefault) {
EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
Expand Down
2 changes: 2 additions & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ test("brave_browser_tests") {
"//brave/browser/brave_content_browser_client_browsertest.cc",
"//brave/browser/brave_features_browsertest.cc",
"//brave/browser/brave_profile_prefs_browsertest.cc",
"//brave/browser/brave_first_run_browsertest.h",
"//brave/browser/brave_first_run_browsertest.cc",
"//brave/browser/brave_resources_browsertest.cc",
"//brave/browser/brave_stats_updater_browsertest.cc",
"//brave/browser/browsing_data/brave_clear_browsing_data_browsertest.cc",
Expand Down