|
| 1 | +/* Copyright (c) 2019 The Brave Authors. All rights reserved. |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | + * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
| 4 | + * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 | + |
| 6 | +#ifndef BRAVE_BROWSER_BRAVE_FIRST_RUN_BROWSERTEST_H_ |
| 7 | +#define BRAVE_BROWSER_BRAVE_FIRST_RUN_BROWSERTEST_H_ |
| 8 | + |
| 9 | +// Copied from chrome/browser/first_run/first_run_browsertest.cc |
| 10 | +// See browser/brave_profile_prefs_browsertest.cc for an example |
| 11 | +// Useful for verifying first-run functionality. |
| 12 | + |
| 13 | +#include <memory> |
| 14 | +#include <string> |
| 15 | + |
| 16 | +#include "base/base_switches.h" |
| 17 | +#include "base/command_line.h" |
| 18 | +#include "base/files/file_path.h" |
| 19 | +#include "base/macros.h" |
| 20 | +#include "base/memory/ref_counted.h" |
| 21 | +#include "base/run_loop.h" |
| 22 | +#include "base/strings/string_util.h" |
| 23 | +#include "base/strings/utf_string_conversions.h" |
| 24 | +#include "base/test/metrics/histogram_tester.h" |
| 25 | +#include "build/build_config.h" |
| 26 | +#include "chrome/browser/browser_process.h" |
| 27 | +#include "chrome/browser/extensions/component_loader.h" |
| 28 | +#include "chrome/browser/first_run/first_run.h" |
| 29 | +#include "chrome/browser/first_run/first_run_internal.h" |
| 30 | +#include "chrome/browser/importer/importer_list.h" |
| 31 | +#include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 32 | +#include "chrome/browser/profiles/profile_manager.h" |
| 33 | +#include "chrome/browser/ui/browser.h" |
| 34 | +#include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 35 | +#include "chrome/common/chrome_switches.h" |
| 36 | +#include "chrome/common/pref_names.h" |
| 37 | +#include "chrome/common/url_constants.h" |
| 38 | +#include "chrome/test/base/in_process_browser_test.h" |
| 39 | +#include "chrome/test/base/ui_test_utils.h" |
| 40 | +#include "components/prefs/pref_service.h" |
| 41 | +#include "components/user_prefs/user_prefs.h" |
| 42 | +#include "components/variations/metrics.h" |
| 43 | +#include "components/variations/pref_names.h" |
| 44 | +#include "components/variations/variations_switches.h" |
| 45 | +#include "content/public/browser/web_contents.h" |
| 46 | +#include "content/public/common/content_switches.h" |
| 47 | +#include "content/public/test/browser_test_utils.h" |
| 48 | +#include "content/public/test/test_launcher.h" |
| 49 | +#include "testing/gtest/include/gtest/gtest.h" |
| 50 | + |
| 51 | +typedef InProcessBrowserTest FirstRunBrowserTest; |
| 52 | + |
| 53 | +// A generic test class to be subclassed by test classes testing specific |
| 54 | +// master_preferences. All subclasses must call SetMasterPreferencesForTest() |
| 55 | +// from their SetUp() method before deferring the remainder of Setup() to this |
| 56 | +// class. |
| 57 | +class FirstRunMasterPrefsBrowserTestBase : public InProcessBrowserTest { |
| 58 | + public: |
| 59 | + FirstRunMasterPrefsBrowserTestBase(); |
| 60 | + ~FirstRunMasterPrefsBrowserTestBase() override; |
| 61 | + |
| 62 | + protected: |
| 63 | + void SetUp() override; |
| 64 | + |
| 65 | + void TearDown() override; |
| 66 | + |
| 67 | + void SetUpCommandLine(base::CommandLine* command_line) override; |
| 68 | + |
| 69 | +#if defined(OS_MACOSX) || defined(OS_LINUX) |
| 70 | + void SetUpInProcessBrowserTestFixture() override; |
| 71 | +#endif |
| 72 | + |
| 73 | + void SetMasterPreferencesForTest(const char text[]) { |
| 74 | + text_.reset(new std::string(text)); |
| 75 | + } |
| 76 | + |
| 77 | + private: |
| 78 | + base::FilePath prefs_file_; |
| 79 | + std::unique_ptr<std::string> text_; |
| 80 | + |
| 81 | + DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestBase); |
| 82 | +}; |
| 83 | + |
| 84 | +template<const char Text[]> |
| 85 | +class FirstRunMasterPrefsBrowserTestT |
| 86 | + : public FirstRunMasterPrefsBrowserTestBase { |
| 87 | + public: |
| 88 | + FirstRunMasterPrefsBrowserTestT() {} |
| 89 | + |
| 90 | + protected: |
| 91 | + void SetUp() override { |
| 92 | + SetMasterPreferencesForTest(Text); |
| 93 | + FirstRunMasterPrefsBrowserTestBase::SetUp(); |
| 94 | + } |
| 95 | + |
| 96 | + private: |
| 97 | + DISALLOW_COPY_AND_ASSIGN(FirstRunMasterPrefsBrowserTestT); |
| 98 | +}; |
| 99 | + |
| 100 | +#endif // BRAVE_BROWSER_BRAVE_FIRST_RUN_BROWSERTEST_H_ |
0 commit comments