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 logging |
5 import unittest | 6 import unittest |
6 | 7 |
| 8 from telemetry import benchmark |
| 9 from telemetry.core.backends import adb_commands |
7 from telemetry.core.backends import android_command_line_backend | 10 from telemetry.core.backends import android_command_line_backend |
8 | 11 |
| 12 class _MockBackendSettings(object): |
| 13 pseudo_exec_name = 'chrome' |
| 14 |
| 15 def __init__(self, path): |
| 16 self._path = path |
| 17 |
| 18 def GetCommandLineFile(self, _is_user_debug_build): |
| 19 return self._path |
| 20 |
9 | 21 |
10 class AndroidCommandLineBackendTest(unittest.TestCase): | 22 class AndroidCommandLineBackendTest(unittest.TestCase): |
11 | 23 |
12 def testQuoteIfNeededNoEquals(self): | 24 def testQuoteIfNeededNoEquals(self): |
13 string = 'value' | 25 string = 'value' |
14 self.assertEqual(string, | 26 self.assertEqual(string, |
15 android_command_line_backend._QuoteIfNeeded(string)) | 27 android_command_line_backend._QuoteIfNeeded(string)) |
16 | 28 |
17 def testQuoteIfNeededNoSpaces(self): | 29 def testQuoteIfNeededNoSpaces(self): |
18 string = 'key=valueA' | 30 string = 'key=valueA' |
19 self.assertEqual(string, | 31 self.assertEqual(string, |
20 android_command_line_backend._QuoteIfNeeded(string)) | 32 android_command_line_backend._QuoteIfNeeded(string)) |
21 | 33 |
22 def testQuoteIfNeededAlreadyQuoted(self): | 34 def testQuoteIfNeededAlreadyQuoted(self): |
23 string = "key='valueA valueB'" | 35 string = "key='valueA valueB'" |
24 self.assertEqual(string, | 36 self.assertEqual(string, |
25 android_command_line_backend._QuoteIfNeeded(string)) | 37 android_command_line_backend._QuoteIfNeeded(string)) |
26 | 38 |
27 def testQuoteIfNeeded(self): | 39 def testQuoteIfNeeded(self): |
28 string = 'key=valueA valueB' | 40 string = 'key=valueA valueB' |
29 expected_output = "key='valueA valueB'" | 41 expected_output = "key='valueA valueB'" |
30 self.assertEqual(expected_output, | 42 self.assertEqual(expected_output, |
31 android_command_line_backend._QuoteIfNeeded(string)) | 43 android_command_line_backend._QuoteIfNeeded(string)) |
| 44 |
| 45 @benchmark.Enabled('android') |
| 46 def testSetUpCommandLineFlagsCmdRestored(self): |
| 47 """Test that a previous command line file is restored. |
| 48 |
| 49 Requires a device connected to the host. |
| 50 """ |
| 51 serial = adb_commands.GetAttachedDevices()[0] |
| 52 cmd_file = '/data/local/tmp/test_cmd' |
| 53 adb = adb_commands.AdbCommands(device=serial) |
| 54 backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd') |
| 55 startup_args = ['--some', '--test', '--args'] |
| 56 device = adb.device() |
| 57 device.WriteFile(cmd_file, 'chrome --args --to --save') |
| 58 with android_command_line_backend.SetUpCommandLineFlags( |
| 59 adb, backend_settings, startup_args): |
| 60 self.assertEqual('chrome --some --test --args', |
| 61 device.ReadFile(cmd_file).strip()) |
| 62 self.assertEqual('chrome --args --to --save', |
| 63 device.ReadFile(cmd_file).strip()) |
| 64 device.RunShellCommand(['rm', '-f', cmd_file], check_return=True) |
| 65 |
| 66 @benchmark.Enabled('android') |
| 67 def testSetUpCommandLineFlagsCmdRemoved(self): |
| 68 """Test that the command line file is removed if it did not exist before. |
| 69 |
| 70 Requires a device connected to the host. |
| 71 """ |
| 72 serial = adb_commands.GetAttachedDevices()[0] |
| 73 cmd_file = '/data/local/tmp/test_cmd' |
| 74 adb = adb_commands.AdbCommands(device=serial) |
| 75 backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd') |
| 76 startup_args = ['--some', '--test', '--args'] |
| 77 device = adb.device() |
| 78 device.RunShellCommand(['rm', '-f', cmd_file], check_return=True) |
| 79 with android_command_line_backend.SetUpCommandLineFlags( |
| 80 adb, backend_settings, startup_args): |
| 81 self.assertEqual('chrome --some --test --args', |
| 82 device.ReadFile(cmd_file).strip()) |
| 83 self.assertFalse(device.FileExists(cmd_file)) |
OLD | NEW |