Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/widget/accessibility/AccessibilityTabSwitcherTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/widget/accessibility/AccessibilityTabSwitcherTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/widget/accessibility/AccessibilityTabSwitcherTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..00050858aff9caa38ac607d786967eb1053a09ab |
| --- /dev/null |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/widget/accessibility/AccessibilityTabSwitcherTest.java |
| @@ -0,0 +1,136 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
|
Ted C
2015/01/02 18:14:45
2014
gone
2015/01/02 18:23:01
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.widget.accessibility; |
| + |
| +import android.test.suitebuilder.annotation.MediumTest; |
| +import android.view.View; |
| +import android.widget.TextView; |
| + |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.test.util.Feature; |
| +import org.chromium.chrome.browser.EmptyTabObserver; |
| +import org.chromium.chrome.browser.Tab; |
| +import org.chromium.chrome.shell.ChromeShellTestBase; |
| +import org.chromium.chrome.shell.R; |
| +import org.chromium.chrome.shell.TabManager; |
| +import org.chromium.content.browser.test.util.Criteria; |
| +import org.chromium.content.browser.test.util.CriteriaHelper; |
| +import org.chromium.content.browser.test.util.TestTouchUtils; |
| +import org.chromium.content_public.browser.LoadUrlParams; |
| + |
| +/** |
| + * Test suite for the accessibility tab switcher. |
| + * |
| + * For future tests, be wary of the button IDs being used and the R files being included. Some IDs |
| + * use the same name in multiple R files and are completely incompatible. |
| + */ |
| +public class AccessibilityTabSwitcherTest extends ChromeShellTestBase { |
| + private static final String PAGE_1_HTML = "data:text/html;charset=utf-8," |
| + + "<html><head><title>Page%201<%2Ftitle><%2Fhead><body><%2Fbody><%2Fhtml>"; |
| + private static final String PAGE_2_HTML = "data:text/html;charset=utf-8," |
| + + "<html><head><title>Page%202<%2Ftitle><%2Fhead><body><%2Fbody><%2Fhtml>"; |
| + |
| + private CharSequence getTabTitleOfListItem(final int index) throws Exception { |
| + final AccessibilityTabModelListView accessibilityView = |
| + (AccessibilityTabModelListView) getActivity().findViewById(R.id.list_view); |
| + assertTrue(accessibilityView.getCount() > index); |
| + |
| + assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
|
Ted C
2015/01/02 18:14:45
Would pollForUIThreadCriteria be better for this (
gone
2015/01/02 18:23:01
Done.
|
| + @Override |
| + public boolean isSatisfied() { |
| + return accessibilityView.getChildCount() > index; |
| + } |
| + })); |
| + |
| + View childView = accessibilityView.getChildAt(0); |
| + TextView childTextView = |
| + (TextView) childView.findViewById(org.chromium.chrome.R.id.tab_title); |
| + return childTextView.getText(); |
| + } |
| + |
| + private void toggleTabSwitcher(final boolean expectVisible) throws Exception { |
| + final TabManager tabManager = (TabManager) getActivity().findViewById(R.id.tab_manager); |
| + TestTouchUtils.performClickOnMainSync(getInstrumentation(), |
|
Ted C
2015/01/02 18:14:45
Use TouchCommon if at all possible.
gone
2015/01/02 18:23:02
Done.
|
| + getActivity().findViewById(R.id.tab_switcher)); |
| + assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return tabManager.isTabSwitcherVisible() == expectVisible; |
| + } |
| + })); |
| + } |
| + |
| + private static class TestObserver extends EmptyTabObserver implements Criteria { |
| + private boolean mTabLoadStarted; |
| + private boolean mTabLoadStopped; |
| + |
| + @Override |
| + public void onLoadStarted(Tab tab) { |
| + mTabLoadStarted = true; |
| + } |
| + |
| + @Override |
| + public void onLoadStopped(Tab tab) { |
| + mTabLoadStopped = true; |
| + } |
| + |
| + @Override |
| + public boolean isSatisfied() { |
| + return mTabLoadStarted && mTabLoadStopped; |
| + } |
| + } |
| + |
| + @MediumTest |
| + @Feature({"Accessibility"}) |
| + public void testCanEnterAndLeaveSwitcher() throws Exception { |
| + launchChromeShellWithUrl(PAGE_1_HTML); |
| + waitForActiveShellToBeDoneLoading(); |
| + |
| + final TabManager tabManager = (TabManager) getActivity().findViewById(R.id.tab_manager); |
| + assertFalse(tabManager.isTabSwitcherVisible()); |
| + |
| + toggleTabSwitcher(true); |
| + assertEquals("Page 1", getTabTitleOfListItem(0)); |
| + toggleTabSwitcher(false); |
| + } |
| + |
| + /** |
| + * Specifically tests that the TabObserver of the {@link AccessibilityTabModelListItem} is added |
| + * back to the Tab after the View is hidden. This requires bringing the tab switcher back twice |
| + * because the TabObserver is removed/added when the tab switcher's View is detached from/ |
| + * attached to the window. |
| + */ |
| + @MediumTest |
| + @Feature({"Accessibility"}) |
| + public void testObservesTitleChanges() throws Exception { |
| + launchChromeShellWithUrl(PAGE_1_HTML); |
| + waitForActiveShellToBeDoneLoading(); |
| + |
| + final TabManager tabManager = (TabManager) getActivity().findViewById(R.id.tab_manager); |
| + assertFalse(tabManager.isTabSwitcherVisible()); |
| + |
| + // Bring the tab switcher forward and send it away twice. |
| + toggleTabSwitcher(true); |
| + assertEquals("Page 1", getTabTitleOfListItem(0)); |
| + toggleTabSwitcher(false); |
| + toggleTabSwitcher(true); |
| + toggleTabSwitcher(false); |
| + |
| + // Load another URL. |
| + final TestObserver observer = new TestObserver(); |
| + getActivity().getActiveTab().addObserver(observer); |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + getActivity().getActiveTab().loadUrl(new LoadUrlParams(PAGE_2_HTML)); |
| + } |
| + }); |
| + assertTrue(CriteriaHelper.pollForCriteria(observer)); |
| + |
| + // Bring the tab switcher forward and check the title. |
| + toggleTabSwitcher(true); |
| + assertEquals("Page 2", getTabTitleOfListItem(0)); |
| + } |
| +} |