Commit aade08e1 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Commit Bot

Add test that <uses-library> is not in monochrome's AndroidManifest.xml

This CL adds tests to monochrome_apk_checker checking that:
- <uses-library> is not in the MonochromePublic.apk's AndroidManifest.xml
- MonochromePublic.apk does not call into org.apache.http

BUG=1115604

Change-Id: I295a97022f146c66ccd78eee6f54640a344e2589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462035
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815169}
parent 4505e671
#!/usr/bin/env python3
#
# Copyright 2020 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.
"""Contains tests which test monochrome's AndroidManifest.xml"""
import os
import sys
CUR_DIR = os.path.dirname(os.path.realpath(__file__))
SRC_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(CUR_DIR))))
TYP_DIR = os.path.join(
SRC_DIR, 'third_party', 'catapult', 'third_party', 'typ')
DEVIL_DIR = os.path.join(SRC_DIR, 'third_party', 'catapult', 'devil')
if TYP_DIR not in sys.path:
sys.path.insert(0, TYP_DIR)
if DEVIL_DIR not in sys.path:
sys.path.insert(0, DEVIL_DIR)
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
import typ
class MonochromeAndroidManifestCheckerTest(typ.TestCase):
def testManifest(self):
monochrome_apk = self.context.monochrome_apk
cmd = [
build_tools.GetPath('aapt'), 'dump', 'xmltree', monochrome_apk,
'AndroidManifest.xml']
status, manifest = cmd_helper.GetCmdStatusAndOutput(cmd)
self.assertEquals(status, 0)
# Check that AndroidManifest.xml does not have any <uses-library> tags.
# crbug.com/115604
self.assertNotIn('uses-library', manifest)
#!/usr/bin/env python3
#
# Copyright 2020 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.
"""Contains tests which use dexdump of monochrome's dex files."""
import os
import shutil
import sys
import tempfile
import zipfile
CUR_DIR = os.path.dirname(os.path.realpath(__file__))
SRC_DIR = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.dirname(CUR_DIR))))
TYP_DIR = os.path.join(
SRC_DIR, 'third_party', 'catapult', 'third_party', 'typ')
DEVIL_DIR = os.path.join(SRC_DIR, 'third_party', 'catapult', 'devil')
if TYP_DIR not in sys.path:
sys.path.insert(0, TYP_DIR)
if DEVIL_DIR not in sys.path:
sys.path.insert(0, DEVIL_DIR)
from devil.android.sdk import build_tools
from devil.utils import cmd_helper
import typ
def _extract_dex_dumps(apk):
build_dir = tempfile.mkdtemp()
extracted_dex_files = _extract_dex_files(apk, build_dir)
cmd = [ build_tools.GetPath('dexdump'), '-d' ] + extracted_dex_files
status, out = cmd_helper.GetCmdStatusAndOutput(cmd)
shutil.rmtree(build_dir)
return (status, out)
def _extract_dex_files(apk, dest_dir):
extracted_files = []
with zipfile.ZipFile(apk) as z:
for info in z.infolist():
if info.filename.endswith('.dex'):
extracted_files.append(z.extract(info.filename, dest_dir))
return extracted_files
class MonochromeDexDumpTest(typ.TestCase):
def testMain(self):
monochrome_apk = self.context.monochrome_apk
status, dump = _extract_dex_dumps(monochrome_apk)
self.assertEquals(status, 0)
# Check that the dexdump does not have any calls to org.apache.http
# crbug.com/115604
self.assertNotIn('org/apache/http', dump)
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