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

Unified Diff: chrome/test/chromedriver/mobile_device.cc

Issue 251933005: [ChromeDriver] Support mobile emulation on desktop Chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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/test/chromedriver/mobile_device.cc
diff --git a/chrome/test/chromedriver/mobile_device.cc b/chrome/test/chromedriver/mobile_device.cc
new file mode 100644
index 0000000000000000000000000000000000000000..93943c7d63c4027b87057bdb57b750e069b17715
--- /dev/null
+++ b/chrome/test/chromedriver/mobile_device.cc
@@ -0,0 +1,67 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/json/json_reader.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_split.h"
+#include "base/values.h"
+#include "chrome/test/chromedriver/chrome/mobile_devices.h"
+#include "chrome/test/chromedriver/chrome/status.h"
+#include "chrome/test/chromedriver/mobile_device.h"
+
+MobileDevice::MobileDevice() {}
+MobileDevice::MobileDevice(DeviceMetrics device_metrics, std::string user_agent)
+ : device_metrics(device_metrics), user_agent(user_agent) {}
+MobileDevice::~MobileDevice() {}
+
+Status FindMobileDevice(std::string device_name,
+ scoped_ptr<MobileDevice>* mobile_device) {
+ base::JSONReader json_reader(base::JSON_ALLOW_TRAILING_COMMAS);
+ scoped_ptr<base::Value> devices_value;
+ devices_value.reset(json_reader.ReadToValue(kMobileDevices));
+ if (!devices_value.get())
+ return Status(kUnknownError,
+ "Could not parse mobile device list because " +
stgao 2014/05/14 05:10:14 lowercase for error message. "Could" -> "could".
sam.rawlins 2014/05/16 21:09:38 Done.
+ json_reader.GetErrorMessage());
+
+ base::ListValue* mobile_devices;
+ if (!devices_value->GetAsList(&mobile_devices))
+ return Status(kUnknownError, "malformed device metrics list");
+
+ for (base::ListValue::iterator it = mobile_devices->begin();
+ it != mobile_devices->end();
+ ++it) {
+ base::ListValue* device = NULL;
+ (*it)->GetAsList(&device);
samuong 2014/05/09 17:58:54 GetAsList, as well as GetString, StringToInt and S
sam.rawlins 2014/05/16 21:09:38 Done.
+ if (device != NULL) {
+ std::string name;
+ device->GetString(0, &name);
+ if (name != device_name)
+ continue;
+
+ scoped_ptr<MobileDevice> tmp_mobile_device(new MobileDevice());
+ std::string device_metrics_string;
+ device->GetString(1, &tmp_mobile_device->user_agent);
+ device->GetString(2, &device_metrics_string);
+ std::vector<std::string> metrics_vector;
+ base::SplitString(device_metrics_string, 'x', &metrics_vector);
+ if (metrics_vector.size() < 3)
+ return Status(kUnknownError, "malformed device metrics string");
+
+ int width = 0;
+ int height = 0;
+ double device_scale_factor = 0.0;
+ base::StringToInt(metrics_vector[0], &width);
+ base::StringToInt(metrics_vector[1], &height);
+ base::StringToDouble(metrics_vector[2], &device_scale_factor);
+ tmp_mobile_device->device_metrics =
+ DeviceMetrics(width, height, device_scale_factor);
+
+ *mobile_device = tmp_mobile_device.Pass();
+ return Status(kOk);
+ }
+ }
+
+ return Status(kUnknownError, "must be a valid device");
+}

Powered by Google App Engine
This is Rietveld 408576698