From e87d2578d26830baf1572d9ca77e748af3046f2c Mon Sep 17 00:00:00 2001
From: Weizhong Xia <weizhong@google.com>
Date: Sun, 21 Mar 2021 16:53:51 +0000
Subject: [PATCH] Reland "Switch run_android_wpt to py3"

This reverts commit a8f403b1abe3c4c6ee8ae483cb0fc22a9eb559cd.

Reason for revert: error causing the revert is fixed

Original change's description:
> Revert "Switch run_android_wpt to py3"
>
> This reverts commit 7d961ecace9954f368e56782bffb1ac60fd5b3fc.
>
> Reason for revert: crbug.com/1187233
>
> Original change's description:
> > Switch run_android_wpt to py3
> >
> > Bug: 1186789
> > Change-Id: I3b669e4ecddda1eb24554fb28b4c14730ed80a72
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2747271
> > Reviewed-by: Dirk Pranke <dpranke@google.com>
> > Reviewed-by: Luke Z <lpz@chromium.org>
> > Commit-Queue: Weizhong Xia <weizhong@google.com>
> > Cr-Commit-Position: refs/heads/master@{#862070}
>
> Bug: 1186789
> Change-Id: I318622363824ae133d46598868887b1afd414afb
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2754211
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#862140}

Bug: 1186789
Change-Id: I573864f66cb50521036f8367bbb5090eaff148df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2755067
Reviewed-by: Dirk Pranke <dpranke@google.com>
Commit-Queue: Weizhong Xia <weizhong@google.com>
Cr-Commit-Position: refs/heads/master@{#865001}
---
 .vpython3                           |  9 ++++++++-
 android_webview/test/BUILD.gn       | 12 +++++++++---
 chrome/android/BUILD.gn             | 11 ++++++++---
 testing/buildbot/gn_isolate_map.pyl | 29 +++--------------------------
 testing/scripts/run_android_wpt.py  |  7 ++++---
 weblayer/shell/android/BUILD.gn     | 12 +++++++++---
 6 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/.vpython3 b/.vpython3
index 26bd1e56256b6..f293af5f33c43 100644
--- a/.vpython3
+++ b/.vpython3
@@ -23,6 +23,13 @@
 #   https://chromium.googlesource.com/infra/infra/+/master/doc/users/vpython.md
 
 python_version: "3.8"
+# Used by:
+#   build/android/pylib/local/emulator/avd.py
+#   components/policy/test_support/policy_testserver.py
+wheel: <
+  name: "infra/python/wheels/protobuf-py2_py3"
+  version: "version:3.6.1"
+>
 
 # TODO(https://crbug.com/898348): Add in necessary wheels as Python3 versions
 # become available.
@@ -33,7 +40,7 @@ wheel: <
 
 # Common utilities.
 wheel: <
-  name: "infra/python/wheels/psutil/${platform}_${py_python}_${py_abi}"
+  name: "infra/python/wheels/psutil/${vpython_platform}"
   version: "version:5.7.2"
 >
 wheel: <
diff --git a/android_webview/test/BUILD.gn b/android_webview/test/BUILD.gn
index 8d3a7bb8bfa43..fd0ee6be8976a 100644
--- a/android_webview/test/BUILD.gn
+++ b/android_webview/test/BUILD.gn
@@ -27,9 +27,15 @@ python_library("webview_cts_tests") {
   data = [ "//android_webview/tools/cts_config/" ]
 }
 
-python_library("system_webview_wpt") {
-  testonly = true
-  pydeps_file = "//testing/scripts/run_android_wpt.pydeps"
+script_test("system_webview_wpt") {
+  script = "//testing/scripts/run_android_wpt.py"
+  args = [
+    "--product=android_webview",
+    "--webview-provider=apks/SystemWebView.apk",
+    "--system-webview-shell=apks/SystemWebViewShell.apk",
+    "--webdriver-binary=clang_x64/chromedriver",
+    "-v",
+  ]
   data_deps = [
     "//android_webview:system_webview_apk",
     "//android_webview/tools/system_webview_shell:system_webview_shell_layout_test_apk",
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
index bba12ce84b82d..b5e2d62d0cf92 100644
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -2960,9 +2960,14 @@ instrumentation_test_runner("trichrome_chrome_bundle_fake_modules_smoke_test") {
       _bundle_smoke_test_extra_args + _bundle_fake_modules_smoke_test_extra_args
 }
 
-python_library("chrome_public_wpt") {
-  testonly = true
-  pydeps_file = "//testing/scripts/run_android_wpt.pydeps"
+script_test("chrome_public_wpt") {
+  script = "//testing/scripts/run_android_wpt.py"
+  args = [
+      "--product=chrome_android",
+      "--chrome-apk=apks/ChromePublic.apk",
+      "--webdriver-binary=clang_x64/chromedriver",
+      "-v",
+    ]
   data_deps = [
     ":chrome_public_apk",
     "//build/android:test_runner_py",
diff --git a/testing/buildbot/gn_isolate_map.pyl b/testing/buildbot/gn_isolate_map.pyl
index 0f2225b138a6d..0575b06c43185 100644
--- a/testing/buildbot/gn_isolate_map.pyl
+++ b/testing/buildbot/gn_isolate_map.pyl
@@ -509,14 +509,7 @@
   },
   "chrome_public_wpt": {
     "label": "//chrome/android:chrome_public_wpt",
-    "type": "script",
-    "script": "//testing/scripts/run_android_wpt.py",
-    "args": [
-      "--product=chrome_android",
-      "--chrome-apk=apks/ChromePublic.apk",
-      "--webdriver-binary=clang_x64/chromedriver",
-      "-v",
-    ],
+    "type": "generated_script",
   },
   "chrome_sandbox": {
     "label": "//sandbox/linux:chrome_sandbox",
@@ -1652,15 +1645,7 @@
   },
   "system_webview_wpt": {
     "label": "//android_webview/test:system_webview_wpt",
-    "type": "script",
-    "script": "//testing/scripts/run_android_wpt.py",
-    "args": [
-      "--product=android_webview",
-      "--webview-provider=apks/SystemWebView.apk",
-      "--system-webview-shell=apks/SystemWebViewShell.apk",
-      "--webdriver-binary=clang_x64/chromedriver",
-      "-v",
-    ],
+    "type": "generated_script",
   },
   "telemetry_gpu_integration_test": {
     "args": [
@@ -1935,15 +1920,7 @@
   },
   "weblayer_shell_wpt": {
     "label": "//weblayer/shell/android:weblayer_shell_wpt",
-    "type": "script",
-    "script": "//testing/scripts/run_android_wpt.py",
-    "args": [
-      "--product=android_weblayer",
-      "--weblayer-shell=apks/WebLayerShell.apk",
-      "--weblayer-support=apks/WebLayerSupport.apk",
-      "--webdriver-binary=clang_x64/chromedriver",
-      "-v",
-    ],
+    "type": "generated_script",
   },
   "weblayer_unittests": {
     "label": "//weblayer/test:weblayer_unittests",
diff --git a/testing/scripts/run_android_wpt.py b/testing/scripts/run_android_wpt.py
index 99815b9578213..ef9713359863b 100755
--- a/testing/scripts/run_android_wpt.py
+++ b/testing/scripts/run_android_wpt.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env vpython
+#!/usr/bin/env vpython3
 # Copyright 2019 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.
@@ -120,10 +120,10 @@ class WPTAndroidAdapter(wpt_common.BaseWptScriptAdapter):
     rest_args.extend([self.options.wpt_path])
 
     # TODO(crbug.com/1166741): We should be running WPT under Python 3.
-    rest_args.extend(["--py2"])
+    rest_args.extend(["--py3"])
 
     # vpython has packages needed by wpt, so force it to skip the setup
-    rest_args.extend(["--venv=../../", "--skip-venv-setup"])
+    rest_args.extend(["--venv=" + SRC_DIR, "--skip-venv-setup"])
 
     rest_args.extend(["run",
       "--tests=" + wpt_common.EXTERNAL_WPT_TESTS_DIR,
@@ -177,6 +177,7 @@ class WPTAndroidAdapter(wpt_common.BaseWptScriptAdapter):
          self._metadata_dir,
          '--additional-expectations',
          ANDROID_DISABLED_TESTS,
+         "--no-process-baselines",
     ]
     metadata_builder_cmd.extend(self._extra_metadata_builder_args())
     return common.run_command(metadata_builder_cmd)
diff --git a/weblayer/shell/android/BUILD.gn b/weblayer/shell/android/BUILD.gn
index ac38f00804cb1..afd5e489ce404 100644
--- a/weblayer/shell/android/BUILD.gn
+++ b/weblayer/shell/android/BUILD.gn
@@ -271,9 +271,15 @@ android_apk("weblayer_support_apk") {
   shared_libraries = [ "//weblayer:libweblayer_test" ]
 }
 
-python_library("weblayer_shell_wpt") {
-  testonly = true
-  pydeps_file = "//testing/scripts/run_android_wpt.pydeps"
+script_test("weblayer_shell_wpt") {
+  script = "//testing/scripts/run_android_wpt.py"
+  args = [
+    "--product=android_weblayer",
+    "--weblayer-shell=apks/WebLayerShell.apk",
+    "--weblayer-support=apks/WebLayerSupport.apk",
+    "--webdriver-binary=clang_x64/chromedriver",
+    "-v",
+  ]
   data_deps = [
     ":weblayer_shell_apk",
     ":weblayer_support_apk",