def run_test(self): with NamedTemporaryDirectory( ) as self._metadata_dir, self._install_apks(): metadata_command_ret = self._maybe_build_metadata() if metadata_command_ret != 0: return metadata_command_ret return super(WPTAndroidAdapter, self).run_test()
def SetUpProcess(cls): """Prepares the test device""" super(WebViewCrxSmokeTests, cls).SetUpProcess() assert cls._finder_options.crx_file, '--crx-file is required' assert cls._finder_options.component_name, '--component-name is required' cls.SetBrowserOptions(cls._finder_options) webview_package_name = cls._finder_options.webview_package_name if not webview_package_name: webview_provider_apk = (cls._browser_to_create .settings.GetApkName(cls._device)) webview_apk_path = util.FindLatestApkOnHost( cls._finder_options.chrome_root, webview_provider_apk) webview_package_name = apk_helper.GetPackageName(webview_apk_path) cls._device_components_dir = ('/data/data/%s/app_webview/components' % webview_package_name) logcat_output_dir = ( os.path.dirname(cls._typ_runner.args.write_full_results_to or '') or os.getcwd()) # Set up a logcat monitor cls._logcat_monitor = logcat_monitor.LogcatMonitor( cls._device.adb, output_file=os.path.join(logcat_output_dir, '%s_logcat.txt' % cls.Name()), filter_specs=_LOGCAT_FILTERS) cls._logcat_monitor.Start() cls._MaybeClearOutComponentsDir() component_id = _COMPONENT_NAME_TO_DATA.get( cls._finder_options.component_name).component_id with zipfile.ZipFile(cls._finder_options.crx_file) as crx_archive, \ NamedTemporaryDirectory() as tmp_dir, \ crx_archive.open('manifest.json') as manifest: crx_device_dir = posixpath.join( cls._device_components_dir, 'cps', component_id, '1_%s' % json.loads(manifest.read())['version']) try: # Create directory on the test device for the CRX files logger.info('Creating directory %r on device' % crx_device_dir) output = cls._device.RunShellCommand( ['mkdir', '-p', crx_device_dir]) logger.debug('Recieved the following output from adb: %s' % output) except Exception as e: logger.exception('Exception %r was raised' % str(e)) raise # Move CRX files to the device directory crx_archive.extractall(tmp_dir) cls._MoveNewCrxToDevice(tmp_dir, crx_device_dir) # Start the browser after the device is in a clean state and the CRX # files are loaded onto the device cls.StartBrowser()
def run_test(self): with NamedTemporaryDirectory() as tmp_dir, self._install_apks(): self._metadata_dir = os.path.join(tmp_dir, 'metadata_dir') metadata_command_ret = self._maybe_build_metadata() if metadata_command_ret != 0: return metadata_command_ret # If there is no metadata then we need to create an # empty directory to pass to wptrunner if not os.path.exists(self._metadata_dir): os.makedirs(self._metadata_dir) return super(WPTAndroidAdapter, self).run_test()
def SetUpProcess(cls): """Prepares the test device""" super(WebViewCrxSmokeTests, cls).SetUpProcess() assert cls._finder_options.crx_file, '--crx-file is required' assert cls._finder_options.component_name, '--component-name is required' assert cls._finder_options.webview_package_name, ( '--webview-package-name is required') cls._device_components_dir = ('/data/data/%s/app_webview/components' % cls._finder_options.webview_package_name) cls.SetBrowserOptions(cls._finder_options) cls._MaybeClearOutComponentsDir() component_id = _COMPONENT_NAME_TO_DATA.get( cls._finder_options.component_name).component_id with zipfile.ZipFile(cls._finder_options.crx_file) as crx_archive, \ NamedTemporaryDirectory() as tmp_dir, \ crx_archive.open('manifest.json') as manifest: crx_device_dir = posixpath.join( cls._device_components_dir, 'cps', component_id, '1_%s' % json.loads(manifest.read())['version']) try: # Create directory on the test device for the CRX files logger.info('Creating directory %r on device' % crx_device_dir) output = cls._device.RunShellCommand( ['mkdir', '-p', crx_device_dir]) logger.debug('Recieved the following output from adb: %s' % output) except Exception as e: logger.exception('Exception %r was raised' % str(e)) raise # Move CRX files to the device directory crx_archive.extractall(tmp_dir) cls._MoveNewCrxToDevice(tmp_dir, crx_device_dir) # Start the browser after the device is in a clean state and the CRX # files are loaded onto the device cls.StartBrowser()
def install_seed(self): """Install finch seed for testing Returns: None """ browser_pkg_name = get_package_name(self.options.browser_apk) app_data_dir = posixpath.join( self.device.GetApplicationDataDirectory(browser_pkg_name), self.app_user_sub_dir()) device_local_state_file = posixpath.join(app_data_dir, 'Local State') with NamedTemporaryDirectory() as tmp_dir: tmp_ls_path = os.path.join(tmp_dir, 'local_state.json') self.device.adb.Pull(device_local_state_file, tmp_ls_path) with open(tmp_ls_path, 'r') as local_state_content, \ open(self.options.finch_seed_path, 'r') as test_seed_content: local_state_json = json.loads(local_state_content.read()) test_seed_json = json.loads(test_seed_content.read()) # Copy over the seed data and signature local_state_json['variations_compressed_seed'] = ( test_seed_json['variations_compressed_seed']) local_state_json['variations_seed_signature'] = ( test_seed_json['variations_seed_signature']) with open(os.path.join(tmp_dir, 'new_local_state.json'), 'w') as new_local_state: new_local_state.write(json.dumps(local_state_json)) self.device.adb.Push(new_local_state.name, device_local_state_file) user_id = self.device.GetUidForPackage(browser_pkg_name) logger.info('Setting owner of Local State file to %r', user_id) self.device.RunShellCommand( ['chown', user_id, device_local_state_file], as_root=True)
def run_test(self): with NamedTemporaryDirectory( ) as self._metadata_dir, self._install_apks(): self._maybe_build_metadata() return super(WPTAndroidAdapter, self).run_test()