Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / telemetry / internal / backends / chrome / tab_list_backend_unittest.py
blob47e3451930ee6b66380293b357c8f6e507c0d33f
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.
5 from telemetry.core import exceptions
6 from telemetry import decorators
7 from telemetry.testing import tab_test_case
10 class TabListBackendTest(tab_test_case.TabTestCase):
11 @decorators.Enabled('has tabs')
12 def testNewTab(self):
13 tabs = set(tab.id for tab in self.tabs)
14 for _ in xrange(10):
15 new_tab_id = self.tabs.New().id
16 self.assertNotIn(new_tab_id, tabs)
17 tabs.add(new_tab_id)
18 new_tabs = set(tab.id for tab in self.tabs)
19 self.assertEqual(tabs, new_tabs)
21 @decorators.Enabled('has tabs')
22 def testTabIdMatchesContextId(self):
23 # Ensure that there are two tabs.
24 while len(self.tabs) < 2:
25 self.tabs.New()
27 # Check that the tab.id matches context_id.
28 tabs = []
29 for context_id in self.tabs._tab_list_backend.IterContextIds():
30 tab = self.tabs.GetTabById(context_id)
31 self.assertEquals(tab.id, context_id)
32 tabs.append(self.tabs.GetTabById(context_id))
34 # https://github.com/catapult-project/catapult/issues/3099 (Android)
35 @decorators.Enabled('has tabs')
36 @decorators.Disabled('android')
37 def testTabIdStableAfterTabCrash(self):
38 # Ensure that there are two tabs.
39 while len(self.tabs) < 2:
40 self.tabs.New()
42 tabs = [t for t in self.tabs]
44 # Crash the first tab.
45 self.assertRaises(exceptions.DevtoolsTargetCrashException,
46 lambda: tabs[0].Navigate('chrome://crash'))
48 # Fetching the second tab by id should still work. Fetching the first tab
49 # should raise an exception.
50 self.assertEquals(tabs[1], self.tabs.GetTabById(tabs[1].id))
51 self.assertRaises(KeyError, lambda: self.tabs.GetTabById(tabs[0].id))