| 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.ViewGroup.LayoutParams; | 9 import android.view.ViewGroup.LayoutParams; |
| 10 import android.widget.LinearLayout; | 10 import android.widget.LinearLayout; |
| 11 | 11 |
| 12 import org.chromium.android_webview.AwContents; | 12 import org.chromium.android_webview.AwContents; |
| 13 import org.chromium.android_webview.AwContentsClient; | 13 import org.chromium.android_webview.AwContentsClient; |
| 14 import org.chromium.android_webview.AwLayoutSizer; | 14 import org.chromium.android_webview.AwLayoutSizer; |
| 15 import org.chromium.android_webview.test.util.CommonResources; | 15 import org.chromium.android_webview.test.util.CommonResources; |
| 16 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
| 17 import org.chromium.content.browser.test.util.CallbackHelper; | 17 import org.chromium.content.browser.test.util.CallbackHelper; |
| 18 import org.chromium.ui.gfx.DeviceDisplayInfo; | 18 import org.chromium.ui.gfx.DeviceDisplayInfo; |
| 19 | 19 |
| 20 import java.util.concurrent.atomic.AtomicReference; | 20 import java.util.concurrent.atomic.AtomicReference; |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Tests for certain edge cases related to integrating with the Android view sys
tem. | 23 * Tests for certain edge cases related to integrating with the Android view sys
tem. |
| 24 */ | 24 */ |
| 25 public class AndroidViewIntegrationTest extends AwTestBase { | 25 public class AndroidViewIntegrationTest extends AwTestBase { |
| 26 final int CONTENT_SIZE_CHANGE_STABILITY_TIMEOUT_MS = 1000; | 26 private static final int CONTENT_SIZE_CHANGE_STABILITY_TIMEOUT_MS = 1000; |
| 27 | 27 |
| 28 private static class OnContentSizeChangedHelper extends CallbackHelper { | 28 private static class OnContentSizeChangedHelper extends CallbackHelper { |
| 29 private int mWidth; | 29 private int mWidth; |
| 30 private int mHeight; | 30 private int mHeight; |
| 31 | 31 |
| 32 public int getWidth() { | 32 public int getWidth() { |
| 33 assert getCallCount() > 0; | 33 assert getCallCount() > 0; |
| 34 return mWidth; | 34 return mWidth; |
| 35 } | 35 } |
| 36 | 36 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 @Override | 69 @Override |
| 70 protected TestDependencyFactory createTestDependencyFactory() { | 70 protected TestDependencyFactory createTestDependencyFactory() { |
| 71 return new TestDependencyFactory() { | 71 return new TestDependencyFactory() { |
| 72 @Override | 72 @Override |
| 73 public AwLayoutSizer createLayoutSizer() { | 73 public AwLayoutSizer createLayoutSizer() { |
| 74 return new TestAwLayoutSizer(); | 74 return new TestAwLayoutSizer(); |
| 75 } | 75 } |
| 76 }; | 76 }; |
| 77 } | 77 } |
| 78 | 78 |
| 79 final LinearLayout.LayoutParams wrapContentLayoutParams = | 79 final LinearLayout.LayoutParams mWrapContentLayoutParams = |
| 80 new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WR
AP_CONTENT); | 80 new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WR
AP_CONTENT); |
| 81 | 81 |
| 82 private AwTestContainerView createCustomTestContainerViewOnMainSync( | 82 private AwTestContainerView createCustomTestContainerViewOnMainSync( |
| 83 final AwContentsClient awContentsClient, final int visibility) throw
s Exception { | 83 final AwContentsClient awContentsClient, final int visibility) throw
s Exception { |
| 84 final AtomicReference<AwTestContainerView> testContainerView = | 84 final AtomicReference<AwTestContainerView> testContainerView = |
| 85 new AtomicReference<AwTestContainerView>(); | 85 new AtomicReference<AwTestContainerView>(); |
| 86 getInstrumentation().runOnMainSync(new Runnable() { | 86 getInstrumentation().runOnMainSync(new Runnable() { |
| 87 @Override | 87 @Override |
| 88 public void run() { | 88 public void run() { |
| 89 testContainerView.set(createAwTestContainerView(awContentsClient
)); | 89 testContainerView.set(createAwTestContainerView(awContentsClient
)); |
| 90 testContainerView.get().setLayoutParams(wrapContentLayoutParams)
; | 90 testContainerView.get().setLayoutParams(mWrapContentLayoutParams
); |
| 91 testContainerView.get().setVisibility(visibility); | 91 testContainerView.get().setVisibility(visibility); |
| 92 } | 92 } |
| 93 }); | 93 }); |
| 94 return testContainerView.get(); | 94 return testContainerView.get(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 private AwTestContainerView createDetachedTestContainerViewOnMainSync( | 97 private AwTestContainerView createDetachedTestContainerViewOnMainSync( |
| 98 final AwContentsClient awContentsClient) { | 98 final AwContentsClient awContentsClient) { |
| 99 final AtomicReference<AwTestContainerView> testContainerView = | 99 final AtomicReference<AwTestContainerView> testContainerView = |
| 100 new AtomicReference<AwTestContainerView>(); | 100 new AtomicReference<AwTestContainerView>(); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 mOnContentSizeChangedHelper.waitForCallback(contentSizeChangeCallCount); | 399 mOnContentSizeChangedHelper.waitForCallback(contentSizeChangeCallCount); |
| 400 | 400 |
| 401 // As a result of calling the onSizeChanged method the layout size shoul
d be updated to | 401 // As a result of calling the onSizeChanged method the layout size shoul
d be updated to |
| 402 // match the width of the webview and the text we previously loaded shou
ld reflow making the | 402 // match the width of the webview and the text we previously loaded shou
ld reflow making the |
| 403 // contents width match the WebView width. | 403 // contents width match the WebView width. |
| 404 assertEquals(expectedWidthCss, mOnContentSizeChangedHelper.getWidth()); | 404 assertEquals(expectedWidthCss, mOnContentSizeChangedHelper.getWidth()); |
| 405 assertTrue(mOnContentSizeChangedHelper.getHeight() < narrowLayoutHeight)
; | 405 assertTrue(mOnContentSizeChangedHelper.getHeight() < narrowLayoutHeight)
; |
| 406 assertTrue(mOnContentSizeChangedHelper.getHeight() > 0); | 406 assertTrue(mOnContentSizeChangedHelper.getHeight() > 0); |
| 407 } | 407 } |
| 408 } | 408 } |
| OLD | NEW |