OLD | NEW |
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 Loading... |
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 List<TemplateUrl> searchEngines = templateUrlService.getLocalizedSearchE
ngines(); |
122 // Ensure known state of default search index before running test. | 123 // Ensure known state of default search index before running test. |
123 int searchEngineIndex = ThreadUtils.runOnUiThreadBlockingNoException( | 124 String searchEngineKeyword = |
124 new Callable<Integer>() { | 125 ThreadUtils.runOnUiThreadBlockingNoException(new Callable<String
>() { |
125 @Override | 126 @Override |
126 public Integer call() throws Exception { | 127 public String call() throws Exception { |
127 return templateUrlService.getDefaultSearchEngineIndex(); | 128 return templateUrlService.getDefaultSearchEngineTemplate
Url().getKeyword(); |
128 } | 129 } |
129 }); | 130 }); |
130 assertEquals(0, searchEngineIndex); | 131 assertEquals(searchEngines.get(0), searchEngineKeyword); |
131 | 132 |
132 // Set search engine index and verified it stuck. | 133 // Set search engine index and verified it stuck. |
133 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 134 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
134 @Override | 135 @Override |
135 public void run() { | 136 public void run() { |
136 List<TemplateUrl> searchEngines = | 137 List<TemplateUrl> searchEngines = |
137 templateUrlService.getLocalizedSearchEngines(); | 138 templateUrlService.getLocalizedSearchEngines(); |
138 assertTrue("There must be more than one search engine to change
searchEngines", | 139 assertTrue("There must be more than one search engine to change
searchEngines", |
139 searchEngines.size() > 1); | 140 searchEngines.size() > 1); |
140 templateUrlService.setSearchEngine(1); | 141 templateUrlService.setSearchEngine(searchEngines.get(1).getKeywo
rd()); |
141 } | 142 } |
142 }); | 143 }); |
143 searchEngineIndex = ThreadUtils.runOnUiThreadBlockingNoException( | 144 searchEngineKeyword = ThreadUtils.runOnUiThreadBlockingNoException(new C
allable<String>() { |
144 new Callable<Integer>() { | 145 @Override |
145 @Override | 146 public String call() throws Exception { |
146 public Integer call() throws Exception { | 147 return templateUrlService.getDefaultSearchEngineTemplateUrl().ge
tKeyword(); |
147 return templateUrlService.getDefaultSearchEngineIndex(); | 148 } |
148 } | 149 }); |
149 }); | 150 assertEquals(searchEngines.get(1), searchEngineKeyword); |
150 assertEquals(1, searchEngineIndex); | |
151 } | 151 } |
152 | 152 |
153 private TemplateUrlService waitForTemplateUrlServiceToLoad() throws Interrup
tedException { | 153 private TemplateUrlService waitForTemplateUrlServiceToLoad() throws Interrup
tedException { |
154 final AtomicBoolean observerNotified = new AtomicBoolean(false); | 154 final AtomicBoolean observerNotified = new AtomicBoolean(false); |
155 final LoadListener listener = new LoadListener() { | 155 final LoadListener listener = new LoadListener() { |
156 @Override | 156 @Override |
157 public void onTemplateUrlServiceLoaded() { | 157 public void onTemplateUrlServiceLoaded() { |
158 observerNotified.set(true); | 158 observerNotified.set(true); |
159 } | 159 } |
160 }; | 160 }; |
(...skipping 11 matching lines...) Expand all Loading... |
172 CriteriaHelper.pollInstrumentationThread(new Criteria( | 172 CriteriaHelper.pollInstrumentationThread(new Criteria( |
173 "Observer wasn't notified of TemplateUrlService load.") { | 173 "Observer wasn't notified of TemplateUrlService load.") { |
174 @Override | 174 @Override |
175 public boolean isSatisfied() { | 175 public boolean isSatisfied() { |
176 return observerNotified.get(); | 176 return observerNotified.get(); |
177 } | 177 } |
178 }); | 178 }); |
179 return templateUrlService; | 179 return templateUrlService; |
180 } | 180 } |
181 } | 181 } |
OLD | NEW |