Commit 2fc0ffd3 authored by John Chen's avatar John Chen Committed by Commit Bot

[ChromeDriver] Fix userAgent for emulated devices

The userAgent strings associated with some emulated mobile devices
contain substring "%s", which should be replaced with Chrome version.

Bug: chromedriver:1883
Change-Id: I475a9a20e72008956bc201b3677cb60f6632e57c
Reviewed-on: https://chromium-review.googlesource.com/689966
Commit-Queue: John Chen <johnchen@chromium.org>
Reviewed-by: default avatarShuotao Gao <stgao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506775}
parent d930ca34
...@@ -517,7 +517,7 @@ TEST(ParseCapabilities, MobileEmulationDeviceName) { ...@@ -517,7 +517,7 @@ TEST(ParseCapabilities, MobileEmulationDeviceName) {
ASSERT_TRUE(capabilities.switches.HasSwitch("user-agent")); ASSERT_TRUE(capabilities.switches.HasSwitch("user-agent"));
ASSERT_EQ( ASSERT_EQ(
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) " "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3227.0 Mobile "
"Safari/537.36", "Safari/537.36",
capabilities.switches.GetSwitchValue("user-agent")); capabilities.switches.GetSwitchValue("user-agent"));
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// This file was generated at (2017-06-01 20:57:49.161613) by running: // This file was generated at (2017-09-29 09:51:48.959567) by running:
// ./chrome/test/chromedriver/embed_mobile_devices_in_cpp.py --directory // ./chrome/test/chromedriver/embed_mobile_devices_in_cpp.py --directory
// chrome/test/chromedriver/chrome/ // chrome/test/chromedriver/chrome/
// third_party/WebKit/Source/devtools/front_end/emulated_devices/module.json // third_party/WebKit/Source/devtools/front_end/emulated_devices/module.json
...@@ -22,19 +22,20 @@ const char kMobileDevices[] = ...@@ -22,19 +22,20 @@ const char kMobileDevices[] =
"Safari/537.10+\"}, \"Nexus 6\": {\"deviceScaleFactor\": 3.5, \"mobile\": " "Safari/537.10+\"}, \"Nexus 6\": {\"deviceScaleFactor\": 3.5, \"mobile\": "
"true, \"height\": 732, \"width\": 412, \"touch\": true, \"userAgent\": " "true, \"height\": 732, \"width\": 412, \"touch\": true, \"userAgent\": "
"\"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) " "\"Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36\"}, " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3227.0 Mobile "
"\"LG Optimus L70\": {\"deviceScaleFactor\": 1.25, \"mobile\": true, " "Safari/537.36\"}, \"LG Optimus L70\": {\"deviceScaleFactor\": 1.25, "
"\"height\": 640, \"width\": 384, \"touch\": true, \"userAgent\": " "\"mobile\": true, \"height\": 640, \"width\": 384, \"touch\": true, "
"\"Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 " "\"userAgent\": \"Mozilla/5.0 (Linux; U; Android 4.4.2; en-us; LGMS323 "
"Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " "Build/KOT49I.MS32310c) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 "
"Chrome/%s Mobile Safari/537.36\"}, \"Nexus 4\": {\"deviceScaleFactor\": " "Chrome/63.0.3227.0 Mobile Safari/537.36\"}, \"Nexus 4\": "
"2, \"mobile\": true, \"height\": 640, \"width\": 384, \"touch\": true, " "{\"deviceScaleFactor\": 2, \"mobile\": true, \"height\": 640, \"width\": "
"\"userAgent\": \"Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) " "384, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Linux; Android 4.4.2; "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36\"}, " "Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) "
"\"Nexus 5\": {\"deviceScaleFactor\": 3, \"mobile\": true, \"height\": " "Chrome/63.0.3227.0 Mobile Safari/537.36\"}, \"Nexus 5\": "
"640, \"width\": 360, \"touch\": true, \"userAgent\": \"Mozilla/5.0 " "{\"deviceScaleFactor\": 3, \"mobile\": true, \"height\": 640, \"width\": "
"(Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, " "360, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Linux; Android 6.0; "
"like Gecko) Chrome/%s Mobile Safari/537.36\"}, \"Blackberry PlayBook\": " "Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/63.0.3227.0 Mobile Safari/537.36\"}, \"Blackberry PlayBook\": "
"{\"deviceScaleFactor\": 1, \"mobile\": true, \"height\": 1024, \"width\": " "{\"deviceScaleFactor\": 1, \"mobile\": true, \"height\": 1024, \"width\": "
"600, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (PlayBook; U; RIM " "600, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (PlayBook; U; RIM "
"Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) " "Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) "
...@@ -46,39 +47,39 @@ const char kMobileDevices[] = ...@@ -46,39 +47,39 @@ const char kMobileDevices[] =
"{\"deviceScaleFactor\": 3.5, \"mobile\": true, \"height\": 732, " "{\"deviceScaleFactor\": 3.5, \"mobile\": true, \"height\": 732, "
"\"width\": 412, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Linux; " "\"width\": 412, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Linux; "
"Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like " "Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like "
"Gecko) Chrome/%s Mobile Safari/537.36\"}, \"Laptop with HiDPI screen\": " "Gecko) Chrome/63.0.3227.0 Mobile Safari/537.36\"}, \"Laptop with HiDPI "
"{\"deviceScaleFactor\": 2, \"mobile\": false, \"height\": 1440, " "screen\": {\"deviceScaleFactor\": 2, \"mobile\": false, \"height\": 1440, "
"\"width\": 900, \"touch\": false, \"userAgent\": \"\"}, \"Nexus 7\": " "\"width\": 900, \"touch\": false, \"userAgent\": \"\"}, \"Nexus 7\": "
"{\"deviceScaleFactor\": 2, \"mobile\": true, \"height\": 960, \"width\": " "{\"deviceScaleFactor\": 2, \"mobile\": true, \"height\": 960, \"width\": "
"600, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Linux; Android 4.3; " "600, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Linux; Android 4.3; "
"Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s " "Nexus 7 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like Gecko) "
"Safari/537.36\"}, \"Nokia N9\": {\"deviceScaleFactor\": 1, \"mobile\": " "Chrome/63.0.3227.0 Safari/537.36\"}, \"Nokia N9\": "
"true, \"height\": 640, \"width\": 360, \"touch\": true, \"userAgent\": " "{\"deviceScaleFactor\": 1, \"mobile\": true, \"height\": 854, \"width\": "
"\"Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) " "480, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (MeeGo; NokiaN9) "
"NokiaBrowser/8.5.0 Mobile Safari/534.13\"}, \"Nokia Lumia 520\": " "AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile "
"{\"deviceScaleFactor\": 1.5, \"mobile\": true, \"height\": 533, " "Safari/534.13\"}, \"Nokia Lumia 520\": {\"deviceScaleFactor\": 1.5, "
"\"width\": 320, \"touch\": true, \"userAgent\": \"Mozilla/5.0 " "\"mobile\": true, \"height\": 533, \"width\": 320, \"touch\": true, "
"(compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; " "\"userAgent\": \"Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; "
"ARM; Touch; NOKIA; Lumia 520)\"}, \"Nexus 10\": {\"deviceScaleFactor\": " "Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 520)\"}, \"Nexus "
"2, \"mobile\": true, \"height\": 1280, \"width\": 800, \"touch\": true, " "10\": {\"deviceScaleFactor\": 2, \"mobile\": true, \"height\": 1280, "
"\"userAgent\": \"Mozilla/5.0 (Linux; Android 4.3; Nexus 10 Build/JSS15Q) " "\"width\": 800, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Linux; "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Safari/537.36\"}, " "Android 4.3; Nexus 10 Build/JSS15Q) AppleWebKit/537.36 (KHTML, like "
"\"Microsoft Lumia 950\": {\"deviceScaleFactor\": 4, \"mobile\": true, " "Gecko) Chrome/63.0.3227.0 Safari/537.36\"}, \"Microsoft Lumia 950\": "
"\"height\": 640, \"width\": 360, \"touch\": true, \"userAgent\": " "{\"deviceScaleFactor\": 4, \"mobile\": true, \"height\": 640, \"width\": "
"\"Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) " "360, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (Windows Phone 10.0; "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile " "Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like "
"Safari/537.36 Edge/14.14263\"}, \"iPhone 5\": {\"deviceScaleFactor\": 2, " "Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/14.14263\"}, \"iPhone "
"\"mobile\": true, \"height\": 568, \"width\": 320, \"touch\": true, " "5\": {\"deviceScaleFactor\": 2, \"mobile\": true, \"height\": 568, "
"\"width\": 320, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (iPhone; "
"CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) "
"Version/9.0 Mobile/13B143 Safari/601.1\"}, \"iPhone 4\": "
"{\"deviceScaleFactor\": 2, \"mobile\": true, \"height\": 480, \"width\": "
"320, \"touch\": true, \"userAgent\": \"Mozilla/5.0 (iPhone; CPU iPhone OS "
"9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 "
"Mobile/13B143 Safari/601.1\"}, \"iPhone 6\": {\"deviceScaleFactor\": 2, "
"\"mobile\": true, \"height\": 667, \"width\": 375, \"touch\": true, "
"\"userAgent\": \"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) " "\"userAgent\": \"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) "
"AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 " "AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 "
"Safari/601.1\"}, \"iPhone 4\": {\"deviceScaleFactor\": 2, \"mobile\": "
"true, \"height\": 480, \"width\": 320, \"touch\": true, \"userAgent\": "
"\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) "
"AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 "
"Safari/601.1\"}, \"iPhone 6\": {\"deviceScaleFactor\": 2, \"mobile\": "
"true, \"height\": 667, \"width\": 375, \"touch\": true, \"userAgent\": "
"\"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) "
"AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 "
"Safari/601.1\"}, \"Galaxy S III\": {\"deviceScaleFactor\": 2, \"mobile\": " "Safari/601.1\"}, \"Galaxy S III\": {\"deviceScaleFactor\": 2, \"mobile\": "
"true, \"height\": 640, \"width\": 360, \"touch\": true, \"userAgent\": " "true, \"height\": 640, \"width\": 360, \"touch\": true, \"userAgent\": "
"\"Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) " "\"Mozilla/5.0 (Linux; U; Android 4.0; en-us; GT-I9300 Build/IMM76D) "
...@@ -98,11 +99,11 @@ const char kMobileDevices[] = ...@@ -98,11 +99,11 @@ const char kMobileDevices[] =
"Safari/601.1\"}, \"Nexus 5X\": {\"deviceScaleFactor\": 2.625, \"mobile\": " "Safari/601.1\"}, \"Nexus 5X\": {\"deviceScaleFactor\": 2.625, \"mobile\": "
"true, \"height\": 732, \"width\": 412, \"touch\": true, \"userAgent\": " "true, \"height\": 732, \"width\": 412, \"touch\": true, \"userAgent\": "
"\"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) " "\"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36\"}, " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3227.0 Mobile "
"\"Galaxy Note II\": {\"deviceScaleFactor\": 2, \"mobile\": true, " "Safari/537.36\"}, \"Galaxy Note II\": {\"deviceScaleFactor\": 2, "
"\"height\": 640, \"width\": 360, \"touch\": true, \"userAgent\": " "\"mobile\": true, \"height\": 640, \"width\": 360, \"touch\": true, "
"\"Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 Build/JRO03C) " "\"userAgent\": \"Mozilla/5.0 (Linux; U; Android 4.1; en-us; GT-N7100 "
"AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile " "Build/JRO03C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile "
"Safari/534.30\"}, \"iPhone 6 Plus\": {\"deviceScaleFactor\": 3, " "Safari/534.30\"}, \"iPhone 6 Plus\": {\"deviceScaleFactor\": 3, "
"\"mobile\": true, \"height\": 736, \"width\": 414, \"touch\": true, " "\"mobile\": true, \"height\": 736, \"width\": 414, \"touch\": true, "
"\"userAgent\": \"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) " "\"userAgent\": \"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) "
...@@ -110,11 +111,11 @@ const char kMobileDevices[] = ...@@ -110,11 +111,11 @@ const char kMobileDevices[] =
"Safari/601.1\"}, \"Galaxy S5\": {\"deviceScaleFactor\": 3, \"mobile\": " "Safari/601.1\"}, \"Galaxy S5\": {\"deviceScaleFactor\": 3, \"mobile\": "
"true, \"height\": 640, \"width\": 360, \"touch\": true, \"userAgent\": " "true, \"height\": 640, \"width\": 360, \"touch\": true, \"userAgent\": "
"\"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) " "\"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s Mobile Safari/537.36\"}, " "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3227.0 Mobile "
"\"Kindle Fire HDX\": {\"deviceScaleFactor\": 2, \"mobile\": true, " "Safari/537.36\"}, \"Kindle Fire HDX\": {\"deviceScaleFactor\": 2, "
"\"height\": 2560, \"width\": 1600, \"touch\": true, \"userAgent\": " "\"mobile\": true, \"height\": 1280, \"width\": 800, \"touch\": true, "
"\"Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) AppleWebKit/535.19 " "\"userAgent\": \"Mozilla/5.0 (Linux; U; en-us; KFAPWI Build/JDQ39) "
"(KHTML, like Gecko) Silk/3.13 Safari/535.19 Silk-Accelerated=true\"}, " "AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.13 Safari/535.19 "
"\"Laptop with MDPI screen\": {\"deviceScaleFactor\": 1, \"mobile\": " "Silk-Accelerated=true\"}, \"Laptop with MDPI screen\": "
"false, \"height\": 1280, \"width\": 800, \"touch\": false, \"userAgent\": " "{\"deviceScaleFactor\": 1, \"mobile\": false, \"height\": 1280, "
"\"\"}}"; "\"width\": 800, \"touch\": false, \"userAgent\": \"\"}}";
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// This file was generated at (2017-06-01 20:57:49.161613) by running: // This file was generated at (2017-09-29 09:51:48.959567) by running:
// ./chrome/test/chromedriver/embed_mobile_devices_in_cpp.py --directory // ./chrome/test/chromedriver/embed_mobile_devices_in_cpp.py --directory
// chrome/test/chromedriver/chrome/ // chrome/test/chromedriver/chrome/
// third_party/WebKit/Source/devtools/front_end/emulated_devices/module.json // third_party/WebKit/Source/devtools/front_end/emulated_devices/module.json
......
...@@ -13,20 +13,41 @@ parsed with JSONReader. ...@@ -13,20 +13,41 @@ parsed with JSONReader.
import json import json
import optparse import optparse
import os
import re import re
import subprocess import subprocess
import sys import sys
import chrome_paths
import cpp_source import cpp_source
def main(): def main():
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option(
'', '--version-file', type='string',
default=os.path.join(chrome_paths.GetSrc(), 'chrome', 'VERSION'),
help='Path to Chrome version file')
parser.add_option( parser.add_option(
'', '--directory', type='string', default='.', '', '--directory', type='string', default='.',
help='Path to directory where the cc/h files should be created') help='Path to directory where the cc/h files should be created')
options, args = parser.parse_args() options, args = parser.parse_args()
# The device userAgent string may contain '%s', which should be replaced with
# current Chrome version. First we read the version file.
version_parts = ['MAJOR', 'MINOR', 'BUILD', 'PATCH']
version = []
version_file = open(options.version_file, 'r')
for part in version_parts:
# The version file should have 4 lines, with format like MAJOR=63
components = version_file.readline().split('=')
if len(components) != 2 or components[0].strip() != part:
print 'Bad version file'
return 1
version.append(components[1].strip())
# Join parts of version together using '.' as separator
version = '.'.join(version)
devices = {} devices = {}
file_name = args[0] file_name = args[0]
inside_list = False inside_list = False
...@@ -37,7 +58,7 @@ def main(): ...@@ -37,7 +58,7 @@ def main():
if extension['type'] == 'emulated-device': if extension['type'] == 'emulated-device':
device = extension['device'] device = extension['device']
devices[device['title']] = { devices[device['title']] = {
'userAgent': device['user-agent'], 'userAgent': device['user-agent'].replace('%s', version),
'width': device['screen']['vertical']['width'], 'width': device['screen']['vertical']['width'],
'height': device['screen']['vertical']['height'], 'height': device['screen']['vertical']['height'],
'deviceScaleFactor': device['screen']['device-pixel-ratio'], 'deviceScaleFactor': device['screen']['device-pixel-ratio'],
......
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