OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; |
8 | 8 |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.pm.ActivityInfo; | 10 import android.content.pm.ActivityInfo; |
11 import android.os.Debug; | 11 import android.os.Debug; |
12 import android.os.Environment; | 12 import android.os.Environment; |
13 import android.os.IBinder; | |
14 import android.os.ResultReceiver; | |
13 import android.os.SystemClock; | 15 import android.os.SystemClock; |
14 import android.test.suitebuilder.annotation.LargeTest; | 16 import android.test.suitebuilder.annotation.LargeTest; |
15 import android.test.suitebuilder.annotation.MediumTest; | 17 import android.test.suitebuilder.annotation.MediumTest; |
16 import android.test.suitebuilder.annotation.SmallTest; | 18 import android.test.suitebuilder.annotation.SmallTest; |
17 import android.test.suitebuilder.annotation.Smoke; | 19 import android.test.suitebuilder.annotation.Smoke; |
18 import android.util.DisplayMetrics; | 20 import android.util.DisplayMetrics; |
19 import android.util.Log; | 21 import android.util.Log; |
20 import android.view.View; | 22 import android.view.View; |
21 | 23 |
22 import org.chromium.base.ThreadUtils; | 24 import org.chromium.base.ThreadUtils; |
(...skipping 30 matching lines...) Expand all Loading... | |
53 import org.chromium.chrome.browser.tabmodel.TabbedModeTabPersistencePolicy; | 55 import org.chromium.chrome.browser.tabmodel.TabbedModeTabPersistencePolicy; |
54 import org.chromium.chrome.browser.toolbar.ToolbarPhone; | 56 import org.chromium.chrome.browser.toolbar.ToolbarPhone; |
55 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; | 57 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
56 import org.chromium.chrome.test.util.ApplicationTestUtils; | 58 import org.chromium.chrome.test.util.ApplicationTestUtils; |
57 import org.chromium.chrome.test.util.ChromeRestriction; | 59 import org.chromium.chrome.test.util.ChromeRestriction; |
58 import org.chromium.chrome.test.util.ChromeTabUtils; | 60 import org.chromium.chrome.test.util.ChromeTabUtils; |
59 import org.chromium.chrome.test.util.MenuUtils; | 61 import org.chromium.chrome.test.util.MenuUtils; |
60 import org.chromium.chrome.test.util.NewTabPageTestUtils; | 62 import org.chromium.chrome.test.util.NewTabPageTestUtils; |
61 import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher; | 63 import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher; |
62 import org.chromium.content.browser.ContentViewCore; | 64 import org.chromium.content.browser.ContentViewCore; |
65 import org.chromium.content.browser.input.ImeAdapter; | |
66 import org.chromium.content.browser.input.InputMethodManagerWrapper; | |
63 import org.chromium.content.browser.test.util.CallbackHelper; | 67 import org.chromium.content.browser.test.util.CallbackHelper; |
64 import org.chromium.content.browser.test.util.Criteria; | 68 import org.chromium.content.browser.test.util.Criteria; |
65 import org.chromium.content.browser.test.util.CriteriaHelper; | 69 import org.chromium.content.browser.test.util.CriteriaHelper; |
70 import org.chromium.content.browser.test.util.DOMUtils; | |
66 import org.chromium.content.browser.test.util.JavaScriptUtils; | 71 import org.chromium.content.browser.test.util.JavaScriptUtils; |
67 import org.chromium.content.browser.test.util.UiUtils; | 72 import org.chromium.content.browser.test.util.UiUtils; |
68 import org.chromium.content.common.ContentSwitches; | 73 import org.chromium.content.common.ContentSwitches; |
69 import org.chromium.content_public.browser.WebContents; | 74 import org.chromium.content_public.browser.WebContents; |
70 import org.chromium.content_public.browser.WebContentsObserver; | 75 import org.chromium.content_public.browser.WebContentsObserver; |
71 import org.chromium.net.test.EmbeddedTestServer; | 76 import org.chromium.net.test.EmbeddedTestServer; |
72 | 77 |
73 import java.io.File; | 78 import java.io.File; |
74 import java.util.Locale; | 79 import java.util.Locale; |
75 import java.util.concurrent.Callable; | 80 import java.util.concurrent.Callable; |
(...skipping 12 matching lines...) Expand all Loading... | |
88 private static final String TEST_PAGE_FILE_PATH = "/chrome/test/data/google/ google.html"; | 93 private static final String TEST_PAGE_FILE_PATH = "/chrome/test/data/google/ google.html"; |
89 | 94 |
90 private EmbeddedTestServer mTestServer; | 95 private EmbeddedTestServer mTestServer; |
91 | 96 |
92 private float mPxToDp = 1.0f; | 97 private float mPxToDp = 1.0f; |
93 private float mTabsViewHeightDp; | 98 private float mTabsViewHeightDp; |
94 private float mTabsViewWidthDp; | 99 private float mTabsViewWidthDp; |
95 | 100 |
96 private boolean mNotifyChangedCalled; | 101 private boolean mNotifyChangedCalled; |
97 | 102 |
103 public boolean mKeyboardShown = false; | |
104 | |
98 private static final int SWIPE_TO_RIGHT_DIRECTION = 1; | 105 private static final int SWIPE_TO_RIGHT_DIRECTION = 1; |
99 private static final int SWIPE_TO_LEFT_DIRECTION = -1; | 106 private static final int SWIPE_TO_LEFT_DIRECTION = -1; |
100 | 107 |
101 private static final long WAIT_RESIZE_TIMEOUT_MS = 3000; | 108 private static final long WAIT_RESIZE_TIMEOUT_MS = 3000; |
102 | 109 |
103 private static final int STRESSFUL_TAB_COUNT = 100; | 110 private static final int STRESSFUL_TAB_COUNT = 100; |
104 | 111 |
105 private static final String INITIAL_SIZE_TEST_URL = UrlUtils.encodeHtmlDataU ri( | 112 private static final String INITIAL_SIZE_TEST_URL = UrlUtils.encodeHtmlDataU ri( |
106 "<html><head><meta name=\"viewport\" content=\"width=device-width\"> " | 113 "<html><head><meta name=\"viewport\" content=\"width=device-width\"> " |
107 + "<script>" | 114 + "<script>" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 | 228 |
222 /** | 229 /** |
223 * Verify New Tab Open and Close Event not from the context menu. | 230 * Verify New Tab Open and Close Event not from the context menu. |
224 * @throws InterruptedException | 231 * @throws InterruptedException |
225 * | 232 * |
226 * https://crbug.com/490473 | 233 * https://crbug.com/490473 |
227 * @LargeTest | 234 * @LargeTest |
228 * @Feature({"Android-TabSwitcher"}) | 235 * @Feature({"Android-TabSwitcher"}) |
229 * @Restriction(RESTRICTION_TYPE_PHONE) | 236 * @Restriction(RESTRICTION_TYPE_PHONE) |
230 */ | 237 */ |
231 @DisabledTest | 238 // @DisabledTest |
239 @LargeTest | |
232 public void testOpenAndCloseNewTabButton() throws InterruptedException { | 240 public void testOpenAndCloseNewTabButton() throws InterruptedException { |
233 mTestServer = EmbeddedTestServer.createAndStartFileServer( | 241 mTestServer = EmbeddedTestServer.createAndStartFileServer( |
234 getInstrumentation().getContext(), Environment.getExternalStorag eDirectory()); | 242 getInstrumentation().getContext(), Environment.getExternalStorag eDirectory()); |
235 startMainActivityWithURL(mTestServer.getURL(TEST_FILE_PATH)); | 243 startMainActivityWithURL(mTestServer.getURL(TEST_FILE_PATH)); |
236 getInstrumentation().runOnMainSync(new Runnable() { | 244 getInstrumentation().runOnMainSync(new Runnable() { |
237 @Override | 245 @Override |
238 public void run() { | 246 public void run() { |
239 String title = getActivity().getCurrentTabModel().getTabAt(0).ge tTitle(); | 247 String title = getActivity().getCurrentTabModel().getTabAt(0).ge tTitle(); |
240 assertEquals("Data file for TabsTest", title); | 248 assertEquals("Data file for TabsTest", title); |
241 } | 249 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 | 282 |
275 ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity()); | 283 ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity()); |
276 getInstrumentation().runOnMainSync(new Runnable() { | 284 getInstrumentation().runOnMainSync(new Runnable() { |
277 @Override | 285 @Override |
278 public void run() { | 286 public void run() { |
279 assertEquals(tabCount, getActivity().getCurrentTabModel().getCou nt()); | 287 assertEquals(tabCount, getActivity().getCurrentTabModel().getCou nt()); |
280 } | 288 } |
281 }); | 289 }); |
282 } | 290 } |
283 | 291 |
292 private void setInputMethodManagerWrapperForTest(final CallbackHelper callba ckHelper) { | |
293 ImeAdapter imeAdapter = | |
Changwan Ryu
2016/10/12 12:15:49
So the flakiness we talked about was caused becaus
Changwan Ryu
2016/10/12 12:19:45
How about listening to TabModelObserver#didSelectT
yabinh
2016/10/13 03:13:45
Actually we use "onViewDetachedFromWindow()" inste
| |
294 getActivity().getActivityTab().getContentViewCore().getImeAdapte rForTest(); | |
295 imeAdapter.setInputMethodManagerWrapperForTest( | |
296 new InputMethodManagerWrapper(getInstrumentation().getContext()) { | |
297 @Override | |
298 public void showSoftInput(View view, int flags, ResultReceiv er resultReceiver) { | |
299 super.showSoftInput(view, flags, resultReceiver); | |
300 mKeyboardShown = true; | |
301 callbackHelper.notifyCalled(); | |
302 } | |
303 | |
304 @Override | |
305 public boolean hideSoftInputFromWindow( | |
306 IBinder windowToken, int flags, ResultReceiver resul tReceiver) { | |
307 super.hideSoftInputFromWindow(windowToken, flags, result Receiver); | |
308 mKeyboardShown = false; | |
309 callbackHelper.notifyCalled(); | |
310 return true; | |
311 } | |
312 }); | |
313 } | |
314 /** | |
315 * Verify that opening a new tab, switching to an existing tab and closing c urrent tab hide | |
316 * keyboard. | |
317 */ | |
318 @LargeTest | |
319 public void testHideKeyboard() throws Exception { | |
320 mTestServer = EmbeddedTestServer.createAndStartFileServer( | |
321 getInstrumentation().getContext(), Environment.getExternalStorag eDirectory()); | |
322 | |
323 // Failed 100% at this step. It didn't happen before. Also, I tried | |
324 // testOpenAndCloseNewTabButton(), it's flaky at this step, but failure rate is not 100%. | |
325 startMainActivityWithURL(mTestServer.getURL(TEST_FILE_PATH)); | |
326 | |
327 final CallbackHelper callbackHelper = new CallbackHelper(); | |
328 int curCallCount = callbackHelper.getCallCount(); | |
329 setInputMethodManagerWrapperForTest(callbackHelper); | |
330 | |
331 DOMUtils.clickNode(this, getActivity().getActivityTab().getContentViewCo re(), "input_text"); | |
332 callbackHelper.waitForCallback(curCallCount, 1); | |
333 assertTrue(mKeyboardShown); | |
334 | |
335 // Opens a new tab. | |
336 curCallCount = callbackHelper.getCallCount(); | |
337 startMainActivityWithURL(mTestServer.getURL(TEST_FILE_PATH)); | |
338 callbackHelper.waitForCallback(curCallCount, 1); // Flaky at this step. | |
339 assertFalse(mKeyboardShown); | |
340 | |
341 // TODO: closes a tab, switches to an existing tab. | |
342 } | |
343 | |
284 /** | 344 /** |
285 * Verify that opening a new tab and navigating immediately sets a size on t he newly created | 345 * Verify that opening a new tab and navigating immediately sets a size on t he newly created |
286 * renderer. https://crbug.com/434477. | 346 * renderer. https://crbug.com/434477. |
287 * @throws InterruptedException | 347 * @throws InterruptedException |
288 * @throws TimeoutException | 348 * @throws TimeoutException |
289 */ | 349 */ |
290 @SmallTest | 350 @SmallTest |
291 @RetryOnFailure | 351 @RetryOnFailure |
292 public void testNewTabSetsContentViewSize() throws InterruptedException, Tim eoutException { | 352 public void testNewTabSetsContentViewSize() throws InterruptedException, Tim eoutException { |
293 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity()); | 353 ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity()); |
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1727 throws InterruptedException { | 1787 throws InterruptedException { |
1728 CriteriaHelper.pollInstrumentationThread( | 1788 CriteriaHelper.pollInstrumentationThread( |
1729 Criteria.equals(expected, new Callable<Boolean>() { | 1789 Criteria.equals(expected, new Callable<Boolean>() { |
1730 @Override | 1790 @Override |
1731 public Boolean call() { | 1791 public Boolean call() { |
1732 return fileToCheck.exists(); | 1792 return fileToCheck.exists(); |
1733 } | 1793 } |
1734 })); | 1794 })); |
1735 } | 1795 } |
1736 } | 1796 } |
OLD | NEW |