Commit e0e000c9 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Restore modified shared pref settings after tests

Changes the behavior of instrumentation tests to automatically
restore any shared preference files modified by
--shared-prefs-file. Also adds a simple script for manually
applying a shared preference JSON file for cases where settings
that are normally only used during automated testing are
needed for manual use.

Change-Id: I94006c1a8e48d910ed2f7e0742f001d8d62b7b15
Reviewed-on: https://chromium-review.googlesource.com/1220557Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593218}
parent ad5d0999
#!/usr/bin/env python
#
# Copyright 2018 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.
"""Manually applies a shared preference JSON file.
If needed during automation, use the --shared-prefs-file in test_runner.py
instead.
"""
import argparse
import sys
# pylint: disable=ungrouped-imports
from pylib.constants import host_paths
if host_paths.DEVIL_PATH not in sys.path:
sys.path.append(host_paths.DEVIL_PATH)
from devil.android import device_utils
from devil.android.sdk import shared_prefs
from pylib.utils import shared_preference_utils
def main():
parser = argparse.ArgumentParser(
description='Manually apply shared preference JSON files.')
parser.add_argument('filepaths', nargs='*',
help='Any number of paths to shared preference JSON '
'files to apply.')
args = parser.parse_args()
all_devices = device_utils.DeviceUtils.HealthyDevices()
if not all_devices:
raise RuntimeError('No healthy devices attached')
for filepath in args.filepaths:
all_settings = shared_preference_utils.ExtractSettingsFromJson(filepath)
for setting in all_settings:
for device in all_devices:
shared_pref = shared_prefs.SharedPrefs(
device, setting['package'], setting['filename'],
use_encrypted_path=setting.get('supports_encrypted_path', False))
shared_preference_utils.ApplySharedPreferenceSetting(
shared_pref, setting)
if __name__ == '__main__':
main()
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import contextlib import contextlib
import copy
import hashlib import hashlib
import json import json
import logging import logging
...@@ -126,6 +127,7 @@ class LocalDeviceInstrumentationTestRun( ...@@ -126,6 +127,7 @@ class LocalDeviceInstrumentationTestRun(
env, test_instance) env, test_instance)
self._flag_changers = {} self._flag_changers = {}
self._replace_package_contextmanager = None self._replace_package_contextmanager = None
self._shared_prefs_to_restore = []
#override #override
def TestPackage(self): def TestPackage(self):
...@@ -226,6 +228,10 @@ class LocalDeviceInstrumentationTestRun( ...@@ -226,6 +228,10 @@ class LocalDeviceInstrumentationTestRun(
shared_pref = shared_prefs.SharedPrefs( shared_pref = shared_prefs.SharedPrefs(
dev, setting['package'], setting['filename'], dev, setting['package'], setting['filename'],
use_encrypted_path=setting.get('supports_encrypted_path', False)) use_encrypted_path=setting.get('supports_encrypted_path', False))
pref_to_restore = copy.copy(shared_pref)
pref_to_restore.Load()
self._shared_prefs_to_restore.append(pref_to_restore)
shared_preference_utils.ApplySharedPreferenceSetting( shared_preference_utils.ApplySharedPreferenceSetting(
shared_pref, setting) shared_pref, setting)
...@@ -311,6 +317,13 @@ class LocalDeviceInstrumentationTestRun( ...@@ -311,6 +317,13 @@ class LocalDeviceInstrumentationTestRun(
valgrind_tools.SetChromeTimeoutScale(dev, None) valgrind_tools.SetChromeTimeoutScale(dev, None)
# Restore any shared preference files that we stored during setup.
# This should be run sometime before the replace package contextmanager
# gets exited so we don't have to special case restoring files of
# replaced system apps.
for pref_to_restore in self._shared_prefs_to_restore:
pref_to_restore.Commit(force_commit=True)
if self._replace_package_contextmanager: if self._replace_package_contextmanager:
# See pylint-related commend above with __enter__() # See pylint-related commend above with __enter__()
# pylint: disable=no-member # pylint: disable=no-member
......
...@@ -151,11 +151,12 @@ headset. The two most common files used are: ...@@ -151,11 +151,12 @@ headset. The two most common files used are:
emulation. emulation.
* `//chrome/android/shared_preference_files/test/vr_ddview_skipdon_setupcomplete.json` * `//chrome/android/shared_preference_files/test/vr_ddview_skipdon_setupcomplete.json`
This will pair the device with a Daydream View headset, set the DON flow to be This will pair the device with a Daydream View headset, set the DON flow to be
skipped, and enable controller emulation. **NOTE** This will prevent you from skipped, and enable controller emulation.
using a real controller outside of tests. To fix this, you can either
reinstall VrCore or apply the Cardboard settings file (there isn't currently a The test runner will automatically revert any changed settings back to their
way to manually re-enable real controller use from within the VrCore developer pre-test values after the test suite has completed. If for whatever reason you
settings) want to manually apply settings outside of a test, you can do so with
`//build/android/apply_shared_preference_file.py`.
#### vr-settings-service-enabled #### vr-settings-service-enabled
......
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