Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: tools/perf/profile_creators/fast_navigation_profile_extender_unittest.py

Issue 907503002: telemetry: Create a helper class to quickly extend profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698