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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/preferences/PreferencesTest.java

Issue 2367373003: [Android] Allow setting recently visited search engines as default search engine (Closed)
Patch Set: remove unnecessary changes. Created 4 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.preferences; 5 package org.chromium.chrome.browser.preferences;
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.content.Context; 9 import android.content.Context;
10 import android.content.Intent; 10 import android.content.Intent;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 /** 76 /**
77 * Change search engine and make sure it works correctly. 77 * Change search engine and make sure it works correctly.
78 */ 78 */
79 @SmallTest 79 @SmallTest
80 @Feature({"Preferences"}) 80 @Feature({"Preferences"})
81 @DisableIf.Build(hardware_is = "sprout", message = "crashes on android-one: crbug.com/540720") 81 @DisableIf.Build(hardware_is = "sprout", message = "crashes on android-one: crbug.com/540720")
82 @RetryOnFailure 82 @RetryOnFailure
83 public void testSearchEnginePreference() throws Exception { 83 public void testSearchEnginePreference() throws Exception {
84 ensureTemplateUrlServiceLoaded(); 84 ensureTemplateUrlServiceLoaded();
85 85
86 final Preferences prefActivity =
87 startPreferences(getInstrumentation(), SearchEnginePreference.cl ass.getName());
88
86 // Set the second search engine as the default using TemplateUrlService. 89 // Set the second search engine as the default using TemplateUrlService.
87 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 90 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
88 @Override 91 @Override
89 public void run() { 92 public void run() {
90 TemplateUrlService.getInstance().setSearchEngine(1); 93 SearchEnginePreference pref =
94 (SearchEnginePreference) prefActivity.getFragmentForTest ();
95 pref.setValueForTesting("1");
91 } 96 }
92 }); 97 });
93 98
94 final Preferences prefActivity =
95 startPreferences(getInstrumentation(), SearchEnginePreference.cl ass.getName());
96 99
97 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 100 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
98 @Override 101 @Override
99 public void run() { 102 public void run() {
100 // Ensure that the second search engine in the list is selected. 103 // Ensure that the second search engine in the list is selected.
101 SearchEnginePreference pref = 104 SearchEnginePreference pref =
102 (SearchEnginePreference) prefActivity.getFragmentForTest (); 105 (SearchEnginePreference) prefActivity.getFragmentForTest ();
103 assertNotNull(pref); 106 assertNotNull(pref);
104 assertEquals("1", pref.getValueForTesting()); 107 assertEquals("1", pref.getValueForTesting());
105 108
106 // Simulate selecting the third search engine, ensure that Templ ateUrlService is 109 // Simulate selecting the third search engine, ensure that Templ ateUrlService is
107 // updated, but location permission not granted for the new engi ne. 110 // updated, but location permission not granted for the new engi ne.
108 pref.setValueForTesting("2"); 111 String keyword2 = pref.setValueForTesting("2");
109 TemplateUrlService templateUrlService = TemplateUrlService.getIn stance(); 112 TemplateUrlService templateUrlService = TemplateUrlService.getIn stance();
110 assertEquals(2, templateUrlService.getDefaultSearchEngineIndex() ); 113 assertEquals(keyword2,
111 assertEquals(ContentSetting.ASK, locationPermissionForSearchEngi ne(2)); 114 templateUrlService.getDefaultSearchEngineTemplateUrl().g etKeyword());
115 assertEquals(ContentSetting.ASK, locationPermissionForSearchEngi ne(keyword2));
112 116
113 // Simulate selecting the fourth search engine and but set a blo cked permission 117 // Simulate selecting the fourth search engine and but set a blo cked permission
114 // first and ensure that location permission is NOT granted. 118 // first and ensure that location permission is NOT granted.
115 String url = templateUrlService.getSearchEngineUrlFromTemplateUr l(3); 119 String keyword3 = pref.getKeywordFromIndexTesting(3);
120 String url = templateUrlService.getSearchEngineUrlFromTemplateUr l(keyword3);
116 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( 121 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(
117 url, url, ContentSetting.BLOCK.toInt(), false); 122 url, url, ContentSetting.BLOCK.toInt(), false);
118 pref.setValueForTesting("3"); 123 keyword3 = pref.setValueForTesting("3");
119 assertEquals(3, TemplateUrlService.getInstance().getDefaultSearc hEngineIndex()); 124 assertEquals(keyword3, TemplateUrlService.getInstance()
120 assertEquals(ContentSetting.BLOCK, locationPermissionForSearchEn gine(3)); 125 .getDefaultSearchEngineTemplateUr l()
121 assertEquals(ContentSetting.ASK, locationPermissionForSearchEngi ne(2)); 126 .getKeyword());
127 assertEquals(ContentSetting.BLOCK, locationPermissionForSearchEn gine(keyword3));
128 assertEquals(ContentSetting.ASK, locationPermissionForSearchEngi ne(keyword2));
122 129
123 // Make sure a pre-existing ALLOW value does not get deleted whe n switching away 130 // Make sure a pre-existing ALLOW value does not get deleted whe n switching away
124 // from a search engine. 131 // from a search engine.
125 url = templateUrlService.getSearchEngineUrlFromTemplateUrl(4); 132 String keyword4 = pref.getKeywordFromIndexTesting(4);
133 url = templateUrlService.getSearchEngineUrlFromTemplateUrl(keywo rd4);
126 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( 134 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(
127 url, url, ContentSetting.ALLOW.toInt(), false); 135 url, url, ContentSetting.ALLOW.toInt(), false);
128 pref.setValueForTesting("4"); 136 keyword4 = pref.setValueForTesting("4");
129 assertEquals(4, TemplateUrlService.getInstance().getDefaultSearc hEngineIndex()); 137 assertEquals(keyword4, TemplateUrlService.getInstance()
130 assertEquals(ContentSetting.ALLOW, locationPermissionForSearchEn gine(4)); 138 .getDefaultSearchEngineTemplateUr l()
131 pref.setValueForTesting("3"); 139 .getKeyword());
132 assertEquals(ContentSetting.ALLOW, locationPermissionForSearchEn gine(4)); 140 assertEquals(ContentSetting.ALLOW, locationPermissionForSearchEn gine(keyword4));
141 keyword3 = pref.setValueForTesting("3");
142 assertEquals(ContentSetting.ALLOW, locationPermissionForSearchEn gine(keyword3));
133 } 143 }
134 }); 144 });
135 } 145 }
136 146
137 /** 147 /**
138 * Make sure that when a user switches to a search engine that uses HTTP, th e location 148 * Make sure that when a user switches to a search engine that uses HTTP, th e location
139 * permission is not added. 149 * permission is not added.
140 */ 150 */
141 @SmallTest 151 @SmallTest
142 @Feature({"Preferences"}) 152 @Feature({"Preferences"})
143 @DisableIf.Build(hardware_is = "sprout", message = "fails on android-one: cr bug.com/540706") 153 @DisableIf.Build(hardware_is = "sprout", message = "fails on android-one: cr bug.com/540706")
144 public void testSearchEnginePreferenceHttp() throws Exception { 154 public void testSearchEnginePreferenceHttp() throws Exception {
145 ensureTemplateUrlServiceLoaded(); 155 ensureTemplateUrlServiceLoaded();
146 156
157 final Preferences prefActivity =
158 startPreferences(getInstrumentation(), SearchEnginePreference.cl ass.getName());
159
147 // Set the first search engine as the default using TemplateUrlService. 160 // Set the first search engine as the default using TemplateUrlService.
148 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 161 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
149 @Override 162 @Override
150 public void run() { 163 public void run() {
151 TemplateUrlService.getInstance().setSearchEngine(0); 164 SearchEnginePreference pref =
165 (SearchEnginePreference) prefActivity.getFragmentForTest ();
166 pref.setValueForTesting("0");
152 } 167 }
153 }); 168 });
154 169
155 final Preferences prefActivity =
156 startPreferences(getInstrumentation(), SearchEnginePreference.cl ass.getName());
157
158 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 170 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
159 @Override 171 @Override
160 public void run() { 172 public void run() {
161 // Ensure that the first search engine in the list is selected. 173 // Ensure that the first search engine in the list is selected.
162 SearchEnginePreference pref = 174 SearchEnginePreference pref =
163 (SearchEnginePreference) prefActivity.getFragmentForTest (); 175 (SearchEnginePreference) prefActivity.getFragmentForTest ();
164 assertNotNull(pref); 176 assertNotNull(pref);
165 assertEquals("0", pref.getValueForTesting()); 177 assertEquals("0", pref.getValueForTesting());
166 178
167 // Simulate selecting a search engine that uses HTTP. 179 // Simulate selecting a search engine that uses HTTP.
168 int index = indexOfFirstHttpSearchEngine(); 180 int index = indexOfFirstHttpSearchEngine(pref);
169 pref.setValueForTesting(Integer.toString(index)); 181 String keyword = pref.setValueForTesting(Integer.toString(index) );
170 182
171 TemplateUrlService templateUrlService = TemplateUrlService.getIn stance(); 183 TemplateUrlService templateUrlService = TemplateUrlService.getIn stance();
172 assertEquals(index, templateUrlService.getDefaultSearchEngineInd ex()); 184 assertEquals(keyword,
173 assertEquals(ContentSetting.ASK, locationPermissionForSearchEngi ne(index)); 185 templateUrlService.getDefaultSearchEngineTemplateUrl().g etKeyword());
186 assertEquals(ContentSetting.ASK, locationPermissionForSearchEngi ne(keyword));
174 } 187 }
175 }); 188 });
176 } 189 }
177 190
178 private int indexOfFirstHttpSearchEngine() { 191 private int indexOfFirstHttpSearchEngine(SearchEnginePreference pref) {
179 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; 192 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ;
180 List<TemplateUrl> urls = templateUrlService.getLocalizedSearchEngines(); 193 List<TemplateUrl> urls = templateUrlService.getLocalizedSearchEngines();
181 int index; 194 int index;
182 for (index = 0; index < urls.size(); ++index) { 195 for (index = 0; index < urls.size(); ++index) {
183 String url = templateUrlService.getSearchEngineUrlFromTemplateUrl(in dex); 196 String keyword = pref.getKeywordFromIndexTesting(index);
197 String url = templateUrlService.getSearchEngineUrlFromTemplateUrl(ke yword);
184 if (url.startsWith("http:")) { 198 if (url.startsWith("http:")) {
185 return index; 199 return index;
186 } 200 }
187 } 201 }
188 fail(); 202 fail();
189 return index; 203 return index;
190 } 204 }
191 205
192 private void ensureTemplateUrlServiceLoaded() throws Exception { 206 private void ensureTemplateUrlServiceLoaded() throws Exception {
193 // Make sure the template_url_service is loaded. 207 // Make sure the template_url_service is loaded.
(...skipping 10 matching lines...) Expand all
204 onTemplateUrlServiceLoadedHelper.notifyCalled(); 218 onTemplateUrlServiceLoadedHelper.notifyCalled();
205 } 219 }
206 }); 220 });
207 TemplateUrlService.getInstance().load(); 221 TemplateUrlService.getInstance().load();
208 } 222 }
209 } 223 }
210 }); 224 });
211 onTemplateUrlServiceLoadedHelper.waitForCallback(0); 225 onTemplateUrlServiceLoadedHelper.waitForCallback(0);
212 } 226 }
213 227
214 private ContentSetting locationPermissionForSearchEngine(int index) { 228 private ContentSetting locationPermissionForSearchEngine(String keyword) {
215 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl(index); 229 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl(keyword);
216 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; 230 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ;
217 ContentSetting locationPermission = locationSettings.getContentSetting() ; 231 ContentSetting locationPermission = locationSettings.getContentSetting() ;
218 return locationPermission; 232 return locationPermission;
219 } 233 }
220 234
221 /** 235 /**
222 * Tests setting FontScaleFactor and ForceEnableZoom in AccessibilityPrefere nces and ensures 236 * Tests setting FontScaleFactor and ForceEnableZoom in AccessibilityPrefere nces and ensures
223 * that ForceEnableZoom changes corresponding to FontScaleFactor. 237 * that ForceEnableZoom changes corresponding to FontScaleFactor.
224 */ 238 */
225 @SmallTest 239 @SmallTest
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 private static void userSetForceEnableZoom(final AccessibilityPreferences ac cessibilityPref, 309 private static void userSetForceEnableZoom(final AccessibilityPreferences ac cessibilityPref,
296 final SeekBarLinkedCheckBoxPreference forceEnableZoomPref, final boo lean enabled) { 310 final SeekBarLinkedCheckBoxPreference forceEnableZoomPref, final boo lean enabled) {
297 ThreadUtils.runOnUiThread(new Runnable() { 311 ThreadUtils.runOnUiThread(new Runnable() {
298 @Override 312 @Override
299 public void run() { 313 public void run() {
300 accessibilityPref.onPreferenceChange(forceEnableZoomPref, enable d); 314 accessibilityPref.onPreferenceChange(forceEnableZoomPref, enable d);
301 } 315 }
302 }); 316 });
303 } 317 }
304 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698