Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/searchwidget/SearchWidgetProviderTest.java

Issue 2834253002: 🔍 Don't display the search engine until First Run completes (Closed)
Patch Set: Cmments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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.searchwidget; 5 package org.chromium.chrome.browser.searchwidget;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.Instrumentation; 8 import android.app.Instrumentation;
9 import android.app.Instrumentation.ActivityMonitor; 9 import android.app.Instrumentation.ActivityMonitor;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 10 matching lines...) Expand all
21 import org.junit.Assert; 21 import org.junit.Assert;
22 22
23 import org.chromium.base.ThreadUtils; 23 import org.chromium.base.ThreadUtils;
24 import org.chromium.base.test.util.AdvancedMockContext; 24 import org.chromium.base.test.util.AdvancedMockContext;
25 import org.chromium.base.test.util.CommandLineFlags; 25 import org.chromium.base.test.util.CommandLineFlags;
26 import org.chromium.base.test.util.InMemorySharedPreferences; 26 import org.chromium.base.test.util.InMemorySharedPreferences;
27 import org.chromium.chrome.R; 27 import org.chromium.chrome.R;
28 import org.chromium.chrome.browser.ChromeSwitches; 28 import org.chromium.chrome.browser.ChromeSwitches;
29 import org.chromium.chrome.browser.firstrun.FirstRunActivity; 29 import org.chromium.chrome.browser.firstrun.FirstRunActivity;
30 import org.chromium.chrome.browser.util.IntentUtils; 30 import org.chromium.chrome.browser.util.IntentUtils;
31 import org.chromium.chrome.test.util.ApplicationTestUtils;
31 import org.chromium.content.browser.test.util.CriteriaHelper; 32 import org.chromium.content.browser.test.util.CriteriaHelper;
32 33
33 import java.util.ArrayList; 34 import java.util.ArrayList;
34 import java.util.List; 35 import java.util.List;
35 36
36 /** 37 /**
37 * Tests for the SearchWidgetProvider. 38 * Tests for the SearchWidgetProvider.
38 */ 39 */
39 @CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) 40 @CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
40 public class SearchWidgetProviderTest extends InstrumentationTestCase { 41 public class SearchWidgetProviderTest extends InstrumentationTestCase {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 private static final String TEXT_GENERIC = "Search"; 83 private static final String TEXT_GENERIC = "Search";
83 private static final String TEXT_SEARCH_ENGINE = "Stuff and Thangs"; 84 private static final String TEXT_SEARCH_ENGINE = "Stuff and Thangs";
84 private static final String TEXT_SEARCH_ENGINE_FULL = "Search with Stuff and Thangs"; 85 private static final String TEXT_SEARCH_ENGINE_FULL = "Search with Stuff and Thangs";
85 86
86 private TestContext mContext; 87 private TestContext mContext;
87 private TestDelegate mDelegate; 88 private TestDelegate mDelegate;
88 89
89 @Override 90 @Override
90 public void setUp() throws Exception { 91 public void setUp() throws Exception {
91 super.setUp(); 92 super.setUp();
93 ApplicationTestUtils.setUp(getInstrumentation().getTargetContext(), true );
92 SearchActivity.disableForTests(); 94 SearchActivity.disableForTests();
93 95
94 mContext = new TestContext(); 96 mContext = new TestContext();
95 mDelegate = new TestDelegate(mContext); 97 mDelegate = new TestDelegate(mContext);
96 SearchWidgetProvider.setDelegateForTest(mDelegate); 98 SearchWidgetProvider.setDelegateForTest(mDelegate);
97 } 99 }
98 100
101 @Override
102 public void tearDown() throws Exception {
103 ApplicationTestUtils.tearDown(getInstrumentation().getTargetContext());
104 super.tearDown();
105 }
106
99 @SmallTest 107 @SmallTest
100 public void testUpdateAll() { 108 public void testUpdateAll() {
101 SearchWidgetProvider.handleAction( 109 SearchWidgetProvider.handleAction(
102 new Intent(SearchWidgetProvider.ACTION_UPDATE_ALL_WIDGETS)); 110 new Intent(SearchWidgetProvider.ACTION_UPDATE_ALL_WIDGETS));
103 111
104 // Without any idea of what the default search engine is, widgets should default to saying 112 // Without any idea of what the default search engine is, widgets should default to saying
105 // just "Search". 113 // just "Search".
106 checkWidgetStates(TEXT_GENERIC, View.VISIBLE); 114 checkWidgetStates(TEXT_GENERIC, View.VISIBLE);
107 115
108 // The microphone icon should disappear if voice queries are unavailable . 116 // The microphone icon should disappear if voice queries are unavailable .
109 mDelegate.mViews.clear(); 117 mDelegate.mViews.clear();
110 SearchWidgetProvider.updateCachedVoiceSearchAvailability(false); 118 SearchWidgetProvider.updateCachedVoiceSearchAvailability(false);
111 checkWidgetStates(TEXT_GENERIC, View.GONE); 119 checkWidgetStates(TEXT_GENERIC, View.GONE);
112 120
113 // After recording that the default search engine is "X", it should say "Search with X". 121 // After recording that the default search engine is "X", it should say "Search with X".
114 mDelegate.mViews.clear(); 122 mDelegate.mViews.clear();
115 SearchWidgetProvider.updateCachedEngineName(TEXT_SEARCH_ENGINE); 123 SearchWidgetProvider.updateCachedEngineName(TEXT_SEARCH_ENGINE);
116 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.GONE); 124 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.GONE);
117 125
118 // The microphone icon should appear if voice queries are available. 126 // The microphone icon should appear if voice queries are available.
119 mDelegate.mViews.clear(); 127 mDelegate.mViews.clear();
120 SearchWidgetProvider.updateCachedVoiceSearchAvailability(true); 128 SearchWidgetProvider.updateCachedVoiceSearchAvailability(true);
121 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.VISIBLE); 129 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.VISIBLE);
122 } 130 }
123 131
132 @SmallTest
133 @CommandLineFlags.Remove(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
134 public void testUpdateCachedEngineNameBeforeFirstRun() {
135 assertFalse(SearchWidgetProvider.shouldShowFullString());
136 SearchWidgetProvider.handleAction(
137 new Intent(SearchWidgetProvider.ACTION_UPDATE_ALL_WIDGETS));
138
139 // Without any idea of what the default search engine is, widgets should default to saying
140 // just "Search".
141 checkWidgetStates(TEXT_GENERIC, View.VISIBLE);
142
143 // Until First Run is complete, no search engine branding should be disp layed. Widgets are
144 // already displaying the generic string, and should continue doing so, so they don't get
145 // updated.
146 mDelegate.mViews.clear();
147 SearchWidgetProvider.updateCachedEngineName(TEXT_SEARCH_ENGINE);
148 assertEquals(0, mDelegate.mViews.size());
149
150 // Manually set the preference, then update the cached engine name again . The
151 // SearchWidgetProvider should now believe that its widgets are displayi ng branding when it
152 // isn't allowed to, then update them.
153 mDelegate.mViews.clear();
154 mDelegate.getSharedPreferences()
155 .edit()
156 .putString(SearchWidgetProvider.PREF_SEARCH_ENGINE_SHORTNAME, TE XT_SEARCH_ENGINE)
157 .apply();
158 SearchWidgetProvider.updateCachedEngineName(TEXT_SEARCH_ENGINE);
159 checkWidgetStates(TEXT_GENERIC, View.VISIBLE);
160 }
161
124 private void checkWidgetStates(final String expectedString, final int expect edMicrophoneState) { 162 private void checkWidgetStates(final String expectedString, final int expect edMicrophoneState) {
125 // Confirm that all the widgets got updated. 163 // Confirm that all the widgets got updated.
126 Assert.assertEquals(TestDelegate.ALL_IDS.length, mDelegate.mViews.size() ); 164 Assert.assertEquals(TestDelegate.ALL_IDS.length, mDelegate.mViews.size() );
127 for (int i = 0; i < TestDelegate.ALL_IDS.length; i++) { 165 for (int i = 0; i < TestDelegate.ALL_IDS.length; i++) {
128 Assert.assertEquals(TestDelegate.ALL_IDS[i], mDelegate.mViews.get(i) .first.intValue()); 166 Assert.assertEquals(TestDelegate.ALL_IDS[i], mDelegate.mViews.get(i) .first.intValue());
129 } 167 }
130 168
131 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 169 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
132 @Override 170 @Override
133 public void run() { 171 public void run() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 boolean exceptionWasThrown = false; 274 boolean exceptionWasThrown = false;
237 try { 275 try {
238 SearchWidgetProvider.run(crashingRunnable); 276 SearchWidgetProvider.run(crashingRunnable);
239 } catch (Exception e) { 277 } catch (Exception e) {
240 exceptionWasThrown = true; 278 exceptionWasThrown = true;
241 } 279 }
242 Assert.assertEquals(3, SearchWidgetProvider.getNumConsecutiveCrashes(pre fs)); 280 Assert.assertEquals(3, SearchWidgetProvider.getNumConsecutiveCrashes(pre fs));
243 Assert.assertTrue(exceptionWasThrown); 281 Assert.assertTrue(exceptionWasThrown);
244 } 282 }
245 } 283 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698