Index: content/test/gpu/gpu_stress_tests/gpu_stress_unittest.py |
diff --git a/content/test/gpu/gpu_stress_tests/gpu_stress_unittest.py b/content/test/gpu/gpu_stress_tests/gpu_stress_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..93f1ba1500c681b89dc4b944a18669d8435fd8f7 |
--- /dev/null |
+++ b/content/test/gpu/gpu_stress_tests/gpu_stress_unittest.py |
@@ -0,0 +1,64 @@ |
+# 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 |
+ |
+CUR_DIR = os.path.dirname(__file__) |
+DATA_DIR = os.path.join(CUR_DIR, os.pardir, os.pardir, 'data', 'gpu') |
+ |
+# 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.SetHTTPServerDirectories([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. |
+ while len(self._tabs) > 1: |
+ self._tabs[random.randrange(1, len(self._tabs))].Close() |
+ |
+ def _GetUrl(self, asset): |
+ return self._browser.http_server.UrlOf(asset) |