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

Side by Side Diff: chrome/android/junit/src/org/chromium/chrome/browser/webapps/WebApkUpdateManagerTest.java

Issue 2671853002: Rename best icon to best primary icon in Web app related code. (Closed)
Patch Set: Addressing comments Created 3 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import static org.junit.Assert.assertEquals; 7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse; 8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertTrue; 9 import static org.junit.Assert.assertTrue;
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 /** 43 /**
44 * Unit tests for WebApkUpdateManager. 44 * Unit tests for WebApkUpdateManager.
45 */ 45 */
46 @RunWith(LocalRobolectricTestRunner.class) 46 @RunWith(LocalRobolectricTestRunner.class)
47 @Config(manifest = Config.NONE) 47 @Config(manifest = Config.NONE)
48 public class WebApkUpdateManagerTest { 48 public class WebApkUpdateManagerTest {
49 @Rule 49 @Rule
50 public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsR ule(); 50 public DisableHistogramsRule mDisableHistogramsRule = new DisableHistogramsR ule();
51 51
52 /** WebAPK's id in {@link WebAppDataStorage}. */ 52 /** WebAPK's id in {@link WebAppDataStorage}. */
53 private static final String WEBAPK_ID = 53 private static final String WEBAPK_ID = WebApkConstants.WEBAPK_ID_PREFIX
54 WebApkConstants.WEBAPK_ID_PREFIX + WebApkTestHelper.WEBAPK_PACKAGE_N AME; 54 + WebApkTestHelper.WEBAPK_PACKAGE_NAME;
55 55
56 /** Web Manifest URL */ 56 /** Web Manifest URL */
57 private static final String WEB_MANIFEST_URL = "manifest.json"; 57 private static final String WEB_MANIFEST_URL = "manifest.json";
58 58
59 private static final String START_URL = "/start_url.html"; 59 private static final String START_URL = "/start_url.html";
60 private static final String SCOPE_URL = "/"; 60 private static final String SCOPE_URL = "/";
61 private static final String NAME = "Long Name"; 61 private static final String NAME = "Long Name";
62 private static final String SHORT_NAME = "Short Name"; 62 private static final String SHORT_NAME = "Short Name";
63 private static final String ICON_URL = "/icon.png"; 63 private static final String ICON_URL = "/icon.png";
64 private static final String ICON_MURMUR2_HASH = "3"; 64 private static final String ICON_MURMUR2_HASH = "3";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 return mDestroyedFetcher; 138 return mDestroyedFetcher;
139 } 139 }
140 140
141 @Override 141 @Override
142 protected WebApkUpdateDataFetcher buildFetcher() { 142 protected WebApkUpdateDataFetcher buildFetcher() {
143 mFetcher = new TestWebApkUpdateDataFetcher(); 143 mFetcher = new TestWebApkUpdateDataFetcher();
144 return mFetcher; 144 return mFetcher;
145 } 145 }
146 146
147 @Override 147 @Override
148 protected void scheduleUpdate(WebApkInfo info, String bestIconUrl, 148 protected void scheduleUpdate(WebApkInfo info, String bestPrimaryIconUrl ,
149 boolean isManifestStale) { 149 boolean isManifestStale) {
150 mUpdateName = info.name(); 150 mUpdateName = info.name();
151 super.scheduleUpdate(info, bestIconUrl, isManifestStale); 151 super.scheduleUpdate(info, bestPrimaryIconUrl, isManifestStale);
152 } 152 }
153 153
154 @Override 154 @Override
155 protected void updateAsyncImpl(WebApkInfo info, String bestIconUrl, 155 protected void updateAsyncImpl(WebApkInfo info, String bestPrimaryIconUr l,
156 boolean isManifestStale) { 156 boolean isManifestStale) {
157 mUpdateRequested = true; 157 mUpdateRequested = true;
158 } 158 }
159 159
160 @Override 160 @Override
161 protected boolean isInForeground() { 161 protected boolean isInForeground() {
162 return mIsWebApkForeground; 162 return mIsWebApkForeground;
163 } 163 }
164 164
165 @Override 165 @Override
(...skipping 17 matching lines...) Expand all
183 return TextUtils.equals(url1, url2); 183 return TextUtils.equals(url1, url2);
184 } 184 }
185 } 185 }
186 186
187 private static class ManifestData { 187 private static class ManifestData {
188 public String startUrl; 188 public String startUrl;
189 public String scopeUrl; 189 public String scopeUrl;
190 public String name; 190 public String name;
191 public String shortName; 191 public String shortName;
192 public Map<String, String> iconUrlToMurmur2HashMap; 192 public Map<String, String> iconUrlToMurmur2HashMap;
193 public String bestIconUrl; 193 public String bestPrimaryIconUrl;
194 public Bitmap bestIcon; 194 public Bitmap bestPrimaryIcon;
195 public int displayMode; 195 public int displayMode;
196 public int orientation; 196 public int orientation;
197 public long themeColor; 197 public long themeColor;
198 public long backgroundColor; 198 public long backgroundColor;
199 } 199 }
200 200
201 private MockClock mClock; 201 private MockClock mClock;
202 202
203 private WebappDataStorage getStorage() { 203 private WebappDataStorage getStorage() {
204 return WebappRegistry.getInstance().getWebappDataStorage(WEBAPK_ID); 204 return WebappRegistry.getInstance().getWebappDataStorage(WEBAPK_ID);
205 } 205 }
206 206
207 /** 207 /**
208 * Registers WebAPK with default package name. Overwrites previous registrat ions. 208 * Registers WebAPK with default package name. Overwrites previous registrat ions.
209 * @param manifestData <meta-data> values for WebAPK's Android Manife st. 209 *
210 * @param manifestData <meta-data> values for WebAPK's Android Manifest.
210 * @param shellApkVersionCode WebAPK's version of the //chrome/android/webap k/shell_apk code. 211 * @param shellApkVersionCode WebAPK's version of the //chrome/android/webap k/shell_apk code.
211 */ 212 */
212 private void registerWebApk(ManifestData manifestData, int shellApkVersionCo de) { 213 private void registerWebApk(ManifestData manifestData, int shellApkVersionCo de) {
213 Bundle metaData = new Bundle(); 214 Bundle metaData = new Bundle();
214 metaData.putInt( 215 metaData.putInt(
215 WebApkMetaDataKeys.SHELL_APK_VERSION, shellApkVersionCode); 216 WebApkMetaDataKeys.SHELL_APK_VERSION, shellApkVersionCode);
216 metaData.putString(WebApkMetaDataKeys.START_URL, manifestData.startUrl); 217 metaData.putString(WebApkMetaDataKeys.START_URL, manifestData.startUrl);
217 metaData.putString(WebApkMetaDataKeys.SCOPE, manifestData.scopeUrl); 218 metaData.putString(WebApkMetaDataKeys.SCOPE, manifestData.scopeUrl);
218 metaData.putString(WebApkMetaDataKeys.NAME, manifestData.name); 219 metaData.putString(WebApkMetaDataKeys.NAME, manifestData.name);
219 metaData.putString(WebApkMetaDataKeys.SHORT_NAME, manifestData.shortName ); 220 metaData.putString(WebApkMetaDataKeys.SHORT_NAME, manifestData.shortName );
(...skipping 19 matching lines...) Expand all
239 private static ManifestData defaultManifestData() { 240 private static ManifestData defaultManifestData() {
240 ManifestData manifestData = new ManifestData(); 241 ManifestData manifestData = new ManifestData();
241 manifestData.startUrl = START_URL; 242 manifestData.startUrl = START_URL;
242 manifestData.scopeUrl = SCOPE_URL; 243 manifestData.scopeUrl = SCOPE_URL;
243 manifestData.name = NAME; 244 manifestData.name = NAME;
244 manifestData.shortName = SHORT_NAME; 245 manifestData.shortName = SHORT_NAME;
245 246
246 manifestData.iconUrlToMurmur2HashMap = new HashMap<String, String>(); 247 manifestData.iconUrlToMurmur2HashMap = new HashMap<String, String>();
247 manifestData.iconUrlToMurmur2HashMap.put(ICON_URL, ICON_MURMUR2_HASH); 248 manifestData.iconUrlToMurmur2HashMap.put(ICON_URL, ICON_MURMUR2_HASH);
248 249
249 manifestData.bestIconUrl = ICON_URL; 250 manifestData.bestPrimaryIconUrl = ICON_URL;
250 manifestData.bestIcon = createBitmap(Color.GREEN); 251 manifestData.bestPrimaryIcon = createBitmap(Color.GREEN);
251 manifestData.displayMode = DISPLAY_MODE; 252 manifestData.displayMode = DISPLAY_MODE;
252 manifestData.orientation = ORIENTATION; 253 manifestData.orientation = ORIENTATION;
253 manifestData.themeColor = THEME_COLOR; 254 manifestData.themeColor = THEME_COLOR;
254 manifestData.backgroundColor = BACKGROUND_COLOR; 255 manifestData.backgroundColor = BACKGROUND_COLOR;
255 return manifestData; 256 return manifestData;
256 } 257 }
257 258
258 private static WebApkInfo infoFromManifestData(ManifestData manifestData) { 259 private static WebApkInfo infoFromManifestData(ManifestData manifestData) {
259 if (manifestData == null) return null; 260 if (manifestData == null) return null;
260 261
261 return WebApkInfo.create(WEBAPK_ID, "", manifestData.scopeUrl, 262 return WebApkInfo.create(WEBAPK_ID, "", manifestData.scopeUrl,
262 new WebApkInfo.Icon(manifestData.bestIcon), manifestData.name, 263 new WebApkInfo.Icon(manifestData.bestPrimaryIcon), manifestData. name,
263 manifestData.shortName, manifestData.displayMode, manifestData.o rientation, -1, 264 manifestData.shortName, manifestData.displayMode, manifestData.o rientation, -1,
264 manifestData.themeColor, manifestData.backgroundColor, 265 manifestData.themeColor, manifestData.backgroundColor,
265 WebApkTestHelper.WEBAPK_PACKAGE_NAME, -1, WEB_MANIFEST_URL, 266 WebApkTestHelper.WEBAPK_PACKAGE_NAME, -1, WEB_MANIFEST_URL,
266 manifestData.startUrl, manifestData.iconUrlToMurmur2HashMap); 267 manifestData.startUrl, manifestData.iconUrlToMurmur2HashMap);
267 } 268 }
268 269
269 /** 270 /**
270 * Creates 1x1 bitmap. 271 * Creates 1x1 bitmap.
272 *
271 * @param color The bitmap color. 273 * @param color The bitmap color.
272 */ 274 */
273 private static Bitmap createBitmap(int color) { 275 private static Bitmap createBitmap(int color) {
274 int colors[] = { color }; 276 int colors[] = {
277 color
278 };
275 return ShadowBitmap.createBitmap(colors, 1, 1, Bitmap.Config.ALPHA_8); 279 return ShadowBitmap.createBitmap(colors, 1, 1, Bitmap.Config.ALPHA_8);
276 } 280 }
277 281
278 private static void updateIfNeeded(WebApkUpdateManager updateManager) { 282 private static void updateIfNeeded(WebApkUpdateManager updateManager) {
279 // Use the intent version of {@link WebApkInfo#create()} in order to tes t default values 283 // Use the intent version of {@link WebApkInfo#create()} in order to tes t default values
280 // set by the intent version of {@link WebApkInfo#create()}. 284 // set by the intent version of {@link WebApkInfo#create()}.
281 Intent intent = new Intent(); 285 Intent intent = new Intent();
282 intent.putExtra(ShortcutHelper.EXTRA_URL, ""); 286 intent.putExtra(ShortcutHelper.EXTRA_URL, "");
283 intent.putExtra( 287 intent.putExtra(
284 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP K_PACKAGE_NAME); 288 ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME, WebApkTestHelper.WEBAP K_PACKAGE_NAME);
285 WebApkInfo info = WebApkInfo.create(intent); 289 WebApkInfo info = WebApkInfo.create(intent);
286 290
287 updateManager.updateIfNeeded(null, info); 291 updateManager.updateIfNeeded(null, info);
288 } 292 }
289 293
290 private static void onGotUnchangedWebManifestData(WebApkUpdateManager update Manager) { 294 private static void onGotUnchangedWebManifestData(WebApkUpdateManager update Manager) {
291 onGotManifestData(updateManager, defaultManifestData()); 295 onGotManifestData(updateManager, defaultManifestData());
292 } 296 }
293 297
294 private static void onGotManifestData(WebApkUpdateManager updateManager, 298 private static void onGotManifestData(WebApkUpdateManager updateManager,
295 ManifestData fetchedManifestData) { 299 ManifestData fetchedManifestData) {
296 String bestIconUrl = randomIconUrl(fetchedManifestData); 300 String bestPrimaryIconUrl = randomIconUrl(fetchedManifestData);
297 updateManager.onGotManifestData(infoFromManifestData(fetchedManifestData ), bestIconUrl); 301 updateManager.onGotManifestData(infoFromManifestData(fetchedManifestData ),
302 bestPrimaryIconUrl);
298 } 303 }
299 304
300 private static String randomIconUrl(ManifestData fetchedManifestData) { 305 private static String randomIconUrl(ManifestData fetchedManifestData) {
301 if (fetchedManifestData == null || fetchedManifestData.iconUrlToMurmur2H ashMap.isEmpty()) { 306 if (fetchedManifestData == null || fetchedManifestData.iconUrlToMurmur2H ashMap.isEmpty()) {
302 return null; 307 return null;
303 } 308 }
304 return fetchedManifestData.iconUrlToMurmur2HashMap.keySet().iterator().n ext(); 309 return fetchedManifestData.iconUrlToMurmur2HashMap.keySet().iterator().n ext();
305 } 310 }
306 311
307 /** 312 /**
308 * Runs {@link WebApkUpdateManager#updateIfNeeded()} and returns whether an 313 * Runs {@link WebApkUpdateManager#updateIfNeeded()} and returns whether an is-update-needed
309 * is-update-needed check has been triggered. 314 * check has been triggered.
310 */ 315 */
311 private boolean updateIfNeededChecksForUpdatedWebManifest() { 316 private boolean updateIfNeededChecksForUpdatedWebManifest() {
312 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck); 317 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck);
313 updateIfNeeded(updateManager); 318 updateIfNeeded(updateManager);
314 return updateManager.updateCheckStarted(); 319 return updateManager.updateCheckStarted();
315 } 320 }
316 321
317 /** 322 /**
318 * Checks whether the WebAPK is updated given data from the WebAPK's Android Manifest and data 323 * Checks whether the WebAPK is updated given data from the WebAPK's Android Manifest and data
319 * from the fetched Web Manifest. 324 * from the fetched Web Manifest.
320 */ 325 */
321 private boolean checkUpdateNeededForFetchedManifest( 326 private boolean checkUpdateNeededForFetchedManifest(
322 ManifestData androidManifestData, ManifestData fetchedManifestData) { 327 ManifestData androidManifestData, ManifestData fetchedManifestData) {
323 registerWebApk(androidManifestData, WebApkVersion.CURRENT_SHELL_APK_VERS ION); 328 registerWebApk(androidManifestData, WebApkVersion.CURRENT_SHELL_APK_VERS ION);
324 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL); 329 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL);
325 330
326 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck); 331 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck);
327 updateIfNeeded(updateManager); 332 updateIfNeeded(updateManager);
328 assertTrue(updateManager.updateCheckStarted()); 333 assertTrue(updateManager.updateCheckStarted());
329 updateManager.onGotManifestData( 334 updateManager.onGotManifestData(
330 infoFromManifestData(fetchedManifestData), fetchedManifestData.b estIconUrl); 335 infoFromManifestData(fetchedManifestData), fetchedManifestData.b estPrimaryIconUrl);
331 return updateManager.updateRequested(); 336 return updateManager.updateRequested();
332 } 337 }
333 338
334 @Before 339 @Before
335 public void setUp() { 340 public void setUp() {
336 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati on); 341 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati on);
337 CommandLine.init(null); 342 CommandLine.init(null);
338 ChromeWebApkHost.initForTesting(true); 343 ChromeWebApkHost.initForTesting(true);
339 344
340 registerWebApk(defaultManifestData(), WebApkVersion.CURRENT_SHELL_APK_VE RSION); 345 registerWebApk(defaultManifestData(), WebApkVersion.CURRENT_SHELL_APK_VE RSION);
341 Settings.Secure.putInt(RuntimeEnvironment.application.getContentResolver (), 346 Settings.Secure.putInt(RuntimeEnvironment.application.getContentResolver (),
342 Settings.Secure.INSTALL_NON_MARKET_APPS, 1); 347 Settings.Secure.INSTALL_NON_MARKET_APPS, 1);
343 348
344 mClock = new MockClock(); 349 mClock = new MockClock();
345 WebappDataStorage.setClockForTests(mClock); 350 WebappDataStorage.setClockForTests(mClock);
346 351
347 WebappRegistry.getInstance().register( 352 WebappRegistry.getInstance().register(
348 WEBAPK_ID, new WebappRegistry.FetchWebappDataStorageCallback() { 353 WEBAPK_ID, new WebappRegistry.FetchWebappDataStorageCallback() {
349 @Override 354 @Override
350 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) {} 355 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) {
356 }
351 }); 357 });
352 ShadowApplication.getInstance().runBackgroundTasks(); 358 ShadowApplication.getInstance().runBackgroundTasks();
353 359
354 WebappDataStorage storage = getStorage(); 360 WebappDataStorage storage = getStorage();
355 storage.updateTimeOfLastCheckForUpdatedWebManifest(); 361 storage.updateTimeOfLastCheckForUpdatedWebManifest();
356 storage.updateTimeOfLastWebApkUpdateRequestCompletion(); 362 storage.updateTimeOfLastWebApkUpdateRequestCompletion();
357 storage.updateDidLastWebApkUpdateRequestSucceed(true); 363 storage.updateDidLastWebApkUpdateRequestSucceed(true);
358 } 364 }
359 365
360 /** 366 /**
361 * Test that if the WebAPK update failed (e.g. because the WebAPK server is not reachable) that 367 * Test that if the WebAPK update failed (e.g. because the WebAPK server is not reachable) that
362 * the is-update-needed check is retried after less time than if the WebAPK update had 368 * the is-update-needed check is retried after less time than if the WebAPK update had
363 * succeeded. 369 * succeeded. The is-update-needed check is the first step in retrying to up date the WebAPK.
364 * The is-update-needed check is the first step in retrying to update the We bAPK.
365 */ 370 */
366 @Test 371 @Test
367 public void testCheckUpdateMoreFrequentlyIfUpdateFails() { 372 public void testCheckUpdateMoreFrequentlyIfUpdateFails() {
368 assertTrue(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL 373 assertTrue(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL
369 > WebApkUpdateManager.RETRY_UPDATE_DURATION); 374 > WebApkUpdateManager.RETRY_UPDATE_DURATION);
370 375
371 WebappDataStorage storage = getStorage(); 376 WebappDataStorage storage = getStorage();
372 377
373 assertTrue(storage.getDidLastWebApkUpdateRequestSucceed()); 378 assertTrue(storage.getDidLastWebApkUpdateRequestSucceed());
374 assertFalse(updateIfNeededChecksForUpdatedWebManifest()); 379 assertFalse(updateIfNeededChecksForUpdatedWebManifest());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 440 }
436 441
437 { 442 {
438 // Relaunching the WebAPK should not do an is-update-needed-check. 443 // Relaunching the WebAPK should not do an is-update-needed-check.
439 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager( mClock); 444 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager( mClock);
440 updateIfNeeded(updateManager); 445 updateIfNeeded(updateManager);
441 assertFalse(updateManager.updateCheckStarted()); 446 assertFalse(updateManager.updateCheckStarted());
442 } 447 }
443 } 448 }
444 449
445 /** 450 /**
pkotwicz 2017/02/03 18:42:15 Leave the bullet points one per line with the AND
F 2017/02/06 12:40:12 Acknowledged. Will avoid auto-formatter next time
446 * Test that the completion time of the previous WebAPK update is not modifi ed if: 451 * Test that the completion time of the previous WebAPK update is not modifi ed if: - The
447 * - The previous WebAPK update succeeded. 452 * previous WebAPK update succeeded. AND - A WebAPK update is not required.
448 * AND
449 * - A WebAPK update is not required.
450 */ 453 */
451 @Test 454 @Test
452 public void testUpdateNotNeeded() { 455 public void testUpdateNotNeeded() {
453 long initialTime = mClock.currentTimeMillis(); 456 long initialTime = mClock.currentTimeMillis();
454 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL); 457 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL);
455 458
456 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck); 459 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck);
457 updateIfNeeded(updateManager); 460 updateIfNeeded(updateManager);
458 assertTrue(updateManager.updateCheckStarted()); 461 assertTrue(updateManager.updateCheckStarted());
459 onGotUnchangedWebManifestData(updateManager); 462 onGotUnchangedWebManifestData(updateManager);
460 assertFalse(updateManager.updateRequested()); 463 assertFalse(updateManager.updateRequested());
461 464
462 WebappDataStorage storage = getStorage(); 465 WebappDataStorage storage = getStorage();
463 assertTrue(storage.getDidLastWebApkUpdateRequestSucceed()); 466 assertTrue(storage.getDidLastWebApkUpdateRequestSucceed());
464 assertEquals(initialTime, storage.getLastWebApkUpdateRequestCompletionTi me()); 467 assertEquals(initialTime, storage.getLastWebApkUpdateRequestCompletionTi me());
465 } 468 }
466 469
467 /** 470 /**
468 * Test that the last WebAPK update is marked as having succeeded if: 471 * Test that the last WebAPK update is marked as having succeeded if: - The previous WebAPK
469 * - The previous WebAPK update failed. 472 * update failed. AND - A WebAPK update is no longer required.
470 * AND
471 * - A WebAPK update is no longer required.
472 */ 473 */
473 @Test 474 @Test
474 public void testMarkUpdateAsSucceededIfUpdateNoLongerNeeded() { 475 public void testMarkUpdateAsSucceededIfUpdateNoLongerNeeded() {
475 WebappDataStorage storage = getStorage(); 476 WebappDataStorage storage = getStorage();
476 storage.updateDidLastWebApkUpdateRequestSucceed(false); 477 storage.updateDidLastWebApkUpdateRequestSucceed(false);
477 mClock.advance(WebApkUpdateManager.RETRY_UPDATE_DURATION); 478 mClock.advance(WebApkUpdateManager.RETRY_UPDATE_DURATION);
478 479
479 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck); 480 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck);
480 updateIfNeeded(updateManager); 481 updateIfNeeded(updateManager);
481 assertTrue(updateManager.updateCheckStarted()); 482 assertTrue(updateManager.updateCheckStarted());
(...skipping 24 matching lines...) Expand all
506 // Chrome is killed. {@link WebApkUpdateManager#onBuiltWebApk} is never called. 507 // Chrome is killed. {@link WebApkUpdateManager#onBuiltWebApk} is never called.
507 508
508 // Check {@link WebappDataStorage} state. 509 // Check {@link WebappDataStorage} state.
509 WebappDataStorage storage = getStorage(); 510 WebappDataStorage storage = getStorage();
510 assertFalse(storage.getDidLastWebApkUpdateRequestSucceed()); 511 assertFalse(storage.getDidLastWebApkUpdateRequestSucceed());
511 assertEquals( 512 assertEquals(
512 mClock.currentTimeMillis(), storage.getLastWebApkUpdateRequestCo mpletionTime()); 513 mClock.currentTimeMillis(), storage.getLastWebApkUpdateRequestCo mpletionTime());
513 } 514 }
514 515
515 /** 516 /**
516 * Test that an update with data from the WebAPK's Android manifest is done if: 517 * Test that an update with data from the WebAPK's Android manifest is done if: - WebAPK's code
517 * - WebAPK's code is out of date 518 * is out of date AND - WebAPK's start_url does not refer to a Web Manifest. It is good to
518 * AND 519 * minimize the number of users with out of date WebAPKs. We try to keep Web APKs up to date even
519 * - WebAPK's start_url does not refer to a Web Manifest. 520 * if the web developer has removed the Web Manifest from their site.
520 *
521 * It is good to minimize the number of users with out of date WebAPKs. We t ry to keep WebAPKs
522 * up to date even if the web developer has removed the Web Manifest from th eir site.
523 */ 521 */
524 @Test 522 @Test
525 public void testShellApkOutOfDateNoWebManifest() { 523 public void testShellApkOutOfDateNoWebManifest() {
526 registerWebApk(defaultManifestData(), WebApkVersion.CURRENT_SHELL_APK_VE RSION - 1); 524 registerWebApk(defaultManifestData(), WebApkVersion.CURRENT_SHELL_APK_VE RSION - 1);
527 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL); 525 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL);
528 526
529 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck); 527 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck);
530 updateIfNeeded(updateManager); 528 updateIfNeeded(updateManager);
531 assertTrue(updateManager.updateCheckStarted()); 529 assertTrue(updateManager.updateCheckStarted());
532 530
(...skipping 21 matching lines...) Expand all
554 assertTrue(updateManager.updateCheckStarted()); 552 assertTrue(updateManager.updateCheckStarted());
555 553
556 onGotManifestData(updateManager, defaultManifestData()); 554 onGotManifestData(updateManager, defaultManifestData());
557 assertTrue(updateManager.updateRequested()); 555 assertTrue(updateManager.updateRequested());
558 assertEquals(NAME, updateManager.requestedUpdateName()); 556 assertEquals(NAME, updateManager.requestedUpdateName());
559 557
560 assertTrue(updateManager.destroyedFetcher()); 558 assertTrue(updateManager.destroyedFetcher());
561 } 559 }
562 560
563 /** 561 /**
564 * Test that an update is requested if: 562 * Test that an update is requested if: - start_url does not refer to a Web Manifest. AND - The
565 * - start_url does not refer to a Web Manifest. 563 * user eventually navigates to a page pointing to a Web Manifest with the c orrect URL. AND -
566 * AND 564 * The Web Manifest has changed. This scenario can occur if the WebAPK's sta rt_url is a
567 * - The user eventually navigates to a page pointing to a Web Manifest with the correct URL. 565 * Javascript redirect.
568 * AND
569 * - The Web Manifest has changed.
570 *
571 * This scenario can occur if the WebAPK's start_url is a Javascript redirec t.
572 */ 566 */
573 @Test 567 @Test
574 public void testStartUrlRedirectsToPageWithUpdatedWebManifest() { 568 public void testStartUrlRedirectsToPageWithUpdatedWebManifest() {
575 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL); 569 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL);
576 570
577 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck); 571 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck);
578 updateIfNeeded(updateManager); 572 updateIfNeeded(updateManager);
579 assertTrue(updateManager.updateCheckStarted()); 573 assertTrue(updateManager.updateCheckStarted());
580 574
581 // start_url does not have a Web Manifest. No update should be requested . 575 // start_url does not have a Web Manifest. No update should be requested .
582 updateManager.onWebManifestForInitialUrlNotWebApkCompatible(); 576 updateManager.onWebManifestForInitialUrlNotWebApkCompatible();
583 assertFalse(updateManager.updateRequested()); 577 assertFalse(updateManager.updateRequested());
584 // {@link ManifestUpgradeDetector} should still be alive so that it can get 578 // {@link ManifestUpgradeDetector} should still be alive so that it can get
585 // {@link #onGotManifestData} when page with the Web Manifest finishes l oading. 579 // {@link #onGotManifestData} when page with the Web Manifest finishes l oading.
586 assertFalse(updateManager.destroyedFetcher()); 580 assertFalse(updateManager.destroyedFetcher());
587 581
588 // start_url redirects to page with Web Manifest. 582 // start_url redirects to page with Web Manifest.
589 583
590 ManifestData manifestData = defaultManifestData(); 584 ManifestData manifestData = defaultManifestData();
591 manifestData.name = DIFFERENT_NAME; 585 manifestData.name = DIFFERENT_NAME;
592 onGotManifestData(updateManager, manifestData); 586 onGotManifestData(updateManager, manifestData);
593 assertTrue(updateManager.updateRequested()); 587 assertTrue(updateManager.updateRequested());
594 assertEquals(DIFFERENT_NAME, updateManager.requestedUpdateName()); 588 assertEquals(DIFFERENT_NAME, updateManager.requestedUpdateName());
595 589
596 assertTrue(updateManager.destroyedFetcher()); 590 assertTrue(updateManager.destroyedFetcher());
597 } 591 }
598 592
599 /** 593 /**
600 * Test that an update is not requested if: 594 * Test that an update is not requested if: - start_url does not refer to a Web Manifest. AND -
601 * - start_url does not refer to a Web Manifest. 595 * The user eventually navigates to a page pointing to a Web Manifest with t he correct URL. AND
602 * AND
603 * - The user eventually navigates to a page pointing to a Web Manifest with the correct URL.
604 * AND
605 * - The Web Manifest has not changed. 596 * - The Web Manifest has not changed.
606 */ 597 */
607 @Test 598 @Test
608 public void testStartUrlRedirectsToPageWithUnchangedWebManifest() { 599 public void testStartUrlRedirectsToPageWithUnchangedWebManifest() {
609 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL); 600 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL);
610 601
611 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck); 602 TestWebApkUpdateManager updateManager = new TestWebApkUpdateManager(mClo ck);
612 updateIfNeeded(updateManager); 603 updateIfNeeded(updateManager);
613 updateManager.onWebManifestForInitialUrlNotWebApkCompatible(); 604 updateManager.onWebManifestForInitialUrlNotWebApkCompatible();
614 onGotManifestData(updateManager, defaultManifestData()); 605 onGotManifestData(updateManager, defaultManifestData());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 assertTrue( 643 assertTrue(
653 !oldData.scopeUrl.equals(ShortcutHelper.getScopeFromUrl(oldData. startUrl))); 644 !oldData.scopeUrl.equals(ShortcutHelper.getScopeFromUrl(oldData. startUrl)));
654 ManifestData fetchedData = defaultManifestData(); 645 ManifestData fetchedData = defaultManifestData();
655 fetchedData.startUrl = "/fancy/scope/special/snowflake.html"; 646 fetchedData.startUrl = "/fancy/scope/special/snowflake.html";
656 fetchedData.scopeUrl = ""; 647 fetchedData.scopeUrl = "";
657 648
658 assertTrue(checkUpdateNeededForFetchedManifest(oldData, fetchedData)); 649 assertTrue(checkUpdateNeededForFetchedManifest(oldData, fetchedData));
659 } 650 }
660 651
661 /** 652 /**
662 * Test that an upgrade is requested when: 653 * Test that an upgrade is requested when: - WebAPK was generated using icon at {@link ICON_URL}
663 * - WebAPK was generated using icon at {@link ICON_URL} from Web Manifest. 654 * from Web Manifest. - Bitmap at {@link ICON_URL} has changed.
664 * - Bitmap at {@link ICON_URL} has changed.
665 */ 655 */
666 @Test 656 @Test
667 public void testHomescreenIconChangeShouldUpgrade() { 657 public void testHomescreenIconChangeShouldUpgrade() {
668 ManifestData fetchedData = defaultManifestData(); 658 ManifestData fetchedData = defaultManifestData();
669 fetchedData.iconUrlToMurmur2HashMap.put(fetchedData.bestIconUrl, ICON_MU RMUR2_HASH + "1"); 659 fetchedData.iconUrlToMurmur2HashMap.put(fetchedData.bestPrimaryIconUrl,
670 fetchedData.bestIcon = createBitmap(Color.BLUE); 660 ICON_MURMUR2_HASH + "1");
661 fetchedData.bestPrimaryIcon = createBitmap(Color.BLUE);
671 assertTrue(checkUpdateNeededForFetchedManifest(defaultManifestData(), fe tchedData)); 662 assertTrue(checkUpdateNeededForFetchedManifest(defaultManifestData(), fe tchedData));
672 } 663 }
673 664
674 /** 665 /**
675 * Test that an upgrade is requested when: 666 * Test that an upgrade is requested when: - WebAPK is generated using icon at {@link ICON_URL}
676 * - WebAPK is generated using icon at {@link ICON_URL} from Web Manifest. 667 * from Web Manifest. - Web Manifest is updated to refer to different icon.
677 * - Web Manifest is updated to refer to different icon.
678 */ 668 */
679 @Test 669 @Test
680 public void testHomescreenBestIconUrlChangeShouldUpgrade() { 670 public void testHomescreenBestPrimaryIconUrlChangeShouldUpgrade() {
681 ManifestData fetchedData = defaultManifestData(); 671 ManifestData fetchedData = defaultManifestData();
682 fetchedData.iconUrlToMurmur2HashMap.clear(); 672 fetchedData.iconUrlToMurmur2HashMap.clear();
683 fetchedData.iconUrlToMurmur2HashMap.put("/icon2.png", "22"); 673 fetchedData.iconUrlToMurmur2HashMap.put("/icon2.png", "22");
684 fetchedData.bestIconUrl = "/icon2.png"; 674 fetchedData.bestPrimaryIconUrl = "/icon2.png";
685 assertTrue(checkUpdateNeededForFetchedManifest(defaultManifestData(), fe tchedData)); 675 assertTrue(checkUpdateNeededForFetchedManifest(defaultManifestData(), fe tchedData));
686 } 676 }
687 677
688 /** 678 /**
689 * Test that an upgrade is not requested if: 679 * Test that an upgrade is not requested if: - icon URL is added to the Web Manifest AND -
690 * - icon URL is added to the Web Manifest 680 * "best" icon URL for the launcher icon did not change.
691 * AND
692 * - "best" icon URL for the launcher icon did not change.
693 */ 681 */
694 @Test 682 @Test
695 public void testIconUrlsChangeShouldNotUpgradeIfTheBestIconUrlDoesNotChange( ) { 683 public void testIconUrlsChangeShouldNotUpgradeIfTheBestPrimaryIconUrlDoesNot Change() {
696 ManifestData fetchedData = defaultManifestData(); 684 ManifestData fetchedData = defaultManifestData();
697 fetchedData.iconUrlToMurmur2HashMap.clear(); 685 fetchedData.iconUrlToMurmur2HashMap.clear();
698 fetchedData.iconUrlToMurmur2HashMap.put(ICON_URL, ICON_MURMUR2_HASH); 686 fetchedData.iconUrlToMurmur2HashMap.put(ICON_URL, ICON_MURMUR2_HASH);
699 fetchedData.iconUrlToMurmur2HashMap.put("/icon2.png", null); 687 fetchedData.iconUrlToMurmur2HashMap.put("/icon2.png", null);
700 assertFalse(checkUpdateNeededForFetchedManifest(defaultManifestData(), f etchedData)); 688 assertFalse(checkUpdateNeededForFetchedManifest(defaultManifestData(), f etchedData));
701 } 689 }
702 690
703 /** 691 /**
704 * Test than upgrade is requested if: 692 * Test than upgrade is requested if: - the WebAPK's meta data has murmur2 h ashes for all of the
705 * - the WebAPK's meta data has murmur2 hashes for all of the icons. 693 * icons. AND - the Web Manifest has not changed AND - the computed best ico n URL is different
706 * AND 694 * from the one stored in the WebAPK's meta data.
707 * - the Web Manifest has not changed
708 * AND
709 * - the computed best icon URL is different from the one stored in the WebA PK's meta data.
710 */ 695 */
711 @Test 696 @Test
712 public void testWebManifestSameButBestIconUrlChangedShouldNotUpgrade() { 697 public void testWebManifestSameButBestPrimaryIconUrlChangedShouldNotUpgrade( ) {
713 String iconUrl1 = "/icon1.png"; 698 String iconUrl1 = "/icon1.png";
714 String iconUrl2 = "/icon2.png"; 699 String iconUrl2 = "/icon2.png";
715 String hash1 = "11"; 700 String hash1 = "11";
716 String hash2 = "22"; 701 String hash2 = "22";
717 702
718 ManifestData oldData = defaultManifestData(); 703 ManifestData oldData = defaultManifestData();
719 oldData.bestIconUrl = iconUrl1; 704 oldData.bestPrimaryIconUrl = iconUrl1;
720 oldData.iconUrlToMurmur2HashMap.clear(); 705 oldData.iconUrlToMurmur2HashMap.clear();
721 oldData.iconUrlToMurmur2HashMap.put(iconUrl1, hash1); 706 oldData.iconUrlToMurmur2HashMap.put(iconUrl1, hash1);
722 oldData.iconUrlToMurmur2HashMap.put(iconUrl2, hash2); 707 oldData.iconUrlToMurmur2HashMap.put(iconUrl2, hash2);
723 708
724 ManifestData fetchedData = defaultManifestData(); 709 ManifestData fetchedData = defaultManifestData();
725 fetchedData.bestIconUrl = iconUrl2; 710 fetchedData.bestPrimaryIconUrl = iconUrl2;
726 fetchedData.iconUrlToMurmur2HashMap.clear(); 711 fetchedData.iconUrlToMurmur2HashMap.clear();
727 fetchedData.iconUrlToMurmur2HashMap.put(iconUrl1, null); 712 fetchedData.iconUrlToMurmur2HashMap.put(iconUrl1, null);
728 fetchedData.iconUrlToMurmur2HashMap.put(iconUrl2, hash2); 713 fetchedData.iconUrlToMurmur2HashMap.put(iconUrl2, hash2);
729 714
730 assertFalse(checkUpdateNeededForFetchedManifest(oldData, fetchedData)); 715 assertFalse(checkUpdateNeededForFetchedManifest(oldData, fetchedData));
731 } 716 }
732 717
733 @Test 718 @Test
734 public void testForceUpdateWhenUncompletedUpdateRequestRechesMaximumTimes() { 719 public void testForceUpdateWhenUncompletedUpdateRequestRechesMaximumTimes() {
735 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL); 720 mClock.advance(WebApkUpdateManager.FULL_CHECK_UPDATE_INTERVAL);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 // Since {@link WebApkActivity#OnStop()} calls {@link requestPendingUpda te()} to trigger an 763 // Since {@link WebApkActivity#OnStop()} calls {@link requestPendingUpda te()} to trigger an
779 // update request, we call it directly for testing. 764 // update request, we call it directly for testing.
780 updateManager.setIsWebApkForeground(false); 765 updateManager.setIsWebApkForeground(false);
781 updateManager.requestPendingUpdate(); 766 updateManager.requestPendingUpdate();
782 767
783 assertFalse(updateManager.getHasPendingUpdateForTesting()); 768 assertFalse(updateManager.getHasPendingUpdateForTesting());
784 assertTrue(updateManager.updateRequested()); 769 assertTrue(updateManager.updateRequested());
785 assertEquals(0, storage.getUpdateRequests()); 770 assertEquals(0, storage.getUpdateRequests());
786 } 771 }
787 } 772 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698