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 package org
.chromium
.chrome
.browser
;
7 import static org
.chromium
.base
.test
.util
.Restriction
.RESTRICTION_TYPE_PHONE
;
9 import android
.test
.suitebuilder
.annotation
.MediumTest
;
10 import android
.widget
.ImageButton
;
12 import org
.chromium
.base
.test
.util
.Feature
;
13 import org
.chromium
.base
.test
.util
.Restriction
;
14 import org
.chromium
.chrome
.R
;
15 import org
.chromium
.chrome
.browser
.toolbar
.TabSwitcherDrawable
;
16 import org
.chromium
.chrome
.test
.ChromeTabbedActivityTestBase
;
17 import org
.chromium
.chrome
.test
.util
.ChromeTabUtils
;
20 * Test suite for the tab count widget on the phone toolbar.
23 public class TabCountLabelTest
extends ChromeTabbedActivityTestBase
{
26 * Check the tabCount string against an expected value.
28 private void tabCountLabelCheck(String stepName
, int tabCountExpected
) {
29 ImageButton tabSwitcherBtn
=
30 (ImageButton
) getActivity().findViewById(R
.id
.tab_switcher_button
);
31 TabSwitcherDrawable drawable
= (TabSwitcherDrawable
) tabSwitcherBtn
.getDrawable();
32 int tabCountFromDrawable
= drawable
.getTabCount();
33 assertTrue(stepName
+ ", " + tabCountExpected
+ " tab[s] expected, label shows "
34 + tabCountFromDrawable
, tabCountExpected
== tabCountFromDrawable
);
38 * Verify displayed Tab Count matches the actual number of tabs.
41 @Feature({"Browser", "Main"})
42 @Restriction(RESTRICTION_TYPE_PHONE
)
43 public void testTabCountLabel() throws InterruptedException
{
44 final int tabCount
= getActivity().getCurrentTabModel().getCount();
45 tabCountLabelCheck("Initial state", tabCount
);
46 ChromeTabUtils
.newTabFromMenu(getInstrumentation(), getActivity());
47 // Make sure the TAB_CREATED notification went through
48 getInstrumentation().waitForIdleSync();
49 tabCountLabelCheck("After new tab", tabCount
+ 1);
50 ChromeTabUtils
.closeCurrentTab(getInstrumentation(), getActivity());
51 // Make sure the TAB_CLOSED notification went through
52 getInstrumentation().waitForIdleSync();
53 tabCountLabelCheck("After close tab", tabCount
);
57 public void startMainActivity() throws InterruptedException
{
58 startMainActivityOnBlankPage();