2018-06-15 16:44:15 +01:00
|
|
|
from wa import Parameter, ApkUiautoWorkload
|
2018-07-03 13:39:53 +01:00
|
|
|
from wa.framework.exception import WorkloadError
|
2018-06-15 16:44:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Chrome(ApkUiautoWorkload):
|
|
|
|
|
|
|
|
name = 'chrome'
|
|
|
|
description = '''
|
2018-06-20 16:57:12 +01:00
|
|
|
A workload to perform standard Web browsing tasks with Google Chrome. The
|
|
|
|
workload carries out a number of typical Web-based tasks, navigating through
|
|
|
|
a handful of Wikipedia pages in multiple browser tabs.
|
2018-06-15 16:44:15 +01:00
|
|
|
|
2018-06-20 16:57:12 +01:00
|
|
|
To run the workload in offline mode, a ``pages.tar`` archive and an
|
|
|
|
``OfflinePages.db`` file are required. For users wishing to generate these
|
|
|
|
files themselves, Chrome should first be operated from an Internet-connected
|
|
|
|
environment and the following Wikipedia pages should be downloaded for
|
|
|
|
offline use within Chrome:
|
2018-06-15 16:44:15 +01:00
|
|
|
|
|
|
|
- https://en.m.wikipedia.org/wiki/Main_Page
|
|
|
|
- https://en.m.wikipedia.org/wiki/United_States
|
|
|
|
- https://en.m.wikipedia.org/wiki/California
|
|
|
|
|
2018-06-20 16:57:12 +01:00
|
|
|
Following this, the files of interest for viewing these pages offline can be
|
|
|
|
found in the ``/data/data/com.android.chrome/app_chrome/Default/Offline
|
|
|
|
Pages`` directory. The ``OfflinePages.db`` file can be copied from the
|
|
|
|
'metadata' subdirectory, while the ``*.mhtml`` files that should make up the
|
|
|
|
``pages.tar`` file can be found in the 'archives' subdirectory. These page
|
|
|
|
files can then be archived to produce a tarball using a command such as
|
|
|
|
``tar -cvf pages.tar -C /path/to/archives .``. Both this and
|
|
|
|
``OfflinePages.db`` should then be placed in the
|
|
|
|
``~/.workload_automation/dependencies/chrome/`` directory on your local
|
|
|
|
machine, creating this if it does not already exist.
|
2018-06-15 16:44:15 +01:00
|
|
|
|
|
|
|
Known working APK version: 65.0.3325.109
|
|
|
|
'''
|
|
|
|
package_names = ['com.android.chrome']
|
|
|
|
|
|
|
|
parameters = [
|
|
|
|
Parameter('offline_mode', kind=bool, default=False, description='''
|
|
|
|
If set to ``True``, the workload will execute in offline mode.
|
2018-06-20 16:57:12 +01:00
|
|
|
This mode requires root and makes use of a tarball of \*.mhtml
|
2018-06-15 16:44:15 +01:00
|
|
|
files 'pages.tar' and an metadata database 'OfflinePages.db'.
|
|
|
|
The tarball is extracted directly to the application's offline
|
2018-06-20 16:57:12 +01:00
|
|
|
pages 'archives' directory, while the database is copied to
|
|
|
|
the offline pages 'metadata' directory.
|
2018-06-15 16:44:15 +01:00
|
|
|
'''),
|
|
|
|
]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def requires_network(self):
|
|
|
|
return not self.offline_mode
|
|
|
|
|
|
|
|
@property
|
|
|
|
def requires_rerun(self):
|
|
|
|
# In offline mode we need to restart the application after modifying its data directory
|
|
|
|
return self.offline_mode
|
|
|
|
|
|
|
|
def __init__(self, target, **kwargs):
|
|
|
|
super(Chrome, self).__init__(target, **kwargs)
|
|
|
|
if self.offline_mode:
|
|
|
|
self.deployable_assets = ['pages.tar', 'OfflinePages.db']
|
2018-06-20 11:06:53 +01:00
|
|
|
self.cleanup_assets = True
|
2018-06-15 16:44:15 +01:00
|
|
|
|
|
|
|
def initialize(self, context):
|
|
|
|
super(Chrome, self).initialize(context)
|
|
|
|
if self.offline_mode and not self.target.is_rooted:
|
|
|
|
raise WorkloadError('This workload requires root to set up Chrome for offline usage.')
|
|
|
|
|
|
|
|
def setup_rerun(self):
|
|
|
|
super(Chrome, self).setup_rerun()
|
|
|
|
offline_pages = self.target.path.join(self.target.package_data_directory, self.package, 'app_chrome', 'Default', 'Offline\ Pages')
|
|
|
|
metadata_src = self.target.path.join(self.target.working_directory, 'OfflinePages.db')
|
|
|
|
metadata_dst = self.target.path.join(offline_pages, 'metadata')
|
|
|
|
archives_src = self.target.path.join(self.target.working_directory, 'pages.tar')
|
|
|
|
archives_dst = self.target.path.join(offline_pages, 'archives')
|
|
|
|
owner = self.target.execute("{} stat -c '%u' {}".format(self.target.busybox, offline_pages), as_root=True).strip()
|
|
|
|
self.target.execute('{} tar -xvf {} -C {}'.format(self.target.busybox, archives_src, archives_dst), as_root=True)
|
|
|
|
self.target.execute('{} cp {} {}'.format(self.target.busybox, metadata_src, metadata_dst), as_root=True)
|
|
|
|
self.target.execute('{} chown -R {}:{} {}'.format(self.target.busybox, owner, owner, offline_pages), as_root=True)
|