Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6240)

Unified Diff: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc

Issue 2006083002: Use fake Input Device Settings with chrome://device-emulator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@DevicePageTestsFixes
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
diff --git a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
index 5f1f17d80fd8cbbf46a3aa0ec0a1669596f1f193..51d4596f68f98b8340f68ee053124a955430ea2e 100644
--- a/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
+++ b/chrome/browser/ui/webui/chromeos/emulator/device_emulator_message_handler.cc
@@ -13,6 +13,7 @@
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
+#include "chrome/browser/chromeos/system/fake_input_device_settings.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cras_audio_client.h"
#include "chromeos/dbus/fake_power_manager_client.h"
@@ -38,6 +39,8 @@ const char kRemoveAudioNode[] = "removeAudioNode";
// Define update functions that will update the power properties to the
// variables defined in the web UI.
const char kRemoveBluetoothDevice[] = "removeBluetoothDevice";
+const char kSetHasMouse[] = "setHasMouse";
+const char kSetHasTouchpad[] = "setHasTouchpad";
const char kUpdateBatteryPercent[] = "updateBatteryPercent";
const char kUpdateBatteryState[] = "updateBatteryState";
const char kUpdateTimeToEmpty[] = "updateTimeToEmpty";
@@ -61,6 +64,10 @@ const char kUpdateBluetoothInfoJSCallback[] =
"device_emulator.bluetoothSettings.updateBluetoothInfo";
const char kUpdatePowerPropertiesJSCallback[] =
"device_emulator.batterySettings.updatePowerProperties";
+const char kMouseExistsCallback[] =
+ "device_emulator.inputDeviceSettings.setMouseExists";
+const char kTouchpadExistsCallback[] =
+ "device_emulator.inputDeviceSettings.setTouchpadExists";
const char kPairedPropertyName[] = "Paired";
@@ -199,13 +206,18 @@ DeviceEmulatorMessageHandler::DeviceEmulatorMessageHandler()
->GetCrasAudioClient())),
fake_power_manager_client_(static_cast<chromeos::FakePowerManagerClient*>(
chromeos::DBusThreadManager::Get()
- ->GetPowerManagerClient())) {}
+ ->GetPowerManagerClient())),
+ fake_input_device_settings_(nullptr),
+ weak_ptr_factory_(this) {}
DeviceEmulatorMessageHandler::~DeviceEmulatorMessageHandler() {
}
void DeviceEmulatorMessageHandler::Init(const base::ListValue* args) {
AllowJavascript();
+ bluetooth_observer_.reset(new BluetoothObserver(this));
+ cras_audio_observer_.reset(new CrasAudioObserver(this));
+ power_observer_.reset(new PowerObserver(this));
}
void DeviceEmulatorMessageHandler::RequestPowerInfo(
@@ -336,6 +348,22 @@ void DeviceEmulatorMessageHandler::HandleRemoveAudioNode(
fake_cras_audio_client_->RemoveAudioNodeFromList(id);
}
+void DeviceEmulatorMessageHandler::HandleSetHasMouse(
+ const base::ListValue* args) {
+ bool has_mouse;
+ CHECK(args->GetBoolean(0, &has_mouse));
+
+ CreateFakeInputDeviceSettingsIfNecessary()->SetMouseExists(has_mouse);
+}
+
+void DeviceEmulatorMessageHandler::HandleSetHasTouchpad(
+ const base::ListValue* args) {
+ bool has_touchpad;
+ CHECK(args->GetBoolean(0, &has_touchpad));
+
+ CreateFakeInputDeviceSettingsIfNecessary()->SetTouchpadExists(has_touchpad);
+}
+
void DeviceEmulatorMessageHandler::UpdateBatteryPercent(
const base::ListValue* args) {
int new_percent;
@@ -507,12 +535,28 @@ void DeviceEmulatorMessageHandler::RegisterMessages() {
kRemoveBluetoothDevice,
base::Bind(&DeviceEmulatorMessageHandler::HandleRemoveBluetoothDevice,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ kSetHasMouse,
+ base::Bind(&DeviceEmulatorMessageHandler::HandleSetHasMouse,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ kSetHasTouchpad,
+ base::Bind(&DeviceEmulatorMessageHandler::HandleSetHasTouchpad,
+ base::Unretained(this)));
}
void DeviceEmulatorMessageHandler::OnJavascriptAllowed() {
bluetooth_observer_.reset(new BluetoothObserver(this));
cras_audio_observer_.reset(new CrasAudioObserver(this));
power_observer_.reset(new PowerObserver(this));
+
+ // Set input device settings to a new fake.
+ CreateFakeInputDeviceSettingsIfNecessary()->MouseExists(
+ base::Bind(&DeviceEmulatorMessageHandler::MouseExists,
+ weak_ptr_factory_.GetWeakPtr()));
+ CreateFakeInputDeviceSettingsIfNecessary()->TouchpadExists(
+ base::Bind(&DeviceEmulatorMessageHandler::TouchpadExists,
+ weak_ptr_factory_.GetWeakPtr()));
}
void DeviceEmulatorMessageHandler::OnJavascriptDisallowed() {
@@ -583,4 +627,30 @@ DeviceEmulatorMessageHandler::GetDeviceInfo(
return device;
}
+system::FakeInputDeviceSettings*
+DeviceEmulatorMessageHandler::CreateFakeInputDeviceSettingsIfNecessary() {
+ if (!fake_input_device_settings_ ||
+ fake_input_device_settings_ != system::InputDeviceSettings::Get()) {
+ // Create a new fake to use.
+ fake_input_device_settings_ = new system::FakeInputDeviceSettings();
+ system::InputDeviceSettings::SetSettingsForTesting(
+ fake_input_device_settings_);
+ }
+ return fake_input_device_settings_;
+}
+
+void DeviceEmulatorMessageHandler::MouseExists(bool exists) {
+ if (!IsJavascriptAllowed())
+ return;
+ web_ui()->CallJavascriptFunction(kMouseExistsCallback,
+ base::FundamentalValue(exists));
+}
+
+void DeviceEmulatorMessageHandler::TouchpadExists(bool exists) {
+ if (!IsJavascriptAllowed())
+ return;
+ web_ui()->CallJavascriptFunction(kTouchpadExistsCallback,
+ base::FundamentalValue(exists));
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698