Enable WizardControllerDemoSetupDeviceDisabled.OnlineDemoSetup

Fixes a race where auto-enrollment screen would just hang if the
auto-enrollment check triggered in posted EULA steps reported
connection error, or server error before the auto enrollment check
screen was started.

The AutoEnrollmentController would report in complete state, but
requests to (re) start auto-enrollment checks would be ignored due
to client_ already being set.

BUG=894384

Change-Id: Idd770f3e9d437a0a80df0e6243fc200dc6ae3e30
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1576144
Commit-Queue: Toni Baržić <tbarzic@chromium.org>
Reviewed-by: Roman Sorokin [CET] <rsorokin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653370}
diff --git a/chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen.cc b/chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen.cc
index 035a64f9..8b9b91a 100644
--- a/chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen.cc
+++ b/chrome/browser/chromeos/login/enrollment/auto_enrollment_check_screen.cc
@@ -111,7 +111,17 @@
   auto_enrollment_state_ = new_auto_enrollment_state;
 
   // Make sure gears are in motion in the background.
-  auto_enrollment_controller_->Start();
+  // Note that if a previous auto-enrollment check ended with a failure,
+  // IsCompleted() would still return false, and Show would not report result
+  // early. In that case auto-enrollment check should be retried.
+  if (auto_enrollment_controller_->state() ==
+          policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR ||
+      auto_enrollment_controller_->state() ==
+          policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR) {
+    auto_enrollment_controller_->Retry();
+  } else {
+    auto_enrollment_controller_->Start();
+  }
   network_portal_detector::GetInstance()->StartPortalDetection(
       false /* force */);
 }
diff --git a/chrome/browser/chromeos/login/wizard_controller_browsertest.cc b/chrome/browser/chromeos/login/wizard_controller_browsertest.cc
index 7c8e0de7..52b57cd 100644
--- a/chrome/browser/chromeos/login/wizard_controller_browsertest.cc
+++ b/chrome/browser/chromeos/login/wizard_controller_browsertest.cc
@@ -2629,9 +2629,8 @@
   DISALLOW_COPY_AND_ASSIGN(WizardControllerDemoSetupDeviceDisabledTest);
 };
 
-// Flaky https://crbug.com/894384.
 IN_PROC_BROWSER_TEST_F(WizardControllerDemoSetupDeviceDisabledTest,
-                       DISABLED_OnlineDemoSetup) {
+                       OnlineDemoSetup) {
   CheckCurrentScreen(OobeScreen::SCREEN_OOBE_WELCOME);
   EXPECT_FALSE(DemoSetupController::IsOobeDemoSetupFlowInProgress());
   WaitUntilJSIsReady();
@@ -2698,8 +2697,9 @@
   WaitForAutoEnrollmentState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR);
 
   // The error screen shows up if device state could not be retrieved.
-  EXPECT_EQ(GetErrorScreen(),
-            WizardController::default_controller()->current_screen());
+  CheckCurrentScreen(OobeScreen::SCREEN_AUTO_ENROLLMENT_CHECK);
+  EXPECT_EQ(OobeScreen::SCREEN_AUTO_ENROLLMENT_CHECK,
+            GetErrorScreen()->GetParentScreen());
   base::DictionaryValue device_state;
   device_state.SetString(policy::kDeviceStateMode,
                          policy::kDeviceStateRestoreModeDisabled);
@@ -2710,6 +2710,8 @@
   EXPECT_CALL(*device_disabled_screen_view_, Show()).Times(1);
   mock_auto_enrollment_check_screen_->ExitScreen();
 
+  base::RunLoop().RunUntilIdle();
+
   ResetAutoEnrollmentCheckScreen();
   CheckCurrentScreen(OobeScreen::SCREEN_DEVICE_DISABLED);