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

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

Issue 1867543002: Enable deep-linking from notifications for recently used web apps on the Android home screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bulk-webappdatastorage
Patch Set: UI thread strikes again Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.assertTrue; 8 import static org.junit.Assert.assertTrue;
9 9
10 import android.content.Context; 10 import android.content.Context;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 private static final int INITIAL_TIME = 0; 43 private static final int INITIAL_TIME = 0;
44 44
45 private SharedPreferences mSharedPreferences; 45 private SharedPreferences mSharedPreferences;
46 private boolean mCallbackCalled; 46 private boolean mCallbackCalled;
47 47
48 private class FetchCallback implements WebappRegistry.FetchCallback { 48 private class FetchCallback implements WebappRegistry.FetchCallback {
49 Set<String> mExpected; 49 Set<String> mExpected;
50 50
51 FetchCallback(Set<String> expected) { 51 FetchCallback(Set<String> expected) {
52 mCallbackCalled = false;
52 mExpected = expected; 53 mExpected = expected;
53 } 54 }
54 55
55 @Override 56 @Override
56 public void onWebappIdsRetrieved(Set<String> actual) { 57 public void onWebappIdsRetrieved(Set<String> actual) {
57 mCallbackCalled = true; 58 mCallbackCalled = true;
58 assertEquals(mExpected, actual); 59 assertEquals(mExpected, actual);
59 } 60 }
60 } 61 }
61 62
62 private class FetchStorageCallback implements WebappRegistry.FetchWebappData StorageCallback { 63 private class FetchStorageCallback implements WebappRegistry.FetchWebappData StorageCallback {
63 Intent mShortcutIntent; 64 Intent mShortcutIntent;
65 boolean mMarkLaunched;
64 66
65 FetchStorageCallback(Intent shortcutIntent) { 67 FetchStorageCallback(Intent shortcutIntent, boolean markLaunched) {
66 mCallbackCalled = false; 68 mCallbackCalled = false;
67 mShortcutIntent = shortcutIntent; 69 mShortcutIntent = shortcutIntent;
70 mMarkLaunched = markLaunched;
68 } 71 }
69 72
70 @Override 73 @Override
71 public void onWebappDataStorageRetrieved(WebappDataStorage storage) { 74 public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
72 mCallbackCalled = true; 75 mCallbackCalled = true;
73 storage.updateFromShortcutIntent(mShortcutIntent); 76 storage.updateFromShortcutIntent(mShortcutIntent);
77 storage.updateLastUsedTime();
78 if (mMarkLaunched) storage.setLaunched();
74 } 79 }
75 } 80 }
76 81
82 private class FetchStorageByUrlCallback
83 implements WebappRegistry.FetchWebappDataStorageCallback {
84 String mUrl;
85 String mScope;
86
87 FetchStorageByUrlCallback(String url, String scope) {
88 mCallbackCalled = false;
89 mUrl = url;
90 mScope = scope;
91 }
92
93 @Override
94 public void onWebappDataStorageRetrieved(WebappDataStorage storage) {
95 mCallbackCalled = true;
gone 2016/04/07 19:10:44 This really should be a member variable of this ca
dominickn 2016/04/08 01:10:46 Done.
96 assertEquals(mUrl, storage.getUrl());
97 assertEquals(mScope, storage.getScope());
98 }
99 }
100
77 private class CallbackRunner implements Runnable { 101 private class CallbackRunner implements Runnable {
78 public CallbackRunner() { 102 public CallbackRunner() {
79 mCallbackCalled = false; 103 mCallbackCalled = false;
80 } 104 }
81 105
82 @Override 106 @Override
83 public void run() { 107 public void run() {
84 mCallbackCalled = true; 108 mCallbackCalled = true;
85 } 109 }
86 } 110 }
(...skipping 22 matching lines...) Expand all
109 BackgroundShadowAsyncTask.runBackgroundTasks(); 133 BackgroundShadowAsyncTask.runBackgroundTasks();
110 134
111 Set<String> actual = mSharedPreferences.getStringSet( 135 Set<String> actual = mSharedPreferences.getStringSet(
112 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); 136 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
113 assertEquals(1, actual.size()); 137 assertEquals(1, actual.size());
114 assertTrue(actual.contains("test")); 138 assertTrue(actual.contains("test"));
115 } 139 }
116 140
117 @Test 141 @Test
118 @Feature({"Webapp"}) 142 @Feature({"Webapp"})
119 public void testWebappRegistrationUpdatesLastUsed() throws Exception { 143 public void testWebappRegistrationUpdatesLastUsedAndDoesNotMarkLaunched() th rows Exception {
120 long before = System.currentTimeMillis();
dominickn 2016/04/06 13:07:01 The before check started being flaky for me, so I
121
122 WebappRegistry.registerWebapp(Robolectric.application, "test", null); 144 WebappRegistry.registerWebapp(Robolectric.application, "test", null);
123 BackgroundShadowAsyncTask.runBackgroundTasks(); 145 BackgroundShadowAsyncTask.runBackgroundTasks();
124 long after = System.currentTimeMillis(); 146 long after = System.currentTimeMillis();
125 147
126 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere nces( 148 SharedPreferences webAppPrefs = Robolectric.application.getSharedPrefere nces(
127 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD E_PRIVATE); 149 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "test", Context.MOD E_PRIVATE);
128 long actual = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED, 150 long actual = webAppPrefs.getLong(WebappDataStorage.KEY_LAST_USED,
129 WebappDataStorage.LAST_USED_INVALID); 151 WebappDataStorage.LAST_USED_INVALID);
130 assertTrue("Timestamp is out of range", before <= actual && actual <= af ter); 152 assertTrue("Timestamp is out of range", actual <= after);
153
154 boolean launched = webAppPrefs.getBoolean(WebappDataStorage.KEY_LAUNCHED , false);
155 assertTrue(!launched);
gone 2016/04/07 19:10:45 can't just assertTrue(!webAppPref....) here?
dominickn 2016/04/08 01:10:46 Done.
131 } 156 }
132 157
133 @Test 158 @Test
134 @Feature({"Webapp"}) 159 @Feature({"Webapp"})
135 public void testWebappIdsRetrieval() throws Exception { 160 public void testWebappIdsRetrieval() throws Exception {
136 final Set<String> expected = addWebappsToRegistry("first", "second"); 161 final Set<String> expected = addWebappsToRegistry("first", "second");
137 162
138 WebappRegistry.getRegisteredWebappIds(Robolectric.application, new Fetch Callback(expected)); 163 WebappRegistry.getRegisteredWebappIds(Robolectric.application, new Fetch Callback(expected));
139 BackgroundShadowAsyncTask.runBackgroundTasks(); 164 BackgroundShadowAsyncTask.runBackgroundTasks();
140 Robolectric.runUiThreadTasks(); 165 Robolectric.runUiThreadTasks();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 341
317 @Test 342 @Test
318 @Feature({"Webapp"}) 343 @Feature({"Webapp"})
319 public void testClearWebappHistory() throws Exception { 344 public void testClearWebappHistory() throws Exception {
320 final String webapp1Url = "https://www.google.com"; 345 final String webapp1Url = "https://www.google.com";
321 final String webapp2Url = "https://drive.google.com"; 346 final String webapp2Url = "https://drive.google.com";
322 Intent shortcutIntent1 = createShortcutIntent(webapp1Url); 347 Intent shortcutIntent1 = createShortcutIntent(webapp1Url);
323 Intent shortcutIntent2 = createShortcutIntent(webapp2Url); 348 Intent shortcutIntent2 = createShortcutIntent(webapp2Url);
324 349
325 WebappRegistry.registerWebapp(Robolectric.application, "webapp1", 350 WebappRegistry.registerWebapp(Robolectric.application, "webapp1",
326 new FetchStorageCallback(shortcutIntent1)); 351 new FetchStorageCallback(shortcutIntent1, true));
327 BackgroundShadowAsyncTask.runBackgroundTasks(); 352 BackgroundShadowAsyncTask.runBackgroundTasks();
328 Robolectric.runUiThreadTasks(); 353 Robolectric.runUiThreadTasks();
329 assertTrue(mCallbackCalled); 354 assertTrue(mCallbackCalled);
330 355
331 WebappRegistry.registerWebapp(Robolectric.application, "webapp2", 356 WebappRegistry.registerWebapp(Robolectric.application, "webapp2",
332 new FetchStorageCallback(shortcutIntent2)); 357 new FetchStorageCallback(shortcutIntent2, false));
333 BackgroundShadowAsyncTask.runBackgroundTasks(); 358 BackgroundShadowAsyncTask.runBackgroundTasks();
334 Robolectric.runUiThreadTasks(); 359 Robolectric.runUiThreadTasks();
335 assertTrue(mCallbackCalled); 360 assertTrue(mCallbackCalled);
336 361
337 SharedPreferences webapp1Prefs = Robolectric.application.getSharedPrefer ences( 362 SharedPreferences webapp1Prefs = Robolectric.application.getSharedPrefer ences(
338 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp1", Context. MODE_PRIVATE); 363 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp1", Context. MODE_PRIVATE);
339 SharedPreferences webapp2Prefs = Robolectric.application.getSharedPrefer ences( 364 SharedPreferences webapp2Prefs = Robolectric.application.getSharedPrefer ences(
340 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp2", Context. MODE_PRIVATE); 365 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp2", Context. MODE_PRIVATE);
341 366
342 WebappRegistry.clearWebappHistory(Robolectric.application, new CallbackR unner()); 367 WebappRegistry.clearWebappHistory(Robolectric.application, new CallbackR unner());
343 BackgroundShadowAsyncTask.runBackgroundTasks(); 368 BackgroundShadowAsyncTask.runBackgroundTasks();
344 Robolectric.runUiThreadTasks(); 369 Robolectric.runUiThreadTasks();
345 assertTrue(mCallbackCalled); 370 assertTrue(mCallbackCalled);
346 371
347 Set<String> actual = mSharedPreferences.getStringSet( 372 Set<String> actual = mSharedPreferences.getStringSet(
348 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); 373 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
349 assertEquals(2, actual.size()); 374 assertEquals(2, actual.size());
350 assertTrue(actual.contains("webapp1")); 375 assertTrue(actual.contains("webapp1"));
351 assertTrue(actual.contains("webapp2")); 376 assertTrue(actual.contains("webapp2"));
352 377
353 // Verify that the last used time for both web apps is WebappDataStorage .LAST_USED_UNSET. 378 // Verify that the last used time for both web apps is WebappDataStorage .LAST_USED_UNSET.
354 long actualLastUsed = webapp1Prefs.getLong( 379 long actualLastUsed = webapp1Prefs.getLong(
355 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS ET); 380 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS ET);
356 assertEquals(WebappDataStorage.LAST_USED_UNSET, actualLastUsed); 381 assertEquals(WebappDataStorage.LAST_USED_UNSET, actualLastUsed);
357 actualLastUsed = webapp2Prefs.getLong( 382 actualLastUsed = webapp2Prefs.getLong(
358 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS ET); 383 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_UNS ET);
359 assertEquals(WebappDataStorage.LAST_USED_UNSET, actualLastUsed); 384 assertEquals(WebappDataStorage.LAST_USED_UNSET, actualLastUsed);
360 385
386 // Verify that neither web app is marked as launched.
387 boolean actualLaunched = webapp1Prefs.getBoolean(WebappDataStorage.KEY_L AUNCHED, false);
388 assertTrue(!actualLaunched);
389 actualLaunched = webapp2Prefs.getBoolean(WebappDataStorage.KEY_LAUNCHED, false);
390 assertTrue(!actualLaunched);
391
361 // Verify that the URL and scope for both web apps is WebappDataStorage. URL_INVALID. 392 // Verify that the URL and scope for both web apps is WebappDataStorage. URL_INVALID.
362 String actualScope = webapp1Prefs.getString( 393 String actualScope = webapp1Prefs.getString(
363 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); 394 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID);
364 assertEquals(WebappDataStorage.URL_INVALID, actualScope); 395 assertEquals(WebappDataStorage.URL_INVALID, actualScope);
365 String actualUrl = webapp1Prefs.getString( 396 String actualUrl = webapp1Prefs.getString(
366 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); 397 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID);
367 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); 398 assertEquals(WebappDataStorage.URL_INVALID, actualUrl);
368 actualScope = webapp2Prefs.getString( 399 actualScope = webapp2Prefs.getString(
369 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); 400 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID);
370 assertEquals(WebappDataStorage.URL_INVALID, actualScope); 401 assertEquals(WebappDataStorage.URL_INVALID, actualScope);
371 actualUrl = webapp2Prefs.getString( 402 actualUrl = webapp2Prefs.getString(
372 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); 403 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID);
373 assertEquals(WebappDataStorage.URL_INVALID, actualUrl); 404 assertEquals(WebappDataStorage.URL_INVALID, actualUrl);
374 } 405 }
375 406
376 @Test 407 @Test
377 @Feature({"Webapp"}) 408 @Feature({"Webapp"})
378 public void testGetAfterClearWebappHistory() throws Exception { 409 public void testGetAfterClearWebappHistory() throws Exception {
379 WebappRegistry.registerWebapp(Robolectric.application, "webapp", null); 410 WebappRegistry.registerWebapp(Robolectric.application, "webapp", null);
380 BackgroundShadowAsyncTask.runBackgroundTasks(); 411 BackgroundShadowAsyncTask.runBackgroundTasks();
381 412
382 SharedPreferences webappPrefs = Robolectric.application.getSharedPrefere nces( 413 SharedPreferences webappPrefs = Robolectric.application.getSharedPrefere nces(
383 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M ODE_PRIVATE); 414 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M ODE_PRIVATE);
384 WebappRegistry.clearWebappHistory(Robolectric.application, new CallbackR unner()); 415 WebappRegistry.clearWebappHistory(Robolectric.application, new CallbackR unner());
385 BackgroundShadowAsyncTask.runBackgroundTasks(); 416 BackgroundShadowAsyncTask.runBackgroundTasks();
386 Robolectric.runUiThreadTasks(); 417 Robolectric.runUiThreadTasks();
387 assertTrue(mCallbackCalled); 418 assertTrue(mCallbackCalled);
388 419
389 // Open the webapp up to set the last used time. 420 // Open the webapp up to set the last used time and launched.
390 WebappRegistry.getWebappDataStorage(Robolectric.application, "webapp", 421 WebappRegistry.getWebappDataStorage(Robolectric.application, "webapp",
391 new FetchStorageCallback(null)); 422 new FetchStorageCallback(null, true));
392 BackgroundShadowAsyncTask.runBackgroundTasks(); 423 BackgroundShadowAsyncTask.runBackgroundTasks();
393 Robolectric.runUiThreadTasks(); 424 Robolectric.runUiThreadTasks();
394 assertTrue(mCallbackCalled); 425 assertTrue(mCallbackCalled);
395 426
396 // Verify that the last used time is valid. 427 // Verify that the last used time is valid.
397 long actualLastUsed = webappPrefs.getLong( 428 long actualLastUsed = webappPrefs.getLong(
398 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_INV ALID); 429 WebappDataStorage.KEY_LAST_USED, WebappDataStorage.LAST_USED_INV ALID);
399 assertTrue(WebappDataStorage.LAST_USED_INVALID != actualLastUsed); 430 assertTrue(WebappDataStorage.LAST_USED_INVALID != actualLastUsed);
400 assertTrue(WebappDataStorage.LAST_USED_UNSET != actualLastUsed); 431 assertTrue(WebappDataStorage.LAST_USED_UNSET != actualLastUsed);
432
433 // Verify that the app is marked as launched.
434 boolean actualLaunched = webappPrefs.getBoolean(WebappDataStorage.KEY_LA UNCHED, false);
435 assertTrue(actualLaunched);
401 } 436 }
402 437
403 @Test 438 @Test
404 @Feature({"Webapp"}) 439 @Feature({"Webapp"})
405 public void testUpdateAfterClearWebappHistory() throws Exception { 440 public void testUpdateAfterClearWebappHistory() throws Exception {
406 final String webappUrl = "http://www.google.com"; 441 final String webappUrl = "http://www.google.com";
442 final String webappScope = "http://www.google.com/";
407 final Intent shortcutIntent = createShortcutIntent(webappUrl); 443 final Intent shortcutIntent = createShortcutIntent(webappUrl);
408 WebappRegistry.registerWebapp(Robolectric.application, "webapp", 444 WebappRegistry.registerWebapp(Robolectric.application, "webapp",
409 new FetchStorageCallback(shortcutIntent)); 445 new FetchStorageCallback(shortcutIntent, false));
410 BackgroundShadowAsyncTask.runBackgroundTasks(); 446 BackgroundShadowAsyncTask.runBackgroundTasks();
411 Robolectric.runUiThreadTasks(); 447 Robolectric.runUiThreadTasks();
412 assertTrue(mCallbackCalled); 448 assertTrue(mCallbackCalled);
413 449
414 SharedPreferences webappPrefs = Robolectric.application.getSharedPrefere nces( 450 SharedPreferences webappPrefs = Robolectric.application.getSharedPrefere nces(
415 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M ODE_PRIVATE); 451 WebappDataStorage.SHARED_PREFS_FILE_PREFIX + "webapp", Context.M ODE_PRIVATE);
416 452
453 // Verify that the app is not marked as launched.
454 boolean actualLaunched = webappPrefs.getBoolean(WebappDataStorage.KEY_LA UNCHED, true);
455 assertTrue(actualLaunched);
456
417 // Verify that the URL and scope match the original in the intent. 457 // Verify that the URL and scope match the original in the intent.
418 String actualURL = webappPrefs.getString( 458 String actualUrl = webappPrefs.getString(
419 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); 459 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID);
420 assertEquals(webappUrl, actualURL); 460 assertEquals(webappUrl, actualUrl);
421 String actualScope = webappPrefs.getString( 461 String actualScope = webappPrefs.getString(
422 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); 462 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID);
423 assertEquals(webappUrl, actualScope); 463 assertEquals(webappScope, actualScope);
424 464
425 WebappRegistry.clearWebappHistory(Robolectric.application, new CallbackR unner()); 465 WebappRegistry.clearWebappHistory(Robolectric.application, new CallbackR unner());
426 BackgroundShadowAsyncTask.runBackgroundTasks(); 466 BackgroundShadowAsyncTask.runBackgroundTasks();
427 Robolectric.runUiThreadTasks(); 467 Robolectric.runUiThreadTasks();
428 assertTrue(mCallbackCalled); 468 assertTrue(mCallbackCalled);
429 469
430 // Update the webapp from the intent again. 470 // Update the webapp from the intent again.
431 WebappRegistry.getWebappDataStorage(Robolectric.application, "webapp", 471 WebappRegistry.getWebappDataStorage(Robolectric.application, "webapp",
432 new FetchStorageCallback(shortcutIntent)); 472 new FetchStorageCallback(shortcutIntent, true));
433 BackgroundShadowAsyncTask.runBackgroundTasks(); 473 BackgroundShadowAsyncTask.runBackgroundTasks();
434 Robolectric.runUiThreadTasks(); 474 Robolectric.runUiThreadTasks();
435 assertTrue(mCallbackCalled); 475 assertTrue(mCallbackCalled);
436 476
477 // Verify that the app is marked as launched.
478 actualLaunched = webappPrefs.getBoolean(WebappDataStorage.KEY_LAUNCHED, true);
479 assertTrue(actualLaunched);
480
437 // Verify that the URL and scope match the original in the intent. 481 // Verify that the URL and scope match the original in the intent.
438 actualURL = webappPrefs.getString( 482 actualUrl = webappPrefs.getString(
439 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID); 483 WebappDataStorage.KEY_URL, WebappDataStorage.URL_INVALID);
440 assertEquals(webappUrl, actualURL); 484 assertEquals(webappUrl, actualUrl);
441 actualScope = webappPrefs.getString( 485 actualScope = webappPrefs.getString(
442 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID); 486 WebappDataStorage.KEY_SCOPE, WebappDataStorage.URL_INVALID);
443 assertEquals(webappUrl, actualScope); 487 assertEquals(webappScope, actualScope);
488 }
489
490 @Test
491 @Feature({"Webapp"})
492 public void testGetWebappDataStorageForUrl() throws Exception {
gone 2016/04/07 19:10:45 Can you add comments here? I'm not sure what I'm
dominickn 2016/04/08 01:10:46 Done.
493 final String webapp1Url = "https://www.google.com/";
494 final String webapp2Url = "https://drive.google.com/";
495 final String webapp3Url = "https://www.google.com/drive/index.html";
496 final String webapp4Url = "https://www.google.com/drive/docs/index.html" ;
497
498 final String webapp3Scope = "https://www.google.com/drive/";
499 final String webapp4Scope = "https://www.google.com/drive/docs/";
500
501 final String test1Url = "https://www.google.com/index.html";
502 final String test2Url = "https://www.google.com/drive/recent.html";
503 final String test3Url = "https://www.google.com/drive/docs/recent.html";
504 final String test4Url = "https://www.google.com/drive/docs/recent/index. html";
505 final String test5Url = "https://maps.google.com/";
506
507 Intent shortcutIntent1 = createShortcutIntent(webapp1Url);
508 Intent shortcutIntent2 = createShortcutIntent(webapp2Url);
509 Intent shortcutIntent3 = createShortcutIntent(webapp3Url);
510 Intent shortcutIntent4 = createShortcutIntent(webapp4Url);
511
512 WebappRegistry.registerWebapp(Robolectric.application, "webapp1",
513 new FetchStorageCallback(shortcutIntent1, true));
514 BackgroundShadowAsyncTask.runBackgroundTasks();
515 Robolectric.runUiThreadTasks();
516 assertTrue(mCallbackCalled);
517
518 WebappRegistry.registerWebapp(Robolectric.application, "webapp2",
519 new FetchStorageCallback(shortcutIntent2, false));
520 BackgroundShadowAsyncTask.runBackgroundTasks();
521 Robolectric.runUiThreadTasks();
522 assertTrue(mCallbackCalled);
523
524 WebappRegistry.registerWebapp(Robolectric.application, "webapp3",
525 new FetchStorageCallback(shortcutIntent3, true));
526 BackgroundShadowAsyncTask.runBackgroundTasks();
527 Robolectric.runUiThreadTasks();
528 assertTrue(mCallbackCalled);
529
530 WebappRegistry.registerWebapp(Robolectric.application, "webapp4",
531 new FetchStorageCallback(shortcutIntent4, false));
532 BackgroundShadowAsyncTask.runBackgroundTasks();
533 Robolectric.runUiThreadTasks();
534 assertTrue(mCallbackCalled);
535
536 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test1 Url,
537 new FetchStorageByUrlCallback(webapp1Url, webapp1Url));
538 BackgroundShadowAsyncTask.runBackgroundTasks();
539 Robolectric.runUiThreadTasks();
540 assertTrue(mCallbackCalled);
541
542 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test2 Url,
543 new FetchStorageByUrlCallback(webapp3Url, webapp3Scope));
544 BackgroundShadowAsyncTask.runBackgroundTasks();
545 Robolectric.runUiThreadTasks();
546 assertTrue(mCallbackCalled);
547
548 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test3 Url,
549 new FetchStorageByUrlCallback(webapp4Url, webapp4Scope));
550 BackgroundShadowAsyncTask.runBackgroundTasks();
551 Robolectric.runUiThreadTasks();
552 assertTrue(mCallbackCalled);
553
554 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test4 Url,
555 new FetchStorageByUrlCallback(webapp4Url, webapp4Scope));
556 BackgroundShadowAsyncTask.runBackgroundTasks();
557 Robolectric.runUiThreadTasks();
558 assertTrue(mCallbackCalled);
559
560 mCallbackCalled = false;
561 WebappRegistry.getWebappDataStorageForUrl(Robolectric.application, test5 Url,
562 new WebappRegistry.FetchWebappDataStorageCallback() {
563 @Override
564 public void onWebappDataStorageRetrieved(WebappDataStorage s torage) {
565 assertEquals(null, storage);
566 mCallbackCalled = true;
567 }
568 }
569 );
570 BackgroundShadowAsyncTask.runBackgroundTasks();
571 Robolectric.runUiThreadTasks();
572 assertTrue(mCallbackCalled);
444 } 573 }
445 574
446 private Set<String> addWebappsToRegistry(String... webapps) { 575 private Set<String> addWebappsToRegistry(String... webapps) {
447 final Set<String> expected = new HashSet<String>(Arrays.asList(webapps)) ; 576 final Set<String> expected = new HashSet<String>(Arrays.asList(webapps)) ;
448 mSharedPreferences.edit() 577 mSharedPreferences.edit()
449 .putStringSet(WebappRegistry.KEY_WEBAPP_SET, expected) 578 .putStringSet(WebappRegistry.KEY_WEBAPP_SET, expected)
450 .commit(); 579 .commit();
451 return expected; 580 return expected;
452 } 581 }
453 582
454 private Set<String> getRegisteredWebapps() { 583 private Set<String> getRegisteredWebapps() {
455 return mSharedPreferences.getStringSet( 584 return mSharedPreferences.getStringSet(
456 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet()); 585 WebappRegistry.KEY_WEBAPP_SET, Collections.<String>emptySet());
457 } 586 }
458 587
459 private Intent createShortcutIntent(String url) { 588 private Intent createShortcutIntent(String url) {
460 return ShortcutHelper.createWebappShortcutIntent("id", "action", url, ur l, "name", 589 return ShortcutHelper.createWebappShortcutIntent("id", "action", url,
461 "shortName", null, ShortcutHelper.WEBAPP_SHORTCUT_VERSION, 0, 0, 0, false); 590 ShortcutHelper.getScopeFromUrl(url), "name", "shortName", null,
591 ShortcutHelper.WEBAPP_SHORTCUT_VERSION, 0, 0, 0, false);
462 } 592 }
463 } 593 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698