Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialogTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialogTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialogTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2e6034f5bb8e923696c0b8af1115d58c45bed9cb |
| --- /dev/null |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/locale/DefaultSearchEnginePromoDialogTest.java |
| @@ -0,0 +1,158 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.locale; |
| + |
| +import android.app.Activity; |
| +import android.app.Instrumentation; |
| +import android.app.Instrumentation.ActivityMonitor; |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.os.Bundle; |
| +import android.support.test.InstrumentationRegistry; |
| +import android.support.test.filters.LargeTest; |
| +import android.support.v4.app.ActivityOptionsCompat; |
| + |
| +import org.junit.Assert; |
| +import org.junit.Before; |
| +import org.junit.Test; |
| +import org.junit.runner.RunWith; |
| + |
| +import org.chromium.base.ActivityState; |
| +import org.chromium.base.ApplicationStatus; |
| +import org.chromium.base.ContextUtils; |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.library_loader.ProcessInitException; |
| +import org.chromium.base.test.util.CallbackHelper; |
| +import org.chromium.base.test.util.CommandLineFlags; |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.ChromeSwitches; |
| +import org.chromium.chrome.browser.ChromeTabbedActivity; |
| +import org.chromium.chrome.browser.init.ChromeBrowserInitializer; |
| +import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| +import org.chromium.chrome.browser.searchwidget.SearchActivity; |
| +import org.chromium.chrome.browser.util.IntentUtils; |
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| +import org.chromium.content.browser.test.util.Criteria; |
| +import org.chromium.content.browser.test.util.CriteriaHelper; |
| + |
| +import java.util.concurrent.Callable; |
| +import java.util.concurrent.ExecutionException; |
| + |
| +/** |
| + * 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.
|
| + */ |
| +@RunWith(ChromeJUnit4ClassRunner.class) |
| +@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) |
| +public class DefaultSearchEnginePromoDialogTest { |
| + @Before |
| + public void setUp() throws Exception { |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + try { |
| + ChromeBrowserInitializer.getInstance(InstrumentationRegistry.getTargetContext()) |
| + .handleSynchronousStartup(); |
| + } catch (ProcessInitException e) { |
| + Assert.fail("Failed to initialize Chrome process"); |
| + } |
| + } |
| + }); |
| + } |
| + |
| + @Test |
| + @LargeTest |
| + public void testOnlyOneLiveDialog() throws Exception { |
| + final CallbackHelper templateUrlServiceInit = new CallbackHelper(); |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + TemplateUrlService.getInstance().registerLoadListener( |
| + new TemplateUrlService.LoadListener() { |
| + @Override |
| + public void onTemplateUrlServiceLoaded() { |
| + TemplateUrlService.getInstance().unregisterLoadListener(this); |
| + templateUrlServiceInit.notifyCalled(); |
| + } |
| + }); |
| + } |
| + }); |
| + templateUrlServiceInit.waitForCallback(0); |
| + |
| + final SearchActivity searchActivity = startActivity(SearchActivity.class); |
| + final DefaultSearchEnginePromoDialog searchDialog = showDialog(searchActivity); |
| + Assert.assertEquals(searchDialog, DefaultSearchEnginePromoDialog.getCurrentDialog()); |
| + |
| + ChromeTabbedActivity tabbedActivity = startActivity(ChromeTabbedActivity.class); |
| + final DefaultSearchEnginePromoDialog tabbedDialog = showDialog(tabbedActivity); |
| + Assert.assertEquals(tabbedDialog, DefaultSearchEnginePromoDialog.getCurrentDialog()); |
| + |
| + CriteriaHelper.pollUiThread(Criteria.equals(false, new Callable<Boolean>() { |
| + @Override |
| + public Boolean call() throws Exception { |
| + return searchDialog.isShowing(); |
| + } |
| + })); |
| + |
| + CriteriaHelper.pollUiThread( |
| + Criteria.equals(ActivityState.DESTROYED, new Callable<Integer>() { |
| + @Override |
| + public Integer call() throws Exception { |
| + return ApplicationStatus.getStateForActivity(searchActivity); |
| + } |
| + })); |
| + |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + tabbedDialog.dismiss(); |
| + } |
| + }); |
| + CriteriaHelper.pollUiThread(new Criteria() { |
| + @Override |
| + public boolean isSatisfied() { |
| + return DefaultSearchEnginePromoDialog.getCurrentDialog() == null; |
| + } |
| + }); |
| + } |
| + |
| + private <T extends Activity> T startActivity(Class<T> clazz) throws Exception { |
|
gone
2017/06/09 17:26:56
We should probably just yank this function out and
|
| + final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); |
| + ActivityMonitor searchMonitor = new ActivityMonitor(clazz.getName(), null, false); |
| + instrumentation.addMonitor(searchMonitor); |
| + |
| + // Launch the SearchActivity. |
| + Context context = ContextUtils.getApplicationContext(); |
| + Intent searchIntent = new Intent(); |
| + searchIntent.setClass(context, clazz); |
| + searchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| + searchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); |
| + |
| + Bundle optionsBundle = |
| + ActivityOptionsCompat.makeCustomAnimation(context, R.anim.activity_open_enter, 0) |
| + .toBundle(); |
| + IntentUtils.safeStartActivity(context, searchIntent, optionsBundle); |
| + |
| + Activity activity = instrumentation.waitForMonitorWithTimeout( |
| + searchMonitor, CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL); |
| + Assert.assertNotNull("Activity didn't start", activity); |
| + Assert.assertTrue("Wrong activity started", clazz.isInstance(activity)); |
| + instrumentation.removeMonitor(searchMonitor); |
| + |
| + return clazz.cast(activity); |
| + } |
| + |
| + private DefaultSearchEnginePromoDialog showDialog(final Activity activity) |
| + throws ExecutionException { |
| + return ThreadUtils.runOnUiThreadBlocking(new Callable<DefaultSearchEnginePromoDialog>() { |
| + @Override |
| + public DefaultSearchEnginePromoDialog call() throws Exception { |
| + DefaultSearchEnginePromoDialog dialog = new DefaultSearchEnginePromoDialog( |
| + activity, LocaleManager.SEARCH_ENGINE_PROMO_SHOW_EXISTING, null); |
| + dialog.show(); |
| + return dialog; |
| + } |
| + }); |
| + } |
| +} |