Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / tools / perf / profile_creators / fast_navigation_profile_extender_unittest.py
blob86e6c81a82d446d332f6159c0eb4b44b6733f1f8
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
6 from profile_creators.fast_navigation_profile_extender import (
7 FastNavigationProfileExtender)
8 from telemetry.core import util
9 from telemetry.unittest_util import options_for_unittests
11 util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock')
12 import mock # pylint: disable=import-error
15 class FakeTab(object):
16 pass
19 class FakeTabList(object):
20 def __init__(self):
21 self._tabs = []
23 def New(self):
24 tab = FakeTab()
25 self._tabs.append(tab)
26 return tab
28 def __len__(self):
29 return len(self._tabs)
32 class FakeBrowser(object):
33 def __init__(self):
34 self.tabs = FakeTabList()
37 # Testing private method.
38 # pylint: disable=protected-access
39 class FastNavigationProfileExtenderTest(unittest.TestCase):
40 def testPerformNavigations(self):
41 maximum_batch_size = 15
42 options = options_for_unittests.GetCopy()
43 extender = FastNavigationProfileExtender(options, maximum_batch_size)
45 navigation_urls = []
46 for i in range(extender._NUM_TABS):
47 navigation_urls.append('http://test%s.com' % i)
48 batch_size = 5
49 navigation_urls_batch = navigation_urls[3:3 + batch_size]
51 extender.GetUrlIterator = mock.MagicMock(
52 return_value=iter(navigation_urls_batch))
53 extender.ShouldExitAfterBatchNavigation = mock.MagicMock(return_value=True)
54 extender._WaitForQueuedTabsToLoad = mock.MagicMock()
56 extender._browser = FakeBrowser()
57 extender._BatchNavigateTabs = mock.MagicMock()
59 # Set up a callback to record the tabs and urls in each navigation.
60 callback_tabs_batch = []
61 callback_urls_batch = []
62 def SideEffect(*args, **_):
63 batch = args[0]
64 for tab, url in batch:
65 callback_tabs_batch.append(tab)
66 callback_urls_batch.append(url)
67 extender._BatchNavigateTabs.side_effect = SideEffect
69 # Perform the navigations.
70 extender._PerformNavigations()
72 # Each url in the batch should have been navigated to exactly once.
73 self.assertEqual(set(callback_urls_batch), set(navigation_urls_batch))
75 # The other urls should not have been navigated to.
76 navigation_urls_remaining = (set(navigation_urls) -
77 set(navigation_urls_batch))
78 self.assertFalse(navigation_urls_remaining & set(callback_urls_batch))
80 # The first couple of tabs should have been navigated once. The remaining
81 # tabs should not have been navigated.
82 for i in range(len(extender._browser.tabs)):
83 tab = extender._browser.tabs._tabs[i]
85 if i < batch_size:
86 expected_tab_navigation_count = 1
87 else:
88 expected_tab_navigation_count = 0
90 count = callback_tabs_batch.count(tab)
91 self.assertEqual(count, expected_tab_navigation_count)