| 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 android.content.Context; | 7 import android.content.Context; |
| 8 import android.test.MoreAsserts; | 8 import android.test.MoreAsserts; |
| 9 import android.test.suitebuilder.annotation.LargeTest; | 9 import android.test.suitebuilder.annotation.LargeTest; |
| 10 import android.util.SparseArray; | 10 import android.util.SparseArray; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
romeActivity> { | 46 public class BindingManagerIntegrationTest extends ChromeActivityTestCaseBase<Ch
romeActivity> { |
| 47 | 47 |
| 48 private static class MockBindingManager implements BindingManager { | 48 private static class MockBindingManager implements BindingManager { |
| 49 // Maps pid to the last received visibility state of the renderer. | 49 // Maps pid to the last received visibility state of the renderer. |
| 50 private final SparseBooleanArray mProcessInForegroundMap = new SparseBoo
leanArray(); | 50 private final SparseBooleanArray mProcessInForegroundMap = new SparseBoo
leanArray(); |
| 51 // Maps pid to a string recording calls to setInForeground() and visibil
ityDetermined(). | 51 // Maps pid to a string recording calls to setInForeground() and visibil
ityDetermined(). |
| 52 private final SparseArray<String> mVisibilityCallsMap = new SparseArray<
String>(); | 52 private final SparseArray<String> mVisibilityCallsMap = new SparseArray<
String>(); |
| 53 private boolean mIsReleaseAllModerateBindingsCalled; | 53 private boolean mIsReleaseAllModerateBindingsCalled; |
| 54 | 54 |
| 55 void assertIsInForeground(final int pid) { | 55 void assertIsInForeground(final int pid) { |
| 56 try { | 56 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 57 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 57 @Override |
| 58 @Override | 58 public boolean isSatisfied() { |
| 59 public boolean isSatisfied() { | 59 return mProcessInForegroundMap.get(pid); |
| 60 return mProcessInForegroundMap.get(pid); | 60 } |
| 61 } | 61 }); |
| 62 }); | |
| 63 } catch (InterruptedException ie) { | |
| 64 fail(); | |
| 65 } | |
| 66 } | 62 } |
| 67 | 63 |
| 68 void assertIsInBackground(final int pid) { | 64 void assertIsInBackground(final int pid) { |
| 69 try { | 65 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 70 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 66 @Override |
| 71 @Override | 67 public boolean isSatisfied() { |
| 72 public boolean isSatisfied() { | 68 return !mProcessInForegroundMap.get(pid); |
| 73 return !mProcessInForegroundMap.get(pid); | 69 } |
| 74 } | 70 }); |
| 75 }); | |
| 76 } catch (InterruptedException ie) { | |
| 77 fail(); | |
| 78 } | |
| 79 } | 71 } |
| 80 | 72 |
| 81 void assertSetInForegroundWasCalled(String message, final int pid) { | 73 void assertSetInForegroundWasCalled(String message, final int pid) { |
| 82 try { | 74 CriteriaHelper.pollInstrumentationThread(new Criteria(message) { |
| 83 CriteriaHelper.pollInstrumentationThread(new Criteria(message) { | 75 @Override |
| 84 @Override | 76 public boolean isSatisfied() { |
| 85 public boolean isSatisfied() { | 77 return mProcessInForegroundMap.indexOfKey(pid) >= 0; |
| 86 return mProcessInForegroundMap.indexOfKey(pid) >= 0; | 78 } |
| 87 } | 79 }); |
| 88 }); | |
| 89 } catch (InterruptedException ie) { | |
| 90 fail(); | |
| 91 } | |
| 92 } | 80 } |
| 93 | 81 |
| 94 void assertIsReleaseAllModerateBindingsCalled() { | 82 void assertIsReleaseAllModerateBindingsCalled() { |
| 95 try { | 83 CriteriaHelper.pollInstrumentationThread(new Criteria() { |
| 96 CriteriaHelper.pollInstrumentationThread(new Criteria() { | 84 @Override |
| 97 @Override | 85 public boolean isSatisfied() { |
| 98 public boolean isSatisfied() { | 86 return mIsReleaseAllModerateBindingsCalled; |
| 99 return mIsReleaseAllModerateBindingsCalled; | 87 } |
| 100 } | 88 }); |
| 101 }); | |
| 102 } catch (InterruptedException ie) { | |
| 103 fail(); | |
| 104 } | |
| 105 } | 89 } |
| 106 | 90 |
| 107 String getVisibilityCalls(int pid) { | 91 String getVisibilityCalls(int pid) { |
| 108 synchronized (mVisibilityCallsMap) { | 92 synchronized (mVisibilityCallsMap) { |
| 109 return mVisibilityCallsMap.get(pid); | 93 return mVisibilityCallsMap.get(pid); |
| 110 } | 94 } |
| 111 } | 95 } |
| 112 | 96 |
| 113 boolean isReleaseAllModerateBindingsCalled() { | 97 boolean isReleaseAllModerateBindingsCalled() { |
| 114 return mIsReleaseAllModerateBindingsCalled; | 98 return mIsReleaseAllModerateBindingsCalled; |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 super.tearDown(); | 641 super.tearDown(); |
| 658 } | 642 } |
| 659 | 643 |
| 660 /** | 644 /** |
| 661 * @return the index of the given tab in the current tab model | 645 * @return the index of the given tab in the current tab model |
| 662 */ | 646 */ |
| 663 private int indexOf(Tab tab) { | 647 private int indexOf(Tab tab) { |
| 664 return getActivity().getCurrentTabModel().indexOf(tab); | 648 return getActivity().getCurrentTabModel().indexOf(tab); |
| 665 } | 649 } |
| 666 } | 650 } |
| OLD | NEW |