Commit 56d00d9b authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

cros: Persist HID detection screen disabled state in the local state

so it persists the reboot during autoupdate integration test.
Looks like the test can't pass the command-line flag after the restart.
So Chrome keep the information in the local state to disable HID
detection screen on restart.

Bug: 1127536
Change-Id: I5fe32479a585fa67b4534a42a3d61aa958e37470
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2426451
Auto-Submit: Roman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813223}
parent 99bbf7de
......@@ -906,7 +906,8 @@ class OobeSpokenFeedbackTest : public OobeBaseTest {
OobeBaseTest::SetUpCommandLine(command_line);
// Many bots don't have keyboard/mice which triggers the HID detection
// dialog in the OOBE. Avoid confusing the tests with that.
command_line->AppendSwitch(chromeos::switches::kDisableHIDDetectionOnOOBE);
command_line->AppendSwitch(
chromeos::switches::kDisableHIDDetectionOnOOBEForTesting);
}
SpeechMonitor sm_;
......
......@@ -161,7 +161,8 @@ class EnableDebuggingTestBase : public OobeBaseTest {
OobeBaseTest::SetUpCommandLine(command_line);
// Disable HID detection because it takes precedence and could block
// enable-debugging UI.
command_line->AppendSwitch(chromeos::switches::kDisableHIDDetectionOnOOBE);
command_line->AppendSwitch(
chromeos::switches::kDisableHIDDetectionOnOOBEForTesting);
}
void SetUpInProcessBrowserTestFixture() override {
std::unique_ptr<DBusThreadManagerSetter> dbus_setter =
......
......@@ -28,6 +28,9 @@
namespace {
constexpr char kDisableHIDDetectionScreenForTests[] =
"oobe.disable_hid_detection_screen_for_tests";
// Saves boolean "Local State" preference and forces its persistence to disk.
void SaveBoolPreferenceForced(const char* pref_name, bool value) {
PrefService* prefs = g_browser_process->local_state();
......@@ -92,6 +95,7 @@ void StartupUtils::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(prefs::kDeviceRegistered, -1);
registry->RegisterBooleanPref(prefs::kEnrollmentRecoveryRequired, false);
registry->RegisterStringPref(prefs::kInitialLocale, "en-US");
registry->RegisterBooleanPref(kDisableHIDDetectionScreenForTests, false);
}
// static
......@@ -177,6 +181,17 @@ void StartupUtils::MarkEnrollmentRecoveryRequired() {
SaveBoolPreferenceForced(prefs::kEnrollmentRecoveryRequired, true);
}
// static
void StartupUtils::DisableHIDDetectionScreenForTests() {
SaveBoolPreferenceForced(kDisableHIDDetectionScreenForTests, true);
}
// static
bool StartupUtils::IsHIDDetectionScreenDisabledForTests() {
return g_browser_process->local_state()->GetBoolean(
kDisableHIDDetectionScreenForTests);
}
// static
std::string StartupUtils::GetInitialLocale() {
std::string locale =
......
......@@ -54,6 +54,10 @@ class StartupUtils {
// Mark a device as requiring enrollment recovery.
static void MarkEnrollmentRecoveryRequired();
static void DisableHIDDetectionScreenForTests();
static bool IsHIDDetectionScreenDisabledForTests();
// Returns initial locale from local settings.
static std::string GetInitialLocale();
......
......@@ -77,7 +77,8 @@ class CaptivePortalWindowTest : public InProcessBrowserTest {
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
command_line->AppendSwitch(chromeos::switches::kLoginManager);
command_line->AppendSwitch(chromeos::switches::kDisableHIDDetectionOnOOBE);
command_line->AppendSwitch(
chromeos::switches::kDisableHIDDetectionOnOOBEForTesting);
}
void SetUpOnMainThread() override {
......
......@@ -227,12 +227,15 @@ const chromeos::StaticOobeScreenId kScreensWithHiddenStatusArea[] = {
// The HID detection screen is only allowed for form factors without built-in
// inputs: Chromebases, Chromebits, and Chromeboxes (crbug.com/965765).
bool CanShowHIDDetectionScreen() {
if (chromeos::StartupUtils::IsHIDDetectionScreenDisabledForTests())
return false;
switch (chromeos::GetDeviceType()) {
case chromeos::DeviceType::kChromebase:
case chromeos::DeviceType::kChromebit:
case chromeos::DeviceType::kChromebox:
return !base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDisableHIDDetectionOnOOBE);
chromeos::switches::kDisableHIDDetectionOnOOBEForTesting);
default:
return false;
}
......@@ -903,6 +906,13 @@ void WizardController::SkipToUpdateForTesting() {
VLOG(1) << "SkipToUpdateForTesting.";
wizard_context_->skip_to_update_for_tests = true;
StartupUtils::MarkEulaAccepted();
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDisableHIDDetectionOnOOBEForTesting)) {
// We store the flag into local state so it persists restart after the
// update. Command line switch does not persist the restart during the
// test.
StartupUtils::DisableHIDDetectionScreenForTests();
}
PerformPostEulaActions();
InitiateOOBEUpdate();
}
......
......@@ -102,6 +102,7 @@
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_utils.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
......@@ -2846,6 +2847,37 @@ IN_PROC_BROWSER_TEST_F(WizardControllerOobeConfigurationTest,
EXPECT_FALSE(configuration->DictEmpty());
}
class HIDDetectionScreenDisabledAfterRestartTest : public OobeBaseTest {
public:
HIDDetectionScreenDisabledAfterRestartTest() = default;
// OobeBaseTest:
void SetUpCommandLine(base::CommandLine* command_line) override {
OobeBaseTest::SetUpCommandLine(command_line);
// Emulating Chrome restart without the flag.
if (content::IsPreTest()) {
command_line->AppendSwitch(
switches::kDisableHIDDetectionOnOOBEForTesting);
}
}
};
IN_PROC_BROWSER_TEST_F(HIDDetectionScreenDisabledAfterRestartTest,
PRE_SkipToUpdate) {
// Pref should be false by default.
EXPECT_FALSE(StartupUtils::IsHIDDetectionScreenDisabledForTests());
WizardController::default_controller()->SkipToUpdateForTesting();
// SkipToUpdateForTesting should set the pref when
// switches::kDisableHIDDetectionOnOOBEForTesting is passed.
EXPECT_TRUE(StartupUtils::IsHIDDetectionScreenDisabledForTests());
}
IN_PROC_BROWSER_TEST_F(HIDDetectionScreenDisabledAfterRestartTest,
SkipToUpdate) {
// The pref should persist restart.
EXPECT_TRUE(StartupUtils::IsHIDDetectionScreenDisabledForTests());
}
// TODO(nkostylev): Add test for WebUI accelerators http://crosbug.com/22571
// TODO(merkulova): Add tests for bluetooth HID detection screen variations when
......
......@@ -221,7 +221,8 @@ const char kDisableFineGrainedTimeZoneDetection[] =
const char kDisableGaiaServices[] = "disable-gaia-services";
// Disables HID-detection OOBE screen.
const char kDisableHIDDetectionOnOOBE[] = "disable-hid-detection-on-oobe";
const char kDisableHIDDetectionOnOOBEForTesting[] =
"disable-hid-detection-on-oobe";
// Avoid doing expensive animations upon login.
const char kDisableLoginAnimations[] = "disable-login-animations";
......
......@@ -84,7 +84,7 @@ COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kDisableFineGrainedTimeZoneDetection[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS) extern const char kDisableGaiaServices[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kDisableHIDDetectionOnOOBE[];
extern const char kDisableHIDDetectionOnOOBEForTesting[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
extern const char kDisableLoginAnimations[];
COMPONENT_EXPORT(CHROMEOS_CONSTANTS)
......
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