OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 import posixpath | |
7 import unittest | |
8 | |
9 from devil.android import flag_changer | |
10 | |
11 | |
12 _CMDLINE_FILE = 'chrome-command-line' | |
13 | |
14 | |
15 class _FakeDevice(object): | |
16 def __init__(self): | |
17 self.build_type = 'user' | |
18 self.has_root = True | |
19 self.file_system = {} | |
20 | |
21 def HasRoot(self): | |
22 return self.has_root | |
23 | |
24 def PathExists(self, filepath): | |
25 return filepath in self.file_system | |
26 | |
27 def RemovePath(self, path, **_kwargs): | |
28 self.file_system.pop(path) | |
29 | |
30 def WriteFile(self, path, contents, **_kwargs): | |
31 self.file_system[path] = contents | |
32 | |
33 def ReadFile(self, path, **_kwargs): | |
34 return self.file_system[path] | |
35 | |
36 | |
37 class FlagChangerTest(unittest.TestCase): | |
38 def setUp(self): | |
39 self.device = _FakeDevice() | |
40 # pylint: disable=protected-access | |
41 self.cmdline_path = posixpath.join(flag_changer._CMDLINE_DIR, _CMDLINE_FILE) | |
42 self.cmdline_path_legacy = posixpath.join( | |
43 flag_changer._CMDLINE_DIR_LEGACY, _CMDLINE_FILE) | |
44 | |
45 def testFlagChanger_removeLegacyCmdLine(self): | |
46 self.device.WriteFile(self.cmdline_path_legacy, 'chrome --old --stuff') | |
47 self.assertTrue(self.device.PathExists(self.cmdline_path_legacy)) | |
48 | |
49 changer = flag_changer.FlagChanger(self.device, 'chrome-command-line') | |
50 self.assertEquals( | |
51 changer._cmdline_path, # pylint: disable=protected-access | |
52 self.cmdline_path) | |
53 self.assertFalse(self.device.PathExists(self.cmdline_path_legacy)) | |
54 | |
55 | |
56 if __name__ == '__main__': | |
57 unittest.main(verbosity=2) | |
OLD | NEW |