OLD | NEW |
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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.app.Instrumentation; | 9 import android.app.Instrumentation; |
10 import android.app.Instrumentation.ActivityMonitor; | 10 import android.app.Instrumentation.ActivityMonitor; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 showSearchEngineDialogIfNeededCallback.notifyCalled(); | 91 showSearchEngineDialogIfNeededCallback.notifyCalled(); |
92 | 92 |
93 if (shouldShowRealSearchDialog) { | 93 if (shouldShowRealSearchDialog) { |
94 LocaleManager.setInstanceForTest(new LocaleManager() { | 94 LocaleManager.setInstanceForTest(new LocaleManager() { |
95 @Override | 95 @Override |
96 public int getSearchEnginePromoShowType() { | 96 public int getSearchEnginePromoShowType() { |
97 return SEARCH_ENGINE_PROMO_SHOW_EXISTING; | 97 return SEARCH_ENGINE_PROMO_SHOW_EXISTING; |
98 } | 98 } |
99 }); | 99 }); |
100 super.showSearchEngineDialogIfNeeded(activity, onSearchEngineFin
alized); | 100 super.showSearchEngineDialogIfNeeded(activity, onSearchEngineFin
alized); |
101 return; | 101 } else { |
| 102 LocaleManager.setInstanceForTest(new LocaleManager() { |
| 103 @Override |
| 104 public boolean needToCheckForSearchEnginePromo() { |
| 105 return false; |
| 106 } |
| 107 }); |
| 108 if (!shouldDelayDeferredInitialization) onSearchEngineFinalized.
onResult(true); |
102 } | 109 } |
103 | |
104 if (!shouldDelayDeferredInitialization) onSearchEngineFinalized.onRe
sult(true); | |
105 } | 110 } |
106 | 111 |
107 @Override | 112 @Override |
108 public void onFinishDeferredInitialization() { | 113 public void onFinishDeferredInitialization() { |
109 onFinishDeferredInitializationCallback.notifyCalled(); | 114 onFinishDeferredInitializationCallback.notifyCalled(); |
110 } | 115 } |
111 | 116 |
112 @Override | 117 @Override |
113 public void onDialogShown(DefaultSearchEnginePromoDialog dialog) { | 118 public void onDialogShown(DefaultSearchEnginePromoDialog dialog) { |
114 shownPromoDialog = dialog; | 119 shownPromoDialog = dialog; |
(...skipping 10 matching lines...) Expand all Loading... |
125 @Before | 130 @Before |
126 public void setUp() { | 131 public void setUp() { |
127 mTestDelegate = new TestDelegate(); | 132 mTestDelegate = new TestDelegate(); |
128 SearchActivity.setDelegateForTests(mTestDelegate); | 133 SearchActivity.setDelegateForTests(mTestDelegate); |
129 DefaultSearchEnginePromoDialog.setObserverForTests(mTestDelegate); | 134 DefaultSearchEnginePromoDialog.setObserverForTests(mTestDelegate); |
130 } | 135 } |
131 | 136 |
132 @After | 137 @After |
133 public void tearDown() { | 138 public void tearDown() { |
134 SearchActivity.setDelegateForTests(null); | 139 SearchActivity.setDelegateForTests(null); |
| 140 LocaleManager.setInstanceForTest(null); |
135 } | 141 } |
136 | 142 |
137 @Test | 143 @Test |
138 @SmallTest | 144 @SmallTest |
139 public void testOmniboxSuggestionContainerAppears() throws Exception { | 145 public void testOmniboxSuggestionContainerAppears() throws Exception { |
140 SearchActivity searchActivity = startSearchActivity(); | 146 SearchActivity searchActivity = startSearchActivity(); |
141 | 147 |
142 // Wait for the Activity to fully load. | 148 // Wait for the Activity to fully load. |
143 mTestDelegate.shouldDelayNativeInitializationCallback.waitForCallback(0)
; | 149 mTestDelegate.shouldDelayNativeInitializationCallback.waitForCallback(0)
; |
144 mTestDelegate.showSearchEngineDialogIfNeededCallback.waitForCallback(0); | 150 mTestDelegate.showSearchEngineDialogIfNeededCallback.waitForCallback(0); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } | 453 } |
448 })); | 454 })); |
449 } | 455 } |
450 | 456 |
451 @SuppressLint("SetTextI18n") | 457 @SuppressLint("SetTextI18n") |
452 private void setUrlBarText(final Activity activity, final String url) { | 458 private void setUrlBarText(final Activity activity, final String url) { |
453 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 459 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
454 @Override | 460 @Override |
455 public void run() { | 461 public void run() { |
456 UrlBar urlBar = (UrlBar) activity.findViewById(R.id.url_bar); | 462 UrlBar urlBar = (UrlBar) activity.findViewById(R.id.url_bar); |
| 463 if (!urlBar.hasFocus()) urlBar.requestFocus(); |
457 urlBar.setText(url); | 464 urlBar.setText(url); |
458 } | 465 } |
459 }); | 466 }); |
460 } | 467 } |
461 } | 468 } |
OLD | NEW |