Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: build/android/pylib/local/device/local_device_instrumentation_test_run.py

Issue 2688913003: Add shared preference file modification option to instrumentation test runner (Closed)
Patch Set: Change to take a path to a file instead of hex-encoded data Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/local/device/local_device_instrumentation_test_run.py
diff --git a/build/android/pylib/local/device/local_device_instrumentation_test_run.py b/build/android/pylib/local/device/local_device_instrumentation_test_run.py
index 4b3f353ba6feefcda60f4d5335ed094223f4b551..7a225c50f02bade188da64709daf678ebd2d3a92 100644
--- a/build/android/pylib/local/device/local_device_instrumentation_test_run.py
+++ b/build/android/pylib/local/device/local_device_instrumentation_test_run.py
@@ -10,6 +10,7 @@ import time
from devil.android import device_errors
from devil.android import flag_changer
+from devil.android.sdk import shared_prefs
from devil.utils import reraiser_thread
from pylib import valgrind_tools
from pylib.android import logdog_logcat_monitor
@@ -109,6 +110,30 @@ class LocalDeviceInstrumentationTestRun(
self._test_instance.package_info.package],
check_return=True)
+ def edit_shared_prefs():
+ for pref in self._test_instance.edit_shared_prefs:
+ prefs = shared_prefs.SharedPrefs(dev, pref['package'],
+ pref['filename'])
+ prefs.Load()
+ for key in pref.get('remove', []):
+ try:
+ prefs.Remove(key)
+ except KeyError:
+ logging.warning("Attempted to remove non-existent key %s", key)
+ for key, value in pref.get('set', {}).iteritems():
+ if type(value) is bool:
jbudorick 2017/02/15 22:38:42 nit: use isinstance for all of these.
bsheedy 2017/02/16 00:28:00 Done.
+ prefs.SetBoolean(key, value)
+ elif type(value) is str:
jbudorick 2017/02/15 22:38:41 isinstance(value, basestring) here
bsheedy 2017/02/16 00:28:00 Done.
+ prefs.SetString(key, value)
+ elif type(value) is long or type(value) is int:
+ prefs.SetLong(key, value)
+ elif type(value) is list:
+ prefs.SetStringSet(key, value)
+ else:
+ logging.warning("Given invalid value type %s for key %s",
jbudorick 2017/02/15 22:38:41 Should this be fatal? It seems bad to be running w
bsheedy 2017/02/16 00:28:00 Done.
+ str(type(value)), key)
+ prefs.Commit()
+
def push_test_data():
device_root = posixpath.join(dev.GetExternalStoragePath(),
'chromium_tests_root')
@@ -139,7 +164,8 @@ class LocalDeviceInstrumentationTestRun(
valgrind_tools.SetChromeTimeoutScale(
dev, self._test_instance.timeout_scale)
- steps = (install_apk, push_test_data, create_flag_changer)
+ steps = (install_apk, edit_shared_prefs, push_test_data,
+ create_flag_changer)
if self._env.concurrent_adb:
reraiser_thread.RunAsync(steps)
else:

Powered by Google App Engine
This is Rietveld 408576698