| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.android_webview.test; | 5 package org.chromium.android_webview.test; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
| 8 import android.view.View; | 8 import android.view.View; |
| 9 import android.view.View.MeasureSpec; | 9 import android.view.View.MeasureSpec; |
| 10 import android.view.ViewGroup.LayoutParams; | 10 import android.view.ViewGroup.LayoutParams; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 mOnContentSizeChangedHelper.onContentSizeChanged(widthCss, heightCss
); | 58 mOnContentSizeChangedHelper.onContentSizeChanged(widthCss, heightCss
); |
| 59 } | 59 } |
| 60 | 60 |
| 61 @Override | 61 @Override |
| 62 public void onPageScaleChanged(double pageScaleFactor) { | 62 public void onPageScaleChanged(double pageScaleFactor) { |
| 63 super.onPageScaleChanged(pageScaleFactor); | 63 super.onPageScaleChanged(pageScaleFactor); |
| 64 mOnPageScaleChangedHelper.notifyCalled(); | 64 mOnPageScaleChangedHelper.notifyCalled(); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 private class DependencyFactory extends TestDependencyFactory { | 68 @Override |
| 69 @Override | 69 protected TestDependencyFactory createTestDependencyFactory() { |
| 70 public AwLayoutSizer createLayoutSizer() { | 70 return new TestDependencyFactory() { |
| 71 return new TestAwLayoutSizer(); | 71 @Override |
| 72 } | 72 public AwLayoutSizer createLayoutSizer() { |
| 73 return new TestAwLayoutSizer(); |
| 74 } |
| 75 }; |
| 73 } | 76 } |
| 74 | 77 |
| 75 final LinearLayout.LayoutParams wrapContentLayoutParams = | 78 final LinearLayout.LayoutParams wrapContentLayoutParams = |
| 76 new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WR
AP_CONTENT); | 79 new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WR
AP_CONTENT); |
| 77 | 80 |
| 78 private AwTestContainerView createCustomTestContainerViewOnMainSync( | 81 private AwTestContainerView createCustomTestContainerViewOnMainSync( |
| 79 final AwContentsClient awContentsClient, final int visibility) throw
s Exception { | 82 final AwContentsClient awContentsClient, final int visibility) throw
s Exception { |
| 80 final AtomicReference<AwTestContainerView> testContainerView = | 83 final AtomicReference<AwTestContainerView> testContainerView = |
| 81 new AtomicReference<AwTestContainerView>(); | 84 new AtomicReference<AwTestContainerView>(); |
| 82 getInstrumentation().runOnMainSync(new Runnable() { | 85 getInstrumentation().runOnMainSync(new Runnable() { |
| 83 @Override | 86 @Override |
| 84 public void run() { | 87 public void run() { |
| 85 testContainerView.set(createAwTestContainerView(awContentsClient
, | 88 testContainerView.set(createAwTestContainerView(awContentsClient
)); |
| 86 new DependencyFactory())); | |
| 87 testContainerView.get().setLayoutParams(wrapContentLayoutParams)
; | 89 testContainerView.get().setLayoutParams(wrapContentLayoutParams)
; |
| 88 testContainerView.get().setVisibility(visibility); | 90 testContainerView.get().setVisibility(visibility); |
| 89 } | 91 } |
| 90 }); | 92 }); |
| 91 return testContainerView.get(); | 93 return testContainerView.get(); |
| 92 } | 94 } |
| 93 | 95 |
| 94 private AwTestContainerView createDetachedTestContainerViewOnMainSync( | 96 private AwTestContainerView createDetachedTestContainerViewOnMainSync( |
| 95 final AwContentsClient awContentsClient) { | 97 final AwContentsClient awContentsClient) { |
| 96 final AtomicReference<AwTestContainerView> testContainerView = | 98 final AtomicReference<AwTestContainerView> testContainerView = |
| 97 new AtomicReference<AwTestContainerView>(); | 99 new AtomicReference<AwTestContainerView>(); |
| 98 getInstrumentation().runOnMainSync(new Runnable() { | 100 getInstrumentation().runOnMainSync(new Runnable() { |
| 99 @Override | 101 @Override |
| 100 public void run() { | 102 public void run() { |
| 101 testContainerView.set(createDetachedAwTestContainerView(awConten
tsClient, | 103 testContainerView.set(createDetachedAwTestContainerView(awConten
tsClient)); |
| 102 new DependencyFactory())); | |
| 103 } | 104 } |
| 104 }); | 105 }); |
| 105 return testContainerView.get(); | 106 return testContainerView.get(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 private void assertZeroHeight(final AwTestContainerView testContainerView) t
hrows Throwable { | 109 private void assertZeroHeight(final AwTestContainerView testContainerView) t
hrows Throwable { |
| 109 // Make sure the test isn't broken by the view having a non-zero height. | 110 // Make sure the test isn't broken by the view having a non-zero height. |
| 110 getInstrumentation().runOnMainSync(new Runnable() { | 111 getInstrumentation().runOnMainSync(new Runnable() { |
| 111 @Override | 112 @Override |
| 112 public void run() { | 113 public void run() { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 assertZeroHeight(testContainerView); | 183 assertZeroHeight(testContainerView); |
| 183 | 184 |
| 184 final int contentSizeChangeCallCount = mOnContentSizeChangedHelper.getCa
llCount(); | 185 final int contentSizeChangeCallCount = mOnContentSizeChangedHelper.getCa
llCount(); |
| 185 final int pageScaleChangeCallCount = mOnPageScaleChangedHelper.getCallCo
unt(); | 186 final int pageScaleChangeCallCount = mOnPageScaleChangedHelper.getCallCo
unt(); |
| 186 loadUrlAsync(testContainerView.getAwContents(), CommonResources.ABOUT_HT
ML); | 187 loadUrlAsync(testContainerView.getAwContents(), CommonResources.ABOUT_HT
ML); |
| 187 mOnPageScaleChangedHelper.waitForCallback(pageScaleChangeCallCount); | 188 mOnPageScaleChangedHelper.waitForCallback(pageScaleChangeCallCount); |
| 188 mOnContentSizeChangedHelper.waitForCallback(contentSizeChangeCallCount); | 189 mOnContentSizeChangedHelper.waitForCallback(contentSizeChangeCallCount); |
| 189 assertTrue(mOnContentSizeChangedHelper.getHeight() > 0); | 190 assertTrue(mOnContentSizeChangedHelper.getHeight() > 0); |
| 190 } | 191 } |
| 191 } | 192 } |
| OLD | NEW |