Index: tools/gpu_validation/tests/gpu_validation_unittest.py |
diff --git a/tools/gpu_validation/tests/gpu_validation_unittest.py b/tools/gpu_validation/tests/gpu_validation_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..92dccc0eeaa43192708bc79ec6f4b8fcad325149 |
--- /dev/null |
+++ b/tools/gpu_validation/tests/gpu_validation_unittest.py |
@@ -0,0 +1,66 @@ |
+# Copyright (c) 2012 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 random |
+import unittest |
+ |
+from telemetry.core import browser_finder |
+from telemetry.test import options_for_unittests |
+ |
+TOP_DIR = os.path.join(os.path.dirname(__file__), os.pardir) |
+DATA_DIR = os.path.join(TOP_DIR, 'unittest_data') |
+ |
+# Number of tabs to open for testing. |
+NUM_TABS = 100 |
+ |
+ |
+class GpuValidationUnittest(unittest.TestCase): |
+ """Verifies that GPU works properly under stress.""" |
+ |
+ def setUp(self): |
+ """Gets the test assets and launches browser. |
+ |
+ Test assets are html files from test data directory. |
+ """ |
+ |
+ # Gets the test assets. |
+ self._asset_list = [] |
+ for _, _, files in os.walk(DATA_DIR): |
+ self._asset_list.extend([f for f in files if f.endswith('.html')]) |
+ self._num_assets = len(self._asset_list) |
+ |
+ # Launches browser. |
+ options = options_for_unittests.GetCopy() |
+ browser_to_create = browser_finder.FindBrowser(options) |
+ self._browser = browser_to_create.Create() |
+ self._browser.SetHTTPServerDirectory(DATA_DIR) |
+ self._tabs = self._browser.tabs |
+ |
+ def tearDown(self): |
+ self._browser.Close() |
+ |
+ def testMultipleTabsInSingleWindow(self): |
+ """Tests with multiple tabs opened in a single window.""" |
+ |
+ # Opens the tabs and navigates to the asset urls. |
+ for i in xrange(NUM_TABS): |
+ asset = self._asset_list[i % self._num_assets] |
+ tab = self._tabs.New() |
+ tab.Navigate(self._GetUrl(asset)) |
+ |
+ # Randomly cycles to the tabs. |
+ tab_nums = range(1, NUM_TABS + 1) |
+ random.shuffle(tab_nums) |
+ for num in tab_nums: |
+ self._tabs[num].Activate() |
+ |
+ # Randomly closes the tabs. |
+ num_tabs = len(self._tabs) |
+ while num_tabs > 1: |
+ self._tabs[random.randrange(1, num_tabs)].Close() |
+ num_tabs -= 1 |
+ |
+ def _GetUrl(self, asset): |
+ return self._browser.http_server.UrlOf(asset) |