Commit 675bd26b authored by Tony de Luna's avatar Tony de Luna Committed by Commit Bot

Enable sync consent tests on regular chormium build

This cl moves sync consent tests to the normal chromium build target.

Made fixes to the sync consent tests:
 * Added FakeGaia mixin to allow the call to ShowSigninScreenForTest to
   complete.
 * Updated the OOBE JS API call for updating language locale.
 * SyncConsentPolicyDisableTest now waits for user session to start
   because OOBE flow can finish before the Waiter started, causing the
   Waiter to wait forever.

Moved the is_official_build_ flag in WizardController to static scope
because a new WizardController instance is created as part of the login
flow. This meant that setting is_official_build_ to true during the
test would be overriden when the new WizardController instace is
created.

Added a helper function ForceOfficialBulidForTesting to WizardController
that temporarily overrides is_official_build_ during the execution
of a test.

Removes some WizardController friend classes that only needed access
to the private is_official_build_ flag.

TBR=antrim@chromium.org

Bug: 952388

Change-Id: I5bd87ef4a21b4a265bdde94656fc2380c770473a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570215
Commit-Queue: Tony De Luna <tonydeluna@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarAlexander Alekseev <alemate@chromium.org>
Cr-Commit-Position: refs/heads/master@{#651776}
parent efad3ec3
......@@ -116,9 +116,7 @@ class OobeConfigurationTest : public OobeBaseTest {
LoadConfiguration();
// Make sure that OOBE is run as an "official" build.
WizardController* wizard_controller =
WizardController::default_controller();
wizard_controller->is_official_build_ = true;
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
// Clear portal list (as it is by default in OOBE).
NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
......@@ -127,7 +125,7 @@ class OobeConfigurationTest : public OobeBaseTest {
protected:
// Owned by DBusThreadManagerSetter
chromeos::FakeUpdateEngineClient* fake_update_engine_client_;
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
base::ScopedTempDir fake_policy_dir_;
private:
......
......@@ -153,7 +153,7 @@ class DemoSetupTest : public LoginManagerTest {
void SetUpOnMainThread() override {
LoginManagerTest::SetUpOnMainThread();
DisableConfirmationDialogAnimations();
WizardController::default_controller()->is_official_build_ = true;
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
DisconnectAllNetworks();
}
......@@ -442,6 +442,7 @@ class DemoSetupTest : public LoginManagerTest {
base::ScopedTempDir fake_demo_resources_dir_;
policy::MockCloudPolicyStore mock_policy_store_;
base::test::ScopedFeatureList scoped_feature_list_;
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
DISALLOW_COPY_AND_ASSIGN(DemoSetupTest);
};
......
......@@ -51,7 +51,7 @@ class HandsOffEnrollmentTest : public MixinBasedInProcessBrowserTest {
ShowLoginWizard(OobeScreen::SCREEN_TEST_NO_WINDOW);
// Set official build so EULA screen is not skipped by default.
WizardController::default_controller()->is_official_build_ = true;
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
// Sets all network services into idle state to simulate disconnected state.
NetworkStateHandler::NetworkStateList networks;
......@@ -82,6 +82,7 @@ class HandsOffEnrollmentTest : public MixinBasedInProcessBrowserTest {
protected:
test::EnrollmentHelperMixin enrollment_helper_{&mixin_host_};
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
private:
DISALLOW_COPY_AND_ASSIGN(HandsOffEnrollmentTest);
......
......@@ -94,6 +94,11 @@ class SyncConsentTest : public OobeBaseTest {
SyncConsentTest() = default;
~SyncConsentTest() override = default;
void SetUpOnMainThread() override {
OobeBaseTest::SetUpOnMainThread();
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
}
void TearDownOnMainThread() override {
// If the login display is still showing, exit gracefully.
if (LoginDisplayHost::default_host()) {
......@@ -115,7 +120,7 @@ class SyncConsentTest : public OobeBaseTest {
void SwitchLanguage(const std::string& language) {
const char get_num_reloads[] = "Oobe.getInstance().reloadContentNumEvents_";
const int prev_reloads = test::OobeJS().GetInt(get_num_reloads);
test::OobeJS().Evaluate("$('connect').onLanguageSelected_('" + language +
test::OobeJS().Evaluate("$('connect').applySelectedLanguage_('" + language +
"');");
const std::string condition =
base::StringPrintf("%s > %d", get_num_reloads, prev_reloads);
......@@ -189,6 +194,9 @@ class SyncConsentTest : public OobeBaseTest {
IDS_LOGIN_SYNC_CONSENT_SCREEN_ACCEPT_AND_CONTINUE,
};
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
FakeGaiaMixin fake_gaia_{&mixin_host_, embedded_test_server()};
private:
DISALLOW_COPY_AND_ASSIGN(SyncConsentTest);
};
......@@ -251,32 +259,31 @@ INSTANTIATE_TEST_SUITE_P(SyncConsentTestWithParamsImpl,
// independently from sync engine statis. So we run test twice, both for "sync
// engine not yet initialized" and "sync engine initialized" cases. Therefore
// we use WithParamInterface<bool> here.
class SyncConsenPolicyDisabledTest : public SyncConsentTest,
public testing::WithParamInterface<bool> {
class SyncConsentPolicyDisabledTest : public SyncConsentTest,
public testing::WithParamInterface<bool> {
};
IN_PROC_BROWSER_TEST_P(SyncConsenPolicyDisabledTest,
IN_PROC_BROWSER_TEST_P(SyncConsentPolicyDisabledTest,
SyncConsentPolicyDisabled) {
LoginToSyncConsentScreen();
SyncConsentScreen* screen = static_cast<SyncConsentScreen*>(
WizardController::default_controller()->GetScreen(
OobeScreen::SCREEN_SYNC_CONSENT));
ConsentRecordedWaiter consent_recorded_waiter;
screen->SetDelegateForTesting(&consent_recorded_waiter);
screen->SetProfileSyncDisabledByPolicyForTesting(true);
screen->SetProfileSyncEngineInitializedForTesting(GetParam());
screen->OnStateChanged(nullptr);
// Expect to see "user image selection" or some other screen here.
test::OobeJS()
.CreateWaiter("Oobe.getInstance().currentScreen.id != 'sync-consent'")
->Wait();
// Expect for other screens to be skipped and begin user session.
content::WindowedNotificationObserver observer(
chrome::NOTIFICATION_SESSION_STARTED,
content::NotificationService::AllSources());
observer.Wait();
}
INSTANTIATE_TEST_SUITE_P(/* no prefix */,
SyncConsenPolicyDisabledTest,
SyncConsentPolicyDisabledTest,
testing::Bool());
} // namespace chromeos
......@@ -266,6 +266,13 @@ bool WizardController::skip_post_login_screens_ = false;
// static
bool WizardController::skip_enrollment_prompts_ = false;
// static
#if defined(GOOGLE_CHROME_BUILD)
bool WizardController::is_official_build_ = true;
#else
bool WizardController::is_official_build_ = false;
#endif
// static
WizardController* WizardController::default_controller() {
auto* host = chromeos::LoginDisplayHost::default_host();
......@@ -578,11 +585,10 @@ void WizardController::ShowTermsOfServiceScreen() {
}
void WizardController::ShowSyncConsentScreen() {
#if defined(GOOGLE_CHROME_BUILD)
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_SYNC_CONSENT));
#else
OnSyncConsentFinished();
#endif
if (is_official_build_)
SetCurrentScreen(GetScreen(OobeScreen::SCREEN_SYNC_CONSENT));
else
OnSyncConsentFinished();
}
void WizardController::ShowFingerprintSetupScreen() {
......@@ -1565,6 +1571,12 @@ void WizardController::SkipEnrollmentPromptsForTesting() {
skip_enrollment_prompts_ = true;
}
// static
std::unique_ptr<base::AutoReset<bool>>
WizardController::ForceOfficialBuildForTesting() {
return std::make_unique<base::AutoReset<bool>>(&is_official_build_, true);
}
// static
bool WizardController::UsingHandsOffEnrollment() {
return policy::DeviceCloudPolicyManagerChromeOS::
......
......@@ -87,6 +87,9 @@ class WizardController : public BaseScreenDelegate {
// Skips any enrollment prompts that may be normally shown.
static void SkipEnrollmentPromptsForTesting();
// Forces screens that should only appear in chrome branded builds to show.
static std::unique_ptr<base::AutoReset<bool>> ForceOfficialBuildForTesting();
// Returns true if OOBE is operating under the
// Zero-Touch Hands-Off Enrollment Flow.
static bool UsingHandsOffEnrollment();
......@@ -340,11 +343,7 @@ class WizardController : public BaseScreenDelegate {
BaseScreen* previous_screen_ = nullptr;
// True if running official BUILD.
#if defined(GOOGLE_CHROME_BUILD)
bool is_official_build_ = true;
#else
bool is_official_build_ = false;
#endif
static bool is_official_build_;
// True if full OOBE flow should be shown.
bool is_out_of_box_ = false;
......@@ -388,11 +387,7 @@ class WizardController : public BaseScreenDelegate {
FRIEND_TEST_ALL_PREFIXES(WizardControllerDeviceStateTest,
ControlFlowNoForcedReEnrollmentOnFirstBoot);
friend class DemoSetupTest;
friend class OobeConfigurationTest;
friend class HandsOffEnrollmentTest;
friend class WizardControllerBrokenLocalStateTest;
friend class WizardControllerDemoSetupTest;
friend class WizardControllerDeviceStateTest;
friend class WizardControllerFlowTest;
friend class WizardControllerOobeConfigurationTest;
......
......@@ -500,9 +500,7 @@ class WizardControllerSupervisionTransitionOobeTest
// Pretend OOBE was complete.
StartupUtils::MarkOobeCompleted();
WizardController* wizard_controller =
WizardController::default_controller();
wizard_controller->is_official_build_ = true;
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
mock_supervision_transition_screen_view_ =
std::make_unique<MockSupervisionTransitionScreenView>();
......@@ -512,7 +510,7 @@ class WizardControllerSupervisionTransitionOobeTest
mock_supervision_transition_screen_view_.get(),
base::BindRepeating(
&WizardController::OnSupervisionTransitionScreenExit,
base::Unretained(wizard_controller))));
base::Unretained(WizardController::default_controller()))));
}
void SetUpCommandLine(base::CommandLine* command_line) override {
......@@ -524,6 +522,7 @@ class WizardControllerSupervisionTransitionOobeTest
MockSupervisionTransitionScreen* mock_supervision_transition_screen_;
std::unique_ptr<MockSupervisionTransitionScreenView>
mock_supervision_transition_screen_view_;
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
private:
DISALLOW_COPY_AND_ASSIGN(WizardControllerSupervisionTransitionOobeTest);
......@@ -565,9 +564,10 @@ class WizardControllerFlowTest : public WizardControllerTest {
WizardControllerTest::SetUpOnMainThread();
// Make sure that OOBE is run as an "official" build.
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
WizardController* wizard_controller =
WizardController::default_controller();
wizard_controller->is_official_build_ = true;
wizard_controller->SetSharedURLLoaderFactoryForTesting(
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_));
......@@ -856,8 +856,8 @@ class WizardControllerFlowTest : public WizardControllerTest {
private:
NetworkPortalDetectorTestImpl* network_portal_detector_ = nullptr;
network::TestURLLoaderFactory test_url_loader_factory_;
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
DISALLOW_COPY_AND_ASSIGN(WizardControllerFlowTest);
};
......@@ -2042,11 +2042,12 @@ class WizardControllerBrokenLocalStateTest : public WizardControllerTest {
WizardControllerTest::SetUpOnMainThread();
// Make sure that OOBE is run as an "official" build.
WizardController::default_controller()->is_official_build_ = true;
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
}
private:
std::unique_ptr<PrefService> local_state_;
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
DISALLOW_COPY_AND_ASSIGN(WizardControllerBrokenLocalStateTest);
};
......@@ -2712,9 +2713,10 @@ class WizardControllerOobeResumeTest : public WizardControllerTest {
WizardControllerTest::SetUpOnMainThread();
// Make sure that OOBE is run as an "official" build.
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
WizardController* wizard_controller =
WizardController::default_controller();
wizard_controller->is_official_build_ = true;
// Clear portal list (as it is by default in OOBE).
NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
......@@ -2746,6 +2748,8 @@ class WizardControllerOobeResumeTest : public WizardControllerTest {
std::unique_ptr<MockEnrollmentScreenView> mock_enrollment_screen_view_;
MockEnrollmentScreen* mock_enrollment_screen_;
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
private:
DISALLOW_COPY_AND_ASSIGN(WizardControllerOobeResumeTest);
};
......@@ -2814,9 +2818,7 @@ class WizardControllerOobeConfigurationTest : public WizardControllerTest {
WizardControllerTest::SetUpOnMainThread();
// Make sure that OOBE is run as an "official" build.
WizardController* wizard_controller =
WizardController::default_controller();
wizard_controller->is_official_build_ = true;
official_build_override_ = WizardController::ForceOfficialBuildForTesting();
// Clear portal list (as it is by default in OOBE).
NetworkHandler::Get()->network_state_handler()->SetCheckPortalList("");
......@@ -2825,8 +2827,9 @@ class WizardControllerOobeConfigurationTest : public WizardControllerTest {
mock_welcome_screen_ =
MockScreenExpectLifecycle(std::make_unique<MockWelcomeScreen>(
mock_welcome_view_.get(),
base::BindRepeating(&WizardController::OnWelcomeScreenExit,
base::Unretained(wizard_controller))));
base::BindRepeating(
&WizardController::OnWelcomeScreenExit,
base::Unretained(WizardController::default_controller()))));
}
void WaitForConfigurationLoaded() {
......@@ -2840,6 +2843,7 @@ class WizardControllerOobeConfigurationTest : public WizardControllerTest {
protected:
std::unique_ptr<MockWelcomeView> mock_welcome_view_;
MockWelcomeScreen* mock_welcome_screen_ = nullptr;
std::unique_ptr<base::AutoReset<bool>> official_build_override_;
private:
DISALLOW_COPY_AND_ASSIGN(WizardControllerOobeConfigurationTest);
......
......@@ -1887,6 +1887,7 @@ test("browser_tests") {
"../browser/chromeos/login/session_login_browsertest.cc",
"../browser/chromeos/login/signin/device_id_browsertest.cc",
"../browser/chromeos/login/signin/oauth2_browsertest.cc",
"../browser/chromeos/login/sync_consent_interactive_ui_test.cc",
"../browser/chromeos/login/test/active_directory_login_mixin.cc",
"../browser/chromeos/login/test/active_directory_login_mixin.h",
"../browser/chromeos/login/test/device_state_mixin.cc",
......@@ -2040,9 +2041,6 @@ test("browser_tests") {
}
if (is_chrome_branded) {
sources += [
# The screen this test is checking exists in official build only.
"../browser/chromeos/login/sync_consent_interactive_ui_test.cc",
# The KioskNext app is available in Chrome-branded builds only.
"../browser/ui/ash/kiosk_next_shell_client_browsertest.cc",
]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment