From 5b4fb350b7ad20ed2ff6e73bea7467a7a6476723 Mon Sep 17 00:00:00 2001 From: zhuyongyong Date: Thu, 16 Jun 2016 17:32:20 +0800 Subject: [PATCH] [Embeddingapi] Fix canZoomInOnUiThread fail issue Impacted tests(approved): new 0, update 2, delete 0 Unit test platform: Crosswalk Project for Android 21.50.537.0 Unit test result summary: pass 2, fail 0, block 0 BUG=https://crosswalk-project.org/jira/browse/CTS-1769 --- .../org/xwalk/embedding/base/XWalkViewTestBase.java | 11 ++++++++++- .../org/xwalk/embedding/test/v5/XWalkViewTest.java | 12 ++---------- .../embedding/asynctest/v5/XWalkViewTestAsync.java | 11 ++--------- .../org/xwalk/embedding/base/XWalkViewTestBase.java | 11 ++++++++++- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java b/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java index bb93e988a..ef6ab3e12 100644 --- a/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java +++ b/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java @@ -558,7 +558,7 @@ public boolean isSatisfied() { return false; } } - }); + }, WAIT_TIMEOUT_MS, CHECK_INTERVAL); } protected void checkHistoryItemList(XWalkView restoreXWalkView) throws Throwable { @@ -1529,4 +1529,13 @@ public String call() throws Exception { } }); } + + protected void waitForScaleToBecome(final float expectedScale) throws Throwable { + pollOnUiThread(new Callable() { + @Override + public Boolean call() throws Exception { + return expectedScale == getPixelScale(); + } + }); + } } diff --git a/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/test/v5/XWalkViewTest.java b/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/test/v5/XWalkViewTest.java index 6eea34698..d0907cb3f 100644 --- a/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/test/v5/XWalkViewTest.java +++ b/embeddingapi/embedding-api-android-tests/embeddingapi/src/org/xwalk/embedding/test/v5/XWalkViewTest.java @@ -13,7 +13,6 @@ import org.xwalk.embedding.base.XWalkViewTestBase; import android.annotation.SuppressLint; import android.test.suitebuilder.annotation.SmallTest; -import android.test.suitebuilder.annotation.MediumTest; import android.util.Pair; @@ -146,16 +145,10 @@ public void testOnCanZoomInAndOut() { try { final float mPageMinimumScale = 0.5f; String url = "file:///android_asset/zoom.html"; + setUseWideViewPortOnUiThreadByXWalkView(true, mXWalkView); assertFalse("Should not be able to zoom in", canZoomInOnUiThread()); loadUrlSync(url); - pollOnUiThread(new Callable() { - @Override - public Boolean call() throws Exception { - return mPageMinimumScale == mTestHelperBridge.getOnScaleChangedHelper().getNewScale(); - } - }); - - Thread.sleep(500); + waitForScaleToBecome(mPageMinimumScale); assertTrue("Should be able to zoom in", canZoomInOnUiThread()); assertFalse("Should not be able to zoom out", canZoomOutOnUiThread()); @@ -164,7 +157,6 @@ public Boolean call() throws Exception { assertTrue(false); e.printStackTrace(); } catch (Throwable e) { - // TODO: handle exception assertTrue(false); e.printStackTrace(); } diff --git a/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/asynctest/v5/XWalkViewTestAsync.java b/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/asynctest/v5/XWalkViewTestAsync.java index d743922b9..242f7e2fa 100644 --- a/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/asynctest/v5/XWalkViewTestAsync.java +++ b/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/asynctest/v5/XWalkViewTestAsync.java @@ -146,16 +146,10 @@ public void testOnCanZoomInAndOut() { try { final float mPageMinimumScale = 0.5f; String url = "file:///android_asset/zoom.html"; + setUseWideViewPortOnUiThreadByXWalkView(true, mXWalkView); assertFalse("Should not be able to zoom in", canZoomInOnUiThread()); loadUrlSync(url); - pollOnUiThread(new Callable() { - @Override - public Boolean call() throws Exception { - return mPageMinimumScale == mTestHelperBridge.getOnScaleChangedHelper().getNewScale(); - } - }); - - Thread.sleep(500); + waitForScaleToBecome(mPageMinimumScale); assertTrue("Should be able to zoom in", canZoomInOnUiThread()); assertFalse("Should not be able to zoom out", canZoomOutOnUiThread()); @@ -164,7 +158,6 @@ public Boolean call() throws Exception { assertTrue(false); e.printStackTrace(); } catch (Throwable e) { - // TODO: handle exception assertTrue(false); e.printStackTrace(); } diff --git a/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java b/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java index 7b0deceda..a516880f3 100644 --- a/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java +++ b/embeddingapi/embedding-asyncapi-android-tests/embeddingapi/src/org/xwalk/embedding/base/XWalkViewTestBase.java @@ -523,7 +523,7 @@ public boolean isSatisfied() { return false; } } - }); + }, WAIT_TIMEOUT_MS, CHECK_INTERVAL); } protected void checkHistoryItemList(XWalkView restoreXWalkView) throws Throwable { @@ -1497,4 +1497,13 @@ public String call() throws Exception { } }); } + + protected void waitForScaleToBecome(final float expectedScale) throws Throwable { + pollOnUiThread(new Callable() { + @Override + public Boolean call() throws Exception { + return expectedScale == getPixelScale(); + } + }); + } }