Source/WebCore: IndexedDB: Introduce putWithIndexKeys and calculate them in the renderer
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / port / chromium_android_unittest.py
1 # Copyright (C) 2012 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 #    * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 #    * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 #    * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 import optparse
30 import StringIO
31 import time
32 import unittest
33
34 from webkitpy.common.system import executive_mock
35 from webkitpy.common.system.executive_mock import MockExecutive2
36 from webkitpy.common.system.systemhost_mock import MockSystemHost
37
38 from webkitpy.layout_tests.port import chromium_android
39 from webkitpy.layout_tests.port import chromium_port_testcase
40 from webkitpy.layout_tests.port import driver
41 from webkitpy.layout_tests.port import webkit_unittest
42
43
44 class ChromiumAndroidPortTest(chromium_port_testcase.ChromiumPortTestCase):
45     port_name = 'chromium-android'
46     port_maker = chromium_android.ChromiumAndroidPort
47     mock_logcat = ''
48
49     def test_attributes(self):
50         port = self.make_port()
51         self.assertTrue(port.get_option('enable_hardware_gpu'))
52         self.assertEquals(port.baseline_path(), port._webkit_baseline_path('chromium-android'))
53
54     def test_default_timeout_ms(self):
55         self.assertEquals(self.make_port(options=optparse.Values({'configuration': 'Release'})).default_timeout_ms(), 10000)
56         self.assertEquals(self.make_port(options=optparse.Values({'configuration': 'Debug'})).default_timeout_ms(), 10000)
57
58     def test_expectations_files(self):
59         # FIXME: override this test temporarily while we're still upstreaming the android port and
60         # using a custom expectations file.
61         pass
62
63     @staticmethod
64     def mock_run_command_fn(args):
65         if args[1] == 'shell':
66             if args[2:] == ['ls', '-n', '/data/tombstones']:
67                 # For 'adb shell ls -n /data/tombstones'
68                 return ('-rw------- 1000     1000       218643 2012-04-26 18:15 tombstone_00\n'
69                         '-rw------- 1000     1000       241695 2012-04-26 18:15 tombstone_01\n'
70                         '-rw------- 1000     1000       219472 2012-04-26 18:16 tombstone_02\n'
71                         '-rw------- 1000     1000        45316 2012-04-27 16:33 tombstone_03\n'
72                         '-rw------- 1000     1000        82022 2012-04-23 16:57 tombstone_04\n'
73                         '-rw------- 1000     1000        82015 2012-04-23 16:57 tombstone_05\n'
74                         '-rw------- 1000     1000        81974 2012-04-23 16:58 tombstone_06\n'
75                         '-rw------- 1000     1000       237409 2012-04-26 17:41 tombstone_07\n'
76                         '-rw------- 1000     1000       276089 2012-04-26 18:15 tombstone_08\n'
77                         '-rw------- 1000     1000       219618 2012-04-26 18:15 tombstone_09\n')
78             elif args[2] == 'cat':
79                 return args[3] + '\nmock_contents\n'
80         elif args[1] == 'logcat':
81             return ChromiumAndroidPortTest.mock_logcat
82         else:
83             return ''
84
85     def test_get_last_stacktrace(self):
86         port = self.make_port()
87
88         def mock_run_command_no_dir(args):
89             return '/data/tombstones: No such file or directory'
90         port._executive = MockExecutive2(run_command_fn=mock_run_command_no_dir)
91         self.assertEquals(port._get_last_stacktrace(), '')
92
93         def mock_run_command_no_file(args):
94             return ''
95         port._executive = MockExecutive2(run_command_fn=mock_run_command_no_file)
96         self.assertEquals(port._get_last_stacktrace(), '')
97
98         port._executive = MockExecutive2(run_command_fn=ChromiumAndroidPortTest.mock_run_command_fn)
99         self.assertEquals(port._get_last_stacktrace(),
100                           '-rw------- 1000 1000 45316 2012-04-27 16:33 tombstone_03\n'
101                           '/data/tombstones/tombstone_03\nmock_contents\n')
102
103     def test_get_crash_log(self):
104         port = self.make_port()
105         port._executive = MockExecutive2(run_command_fn=ChromiumAndroidPortTest.mock_run_command_fn)
106         ChromiumAndroidPortTest.mock_logcat = 'logcat contents\n'
107         self.assertEquals(port._get_crash_log('foo', 1234, 'out bar\nout baz\n', 'err bar\nerr baz\n', newer_than=None),
108             (u'crash log for foo (pid 1234):\n'
109              u'STDOUT: out bar\n'
110              u'STDOUT: out baz\n'
111              u'STDOUT: ********* Logcat:\n'
112              u'STDOUT: logcat contents\n'
113              u'STDERR: err bar\n'
114              u'STDERR: err baz\n'
115              u'STDERR: ********* Tombstone file:\n'
116              u'STDERR: -rw------- 1000 1000 45316 2012-04-27 16:33 tombstone_03\n'
117              u'STDERR: /data/tombstones/tombstone_03\n'
118              u'STDERR: mock_contents\n'))
119         self.assertEquals(port._get_crash_log(None, None, None, None, newer_than=None),
120             (u'crash log for <unknown process name> (pid <unknown>):\n'
121              u'STDOUT: ********* Logcat:\n'
122              u'STDOUT: logcat contents\n'
123              u'STDERR: ********* Tombstone file:\n'
124              u'STDERR: -rw------- 1000 1000 45316 2012-04-27 16:33 tombstone_03\n'
125              u'STDERR: /data/tombstones/tombstone_03\n'
126              u'STDERR: mock_contents\n'))
127
128     def test_driver_cmd_line(self):
129         # Overriding PortTestCase.test_cmd_line(). Use ChromiumAndroidDriverTest.test_cmd_line() instead.
130         return
131
132
133 class ChromiumAndroidDriverTest(unittest.TestCase):
134     def setUp(self):
135         mock_port = chromium_android.ChromiumAndroidPort(MockSystemHost(), 'chromium-android')
136         self.driver = chromium_android.ChromiumAndroidDriver(mock_port, worker_number=0, pixel_tests=True)
137
138     def test_cmd_line(self):
139         cmd_line = self.driver.cmd_line(True, ['anything'])
140         self.assertEquals(['adb', 'shell'], cmd_line)
141
142     def test_drt_cmd_line(self):
143         cmd_line = self.driver._drt_cmd_line(True, ['--a'])
144         self.assertTrue('--a' in cmd_line)
145         self.assertTrue('--in-fifo=' + chromium_android.DRT_APP_FILES_DIR + 'DumpRenderTree.in' in cmd_line)
146         self.assertTrue('--out-fifo=' + chromium_android.DRT_APP_FILES_DIR + 'DumpRenderTree.out' in cmd_line)
147         self.assertTrue('--err-fifo=' + chromium_android.DRT_APP_FILES_DIR + 'DumpRenderTree.err' in cmd_line)
148
149     def test_read_prompt(self):
150         self.driver._server_process = webkit_unittest.MockServerProcess(['root@android:/ # '])
151         self.assertEquals(self.driver._read_prompt(time.time() + 1), None)
152         self.driver._server_process = webkit_unittest.MockServerProcess(['$ '])
153         self.assertRaises(AssertionError, self.driver._read_prompt, time.time() + 1)
154
155     def test_command_from_driver_input(self):
156         driver_input = driver.DriverInput('foo/bar/test.html', 10, 'checksum', True)
157         expected_command = "/data/local/tmp/third_party/WebKit/LayoutTests/foo/bar/test.html'checksum\n"
158         self.assertEquals(self.driver._command_from_driver_input(driver_input), expected_command)
159
160         driver_input = driver.DriverInput('http/tests/foo/bar/test.html', 10, 'checksum', True)
161         expected_command = "http://127.0.0.1:8000/foo/bar/test.html'checksum\n"
162         self.assertEquals(self.driver._command_from_driver_input(driver_input), expected_command)
163
164
165 if __name__ == '__main__':
166     unittest.main()