Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Change user agent in TelemetryActivity in system webview shell for
Browse files Browse the repository at this point in the history
perf testing with Extra String that comes with the intent

This is to fix one of the issues in android_webview_aosp_perf. Android
WebView doesn't support "--user-agent" commandline flag and it causing
some of the pages to reload in Telemetry tests.

BUG=554430

Review URL: https://codereview.chromium.org/1433193002

Cr-Commit-Position: refs/heads/master@{#360219}
  • Loading branch information
yolandyan authored and Commit bot committed Nov 18, 2015
1 parent 30b6df3 commit ffa5a6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package org.chromium.webview_shell;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.CookieManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

Expand All @@ -24,7 +26,14 @@ public void onCreate(Bundle savedInstanceState) {

WebView webView = (WebView) findViewById(R.id.webview);
CookieManager.setAcceptFileSchemeCookies(true);
webView.getSettings().setJavaScriptEnabled(true);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);

Intent intent = getIntent();
String userAgentString = intent.getStringExtra("userAgent");
if (userAgentString != null) {
settings.setUserAgentString(userAgentString);
}

webView.setWebViewClient(new WebViewClient() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from telemetry.internal.backends import android_command_line_backend
from telemetry.internal.backends import browser_backend
from telemetry.internal.backends.chrome import chrome_browser_backend
from telemetry.internal.browser import user_agent
from telemetry.internal import forwarders

from devil.android.sdk import intent
Expand Down Expand Up @@ -99,13 +100,17 @@ def Start(self):

self.platform_backend.DismissCrashDialogIfNeeded()

user_agent_dict = user_agent.GetChromeUserAgentDictFromType(
self.browser_options.browser_user_agent_type)

browser_startup_args = self.GetBrowserStartupArgs()
with android_command_line_backend.SetUpCommandLineFlags(
self.device, self._backend_settings, browser_startup_args):
self.device.StartActivity(
intent.Intent(package=self._backend_settings.package,
activity=self._backend_settings.activity,
action=None, data=url, category=None),
action=None, data=url, category=None,
extras=user_agent_dict),
blocking=True)

remote_devtools_port = self._backend_settings.GetDevtoolsRemotePort(
Expand Down
5 changes: 5 additions & 0 deletions tools/telemetry/telemetry/internal/browser/user_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ def GetChromeUserAgentArgumentFromType(user_agent_type):
if user_agent_type:
return ['--user-agent=%s' % UA_TYPE_MAPPING[user_agent_type]]
return []

def GetChromeUserAgentDictFromType(user_agent_type):
if user_agent_type:
return {'userAgent': UA_TYPE_MAPPING[user_agent_type]}
return ''

0 comments on commit ffa5a6c

Please sign in to comment.