Commit 3f7cf703 authored by Theresa's avatar Theresa Committed by Commit Bot

Add NewTabPageTest#testSimplifiedNtp_DefaultSearchEngineChange

Add an instrumentation test that checks for element visibility when the
default search engine is toggled.

BUG=841928

Change-Id: I878a4b486b988310899fcc3f88a751e90a97ee3e
Reviewed-on: https://chromium-review.googlesource.com/1091188Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: Theresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565458}
parent 1c30abaa
......@@ -1910,6 +1910,7 @@ chrome_test_java_sources = [
"javatests/src/org/chromium/chrome/browser/SubresourceFilterTest.java",
"javatests/src/org/chromium/chrome/browser/MockSafeBrowsingApiHandler.java",
"javatests/src/org/chromium/chrome/browser/search_engines/TemplateUrlServiceTest.java",
"javatests/src/org/chromium/chrome/browser/search_engines/TemplateUrlServiceTestUtils.java",
"javatests/src/org/chromium/chrome/browser/searchwidget/SearchActivityTest.java",
"javatests/src/org/chromium/chrome/browser/searchwidget/SearchWidgetProviderTest.java",
"javatests/src/org/chromium/chrome/browser/services/GoogleServicesManagerIntegrationTest.java",
......
......@@ -56,6 +56,7 @@ import org.chromium.chrome.browser.omnibox.LocationBarLayout;
import org.chromium.chrome.browser.omnibox.UrlBar;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceTestUtils;
import org.chromium.chrome.browser.suggestions.SiteSuggestion;
import org.chromium.chrome.browser.suggestions.TileSectionType;
import org.chromium.chrome.browser.suggestions.TileSource;
......@@ -264,6 +265,26 @@ public class NewTabPageTest {
Assert.assertEquals(1, activityMonitor.getHits());
}
@Test
@MediumTest
@Feature({"NewTabPage"})
@EnableFeatures({ChromeFeatureList.SIMPLIFIED_NTP})
@Restriction(UiRestriction.RESTRICTION_TYPE_PHONE)
public void testSimplifiedNtp_DefaultSearchEngineChange() throws Exception {
View logo = mNtp.getView().findViewById(R.id.search_provider_logo);
View shortcuts = mNtp.getView().findViewById(R.id.shortcuts);
Assert.assertEquals(View.VISIBLE, logo.getVisibility());
Assert.assertEquals(View.VISIBLE, shortcuts.getVisibility());
TemplateUrlServiceTestUtils.setSearchEngine("bing.com");
Assert.assertEquals(View.GONE, logo.getVisibility());
Assert.assertEquals(View.VISIBLE, shortcuts.getVisibility());
TemplateUrlServiceTestUtils.setSearchEngine("google.com");
Assert.assertEquals(View.VISIBLE, logo.getVisibility());
Assert.assertEquals(View.VISIBLE, shortcuts.getVisibility());
}
@Test
@MediumTest
@Feature({"NewTabPage"})
......
......@@ -15,7 +15,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.Restriction;
......@@ -23,7 +22,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.search_engines.TemplateUrlService;
import org.chromium.chrome.browser.search_engines.TemplateUrlServiceTestUtils;
import org.chromium.chrome.browser.toolbar.ToolbarModel;
import org.chromium.chrome.browser.widget.TintedImageButton;
import org.chromium.chrome.test.ChromeActivityTestRule;
......@@ -130,24 +129,6 @@ public class LocationBarLayoutTest {
}
}
// Partially lifted from TemplateUrlServiceTest.
private void setSearchEngine(String keyword)
throws ExecutionException, InterruptedException, TimeoutException {
CallbackHelper callback = new CallbackHelper();
Callable<Void> setSearchEngineCallable = new Callable<Void>() {
@Override
public Void call() {
TemplateUrlService.getInstance().runWhenLoaded(() -> {
TemplateUrlService.getInstance().setSearchEngine(keyword);
callback.notifyCalled();
});
return null;
}
};
ThreadUtils.runOnUiThreadBlocking(setSearchEngineCallable);
callback.waitForCallback("Failed to set search engine", 0);
}
private UrlBar getUrlBar() {
return (UrlBar) mActivityTestRule.getActivity().findViewById(R.id.url_bar);
}
......@@ -257,7 +238,7 @@ public class LocationBarLayoutTest {
final UrlBar urlBar = getUrlBar();
final LocationBarLayout locationBar = getLocationBar();
setSearchEngine("bing.com");
TemplateUrlServiceTestUtils.setSearchEngine("bing.com");
mTestToolbarModel.setCurrentUrl(BING_SRP_URL);
mTestToolbarModel.setSecurityLevel(ConnectionSecurityLevel.SECURE);
setUrlToPageUrl(locationBar);
......@@ -274,7 +255,7 @@ public class LocationBarLayoutTest {
final UrlBar urlBar = getUrlBar();
final LocationBarLayout locationBar = getLocationBar();
setSearchEngine("bing.com");
TemplateUrlServiceTestUtils.setSearchEngine("bing.com");
mTestToolbarModel.setCurrentUrl(GOOGLE_SRP_URL);
mTestToolbarModel.setSecurityLevel(ConnectionSecurityLevel.SECURE);
setUrlToPageUrl(locationBar);
......
// Copyright 2018 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.search_engines;
import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
/** Utility methods for tests that need to interact with the {@link TemplateUrlService}. */
public class TemplateUrlServiceTestUtils {
/**
* Set the search engine.
* @param keyword The keyword of the selected search engine, e.g. "google.com".
*/
public static void setSearchEngine(String keyword)
throws ExecutionException, InterruptedException, TimeoutException {
CallbackHelper callback = new CallbackHelper();
Callable<Void> setSearchEngineCallable = new Callable<Void>() {
@Override
public Void call() {
TemplateUrlService.getInstance().runWhenLoaded(() -> {
TemplateUrlService.getInstance().setSearchEngine(keyword);
callback.notifyCalled();
});
return null;
}
};
ThreadUtils.runOnUiThreadBlocking(setSearchEngineCallable);
callback.waitForCallback("Failed to set search engine", 0);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment