| 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; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; | 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.os.Build; | 10 import android.os.Build; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 public class BindingManagerInDocumentModeIntegrationTest extends DocumentModeTes
tBase { | 35 public class BindingManagerInDocumentModeIntegrationTest extends DocumentModeTes
tBase { |
| 36 private static class MockBindingManager implements BindingManager { | 36 private static class MockBindingManager implements BindingManager { |
| 37 // Maps pid to the last received visibility state of the renderer. | 37 // Maps pid to the last received visibility state of the renderer. |
| 38 private final SparseBooleanArray mProcessInForegroundMap = new SparseBoo
leanArray(); | 38 private final SparseBooleanArray mProcessInForegroundMap = new SparseBoo
leanArray(); |
| 39 // Maps pid to a string recording calls to setInForeground() and visibil
ityDetermined(). | 39 // Maps pid to a string recording calls to setInForeground() and visibil
ityDetermined(). |
| 40 private final SparseArray<String> mVisibilityCallsMap = new SparseArray<
String>(); | 40 private final SparseArray<String> mVisibilityCallsMap = new SparseArray<
String>(); |
| 41 private boolean mIsReleaseAllModerateBindingsCalled; | 41 private boolean mIsReleaseAllModerateBindingsCalled; |
| 42 | 42 |
| 43 void assertIsInForeground(final int pid) { | 43 void assertIsInForeground(final int pid) { |
| 44 try { | 44 try { |
| 45 CriteriaHelper.pollForCriteria(new Criteria() { | 45 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 46 @Override | 46 @Override |
| 47 public boolean isSatisfied() { | 47 public boolean isSatisfied() { |
| 48 return mProcessInForegroundMap.get(pid); | 48 return mProcessInForegroundMap.get(pid); |
| 49 } | 49 } |
| 50 }); | 50 }); |
| 51 } catch (InterruptedException ie) { | 51 } catch (InterruptedException ie) { |
| 52 fail(); | 52 fail(); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 void assertIsInBackground(final int pid) { | 56 void assertIsInBackground(final int pid) { |
| 57 try { | 57 try { |
| 58 CriteriaHelper.pollForCriteria(new Criteria() { | 58 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 59 @Override | 59 @Override |
| 60 public boolean isSatisfied() { | 60 public boolean isSatisfied() { |
| 61 return !mProcessInForegroundMap.get(pid); | 61 return !mProcessInForegroundMap.get(pid); |
| 62 } | 62 } |
| 63 }); | 63 }); |
| 64 } catch (InterruptedException ie) { | 64 } catch (InterruptedException ie) { |
| 65 fail(); | 65 fail(); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 void assertSetInForegroundWasCalled(String message, final int pid) { | 69 void assertSetInForegroundWasCalled(String message, final int pid) { |
| 70 try { | 70 try { |
| 71 CriteriaHelper.pollForCriteria(new Criteria(message) { | 71 CriteriaHelper.pollInstrumentationThread(new Criteria(message) { |
| 72 @Override | 72 @Override |
| 73 public boolean isSatisfied() { | 73 public boolean isSatisfied() { |
| 74 return mProcessInForegroundMap.indexOfKey(pid) >= 0; | 74 return mProcessInForegroundMap.indexOfKey(pid) >= 0; |
| 75 } | 75 } |
| 76 }); | 76 }); |
| 77 } catch (InterruptedException ie) { | 77 } catch (InterruptedException ie) { |
| 78 fail(); | 78 fail(); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void assertIsReleaseAllModerateBindingsCalled() { | 82 void assertIsReleaseAllModerateBindingsCalled() { |
| 83 try { | 83 try { |
| 84 CriteriaHelper.pollForCriteria(new Criteria() { | 84 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 85 @Override | 85 @Override |
| 86 public boolean isSatisfied() { | 86 public boolean isSatisfied() { |
| 87 return mIsReleaseAllModerateBindingsCalled; | 87 return mIsReleaseAllModerateBindingsCalled; |
| 88 } | 88 } |
| 89 }); | 89 }); |
| 90 } catch (InterruptedException ie) { | 90 } catch (InterruptedException ie) { |
| 91 fail(); | 91 fail(); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 @Feature({"ProcessManagement"}) | 210 @Feature({"ProcessManagement"}) |
| 211 public void testCrashInForeground() throws Exception { | 211 public void testCrashInForeground() throws Exception { |
| 212 // Create a tab in foreground and wait until it is loaded. | 212 // Create a tab in foreground and wait until it is loaded. |
| 213 final Tab tab = ChromeApplication.getDocumentTabModelSelector().getTabBy
Id( | 213 final Tab tab = ChromeApplication.getDocumentTabModelSelector().getTabBy
Id( |
| 214 launchViaViewIntent(false, URL_1, "Page 1")); | 214 launchViaViewIntent(false, URL_1, "Page 1")); |
| 215 | 215 |
| 216 // Kill the renderer and wait for the crash to be noted by the browser p
rocess. | 216 // Kill the renderer and wait for the crash to be noted by the browser p
rocess. |
| 217 assertTrue(ChildProcessLauncher.crashProcessForTesting( | 217 assertTrue(ChildProcessLauncher.crashProcessForTesting( |
| 218 tab.getContentViewCore().getCurrentRenderProcessId())); | 218 tab.getContentViewCore().getCurrentRenderProcessId())); |
| 219 | 219 |
| 220 CriteriaHelper.pollForCriteria( | 220 CriteriaHelper.pollInstrumentationThread( |
| 221 new Criteria("Renderer crash wasn't noticed by the browser.") { | 221 new Criteria("Renderer crash wasn't noticed by the browser.") { |
| 222 @Override | 222 @Override |
| 223 public boolean isSatisfied() { | 223 public boolean isSatisfied() { |
| 224 return tab.getContentViewCore().getCurrentRenderProcessI
d() == 0; | 224 return tab.getContentViewCore().getCurrentRenderProcessI
d() == 0; |
| 225 } | 225 } |
| 226 }); | 226 }); |
| 227 | 227 |
| 228 // Reload the tab, respawning the renderer. | 228 // Reload the tab, respawning the renderer. |
| 229 getInstrumentation().runOnMainSync(new Runnable() { | 229 getInstrumentation().runOnMainSync(new Runnable() { |
| 230 @Override | 230 @Override |
| 231 public void run() { | 231 public void run() { |
| 232 tab.reload(); | 232 tab.reload(); |
| 233 } | 233 } |
| 234 }); | 234 }); |
| 235 | 235 |
| 236 // Wait until the process is spawned and its visibility is determined. | 236 // Wait until the process is spawned and its visibility is determined. |
| 237 CriteriaHelper.pollForCriteria( | 237 CriteriaHelper.pollInstrumentationThread( |
| 238 new Criteria("Process for the crashed tab was not respawned.") { | 238 new Criteria("Process for the crashed tab was not respawned.") { |
| 239 @Override | 239 @Override |
| 240 public boolean isSatisfied() { | 240 public boolean isSatisfied() { |
| 241 return tab.getContentViewCore().getCurrentRenderProcessI
d() != 0; | 241 return tab.getContentViewCore().getCurrentRenderProcessI
d() != 0; |
| 242 } | 242 } |
| 243 }); | 243 }); |
| 244 | 244 |
| 245 mBindingManager.assertSetInForegroundWasCalled( | 245 mBindingManager.assertSetInForegroundWasCalled( |
| 246 "isInForeground() was not called for the process.", | 246 "isInForeground() was not called for the process.", |
| 247 tab.getContentViewCore().getCurrentRenderProcessId()); | 247 tab.getContentViewCore().getCurrentRenderProcessId()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 325 |
| 326 @Override | 326 @Override |
| 327 public void setUp() throws Exception { | 327 public void setUp() throws Exception { |
| 328 super.setUp(); | 328 super.setUp(); |
| 329 | 329 |
| 330 // Hook in the test binding manager. | 330 // Hook in the test binding manager. |
| 331 mBindingManager = new MockBindingManager(); | 331 mBindingManager = new MockBindingManager(); |
| 332 ChildProcessLauncher.setBindingManagerForTesting(mBindingManager); | 332 ChildProcessLauncher.setBindingManagerForTesting(mBindingManager); |
| 333 } | 333 } |
| 334 } | 334 } |
| OLD | NEW |