1 # Copyright 2016 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.
9 from telemetry
.testing
import serially_executed_browser_test_case
12 _prev_test_name
= None
15 serially_executed_browser_test_case
.SeriallyExecutedBrowserTestCase
):
18 def AddCommandlineArgs(cls
, parser
):
19 parser
.add_option('--adder-sum', type=int, default
=5)
25 def GenerateTestCases_AdderTest(cls
, options
):
26 yield 'add_1_and_2', (1, 2, options
.adder_sum
)
27 yield 'add_2_and_3', (2, 3, options
.adder_sum
)
28 yield 'add_7_and_3', (7, 3, options
.adder_sum
)
29 # Filtered out in browser_test_runner_unittest.py
30 yield 'dontrun_add_1_and_2', (1, 2, options
.adder_sum
)
33 def GenerateTestCases_AlphabeticalTest(cls
, options
):
35 prefix
= 'Alphabetical_'
37 for character
in string
.lowercase
[:26]:
38 test_names
.append(prefix
+ character
)
39 for character
in string
.uppercase
[:26]:
40 test_names
.append(prefix
+ character
)
41 for num
in xrange(20):
42 test_names
.append(prefix
+ str(num
))
44 # Shuffle |test_names| so the tests will be generated in a random order.
45 test_names
= (test_names
[25:40] + test_names
[40:70] + test_names
[:25] +
50 def AlphabeticalTest(self
):
52 global _prev_test_name
53 self
.assertLess(_prev_test_name
, test_name
)
54 _prev_test_name
= test_name
56 def AdderTest(self
, a
, b
, partial_sum
):
57 self
.assertEqual(a
+ b
, partial_sum
)
60 def GenerateTestCases_MultiplierTest(cls
, options
):
62 yield 'multiplier_simple', (10, 2, 4)
63 yield 'multiplier_simple_2', (2, 3, 5)
64 yield 'multiplier_simple_3', (10, 3, 6)
65 # Filtered out in browser_test_runner_unittest.py
66 yield 'dontrun_multiplier_simple', (10, 2, 4)
68 def MultiplierTest(self
, a
, b
, partial_sum
):
69 self
.assertEqual(a
* b
, partial_sum
* self
.extra
)
73 self
.assertEqual(1, self
.extra
)
75 def TestException(self
):
76 raise Exception('Expected exception')
79 def load_tests(loader
, tests
, pattern
):
80 del loader
, tests
, pattern
# Unused.
81 return serially_executed_browser_test_case
.LoadAllTestsInModule(
82 sys
.modules
[__name__
])