OLD | NEW |
---|---|
(Empty) | |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 import unittest | |
6 | |
7 from telemetry.core import browser_options | |
8 from telemetry.core import util | |
9 from telemetry.core.backends.chrome import android_browser_backend | |
10 from telemetry.core.platform import android_device | |
11 from telemetry.core.platform import android_platform_backend | |
12 | |
13 util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') | |
14 from pylib.device import device_errors | |
15 from pylib.device import device_utils | |
16 | |
17 util.AddDirToPythonPath(util.GetChromiumSrcDir(), | |
18 'third_party', 'pymock') | |
19 import mock # pylint: disable=import-error | |
20 | |
21 | |
22 class MockBrowserBackend(android_browser_backend.AndroidBrowserBackend): | |
23 """Mock of an AndroidBrowserBackend with a custom device object""" | |
24 | |
25 def __init__(self, device): | |
26 platform_backend = mock.Mock( | |
27 spec=android_platform_backend.AndroidPlatformBackend) | |
28 platform_backend.adb.device.return_value = device | |
29 browser_opts = browser_options.BrowserOptions() | |
30 browser_opts.browser_type = 'android-chrome-shell' | |
31 super(MockBrowserBackend, self).__init__( | |
32 android_platform_backend=platform_backend, | |
33 browser_options=browser_opts, | |
34 backend_settings=android_browser_backend.ChromeShellBackendSettings( | |
35 'test.package.name'), | |
36 use_rndis_forwarder=False, | |
37 output_profile_path=None, | |
38 extensions_to_load=[], | |
39 target_arch=None) | |
40 | |
41 class AndroidBrowserBackendTest(unittest.TestCase): | |
42 """Test Chrome command line set-up/restore.""" | |
43 | |
44 def testRestoreOldCommandLine_restoreExisting(self): | |
45 old_command_line = 'chrome_shell --with --some --old --options' | |
46 device = mock.Mock(spec=device_utils.DeviceUtils) | |
47 device.old_interface = mock.Mock() | |
48 device.ReadFile.return_value = old_command_line | |
49 browser_backend = MockBrowserBackend(device) | |
50 browser_backend._SetUpCommandLine() | |
51 device.WriteFile.assert_called_once_with(mock.ANY, mock.ANY, as_root=True) | |
tonyg
2015/01/05 17:28:43
I think these mock-style unittests are just closel
jbudorick
2015/01/05 17:50:42
We've generally been switching to this style of te
| |
52 device.WriteFile.reset_mock() | |
53 browser_backend._RestoreCommandLine() | |
54 device.WriteFile.assert_called_once_with(mock.ANY, old_command_line, | |
55 as_root=True) | |
56 | |
57 def testRestoreOldCommandLine_didNotExist(self): | |
58 device = mock.Mock(spec=device_utils.DeviceUtils) | |
59 device.old_interface = mock.Mock() | |
60 device.ReadFile.side_effect = device_errors.CommandFailedError( | |
61 'File not found', str(device)) | |
62 browser_backend = MockBrowserBackend(device) | |
63 browser_backend._SetUpCommandLine() | |
64 device.WriteFile.assert_called_once_with(mock.ANY, mock.ANY, as_root=True) | |
65 device.WriteFile.reset_mock() | |
66 browser_backend._RestoreCommandLine() | |
67 self.assertFalse(device.WriteFile.called) | |
68 device.RunShellCommand.assert_called_once_with(['rm', mock.ANY], | |
69 as_root=True) | |
OLD | NEW |