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.locale; |
| 6 |
| 7 import android.app.Activity; |
| 8 import android.support.test.InstrumentationRegistry; |
| 9 import android.support.test.filters.LargeTest; |
| 10 |
| 11 import org.junit.Assert; |
| 12 import org.junit.Before; |
| 13 import org.junit.Test; |
| 14 import org.junit.runner.RunWith; |
| 15 |
| 16 import org.chromium.base.ThreadUtils; |
| 17 import org.chromium.base.library_loader.ProcessInitException; |
| 18 import org.chromium.base.test.util.CallbackHelper; |
| 19 import org.chromium.base.test.util.CommandLineFlags; |
| 20 import org.chromium.chrome.browser.ChromeSwitches; |
| 21 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 22 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| 23 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| 24 import org.chromium.chrome.browser.searchwidget.SearchActivity; |
| 25 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 26 import org.chromium.chrome.test.util.ActivityUtils; |
| 27 import org.chromium.content.browser.test.util.Criteria; |
| 28 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 29 |
| 30 import java.util.concurrent.Callable; |
| 31 import java.util.concurrent.ExecutionException; |
| 32 |
| 33 /** |
| 34 * Integration tests for the {@link DefaultSearchEnginePromoDialog}. |
| 35 */ |
| 36 @RunWith(ChromeJUnit4ClassRunner.class) |
| 37 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) |
| 38 public class DefaultSearchEnginePromoDialogTest { |
| 39 @Before |
| 40 public void setUp() throws Exception { |
| 41 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 42 @Override |
| 43 public void run() { |
| 44 try { |
| 45 ChromeBrowserInitializer.getInstance(InstrumentationRegistry
.getTargetContext()) |
| 46 .handleSynchronousStartup(); |
| 47 } catch (ProcessInitException e) { |
| 48 Assert.fail("Failed to initialize Chrome process"); |
| 49 } |
| 50 } |
| 51 }); |
| 52 } |
| 53 |
| 54 @Test |
| 55 @LargeTest |
| 56 public void testOnlyOneLiveDialog() throws Exception { |
| 57 final CallbackHelper templateUrlServiceInit = new CallbackHelper(); |
| 58 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 59 @Override |
| 60 public void run() { |
| 61 TemplateUrlService.getInstance().registerLoadListener( |
| 62 new TemplateUrlService.LoadListener() { |
| 63 @Override |
| 64 public void onTemplateUrlServiceLoaded() { |
| 65 TemplateUrlService.getInstance().unregisterLoadL
istener(this); |
| 66 templateUrlServiceInit.notifyCalled(); |
| 67 } |
| 68 }); |
| 69 } |
| 70 }); |
| 71 templateUrlServiceInit.waitForCallback(0); |
| 72 |
| 73 final SearchActivity searchActivity = ActivityUtils.waitForActivity( |
| 74 InstrumentationRegistry.getInstrumentation(), SearchActivity.cla
ss); |
| 75 final DefaultSearchEnginePromoDialog searchDialog = showDialog(searchAct
ivity); |
| 76 Assert.assertEquals(searchDialog, DefaultSearchEnginePromoDialog.getCurr
entDialog()); |
| 77 |
| 78 ChromeTabbedActivity tabbedActivity = ActivityUtils.waitForActivity( |
| 79 InstrumentationRegistry.getInstrumentation(), ChromeTabbedActivi
ty.class); |
| 80 final DefaultSearchEnginePromoDialog tabbedDialog = showDialog(tabbedAct
ivity); |
| 81 Assert.assertEquals(tabbedDialog, DefaultSearchEnginePromoDialog.getCurr
entDialog()); |
| 82 |
| 83 CriteriaHelper.pollUiThread(Criteria.equals(false, new Callable<Boolean>
() { |
| 84 @Override |
| 85 public Boolean call() throws Exception { |
| 86 return searchDialog.isShowing(); |
| 87 } |
| 88 })); |
| 89 |
| 90 CriteriaHelper.pollUiThread(Criteria.equals(true, new Callable<Boolean>(
) { |
| 91 @Override |
| 92 public Boolean call() throws Exception { |
| 93 return searchActivity.isFinishing(); |
| 94 } |
| 95 })); |
| 96 |
| 97 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 98 @Override |
| 99 public void run() { |
| 100 tabbedDialog.dismiss(); |
| 101 } |
| 102 }); |
| 103 CriteriaHelper.pollUiThread(new Criteria() { |
| 104 @Override |
| 105 public boolean isSatisfied() { |
| 106 return DefaultSearchEnginePromoDialog.getCurrentDialog() == null
; |
| 107 } |
| 108 }); |
| 109 } |
| 110 |
| 111 private DefaultSearchEnginePromoDialog showDialog(final Activity activity) |
| 112 throws ExecutionException { |
| 113 return ThreadUtils.runOnUiThreadBlocking(new Callable<DefaultSearchEngin
ePromoDialog>() { |
| 114 @Override |
| 115 public DefaultSearchEnginePromoDialog call() throws Exception { |
| 116 DefaultSearchEnginePromoDialog dialog = new DefaultSearchEngineP
romoDialog( |
| 117 activity, LocaleManager.SEARCH_ENGINE_PROMO_SHOW_EXISTIN
G, null); |
| 118 dialog.show(); |
| 119 return dialog; |
| 120 } |
| 121 }); |
| 122 } |
| 123 } |
OLD | NEW |