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..0f0598f1f9aefcfc486b51b8e9fc4d2310270d47 |
--- /dev/null |
+++ b/content/test/gpu/gpu_stress_tests/gpu_stress_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 |
+ |
+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) |
dtu
2013/04/03 00:32:49
xrange
Danh Nguyen
2013/04/03 15:21:58
xrange doesn't work with random.shuffle() on the n
|
+ 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: |
dtu
2013/04/03 00:32:49
Why not just always len(self._tabs)?
Danh Nguyen
2013/04/03 15:21:58
Done. Thanks, Dave. The loop looks much better no
|
+ self._tabs[random.randrange(1, num_tabs)].Close() |
+ num_tabs -= 1 |
+ |
+ def _GetUrl(self, asset): |
+ return self._browser.http_server.UrlOf(asset) |