OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 |
| 5 package org.chromium.chrome.browser.appmenu; |
| 6 |
| 7 import android.support.test.filters.SmallTest; |
| 8 |
| 9 import org.chromium.base.ThreadUtils; |
| 10 import org.chromium.base.test.util.UrlUtils; |
| 11 import org.chromium.chrome.test.BottomSheetTestCaseBase; |
| 12 import org.chromium.content.browser.test.util.Criteria; |
| 13 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 14 |
| 15 /** |
| 16 * Tests for the app menu when Chrome Home is enabled. |
| 17 */ |
| 18 public class ChromeHomeAppMenuTest extends BottomSheetTestCaseBase { |
| 19 private static final String TEST_URL = UrlUtils.encodeHtmlDataUri("<html>foo
</html>"); |
| 20 private AppMenuHandler mAppMenuHandler; |
| 21 |
| 22 @Override |
| 23 protected void setUp() throws Exception { |
| 24 super.setUp(); |
| 25 |
| 26 mAppMenuHandler = getActivity().getAppMenuHandler(); |
| 27 } |
| 28 |
| 29 @SmallTest |
| 30 public void testPageMenu() throws IllegalArgumentException, InterruptedExcep
tion { |
| 31 loadUrl(TEST_URL); |
| 32 |
| 33 showAppMenuAndAssertMenuShown(); |
| 34 AppMenu appMenu = getActivity().getAppMenuHandler().getAppMenu(); |
| 35 AppMenuIconRowFooter iconRow = (AppMenuIconRowFooter) appMenu.getPromptV
iew(); |
| 36 |
| 37 assertFalse(iconRow.getForwardButtonForTests().isEnabled()); |
| 38 assertTrue(iconRow.getBookmarkButtonForTests().isEnabled()); |
| 39 // Only HTTP/S pages can be downloaded. |
| 40 assertFalse(iconRow.getDownloadButtonForTests().isEnabled()); |
| 41 assertTrue(iconRow.getPageInfoButtonForTests().isEnabled()); |
| 42 assertTrue(iconRow.getReloadButtonForTests().isEnabled()); |
| 43 |
| 44 // Navigate backward, open the menu and assert forward button is enabled
. |
| 45 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 46 @Override |
| 47 public void run() { |
| 48 mAppMenuHandler.hideAppMenu(); |
| 49 getActivity().getActivityTab().goBack(); |
| 50 } |
| 51 }); |
| 52 |
| 53 showAppMenuAndAssertMenuShown(); |
| 54 iconRow = (AppMenuIconRowFooter) appMenu.getPromptView(); |
| 55 assertTrue(iconRow.getForwardButtonForTests().isEnabled()); |
| 56 } |
| 57 |
| 58 @SmallTest |
| 59 public void testTabSwitcherMenu() throws IllegalArgumentException { |
| 60 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 61 @Override |
| 62 public void run() { |
| 63 getActivity().getLayoutManager().showOverview(false); |
| 64 } |
| 65 }); |
| 66 |
| 67 showAppMenuAndAssertMenuShown(); |
| 68 AppMenu appMenu = getActivity().getAppMenuHandler().getAppMenu(); |
| 69 |
| 70 assertNull(appMenu.getPromptView()); |
| 71 } |
| 72 |
| 73 private void showAppMenuAndAssertMenuShown() { |
| 74 ThreadUtils.runOnUiThread(new Runnable() { |
| 75 @Override |
| 76 public void run() { |
| 77 mAppMenuHandler.showAppMenu(null, false); |
| 78 } |
| 79 }); |
| 80 CriteriaHelper.pollUiThread(new Criteria("AppMenu did not show") { |
| 81 @Override |
| 82 public boolean isSatisfied() { |
| 83 return mAppMenuHandler.isAppMenuShowing(); |
| 84 } |
| 85 }); |
| 86 } |
| 87 } |
OLD | NEW |