OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 package org.chromium.chrome.browser.tab; |
| 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 |
| 9 import android.test.suitebuilder.annotation.LargeTest; |
| 10 |
| 11 import org.chromium.base.CommandLine; |
| 12 import org.chromium.base.ThreadUtils; |
| 13 import org.chromium.base.test.util.Restriction; |
| 14 import org.chromium.base.test.util.UrlUtils; |
| 15 import org.chromium.chrome.browser.ChromeSwitches; |
| 16 import org.chromium.chrome.browser.Tab; |
| 17 import org.chromium.chrome.browser.snackbar.SnackbarManager; |
| 18 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 19 import org.chromium.chrome.browser.tabmodel.TabModelUtils; |
| 20 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
| 21 import org.chromium.content.browser.test.util.Criteria; |
| 22 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 23 import org.chromium.content.browser.test.util.DOMUtils; |
| 24 |
| 25 import java.util.concurrent.TimeoutException; |
| 26 |
| 27 /** |
| 28 * Tests undo and it's interactions with the UI. |
| 29 */ |
| 30 public class UndoIntegrationTest extends ChromeTabbedActivityTestBase { |
| 31 private static final String WINDOW_OPEN_BUTTON_URL = UrlUtils.encodeHtmlData
Uri( |
| 32 "<html>" |
| 33 + " <head>" |
| 34 + " <script>" |
| 35 + " function openWindow() {" |
| 36 + " window.open('about:blank');" |
| 37 + " }" |
| 38 + " </script>" |
| 39 + " </head>" |
| 40 + " <body>" |
| 41 + " <a id=\"link\" onclick=\"setTimeout(openWindow, 500);\">Open<
/a>" |
| 42 + " </body>" |
| 43 + "</html>" |
| 44 ); |
| 45 |
| 46 @Override |
| 47 public void startMainActivity() throws InterruptedException { |
| 48 CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_HIGH_END_UI
_UNDO); |
| 49 SnackbarManager.setTimeoutForTesting(1500); |
| 50 startMainActivityOnBlankPage(); |
| 51 } |
| 52 |
| 53 /** |
| 54 * Test that a tab that is closing can't open other windows. |
| 55 * @throws InterruptedException |
| 56 * @throws TimeoutException |
| 57 */ |
| 58 @LargeTest |
| 59 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) |
| 60 public void testAddNewContentsFromClosingTab() throws InterruptedException,
TimeoutException { |
| 61 loadUrl(WINDOW_OPEN_BUTTON_URL); |
| 62 |
| 63 final TabModel model = getActivity().getTabModelSelector().getCurrentMod
el(); |
| 64 final Tab tab = TabModelUtils.getCurrentTab(model); |
| 65 |
| 66 // Clock on the link that will trigger a delayed window popup. |
| 67 DOMUtils.clickNode(this, tab.getContentViewCore(), "link"); |
| 68 |
| 69 // Attempt to close the tab, which will delay closing until the undo tim
eout goes away. |
| 70 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 71 @Override |
| 72 public void run() { |
| 73 TabModelUtils.closeTabById(model, tab.getId(), true); |
| 74 assertTrue("Tab was not marked as closing", tab.isClosing()); |
| 75 assertTrue("Tab is not actually closing", model.isClosurePending
(tab.getId())); |
| 76 } |
| 77 }); |
| 78 |
| 79 // Give the model a chance to process the undo and close the tab. |
| 80 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 81 @Override |
| 82 public boolean isSatisfied() { |
| 83 return !model.isClosurePending(tab.getId()) && model.getCount()
== 0; |
| 84 } |
| 85 }); |
| 86 |
| 87 // Validate that the model doesn't contain the original tab or any newly
opened tabs. |
| 88 assertFalse("Model is still waiting to close the tab", model.isClosurePe
nding(tab.getId())); |
| 89 assertEquals("Model still has tabs", 0, model.getCount()); |
| 90 } |
| 91 } |
OLD | NEW |