Index: tools/telemetry/telemetry/unittest/browser_test_case.py |
diff --git a/tools/telemetry/telemetry/unittest/browser_test_case.py b/tools/telemetry/telemetry/unittest/browser_test_case.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c824e74c5bed2b1a8c8c9c42527976b31036b57f |
--- /dev/null |
+++ b/tools/telemetry/telemetry/unittest/browser_test_case.py |
@@ -0,0 +1,45 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import os |
+import unittest |
+ |
+from telemetry.core import browser_finder |
+from telemetry.unittest import options_for_unittests |
+from telemetry.util import path |
+ |
+ |
+class BrowserTestCase(unittest.TestCase): |
+ @classmethod |
+ def setUpClass(cls): |
+ options = options_for_unittests.GetCopy() |
+ cls.CustomizeBrowserOptions(options.browser_options) |
+ browser_to_create = browser_finder.FindBrowser(options) |
+ if not browser_to_create: |
+ raise Exception('No browser found, cannot continue test.') |
+ |
+ cls._browser = None |
+ try: |
+ cls._browser = browser_to_create.Create() |
+ cls._browser.Start() |
+ except: |
+ cls.tearDownClass() |
+ raise |
+ |
+ @classmethod |
+ def tearDownClass(cls): |
+ if cls._browser: |
+ cls._browser.Close() |
+ cls._browser = None |
+ |
+ @classmethod |
+ def CustomizeBrowserOptions(cls, options): |
+ """Override to add test-specific options to the BrowserOptions object""" |
+ pass |
+ |
+ @classmethod |
+ def UrlOfUnittestFile(cls, filename): |
+ cls._browser.SetHTTPServerDirectories(path.GetUnittestDataDir()) |
+ file_path = os.path.join(path.GetUnittestDataDir(), filename) |
+ return cls._browser.http_server.UrlOf(file_path) |