#include <vector>
#include "base/memory/raw_ptr.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "chrome/browser/about_flags.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_model.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_prefs.h"
#include "chrome/browser/ui/toolbar/chrome_labs/chrome_labs_utils.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs/chrome_labs_bubble_view.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs/chrome_labs_button.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs/chrome_labs_coordinator.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs/chrome_labs_item_view.h"
#include "chrome/browser/ui/views/toolbar/chrome_labs/chrome_labs_view_controller.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/unexpire_flags.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/flags_ui/feature_entry_macros.h"
#include "components/flags_ui/flags_state.h"
#include "components/flags_ui/pref_service_flags_storage.h"
#include "components/user_education/views/new_badge_label.h"
#include "components/version_info/channel.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event_utils.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/test/combobox_test_api.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/memory/ptr_util.h"
#include "chrome/browser/ash/ownership/owner_settings_service_ash.h"
#include "chrome/browser/ash/ownership/owner_settings_service_ash_factory.h"
#include "chrome/browser/ash/settings/about_flags.h"
#include "chromeos/ash/components/cryptohome/cryptohome_parameters.h"
#include "chromeos/ash/components/dbus/session_manager/fake_session_manager_client.h"
#include "components/user_manager/user_manager.h"
#endif
#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && !BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/test/base/scoped_channel_override.h"
#endif
#if !BUILDFLAG(IS_CHROMEOS_ASH) || !BUILDFLAG(GOOGLE_CHROME_BRANDING)
namespace {
const char kFirstTestFeatureId[] = …;
const char kTestFeatureWithVariationId[] = …;
const char kThirdTestFeatureId[] = …;
const char kExpiredFlagTestFeatureId[] = …;
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
BASE_FEATURE(…);
const flags_ui::FeatureEntry::FeatureParam kTestVariationOther2[] = …;
const flags_ui::FeatureEntry::FeatureVariation kTestVariations2[] = …;
std::vector<LabInfo> TestLabInfo() { … }
}
class ChromeLabsCoordinatorTest : public TestWithBrowserView { … };
TEST_F(ChromeLabsCoordinatorTest, ShowBubbleTest) { … }
TEST_F(ChromeLabsCoordinatorTest, NewBadgeTest) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(ChromeLabsCoordinatorTest, ShowBubbleWhenUserIsOwner) {
chrome_labs_coordinator_->Show(
ChromeLabsCoordinator::ShowUserType::kChromeOsOwnerUserType);
views::test::WidgetDestroyedWaiter destroyed_waiter(
chrome_labs_coordinator_->GetChromeLabsBubbleView()->GetWidget());
chrome_labs_coordinator_->Hide();
destroyed_waiter.Wait();
chrome_labs_coordinator_->Show(
ChromeLabsCoordinator::ShowUserType::kChromeOsOwnerUserType);
}
#endif
class ChromeLabsViewControllerTest : public TestWithBrowserView { … };
class ChromeLabsFeatureTest : public ChromeLabsViewControllerTest,
public testing::WithParamInterface<int> { … };
#if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_P(ChromeLabsFeatureTest, ChangeSelectedOption) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(ChromeLabsViewControllerTest, ResetToDefault) { … }
#endif
#if BUILDFLAG(IS_CHROMEOS_ASH)
namespace ash {
class ChromeLabsAshFeatureTest : public ChromeLabsFeatureTest {
public:
ChromeLabsAshFeatureTest() {
SessionManagerClient::InitializeFakeInMemory();
FakeSessionManagerClient::Get()->set_supports_browser_restart(true);
}
};
TEST_P(ChromeLabsAshFeatureTest, ChangeSelectedOption) {
int row = GetParam();
std::unique_ptr<ChromeLabsViewController> view_controller =
CreateViewController();
ChromeLabsItemView* lab_item = first_lab_item();
views::Combobox* lab_item_combobox =
lab_item->GetLabStateComboboxForTesting();
lab_item_combobox->SetSelectedRow(row);
const flags_ui::FeatureEntry* feature_entry = lab_item->GetFeatureEntry();
EXPECT_TRUE(IsSelected(row, feature_entry, GetFlagsStorage()));
ChromeLabsItemView* lab_item_with_params = second_lab_item();
views::Combobox* lab_item_with_params_combobox =
lab_item_with_params->GetLabStateComboboxForTesting();
lab_item_with_params_combobox->SetSelectedRow(row);
const flags_ui::FeatureEntry* feature_entry_with_params =
lab_item_with_params->GetFeatureEntry();
EXPECT_TRUE(IsSelected(row, feature_entry_with_params, GetFlagsStorage()));
AccountId user_id =
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId();
std::vector<std::string> raw_flags;
FakeSessionManagerClient* session_manager = FakeSessionManagerClient::Get();
view_controller->RestartToApplyFlagsForTesting();
const bool has_user_flags = session_manager->GetFlagsForUser(
cryptohome::CreateAccountIdentifierFromAccountId(user_id), &raw_flags);
EXPECT_TRUE(has_user_flags);
}
INSTANTIATE_TEST_SUITE_P(All, ChromeLabsAshFeatureTest, testing::Values(1, 2));
TEST_F(ChromeLabsViewControllerTest, ResetToDefault) {
std::unique_ptr<ChromeLabsViewController> view_controller =
CreateViewController();
ChromeLabsItemView* lab_item = first_lab_item();
views::Combobox* lab_item_combobox =
lab_item->GetLabStateComboboxForTesting();
const flags_ui::FeatureEntry* feature_entry = lab_item->GetFeatureEntry();
lab_item_combobox->SetSelectedRow(1);
EXPECT_FALSE(IsDefault(feature_entry, GetFlagsStorage()));
lab_item_combobox->SetSelectedRow(0);
EXPECT_TRUE(IsDefault(feature_entry, GetFlagsStorage()));
}
}
#endif
TEST_F(ChromeLabsViewControllerTest, OnlyCompatibleFeaturesShow) { … }
TEST_F(ChromeLabsViewControllerTest, RestartPromptShows) { … }
TEST_F(ChromeLabsViewControllerTest, SelectDefaultTwiceNoRestart) { … }
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
TEST_F(ChromeLabsViewControllerTest, DISABLED_ShowFeedbackPage) { … }
#endif
TEST_F(ChromeLabsViewControllerTest, CleanUpNewBadgePrefsTest) { … }
#endif