Chromium Code Reviews| 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.app.Instrumentation; | |
| 9 import android.app.Instrumentation.ActivityMonitor; | |
| 10 import android.content.Context; | |
| 11 import android.content.Intent; | |
| 12 import android.os.Bundle; | |
| 13 import android.support.test.InstrumentationRegistry; | |
| 14 import android.support.test.filters.LargeTest; | |
| 15 import android.support.v4.app.ActivityOptionsCompat; | |
| 16 | |
| 17 import org.junit.Assert; | |
| 18 import org.junit.Before; | |
| 19 import org.junit.Test; | |
| 20 import org.junit.runner.RunWith; | |
| 21 | |
| 22 import org.chromium.base.ActivityState; | |
| 23 import org.chromium.base.ApplicationStatus; | |
| 24 import org.chromium.base.ContextUtils; | |
| 25 import org.chromium.base.ThreadUtils; | |
| 26 import org.chromium.base.library_loader.ProcessInitException; | |
| 27 import org.chromium.base.test.util.CallbackHelper; | |
| 28 import org.chromium.base.test.util.CommandLineFlags; | |
| 29 import org.chromium.chrome.R; | |
| 30 import org.chromium.chrome.browser.ChromeSwitches; | |
| 31 import org.chromium.chrome.browser.ChromeTabbedActivity; | |
| 32 import org.chromium.chrome.browser.init.ChromeBrowserInitializer; | |
| 33 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | |
| 34 import org.chromium.chrome.browser.searchwidget.SearchActivity; | |
| 35 import org.chromium.chrome.browser.util.IntentUtils; | |
| 36 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | |
| 37 import org.chromium.content.browser.test.util.Criteria; | |
| 38 import org.chromium.content.browser.test.util.CriteriaHelper; | |
| 39 | |
| 40 import java.util.concurrent.Callable; | |
| 41 import java.util.concurrent.ExecutionException; | |
| 42 | |
| 43 /** | |
| 44 * Integration tests for the default search engine promo dialog. | |
|
gone
2017/06/09 17:26:56
{@link DefaultSearchEnginePromoDialog}
Ted C
2017/06/09 21:31:52
Done.
| |
| 45 */ | |
| 46 @RunWith(ChromeJUnit4ClassRunner.class) | |
| 47 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) | |
| 48 public class DefaultSearchEnginePromoDialogTest { | |
| 49 @Before | |
| 50 public void setUp() throws Exception { | |
| 51 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 52 @Override | |
| 53 public void run() { | |
| 54 try { | |
| 55 ChromeBrowserInitializer.getInstance(InstrumentationRegistry .getTargetContext()) | |
| 56 .handleSynchronousStartup(); | |
| 57 } catch (ProcessInitException e) { | |
| 58 Assert.fail("Failed to initialize Chrome process"); | |
| 59 } | |
| 60 } | |
| 61 }); | |
| 62 } | |
| 63 | |
| 64 @Test | |
| 65 @LargeTest | |
| 66 public void testOnlyOneLiveDialog() throws Exception { | |
| 67 final CallbackHelper templateUrlServiceInit = new CallbackHelper(); | |
| 68 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 69 @Override | |
| 70 public void run() { | |
| 71 TemplateUrlService.getInstance().registerLoadListener( | |
| 72 new TemplateUrlService.LoadListener() { | |
| 73 @Override | |
| 74 public void onTemplateUrlServiceLoaded() { | |
| 75 TemplateUrlService.getInstance().unregisterLoadL istener(this); | |
| 76 templateUrlServiceInit.notifyCalled(); | |
| 77 } | |
| 78 }); | |
| 79 } | |
| 80 }); | |
| 81 templateUrlServiceInit.waitForCallback(0); | |
| 82 | |
| 83 final SearchActivity searchActivity = startActivity(SearchActivity.class ); | |
| 84 final DefaultSearchEnginePromoDialog searchDialog = showDialog(searchAct ivity); | |
| 85 Assert.assertEquals(searchDialog, DefaultSearchEnginePromoDialog.getCurr entDialog()); | |
| 86 | |
| 87 ChromeTabbedActivity tabbedActivity = startActivity(ChromeTabbedActivity .class); | |
| 88 final DefaultSearchEnginePromoDialog tabbedDialog = showDialog(tabbedAct ivity); | |
| 89 Assert.assertEquals(tabbedDialog, DefaultSearchEnginePromoDialog.getCurr entDialog()); | |
| 90 | |
| 91 CriteriaHelper.pollUiThread(Criteria.equals(false, new Callable<Boolean> () { | |
| 92 @Override | |
| 93 public Boolean call() throws Exception { | |
| 94 return searchDialog.isShowing(); | |
| 95 } | |
| 96 })); | |
| 97 | |
| 98 CriteriaHelper.pollUiThread( | |
| 99 Criteria.equals(ActivityState.DESTROYED, new Callable<Integer>() { | |
| 100 @Override | |
| 101 public Integer call() throws Exception { | |
| 102 return ApplicationStatus.getStateForActivity(searchActiv ity); | |
| 103 } | |
| 104 })); | |
| 105 | |
| 106 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
| 107 @Override | |
| 108 public void run() { | |
| 109 tabbedDialog.dismiss(); | |
| 110 } | |
| 111 }); | |
| 112 CriteriaHelper.pollUiThread(new Criteria() { | |
| 113 @Override | |
| 114 public boolean isSatisfied() { | |
| 115 return DefaultSearchEnginePromoDialog.getCurrentDialog() == null ; | |
| 116 } | |
| 117 }); | |
| 118 } | |
| 119 | |
| 120 private <T extends Activity> T startActivity(Class<T> clazz) throws Exceptio n { | |
|
gone
2017/06/09 17:26:56
We should probably just yank this function out and
| |
| 121 final Instrumentation instrumentation = InstrumentationRegistry.getInstr umentation(); | |
| 122 ActivityMonitor searchMonitor = new ActivityMonitor(clazz.getName(), nul l, false); | |
| 123 instrumentation.addMonitor(searchMonitor); | |
| 124 | |
| 125 // Launch the SearchActivity. | |
| 126 Context context = ContextUtils.getApplicationContext(); | |
| 127 Intent searchIntent = new Intent(); | |
| 128 searchIntent.setClass(context, clazz); | |
| 129 searchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 130 searchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); | |
| 131 | |
| 132 Bundle optionsBundle = | |
| 133 ActivityOptionsCompat.makeCustomAnimation(context, R.anim.activi ty_open_enter, 0) | |
| 134 .toBundle(); | |
| 135 IntentUtils.safeStartActivity(context, searchIntent, optionsBundle); | |
| 136 | |
| 137 Activity activity = instrumentation.waitForMonitorWithTimeout( | |
| 138 searchMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); | |
| 139 Assert.assertNotNull("Activity didn't start", activity); | |
| 140 Assert.assertTrue("Wrong activity started", clazz.isInstance(activity)); | |
| 141 instrumentation.removeMonitor(searchMonitor); | |
| 142 | |
| 143 return clazz.cast(activity); | |
| 144 } | |
| 145 | |
| 146 private DefaultSearchEnginePromoDialog showDialog(final Activity activity) | |
| 147 throws ExecutionException { | |
| 148 return ThreadUtils.runOnUiThreadBlocking(new Callable<DefaultSearchEngin ePromoDialog>() { | |
| 149 @Override | |
| 150 public DefaultSearchEnginePromoDialog call() throws Exception { | |
| 151 DefaultSearchEnginePromoDialog dialog = new DefaultSearchEngineP romoDialog( | |
| 152 activity, LocaleManager.SEARCH_ENGINE_PROMO_SHOW_EXISTIN G, null); | |
| 153 dialog.show(); | |
| 154 return dialog; | |
| 155 } | |
| 156 }); | |
| 157 } | |
| 158 } | |
| OLD | NEW |