OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import unittest | 5 import unittest |
6 | 6 |
7 from telemetry.core.backends import adb_commands | |
7 from telemetry.core.backends import android_command_line_backend | 8 from telemetry.core.backends import android_command_line_backend |
8 | 9 |
10 class _MockBackendSettings(object): | |
11 pseudo_exec_name = 'chrome' | |
12 | |
13 def __init__(self, path): | |
14 self._path = path | |
15 | |
16 def GetCommandLineFile(self, _is_user_debug_build): | |
17 return self._path | |
18 | |
9 | 19 |
10 class AndroidCommandLineBackendTest(unittest.TestCase): | 20 class AndroidCommandLineBackendTest(unittest.TestCase): |
11 | 21 |
12 def testQuoteIfNeededNoEquals(self): | 22 def testQuoteIfNeededNoEquals(self): |
13 string = 'value' | 23 string = 'value' |
14 self.assertEqual(string, | 24 self.assertEqual(string, |
15 android_command_line_backend._QuoteIfNeeded(string)) | 25 android_command_line_backend._QuoteIfNeeded(string)) |
16 | 26 |
17 def testQuoteIfNeededNoSpaces(self): | 27 def testQuoteIfNeededNoSpaces(self): |
18 string = 'key=valueA' | 28 string = 'key=valueA' |
19 self.assertEqual(string, | 29 self.assertEqual(string, |
20 android_command_line_backend._QuoteIfNeeded(string)) | 30 android_command_line_backend._QuoteIfNeeded(string)) |
21 | 31 |
22 def testQuoteIfNeededAlreadyQuoted(self): | 32 def testQuoteIfNeededAlreadyQuoted(self): |
23 string = "key='valueA valueB'" | 33 string = "key='valueA valueB'" |
24 self.assertEqual(string, | 34 self.assertEqual(string, |
25 android_command_line_backend._QuoteIfNeeded(string)) | 35 android_command_line_backend._QuoteIfNeeded(string)) |
26 | 36 |
27 def testQuoteIfNeeded(self): | 37 def testQuoteIfNeeded(self): |
28 string = 'key=valueA valueB' | 38 string = 'key=valueA valueB' |
29 expected_output = "key='valueA valueB'" | 39 expected_output = "key='valueA valueB'" |
30 self.assertEqual(expected_output, | 40 self.assertEqual(expected_output, |
31 android_command_line_backend._QuoteIfNeeded(string)) | 41 android_command_line_backend._QuoteIfNeeded(string)) |
42 | |
43 def testSetUpCommandLineFlagsCmdRestored(self): | |
44 """Test that a previous command line file is restored. | |
45 | |
46 Requires a device connected to the host. | |
47 """ | |
48 cmd_file = '/data/local/tmp/test_cmd' | |
49 serial = adb_commands.GetAttachedDevices()[0] | |
jbudorick
2015/01/20 14:30:31
Looks like this failed on the bot because it can't
tonyg
2015/01/20 17:14:26
I'd expect that we already have an adb_commands co
| |
50 adb = adb_commands.AdbCommands(device=serial) | |
51 backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd') | |
52 startup_args = ['--some', '--test', '--args'] | |
53 device = adb.device() | |
54 device.WriteFile(cmd_file, 'chrome --args --to --save') | |
55 with android_command_line_backend.SetUpCommandLineFlags( | |
56 adb, backend_settings, startup_args): | |
57 self.assertEqual('chrome --some --test --args', | |
58 device.ReadFile(cmd_file).strip()) | |
59 self.assertEqual('chrome --args --to --save', | |
60 device.ReadFile(cmd_file).strip()) | |
61 device.RunShellCommand(['rm', '-f', cmd_file], check_return=True) | |
62 | |
63 def testSetUpCommandLineFlagsCmdRemoved(self): | |
64 """Test that the command line file is removed if it did not exist before. | |
65 | |
66 Requires a device connected to the host. | |
67 """ | |
68 cmd_file = '/data/local/tmp/test_cmd' | |
69 serial = adb_commands.GetAttachedDevices()[0] | |
jbudorick
2015/01/20 14:30:31
(same)
| |
70 adb = adb_commands.AdbCommands(device=serial) | |
71 backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd') | |
72 startup_args = ['--some', '--test', '--args'] | |
73 device = adb.device() | |
74 device.RunShellCommand(['rm', '-f', cmd_file], check_return=True) | |
75 with android_command_line_backend.SetUpCommandLineFlags( | |
76 adb, backend_settings, startup_args): | |
77 self.assertEqual('chrome --some --test --args', | |
78 device.ReadFile(cmd_file).strip()) | |
79 self.assertFalse(device.FileExists(cmd_file)) | |
OLD | NEW |