chromium/chrome/browser/ui/profiles/profile_picker_unittest.cc

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

#include "chrome/browser/ui/profiles/profile_picker.h"

#include "base/files/file_path.h"
#include "base/functional/callback.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_file_util.h"
#include "base/time/time.h"
#include "build/buildflag.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/fake_profile_manager.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"

class ProfilePickerTest : public testing::Test {};

TEST_F(ProfilePickerTest, ShouldShowAtLaunch_MultipleProfiles_TwoActive) {}

TEST_F(ProfilePickerTest,
       ShouldShowAtLaunch_MultipleProfiles_Inactive_SeenPicker) {}

TEST_F(ProfilePickerTest, ShouldShowAtLaunch_MultipleProfiles_OneGuest) {}

TEST_F(ProfilePickerTest,
       ShouldShowAtLaunch_MultipleProfiles_TwoActive_Disabled) {}

TEST_F(ProfilePickerTest, ShouldShowAtLaunch_MultipleProfiles_Inactive) {}

TEST_F(ProfilePickerTest, ShouldShowAtLaunch_MultipleProfiles_Expired) {}

TEST_F(ProfilePickerTest, ShouldShowAtLaunch_MultipleProfiles_OneActive) {}

TEST_F(ProfilePickerTest, ShouldShowAtLaunch_SingleProfile) {}

class ProfilePickerParamsTest : public testing::Test {};

TEST_F(ProfilePickerParamsTest, FromEntryPoint_ProfilePath) {}

TEST_F(ProfilePickerParamsTest, CanReuse) {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_F(ProfilePickerParamsTest, ForLacrosSelectAvailableAccount) {
  base::FilePath path = base::FilePath::FromASCII("/test/path");
  testing::StrictMock<base::MockOnceCallback<void(const std::string&)>>
      callback;
  {
    ProfilePicker::Params params =
        ProfilePicker::Params::ForLacrosSelectAvailableAccount(path,
                                                               callback.Get());
    EXPECT_EQ(path, params.profile_path());
    // The callback is called at destruction.
    EXPECT_CALL(callback, Run(std::string()));
  }
}

TEST_F(ProfilePickerParamsTest, ForFirstRun_Exit) {
  testing::StrictMock<
      base::MockOnceCallback<void(ProfilePicker::FirstRunExitStatus)>>
      callback;
  {
    ProfilePicker::Params params = ProfilePicker::Params::ForFirstRun(
        ProfileManager::GetPrimaryUserProfilePath(), callback.Get());
    EXPECT_EQ(base::FilePath::FromASCII(chrome::kInitialProfile),
              params.profile_path().BaseName());
    // The callback is called at destruction.
    EXPECT_CALL(callback, Run(ProfilePicker::FirstRunExitStatus::kQuitEarly));
  }
}

TEST_F(ProfilePickerParamsTest, ForFirstRun_Notify) {
  testing::StrictMock<
      base::MockOnceCallback<void(ProfilePicker::FirstRunExitStatus)>>
      callback;
  {
    ProfilePicker::Params params = ProfilePicker::Params::ForFirstRun(
        ProfileManager::GetPrimaryUserProfilePath(), callback.Get());
    EXPECT_EQ(base::FilePath::FromASCII(chrome::kInitialProfile),
              params.profile_path().BaseName());
    EXPECT_CALL(callback, Run(ProfilePicker::FirstRunExitStatus::kCompleted));
    params.NotifyFirstRunExited(ProfilePicker::FirstRunExitStatus::kCompleted);
  }
}
#endif