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

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

Issue 2839943002: Revert of 🔍 Don't display the search engine until First Run completes (Closed)
Patch Set: 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;
32 import org.chromium.content.browser.test.util.CriteriaHelper; 31 import org.chromium.content.browser.test.util.CriteriaHelper;
33 32
34 import java.util.ArrayList; 33 import java.util.ArrayList;
35 import java.util.List; 34 import java.util.List;
36 35
37 /** 36 /**
38 * Tests for the SearchWidgetProvider. 37 * Tests for the SearchWidgetProvider.
39 */ 38 */
40 @CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE) 39 @CommandLineFlags.Add(ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE)
41 public class SearchWidgetProviderTest extends InstrumentationTestCase { 40 public class SearchWidgetProviderTest extends InstrumentationTestCase {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 private static final String TEXT_GENERIC = "Search"; 82 private static final String TEXT_GENERIC = "Search";
84 private static final String TEXT_SEARCH_ENGINE = "Stuff and Thangs"; 83 private static final String TEXT_SEARCH_ENGINE = "Stuff and Thangs";
85 private static final String TEXT_SEARCH_ENGINE_FULL = "Search with Stuff and Thangs"; 84 private static final String TEXT_SEARCH_ENGINE_FULL = "Search with Stuff and Thangs";
86 85
87 private TestContext mContext; 86 private TestContext mContext;
88 private TestDelegate mDelegate; 87 private TestDelegate mDelegate;
89 88
90 @Override 89 @Override
91 public void setUp() throws Exception { 90 public void setUp() throws Exception {
92 super.setUp(); 91 super.setUp();
93 ApplicationTestUtils.setUp(getInstrumentation().getTargetContext(), true );
94 SearchActivity.disableForTests(); 92 SearchActivity.disableForTests();
95 93
96 mContext = new TestContext(); 94 mContext = new TestContext();
97 mDelegate = new TestDelegate(mContext); 95 mDelegate = new TestDelegate(mContext);
98 SearchWidgetProvider.setDelegateForTest(mDelegate); 96 SearchWidgetProvider.setDelegateForTest(mDelegate);
99 } 97 }
100 98
101 @Override
102 public void tearDown() throws Exception {
103 ApplicationTestUtils.tearDown(getInstrumentation().getTargetContext());
104 super.tearDown();
105 }
106
107 @SmallTest 99 @SmallTest
108 public void testUpdateAll() { 100 public void testUpdateAll() {
109 SearchWidgetProvider.handleAction( 101 SearchWidgetProvider.handleAction(
110 new Intent(SearchWidgetProvider.ACTION_UPDATE_ALL_WIDGETS)); 102 new Intent(SearchWidgetProvider.ACTION_UPDATE_ALL_WIDGETS));
111 103
112 // Without any idea of what the default search engine is, widgets should default to saying 104 // Without any idea of what the default search engine is, widgets should default to saying
113 // just "Search". 105 // just "Search".
114 checkWidgetStates(TEXT_GENERIC, View.VISIBLE); 106 checkWidgetStates(TEXT_GENERIC, View.VISIBLE);
115 107
116 // The microphone icon should disappear if voice queries are unavailable . 108 // The microphone icon should disappear if voice queries are unavailable .
117 mDelegate.mViews.clear(); 109 mDelegate.mViews.clear();
118 SearchWidgetProvider.updateCachedVoiceSearchAvailability(false); 110 SearchWidgetProvider.updateCachedVoiceSearchAvailability(false);
119 checkWidgetStates(TEXT_GENERIC, View.GONE); 111 checkWidgetStates(TEXT_GENERIC, View.GONE);
120 112
121 // After recording that the default search engine is "X", it should say "Search with X". 113 // After recording that the default search engine is "X", it should say "Search with X".
122 mDelegate.mViews.clear(); 114 mDelegate.mViews.clear();
123 SearchWidgetProvider.updateCachedEngineName(TEXT_SEARCH_ENGINE); 115 SearchWidgetProvider.updateCachedEngineName(TEXT_SEARCH_ENGINE);
124 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.GONE); 116 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.GONE);
125 117
126 // The microphone icon should appear if voice queries are available. 118 // The microphone icon should appear if voice queries are available.
127 mDelegate.mViews.clear(); 119 mDelegate.mViews.clear();
128 SearchWidgetProvider.updateCachedVoiceSearchAvailability(true); 120 SearchWidgetProvider.updateCachedVoiceSearchAvailability(true);
129 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.VISIBLE); 121 checkWidgetStates(TEXT_SEARCH_ENGINE_FULL, View.VISIBLE);
130 } 122 }
131 123
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
162 private void checkWidgetStates(final String expectedString, final int expect edMicrophoneState) { 124 private void checkWidgetStates(final String expectedString, final int expect edMicrophoneState) {
163 // Confirm that all the widgets got updated. 125 // Confirm that all the widgets got updated.
164 Assert.assertEquals(TestDelegate.ALL_IDS.length, mDelegate.mViews.size() ); 126 Assert.assertEquals(TestDelegate.ALL_IDS.length, mDelegate.mViews.size() );
165 for (int i = 0; i < TestDelegate.ALL_IDS.length; i++) { 127 for (int i = 0; i < TestDelegate.ALL_IDS.length; i++) {
166 Assert.assertEquals(TestDelegate.ALL_IDS[i], mDelegate.mViews.get(i) .first.intValue()); 128 Assert.assertEquals(TestDelegate.ALL_IDS[i], mDelegate.mViews.get(i) .first.intValue());
167 } 129 }
168 130
169 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 131 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
170 @Override 132 @Override
171 public void run() { 133 public void run() {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 boolean exceptionWasThrown = false; 236 boolean exceptionWasThrown = false;
275 try { 237 try {
276 SearchWidgetProvider.run(crashingRunnable); 238 SearchWidgetProvider.run(crashingRunnable);
277 } catch (Exception e) { 239 } catch (Exception e) {
278 exceptionWasThrown = true; 240 exceptionWasThrown = true;
279 } 241 }
280 Assert.assertEquals(3, SearchWidgetProvider.getNumConsecutiveCrashes(pre fs)); 242 Assert.assertEquals(3, SearchWidgetProvider.getNumConsecutiveCrashes(pre fs));
281 Assert.assertTrue(exceptionWasThrown); 243 Assert.assertTrue(exceptionWasThrown);
282 } 244 }
283 } 245 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698