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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/omaha/UpdateMenuItemHelperTest.java

Issue 1505913003: Add update menu item and app menu icon badge (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add code create 1dp transparent border in LocatoinBarPhone Created 5 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
gone 2015/12/08 22:27:54 Guessing you'll delete the OmahaUpdateInfoBarTest
Theresa 2015/12/10 03:53:18 Yes.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.omaha;
6
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_PHONE;
8
9 import android.content.Context;
10 import android.test.suitebuilder.annotation.MediumTest;
11 import android.view.View;
12
13 import org.chromium.base.ThreadUtils;
14 import org.chromium.base.test.util.CommandLineFlags;
15 import org.chromium.base.test.util.Feature;
16 import org.chromium.base.test.util.Restriction;
17 import org.chromium.chrome.R;
18 import org.chromium.chrome.browser.UrlConstants;
19 import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
20 import org.chromium.chrome.test.util.OverviewModeBehaviorWatcher;
21 import org.chromium.content.browser.test.util.Criteria;
22 import org.chromium.content.browser.test.util.CriteriaHelper;
23
24
25 /**
26 * Tests for the UpdateMenuItemHelper.
27 */
28 @CommandLineFlags.Add("enable_update_menu_item")
29 public class UpdateMenuItemHelperTest extends ChromeTabbedActivityTestBase {
30
31 private static final long MS_TIMEOUT = 2000;
32 private static final long MS_INTERVAL = 500;
33
34 /** Reports versions that we want back to OmahaClient. */
35 private static class MockVersionNumberGetter extends VersionNumberGetter {
36 // Both of these strings must be of the format "#.#.#.#".
37 private final String mCurrentVersion;
38 private final String mLatestVersion;
39
40 private boolean mAskedForCurrentVersion;
41 private boolean mAskedForLatestVersion;
42
43 public MockVersionNumberGetter(String currentVersion, String latestVersi on) {
44 mCurrentVersion = currentVersion;
45 mLatestVersion = latestVersion;
46 }
47
48 @Override
49 public String getCurrentlyUsedVersion(Context applicationContext) {
50 assertNotNull("Never set the current version", mCurrentVersion);
51 mAskedForCurrentVersion = true;
52 return mCurrentVersion;
53 }
54
55 @Override
56 public String getLatestKnownVersion(
57 Context applicationContext, String prefPackage, String prefLates tVersion) {
58 assertNotNull("Never set the latest version", mLatestVersion);
59 mAskedForLatestVersion = true;
60 return mLatestVersion;
61 }
62
63 public boolean askedForCurrentVersion() {
64 return mAskedForCurrentVersion;
65 }
66
67 public boolean askedForLatestVersion() {
68 return mAskedForLatestVersion;
69 }
70 }
71
72 /** Reports a dummy market URL back to OmahaClient. */
73 private static class MockMarketURLGetter extends MarketURLGetter {
74 private final String mURL;
75
76 MockMarketURLGetter(String url) {
77 mURL = url;
78 }
79
80 @Override
81 public String getMarketURL(
82 Context applicationContext, String prefPackage, String prefMarke tUrl) {
83 return mURL;
84 }
85 }
86
87 private MockVersionNumberGetter mMockVersionNumberGetter;
88 private MockMarketURLGetter mMockMarketURLGetter;
89
90 @Override
91 public void setUp() throws Exception {
92 super.setUp();
93
94 // This test explicitly tests for the menu item, so turn it on.
95 OmahaClient.setEnableUpdateDetection(true);
96 }
97
98 @Override
99 public void startMainActivity() {
100 // Don't start Main until we've had a chance to override everything.
101 }
102
103 /**
104 * Prepares Main before actually launching it. This is required since we do n't have all of the
105 * info we need in setUp().
106 * @param currentVersion Version to report as the current version of Chrome
107 * @param latestVersion Version to report is available by Omaha
108 */
109 private void prepareAndStartMainActivity(String currentVersion, String lates tVersion)
110 throws Exception {
111 // Report fake versions back to Main when it asks.
112 mMockVersionNumberGetter = new MockVersionNumberGetter(currentVersion, l atestVersion);
113 OmahaClient.setVersionNumberGetterForTests(mMockVersionNumberGetter);
114
115 // Report a dummy URL to Omaha.
116 mMockMarketURLGetter = new MockMarketURLGetter(
117 "https://market.android.com/details?id=com.google.android.apps.c hrome");
118 OmahaClient.setMarketURLGetterForTests(mMockMarketURLGetter);
119
120 // Start up main.
121 startMainActivityWithURL(UrlConstants.NTP_URL);
122
123 // Check to make sure that the version numbers get queried.
124 versionNumbersQueried();
125 }
126
127 private void versionNumbersQueried() throws Exception {
128 CriteriaHelper.pollForCriteria(
129 new Criteria() {
130 @Override
131 public boolean isSatisfied() {
132 return mMockVersionNumberGetter.askedForCurrentVersion()
133 && mMockVersionNumberGetter.askedForLatestVersio n();
134 }
135 },
136 MS_TIMEOUT, MS_INTERVAL);
137 }
138
139 /**
140 * Checks that the menu item is shown when a new version is available.
141 */
142 private void checkUpdateMenuItemIsShowing(String currentVersion, String late stVersion)
143 throws Exception {
144 prepareAndStartMainActivity(currentVersion, latestVersion);
145 showAppMenuAndAssertMenuShown();
146 assertTrue("Update menu item is not showing.",
147 getActivity().getAppMenuHandler().getAppMenuForTest().getMenuFor Test().findItem(
148 R.id.update_menu_id).isVisible());
149 }
150
151 /**
152 * Checks that the menu item is not shown when a new version is not availabl e.
153 */
154 private void checkUpdateMenuItemIsNotShowing(String currentVersion, String l atestVersion)
155 throws Exception {
156 prepareAndStartMainActivity(currentVersion, latestVersion);
157 showAppMenuAndAssertMenuShown();
158 assertFalse("Update menu item is showing.",
159 getActivity().getAppMenuHandler().getAppMenuForTest().getMenuFor Test().findItem(
160 R.id.update_menu_id).isVisible());
161 }
162
163 @MediumTest
164 @Feature({"Omaha"})
165 public void testCurrentVersionIsOlder() throws Exception {
166 checkUpdateMenuItemIsShowing("0.0.0.0", "1.2.3.4");
167 }
168
169 @MediumTest
170 @Feature({"Omaha"})
171 public void testCurrentVersionIsSame() throws Exception {
172 checkUpdateMenuItemIsNotShowing("1.2.3.4", "1.2.3.4");
173 }
174
175 @MediumTest
176 @Feature({"Omaha"})
177 public void testCurrentVersionIsNewer() throws Exception {
178 checkUpdateMenuItemIsNotShowing("27.0.1453.42", "26.0.1410.49");
179 }
180
181 @MediumTest
182 @Feature({"Omaha"})
183 public void testNoVersionKnown() throws Exception {
184 checkUpdateMenuItemIsNotShowing("1.2.3.4", "0");
185 }
186
187 @MediumTest
188 @Feature({"Omaha"})
189 @Restriction(RESTRICTION_TYPE_PHONE)
190 public void testMenuItemNotShownInOverview() throws Exception {
191 checkUpdateMenuItemIsShowing("0.0.0.0", "1.2.3.4");
192
193 // checkUpdateMenuItemIsShowing() opens the menu; hide it and assert it' s dismissed.
194 hideAppMenuAndAssertMenuShown();
195
196 // Ensure not shown in tab switcher app menu.
197 OverviewModeBehaviorWatcher overviewModeWatcher = new OverviewModeBehavi orWatcher(
198 getActivity().getLayoutManager(), true, false);
199 View tabSwitcherButton = getActivity().findViewById(R.id.tab_switcher_bu tton);
200 assertNotNull("'tab_switcher_button' view is not found", tabSwitcherButt on);
201 singleClickView(tabSwitcherButton);
202 overviewModeWatcher.waitForBehavior();
203 showAppMenuAndAssertMenuShown();
204 assertFalse("Update menu item is showing.",
205 getActivity().getAppMenuHandler().getAppMenuForTest().getMenuFor Test().findItem(
206 R.id.update_menu_id).isVisible());
207 }
208
209 private void showAppMenuAndAssertMenuShown() throws InterruptedException {
210 ThreadUtils.runOnUiThread(new Runnable() {
211 @Override
212 public void run() {
213 getActivity().getAppMenuHandler().showAppMenu(null, false);
214 }
215 });
216 CriteriaHelper.pollForCriteria(new Criteria() {
217 @Override
218 public boolean isSatisfied() {
219 return getActivity().getAppMenuHandler().isAppMenuShowing();
220 }
221 });
222 }
223
224 private void hideAppMenuAndAssertMenuShown() throws InterruptedException {
225 ThreadUtils.runOnUiThread(new Runnable() {
226 @Override
227 public void run() {
228 getActivity().getAppMenuHandler().hideAppMenu();
229 }
230 });
231 CriteriaHelper.pollForCriteria(new Criteria() {
232 @Override
233 public boolean isSatisfied() {
234 return !getActivity().getAppMenuHandler().isAppMenuShowing();
235 }
236 });
237 }
238 }
239
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698