OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 catapult_base import cloud_storage |
7 from telemetry.internal.browser import browser_finder | 8 from telemetry.internal.browser import browser_finder |
8 from telemetry.testing import options_for_unittests | 9 from telemetry.testing import options_for_unittests |
| 10 from telemetry.util import wpr_modes |
9 | 11 |
10 | 12 |
11 class SeriallyBrowserTestCase(unittest.TestCase): | 13 class SeriallyExecutedBrowserTestCase(unittest.TestCase): |
| 14 def __init__(self, methodName): |
| 15 super(SeriallyExecutedBrowserTestCase, self).__init__(methodName) |
| 16 self._private_methodname = methodName |
| 17 |
| 18 def shortName(self): |
| 19 """Returns the method name this test runs, without the package prefix.""" |
| 20 return self._private_methodname |
| 21 |
12 @classmethod | 22 @classmethod |
13 def Name(cls): | 23 def Name(cls): |
14 return cls.__name__ | 24 return cls.__name__ |
15 | 25 |
16 @classmethod | 26 @classmethod |
17 def AddCommandlineArgs(cls, parser): | 27 def AddCommandlineArgs(cls, parser): |
18 pass | 28 pass |
19 | 29 |
20 @classmethod | 30 @classmethod |
21 def setUpClass(cls): | 31 def setUpClass(cls): |
22 cls._finder_options = options_for_unittests.GetCopy() | 32 cls._finder_options = options_for_unittests.GetCopy() |
23 cls._platform = None | |
24 cls._browser = None | |
25 cls.platform = None | 33 cls.platform = None |
26 cls.browser = None | 34 cls.browser = None |
| 35 cls._browser_to_create = None |
| 36 cls._browser_options = None |
27 | 37 |
28 @classmethod | 38 @classmethod |
29 def StartBrowser(cls, options): | 39 def SetBrowserOptions(cls, browser_options): |
30 assert not cls.browser, 'Browser is started. Must close it first' | 40 """Sets the browser option for the browser to create. |
31 browser_to_create = browser_finder.FindBrowser(options) | 41 |
32 cls.browser = browser_to_create.Create(options) | 42 Args: |
33 cls._browser = cls.browser | 43 browser_options: Browser options object for the browser we want to test. |
| 44 """ |
| 45 cls._browser_options = browser_options |
| 46 cls._browser_to_create = browser_finder.FindBrowser(browser_options) |
34 if not cls.platform: | 47 if not cls.platform: |
35 cls.platform = cls.browser.platform | 48 cls.platform = cls._browser_to_create.platform |
36 cls._platform = cls.platform | |
37 else: | 49 else: |
38 assert cls.platform == cls.browser.platform, ( | 50 assert cls.platform == cls._browser_to_create.platform, ( |
39 'All browser launches within same test suite must use browsers on ' | 51 'All browser launches within same test suite must use browsers on ' |
40 'the same platform') | 52 'the same platform') |
41 | 53 |
42 @classmethod | 54 @classmethod |
| 55 def StartWPRServer(cls, archive_path=None, archive_bucket=None): |
| 56 """Start a webpage replay server. |
| 57 |
| 58 Args: |
| 59 archive_path: Path to the WPR file. If there is a corresponding sha1 file, |
| 60 this archive will be automatically downloaded from Google Storage. |
| 61 archive_bucket: The bucket to look for the WPR archive. |
| 62 """ |
| 63 assert cls._browser_options, ( |
| 64 'Browser options must be set with |SetBrowserOptions| prior to ' |
| 65 'starting WPR') |
| 66 assert not cls.browser, 'WPR must be started prior to browser being started' |
| 67 |
| 68 cloud_storage.GetIfChanged(archive_path, archive_bucket) |
| 69 cls.platform.network_controller.Open(wpr_modes.WPR_REPLAY, []) |
| 70 cls.platform.network_controller.StartReplay(archive_path=archive_path) |
| 71 |
| 72 @classmethod |
| 73 def StopWPRServer(cls): |
| 74 cls.platform.network_controller.StopReplay() |
| 75 |
| 76 @classmethod |
| 77 def StartBrowser(cls): |
| 78 assert cls._browser_options, ( |
| 79 'Browser options must be set with |SetBrowserOptions| prior to ' |
| 80 'starting WPR') |
| 81 assert not cls.browser, 'Browser is started. Must close it first' |
| 82 |
| 83 cls.browser = cls._browser_to_create.Create(cls._browser_options) |
| 84 |
| 85 @classmethod |
43 def StopBrowser(cls): | 86 def StopBrowser(cls): |
44 assert cls.browser, 'Browser is not started' | 87 assert cls.browser, 'Browser is not started' |
45 cls.browser.Close() | 88 cls.browser.Close() |
46 cls.browser = None | 89 cls.browser = None |
47 cls._browser = None | |
48 | 90 |
49 @classmethod | 91 @classmethod |
50 def tearDownClass(cls): | 92 def tearDownClass(cls): |
51 if cls.platform: | 93 if cls.platform: |
52 cls.platform.StopAllLocalServers() | 94 cls.platform.StopAllLocalServers() |
53 if cls.browser: | 95 if cls.browser: |
54 cls.StopBrowser() | 96 cls.StopBrowser() |
55 | 97 |
56 @classmethod | 98 @classmethod |
57 def SetStaticServerDir(cls, dir_path): | 99 def SetStaticServerDir(cls, dir_path): |
58 assert cls.platform | 100 assert cls.platform |
59 cls.platform.SetHTTPServerDirectories(dir_path) | 101 cls.platform.SetHTTPServerDirectories(dir_path) |
60 | 102 |
61 @classmethod | 103 @classmethod |
62 def UrlOfStaticFilePath(cls, file_path): | 104 def UrlOfStaticFilePath(cls, file_path): |
63 return cls.platform.http_server.UrlOf(file_path) | 105 return cls.platform.http_server.UrlOf(file_path) |
OLD | NEW |