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
......
...@@ -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