OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os |
| 6 import random |
| 7 import unittest |
| 8 |
| 9 from telemetry.core import browser_finder |
| 10 from telemetry.test import options_for_unittests |
| 11 |
| 12 TOP_DIR = os.path.join(os.path.dirname(__file__), os.pardir) |
| 13 DATA_DIR = os.path.join(TOP_DIR, 'unittest_data') |
| 14 |
| 15 # Number of tabs to open for testing. |
| 16 NUM_TABS = 100 |
| 17 |
| 18 |
| 19 class GpuValidationUnittest(unittest.TestCase): |
| 20 """Verifies that GPU works properly under stress.""" |
| 21 |
| 22 def setUp(self): |
| 23 """Gets the test assets and launches browser. |
| 24 |
| 25 Test assets are html files from test data directory. |
| 26 """ |
| 27 |
| 28 # Gets the test assets. |
| 29 self._asset_list = [] |
| 30 for _, _, files in os.walk(DATA_DIR): |
| 31 self._asset_list.extend([f for f in files if f.endswith('.html')]) |
| 32 self._num_assets = len(self._asset_list) |
| 33 |
| 34 # Launches browser. |
| 35 options = options_for_unittests.GetCopy() |
| 36 browser_to_create = browser_finder.FindBrowser(options) |
| 37 self._browser = browser_to_create.Create() |
| 38 self._browser.SetHTTPServerDirectory(DATA_DIR) |
| 39 self._tabs = self._browser.tabs |
| 40 |
| 41 def tearDown(self): |
| 42 self._browser.Close() |
| 43 |
| 44 def testMultipleTabsInSingleWindow(self): |
| 45 """Tests with multiple tabs opened in a single window.""" |
| 46 |
| 47 # Opens the tabs and navigates to the asset urls. |
| 48 for i in xrange(NUM_TABS): |
| 49 asset = self._asset_list[i % self._num_assets] |
| 50 tab = self._tabs.New() |
| 51 tab.Navigate(self._GetUrl(asset)) |
| 52 |
| 53 # Randomly cycles to the tabs. |
| 54 tab_nums = range(1, NUM_TABS + 1) |
| 55 random.shuffle(tab_nums) |
| 56 for num in tab_nums: |
| 57 self._tabs[num].Activate() |
| 58 |
| 59 # Randomly closes the tabs. |
| 60 num_tabs = len(self._tabs) |
| 61 while num_tabs > 1: |
| 62 self._tabs[random.randrange(1, num_tabs)].Close() |
| 63 num_tabs -= 1 |
| 64 |
| 65 def _GetUrl(self, asset): |
| 66 return self._browser.http_server.UrlOf(asset) |
OLD | NEW |