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')
13 tabs
= set(tab
.id for tab
in self
.tabs
)
15 new_tab_id
= self
.tabs
.New().id
16 self
.assertNotIn(new_tab_id
, tabs
)
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:
27 # Check that the tab.id matches context_id.
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:
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))