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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/search_engines/TemplateUrlServiceTest.java

Issue 2367373003: [Android] Allow setting recently visited search engines as default search engine (Closed)
Patch Set: Update based on Peter and Dan's comments. Created 4 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.search_engines; 5 package org.chromium.chrome.browser.search_engines;
6 6
7 import android.net.Uri; 7 import android.net.Uri;
8 import android.test.suitebuilder.annotation.SmallTest; 8 import android.test.suitebuilder.annotation.SmallTest;
9 9
10 import org.chromium.base.ThreadUtils; 10 import org.chromium.base.ThreadUtils;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return TemplateUrlService.getInstance().isLoaded(); 112 return TemplateUrlService.getInstance().isLoaded();
113 } 113 }
114 })); 114 }));
115 } 115 }
116 116
117 @SmallTest 117 @SmallTest
118 @Feature({"SearchEngines"}) 118 @Feature({"SearchEngines"})
119 public void testSetAndGetSearchEngine() throws InterruptedException { 119 public void testSetAndGetSearchEngine() throws InterruptedException {
120 final TemplateUrlService templateUrlService = waitForTemplateUrlServiceT oLoad(); 120 final TemplateUrlService templateUrlService = waitForTemplateUrlServiceT oLoad();
121 121
122 // Ensure known state of default search index before running test. 122 List<TemplateUrl> searchEngines =
123 int searchEngineIndex = ThreadUtils.runOnUiThreadBlockingNoException( 123 ThreadUtils.runOnUiThreadBlockingNoException(new Callable<List<T emplateUrl>>() {
124 new Callable<Integer>() {
125 @Override 124 @Override
126 public Integer call() throws Exception { 125 public List<TemplateUrl> call() throws Exception {
127 return templateUrlService.getDefaultSearchEngineIndex(); 126 return templateUrlService.getSearchEngines();
128 } 127 }
129 }); 128 });
130 assertEquals(0, searchEngineIndex); 129 // Ensure known state of default search index before running test.
130 String searchEngineKeyword =
131 ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String >() {
132 @Override
133 public String call() throws Exception {
134 return templateUrlService.getDefaultSearchEngineTemplate Url().getKeyword();
135 }
136 });
137 assertEquals(searchEngines.get(0).getKeyword(), searchEngineKeyword);
131 138
132 // Set search engine index and verified it stuck. 139 // Set search engine index and verified it stuck.
133 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 140 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
134 @Override 141 @Override
135 public void run() { 142 public void run() {
136 List<TemplateUrl> searchEngines = 143 List<TemplateUrl> searchEngines = templateUrlService.getSearchEn gines();
137 templateUrlService.getLocalizedSearchEngines();
138 assertTrue("There must be more than one search engine to change searchEngines", 144 assertTrue("There must be more than one search engine to change searchEngines",
139 searchEngines.size() > 1); 145 searchEngines.size() > 1);
140 templateUrlService.setSearchEngine(1); 146 templateUrlService.setSearchEngine(searchEngines.get(1).getKeywo rd());
141 } 147 }
142 }); 148 });
143 searchEngineIndex = ThreadUtils.runOnUiThreadBlockingNoException( 149 searchEngineKeyword = ThreadUtils.runOnUiThreadBlockingNoException(new C allable<String>() {
144 new Callable<Integer>() { 150 @Override
145 @Override 151 public String call() throws Exception {
146 public Integer call() throws Exception { 152 return templateUrlService.getDefaultSearchEngineTemplateUrl().ge tKeyword();
147 return templateUrlService.getDefaultSearchEngineIndex(); 153 }
148 } 154 });
149 }); 155 assertEquals(searchEngines.get(1).getKeyword(), searchEngineKeyword);
150 assertEquals(1, searchEngineIndex);
151 } 156 }
152 157
153 private TemplateUrlService waitForTemplateUrlServiceToLoad() throws Interrup tedException { 158 private TemplateUrlService waitForTemplateUrlServiceToLoad() throws Interrup tedException {
154 final AtomicBoolean observerNotified = new AtomicBoolean(false); 159 final AtomicBoolean observerNotified = new AtomicBoolean(false);
155 final LoadListener listener = new LoadListener() { 160 final LoadListener listener = new LoadListener() {
156 @Override 161 @Override
157 public void onTemplateUrlServiceLoaded() { 162 public void onTemplateUrlServiceLoaded() {
158 observerNotified.set(true); 163 observerNotified.set(true);
159 } 164 }
160 }; 165 };
(...skipping 11 matching lines...) Expand all
172 CriteriaHelper.pollInstrumentationThread(new Criteria( 177 CriteriaHelper.pollInstrumentationThread(new Criteria(
173 "Observer wasn't notified of TemplateUrlService load.") { 178 "Observer wasn't notified of TemplateUrlService load.") {
174 @Override 179 @Override
175 public boolean isSatisfied() { 180 public boolean isSatisfied() {
176 return observerNotified.get(); 181 return observerNotified.get();
177 } 182 }
178 }); 183 });
179 return templateUrlService; 184 return templateUrlService;
180 } 185 }
181 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698