Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 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 import unittest | |
| 5 | |
| 6 from profile_creators.fast_navigation_profile_extender import ( | |
| 7 FastNavigationProfileExtender) | |
| 8 from telemetry.core import util | |
| 9 | |
| 10 util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock') | |
| 11 import mock | |
| 12 | |
| 13 | |
| 14 class FakeTab(object): | |
| 15 pass | |
| 16 | |
| 17 | |
| 18 class FakeBrowser(object): | |
| 19 def __init__(self, tab_count): | |
| 20 self.tabs = [] | |
| 21 for _ in range(tab_count): | |
| 22 self.tabs.append(FakeTab()) | |
| 23 | |
| 24 | |
| 25 # Testing private method. | |
| 26 # pylint: disable=W0212 | |
|
nednguyen
2015/02/12 02:10:53
Nit: please use pylint: disable=access-protected..
erikchen
2015/02/12 03:02:58
Done.
| |
| 27 class FastNavigationProfileExtenderTest(unittest.TestCase): | |
| 28 def testPerformNavigations(self): | |
| 29 extender = FastNavigationProfileExtender() | |
| 30 num_urls = extender._NUM_PARALLEL_PAGES * 3 + 4 | |
| 31 num_tabs = extender._NUM_TABS | |
| 32 | |
| 33 navigation_urls = [] | |
| 34 for i in range(num_urls): | |
| 35 navigation_urls.append('http://test%s.com' % i) | |
| 36 | |
| 37 extender._navigation_urls = navigation_urls | |
| 38 extender._browser = FakeBrowser(num_tabs) | |
| 39 extender._BatchNavigateTabs = mock.MagicMock() | |
| 40 | |
| 41 # Set up a callback to record the tabs and urls in each navigation. | |
| 42 batch_callback_tabs = [] | |
| 43 batch_callback_urls = [] | |
| 44 def SideEffect(*args, **_): | |
| 45 batch = args[0] | |
| 46 for tab, url in batch: | |
| 47 batch_callback_tabs.append(tab) | |
| 48 batch_callback_urls.append(url) | |
| 49 extender._BatchNavigateTabs.side_effect = SideEffect | |
| 50 | |
| 51 # Perform the navigations. | |
| 52 extender._PerformNavigations() | |
| 53 | |
| 54 # Each url should have been navigated to exactly once. | |
| 55 self.assertEqual(set(batch_callback_urls), set(navigation_urls)) | |
| 56 | |
| 57 # The first 4 tabs should have been navigated 4 times. The remaining tabs | |
| 58 # should have been navigated 3 times. | |
| 59 num_navigations_per_tab = 3 | |
| 60 num_tabs_with_one_extra_navigation = 4 | |
| 61 for i in range(len(extender._browser.tabs)): | |
| 62 tab = extender._browser.tabs[i] | |
| 63 | |
| 64 expected_tab_navigation_count = num_navigations_per_tab | |
| 65 if i < num_tabs_with_one_extra_navigation: | |
| 66 expected_tab_navigation_count += 1 | |
| 67 | |
| 68 count = batch_callback_tabs.count(tab) | |
| 69 self.assertEqual(count, expected_tab_navigation_count) | |
|
nednguyen
2015/02/12 03:17:59
Can we add a regression test that actually create
nednguyen
2015/02/12 16:53:56
Actually, I realize that you will need either to u
erikchen
2015/02/12 18:16:46
What specifically are you trying to get from the r
| |
| OLD | NEW |