chromium/chrome/browser/profile_resetter/profile_resetter_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/profile_resetter/profile_resetter.h"

#include <stddef.h>

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <utility>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_path_override.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/prefs/session_startup_pref.h"
#include "chrome/browser/profile_resetter/brandcode_config_fetcher.h"
#include "chrome/browser/profile_resetter/profile_reset_report.pb.h"
#include "chrome/browser/profile_resetter/profile_resetter_test_base.h"
#include "chrome/browser/profile_resetter/resettable_settings_snapshot.h"
#include "chrome/browser/search/background/ntp_custom_background_service.h"
#include "chrome/browser/search/background/ntp_custom_background_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/themes/test/theme_service_changed_waiter.h"
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/webdata_services/web_data_service_factory.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "components/content_settings/core/browser/content_settings_info.h"
#include "components/content_settings/core/browser/content_settings_registry.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/browser/website_settings_info.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_status_code.h"
#include "net/http/http_util.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "services/network/test/test_utils.h"
#include "url/gurl.h"

#if BUILDFLAG(IS_WIN)
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/process/process_handle.h"
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/win/scoped_com_initializer.h"
#include "base/win/shortcut.h"
#endif

ManifestLocation;

namespace {

const char kDistributionConfig[] =;

const char kXmlConfig[] =;

Extension;
Manifest;

class FakeNtpCustomBackgroundService : public NtpCustomBackgroundService {};

std::unique_ptr<KeyedService> CreateFakeNtpCustomBackgroundService(
    content::BrowserContext* context) {}

// ProfileResetterTest --------------------------------------------------------

// ProfileResetterTest sets up the extension, WebData and TemplateURL services.
class ProfileResetterTest : public extensions::ExtensionServiceTestBase,
                            public ProfileResetterTestBase {};

ProfileResetterTest::ProfileResetterTest()
#if BUILDFLAG(IS_WIN)
    :{}

ProfileResetterTest::~ProfileResetterTest() {}

void ProfileResetterTest::SetUp() {}

// PinnedTabsResetTest --------------------------------------------------------

class PinnedTabsResetTest : public BrowserWithTestWindowTest,
                            public ProfileResetterTestBase {};

void PinnedTabsResetTest::SetUp() {}

std::unique_ptr<content::WebContents> PinnedTabsResetTest::CreateWebContents() {}


// ConfigParserTest -----------------------------------------------------------

class ConfigParserTest : public testing::Test {};

ConfigParserTest::ConfigParserTest()
    :{}

ConfigParserTest::~ConfigParserTest() {}

std::unique_ptr<BrandcodeConfigFetcher> ConfigParserTest::WaitForRequest(
    const GURL& url) {}

// A helper class to create/delete/check a Chrome desktop shortcut on Windows.
class ShortcutHandler {};

#if BUILDFLAG(IS_WIN)
ShortcutHandler::ShortcutHandler() {
}

ShortcutHandler::~ShortcutHandler() {
  if (!shortcut_path_.empty())
    Delete();
}

// static
bool ShortcutHandler::IsSupported() {
  return true;
}

ShortcutCommand ShortcutHandler::CreateWithArguments(const std::wstring& name,
                                                     const std::wstring& args) {
  EXPECT_TRUE(shortcut_path_.empty());
  base::FilePath path_to_create;
  EXPECT_TRUE(base::PathService::Get(base::DIR_USER_DESKTOP, &path_to_create));
  path_to_create = path_to_create.Append(name);
  EXPECT_FALSE(base::PathExists(path_to_create)) << path_to_create.value();

  base::FilePath path_exe;
  EXPECT_TRUE(base::PathService::Get(base::FILE_EXE, &path_exe));
  base::win::ShortcutProperties shortcut_properties;
  shortcut_properties.set_target(path_exe);
  shortcut_properties.set_arguments(args);
  EXPECT_TRUE(base::win::CreateOrUpdateShortcutLink(
      path_to_create, shortcut_properties,
      base::win::ShortcutOperation::kCreateAlways))
      << path_to_create.value();
  shortcut_path_ = path_to_create;
  return ShortcutCommand(shortcut_path_, args);
}

void ShortcutHandler::CheckShortcutHasArguments(
    const std::wstring& desired_args) const {
  EXPECT_FALSE(shortcut_path_.empty());
  std::wstring args;
  EXPECT_TRUE(base::win::ResolveShortcut(shortcut_path_, NULL, &args));
  EXPECT_EQ(desired_args, args);
}

void ShortcutHandler::Delete() {
  EXPECT_FALSE(shortcut_path_.empty());
  EXPECT_TRUE(base::DeleteFile(shortcut_path_));
  shortcut_path_.clear();
}

void ShortcutHandler::HideFile() {
  DWORD attributes = ::GetFileAttributes(shortcut_path_.value().c_str());
  ASSERT_NE(attributes, INVALID_FILE_ATTRIBUTES);
  ASSERT_TRUE(::SetFileAttributes(shortcut_path_.value().c_str(),
                                  attributes | FILE_ATTRIBUTE_HIDDEN));
}

bool ShortcutHandler::IsFileHidden() const {
  DWORD attributes = ::GetFileAttributes(shortcut_path_.value().c_str());
  EXPECT_NE(attributes, INVALID_FILE_ATTRIBUTES);
  return attributes & FILE_ATTRIBUTE_HIDDEN;
}

#else
ShortcutHandler::ShortcutHandler() {}

ShortcutHandler::~ShortcutHandler() {}

// static
bool ShortcutHandler::IsSupported() {}

ShortcutCommand ShortcutHandler::CreateWithArguments(const std::wstring& name,
                                                     const std::wstring& args) {}

void ShortcutHandler::CheckShortcutHasArguments(
    const std::wstring& desired_args) const {}

void ShortcutHandler::Delete() {}

void ShortcutHandler::HideFile() {}

bool ShortcutHandler::IsFileHidden() const {}
#endif  // BUILDFLAG(IS_WIN)

// helper functions -----------------------------------------------------------

scoped_refptr<Extension> CreateExtension(const std::u16string& name,
                                         const base::FilePath& path,
                                         ManifestLocation location,
                                         extensions::Manifest::Type type,
                                         bool installed_by_default) {}

void ReplaceString(std::string* str,
                   const std::string& placeholder,
                   const std::string& substitution) {}


/********************* Tests *********************/

TEST_F(ProfileResetterTest, ResetNothing) {}

TEST_F(ProfileResetterTest, ResetDefaultSearchEngineNonOrganic) {}

TEST_F(ProfileResetterTest, ResetDefaultSearchEnginePartially) {}

TEST_F(ProfileResetterTest, ResetHomepageNonOrganic) {}

TEST_F(ProfileResetterTest, ResetHomepagePartially) {}

TEST_F(ProfileResetterTest, ResetContentSettings) {}

TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) {}

TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) {}

TEST_F(ProfileResetterTest, ResetExtensionsAndDefaultApps) {}

TEST_F(ProfileResetterTest, ResetExtensionsByReenablingExternalComponents) {}

TEST_F(ProfileResetterTest, ResetStartPageNonOrganic) {}


TEST_F(ProfileResetterTest, ResetStartPagePartially) {}

TEST_F(PinnedTabsResetTest, ResetPinnedTabs) {}

TEST_F(ProfileResetterTest, ResetShortcuts) {}

TEST_F(ProfileResetterTest, ResetFewFlags) {}

// Tries to load unavailable config file.
TEST_F(ConfigParserTest, NoConnectivity) {}

// Tries to load available config file.
TEST_F(ConfigParserTest, ParseConfig) {}

// Return an invalid response from the fetch request and delete the
// Fetcher object in the callback, which mimics how ResetSettingsHandler uses
// the class. See https://crbug.com/1491296.
TEST_F(ConfigParserTest, InvalidResponseDeleteFromCallback) {}

TEST_F(ProfileResetterTest, CheckSnapshots) {}

TEST_F(ProfileResetterTest, FeedbackSerializationAsProtoTest) {}

struct FeedbackCapture {};

// Make sure GetReadableFeedback handles non-ascii letters.
TEST_F(ProfileResetterTest, GetReadableFeedback) {}

TEST_F(ProfileResetterTest, DestroySnapshotFast) {}

TEST_F(ProfileResetterTest, ResetNTPCustomizationsTest) {}

}  // namespace