| OLD | NEW |
| 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 android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.SharedPreferences; | 10 import android.content.SharedPreferences; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 Intent intent = createIntent(id, url, title, icon, addMac); | 86 Intent intent = createIntent(id, url, title, icon, addMac); |
| 87 | 87 |
| 88 getInstrumentation().getTargetContext().startActivity(intent); | 88 getInstrumentation().getTargetContext().startActivity(intent); |
| 89 getInstrumentation().waitForIdleSync(); | 89 getInstrumentation().waitForIdleSync(); |
| 90 ApplicationTestUtils.waitUntilChromeInForeground(); | 90 ApplicationTestUtils.waitUntilChromeInForeground(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 @Override | 93 @Override |
| 94 public void setUp() throws Exception { | 94 public void setUp() throws Exception { |
| 95 super.setUp(); | 95 super.setUp(); |
| 96 WebappRegistry.refreshSharedPrefsForTesting(); |
| 96 | 97 |
| 97 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is | 98 // Register the webapps so when the data storage is opened, the test doe
sn't crash. There is |
| 98 // no race condition with the retrieval as AsyncTasks are run sequential
ly on the background | 99 // no race condition with the retrieval as AsyncTasks are run sequential
ly on the background |
| 99 // thread. | 100 // thread. |
| 100 WebappRegistry.registerWebapp( | 101 WebappRegistry.getInstance().register( |
| 101 WEBAPP_1_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ | 102 WEBAPP_1_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ |
| 102 @Override | 103 @Override |
| 103 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { | 104 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { |
| 104 storage.updateFromShortcutIntent(createIntent( | 105 storage.updateFromShortcutIntent(createIntent( |
| 105 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); | 106 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); |
| 106 } | 107 } |
| 107 }); | 108 }); |
| 108 WebappRegistry.registerWebapp( | 109 WebappRegistry.getInstance().register( |
| 109 WEBAPP_2_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ | 110 WEBAPP_2_ID, new WebappRegistry.FetchWebappDataStorageCallback()
{ |
| 110 @Override | 111 @Override |
| 111 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { | 112 public void onWebappDataStorageRetrieved(WebappDataStorage s
torage) { |
| 112 storage.updateFromShortcutIntent(createIntent( | 113 storage.updateFromShortcutIntent(createIntent( |
| 113 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); | 114 WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAP
P_ICON, true)); |
| 114 } | 115 } |
| 115 }); | 116 }); |
| 116 } | 117 } |
| 117 | 118 |
| 118 /** | 119 /** |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 324 |
| 324 WebappActivity webappActivity = (WebappActivity) lastActivity; | 325 WebappActivity webappActivity = (WebappActivity) lastActivity; |
| 325 if (webappActivity.getActivityTab() == null) return false; | 326 if (webappActivity.getActivityTab() == null) return false; |
| 326 | 327 |
| 327 View rootView = webappActivity.findViewById(android.R.id.content); | 328 View rootView = webappActivity.findViewById(android.R.id.content); |
| 328 if (!rootView.hasWindowFocus()) return false; | 329 if (!rootView.hasWindowFocus()) return false; |
| 329 | 330 |
| 330 return true; | 331 return true; |
| 331 } | 332 } |
| 332 } | 333 } |
| OLD | NEW |