Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
perezju
2017/01/16 14:12:19
Didn't notice on my previous CL, file should be na
| |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 """ | |
| 6 Unit tests for the contents of flag_changer.py. | |
| 7 The test will invoke real devices | |
| 8 """ | |
| 9 | |
| 10 import os | |
| 11 import posixpath | |
| 12 import sys | |
| 13 import unittest | |
| 14 | |
| 15 if __name__ == '__main__': | |
| 16 sys.path.append( | |
| 17 os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', ))) | |
| 18 | |
| 19 from devil.android import device_test_case | |
| 20 from devil.android import device_utils | |
| 21 from devil.android import flag_changer | |
| 22 from devil.android.sdk import adb_wrapper | |
| 23 | |
| 24 | |
| 25 _CMDLINE_FILE = 'dummy-command-line' | |
| 26 | |
| 27 | |
| 28 class FlagChangerTest(device_test_case.DeviceTestCase): | |
| 29 | |
| 30 def setUp(self): | |
| 31 super(FlagChangerTest, self).setUp() | |
| 32 self.adb = adb_wrapper.AdbWrapper(self.serial) | |
| 33 self.adb.WaitForDevice() | |
| 34 self.device = device_utils.DeviceUtils( | |
| 35 self.adb, default_timeout=10, default_retries=0) | |
| 36 # pylint: disable=protected-access | |
| 37 self.cmdline_path = posixpath.join(flag_changer._CMDLINE_DIR, _CMDLINE_FILE) | |
| 38 self.cmdline_path_legacy = posixpath.join( | |
| 39 flag_changer._CMDLINE_DIR_LEGACY, _CMDLINE_FILE) | |
| 40 | |
| 41 def tearDown(self): | |
| 42 self.device.RemovePath( | |
| 43 [self.cmdline_path, self.cmdline_path_legacy], force=True, as_root=True) | |
| 44 | |
| 45 def testFlagChanger(self): | |
| 46 if not self.device.HasRoot(): | |
| 47 self.skipTest('Test needs a rooted device') | |
| 48 | |
| 49 # Write some custom chrome command line flags. | |
| 50 self.device.WriteFile( | |
| 51 self.cmdline_path, 'chrome --custom --flags') | |
| 52 | |
| 53 # Write some more flags on a command line file in the legacy location. | |
| 54 self.device.WriteFile( | |
| 55 self.cmdline_path_legacy, 'some --stray --flags', as_root=True) | |
| 56 self.assertTrue(self.device.PathExists(self.cmdline_path_legacy)) | |
| 57 | |
| 58 changer = flag_changer.FlagChanger(self.device, _CMDLINE_FILE) | |
| 59 | |
| 60 # Legacy command line file is removed, ensuring Chrome picks up the | |
| 61 # right file. | |
| 62 self.assertFalse(self.device.PathExists(self.cmdline_path_legacy)) | |
| 63 | |
| 64 changer.ReplaceFlags(['--my', '--new', '--flags']) | |
| 65 # TODO(perezju): assert that new flags are now set. | |
| 66 | |
| 67 changer.Restore() | |
| 68 # TODO(perezju): assert that flags are back to --custom --flags. | |
| 69 | |
| 70 | |
| 71 if __name__ == '__main__': | |
| 72 unittest.main() | |
| OLD | NEW |