Skip to content

Commit

Permalink
Merge pull request #3154 from brave/bsc-shields-advanced-default-change
Browse files Browse the repository at this point in the history
Default shield advanced view to TRUE for existing users.
  • Loading branch information
bsclifton committed Sep 4, 2019
1 parent ddabfa4 commit bb0c7ce
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 1 deletion.
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_
14 changes: 13 additions & 1 deletion browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include "brave/components/brave_webtorrent/browser/webtorrent_util.h"
#endif

#if !defined(OS_ANDROID)
#include "chrome/browser/first_run/first_run.h"
#endif

using extensions::FeatureSwitch;

namespace brave {
Expand All @@ -52,7 +56,15 @@ 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 = false;

#if !defined(OS_ANDROID)
is_new_user = first_run::IsChromeFirstRun();
#endif

registry->RegisterBooleanPref(kShieldsAdvancedViewEnabled,
is_new_user == false);
registry->RegisterBooleanPref(kFBEmbedControlType, true);
registry->RegisterBooleanPref(kTwitterEmbedControlType, true);
registry->RegisterBooleanPref(kLinkedInEmbedControlType, false);
Expand Down
23 changes: 23 additions & 0 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 Down Expand Up @@ -50,6 +51,28 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
browser()->profile()->GetPrefs()->GetBoolean(kIPFSCompanionEnabled));
}

// First run of Brave should default Shields to Simple view
#if !defined(OS_ANDROID)
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));
}
#endif

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 @@ -383,6 +383,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

0 comments on commit bb0c7ce

Please sign in to comment.