Commit 967ffdc9 authored by mnaganov@chromium.org's avatar mnaganov@chromium.org

[Android WebView] Unflake AwViewportTest#testInitialScaleClobberQuirk

Make the test resilient to spurious page scale changes that
can occur after calling WebView.setInitialScale.

Also, update AwViewportTest#testNoUserScalableQuirk to wait
for page scale change events instead of page scale polling.

BUG=319353

Review URL: https://codereview.chromium.org/71203004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235671 0039d316-1c4b-4281-b951-d872f2087c98
parent 291fe0d6
...@@ -223,12 +223,8 @@ public class AwViewportTest extends AwTestBase { ...@@ -223,12 +223,8 @@ public class AwViewportTest extends AwTestBase {
assertEquals(pageWidth, width); assertEquals(pageWidth, width);
} }
/* @MediumTest
* @MediumTest @Feature({"AndroidWebView"})
* @Feature({"AndroidWebView"})
* http://crbug.com/319353
*/
@DisabledTest
public void testInitialScaleClobberQuirk() throws Throwable { public void testInitialScaleClobberQuirk() throws Throwable {
final TestAwContentsClient contentClient = new TestAwContentsClient(); final TestAwContentsClient contentClient = new TestAwContentsClient();
final AwTestContainerView testContainerView = final AwTestContainerView testContainerView =
...@@ -237,30 +233,28 @@ public class AwViewportTest extends AwTestBase { ...@@ -237,30 +233,28 @@ public class AwViewportTest extends AwTestBase {
AwSettings settings = getAwSettingsOnUiThread(awContents); AwSettings settings = getAwSettingsOnUiThread(awContents);
CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper(); CallbackHelper onPageFinishedHelper = contentClient.getOnPageFinishedHelper();
final String pageScale4 = "<html><head>" + final String pageTemplate = "<html><head>" +
"<meta name='viewport' content='initial-scale=4' />" + "<meta name='viewport' content='initial-scale=%d' />" +
"</head><body>" +
"<div style='width:10000px;height:200px'>A big div</div>" +
"</body></html>";
final String page = "<html><head>" +
"<meta name='viewport' content='initial-scale=1' />" +
"</head><body>" + "</head><body>" +
"<div style='width:10000px;height:200px'>A big div</div>" + "<div style='width:10000px;height:200px'>A big div</div>" +
"</body></html>"; "</body></html>";
final String pageScale4 = String.format(pageTemplate, 4);
final String page = String.format(pageTemplate, 1);
// Page scale updates are asynchronous. There is an issue that we can't // Page scale updates are asynchronous. There is an issue that we can't
// reliably check, whether the scale as NOT changed (i.e. remains to be 1.0). // reliably check, whether the scale as NOT changed (i.e. remains to be 1.0).
// So we first change the scale to some non-default value, and then wait // So we first change the scale to some non-default value, and then wait
// until it gets back to 1.0. // until it gets back to 1.0.
float previousScale = getPixelScaleOnUiThread(awContents); int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount();
loadDataSync(awContents, onPageFinishedHelper, pageScale4, "text/html", false); loadDataSync(awContents, onPageFinishedHelper, pageScale4, "text/html", false);
assertTrue(waitForScaleChange(previousScale, awContents)); contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
previousScale = getPixelScaleOnUiThread(awContents); assertEquals(4.0f, getScaleOnUiThread(awContents));
// The following call to set initial scale will be ignored. // The following call to set initial scale will be ignored. However, a temporary
// page scale change may occur, and this makes the usual onScaleChanged-based workflow
// flaky. So instead, we are just polling the scale until it becomes 1.0.
settings.setInitialPageScale(50); settings.setInitialPageScale(50);
loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
assertTrue(waitForScaleChange(previousScale, awContents)); assertTrue(waitUntilScaleBecomes(1.0f, awContents));
assertEquals(1.0f, getScaleOnUiThread(awContents));
} }
@MediumTest @MediumTest
...@@ -288,25 +282,26 @@ public class AwViewportTest extends AwTestBase { ...@@ -288,25 +282,26 @@ public class AwViewportTest extends AwTestBase {
// reliably check, whether the scale as NOT changed (i.e. remains to be 1.0). // reliably check, whether the scale as NOT changed (i.e. remains to be 1.0).
// So we first change the scale to some non-default value, and then wait // So we first change the scale to some non-default value, and then wait
// until it gets back to 1.0. // until it gets back to 1.0.
float previousScale = getPixelScaleOnUiThread(awContents); int onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount();
loadDataSync(awContents, onPageFinishedHelper, pageScale4, "text/html", false); loadDataSync(awContents, onPageFinishedHelper, pageScale4, "text/html", false);
assertTrue(waitForScaleChange(previousScale, awContents)); contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
previousScale = getPixelScaleOnUiThread(awContents); assertEquals(4.0f, getScaleOnUiThread(awContents));
onScaleChangedCallCount = contentClient.getOnScaleChangedHelper().getCallCount();
loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false); loadDataSync(awContents, onPageFinishedHelper, page, "text/html", false);
assertTrue(waitForScaleChange(previousScale, awContents)); contentClient.getOnScaleChangedHelper().waitForCallback(onScaleChangedCallCount);
assertEquals(1.0f, getScaleOnUiThread(awContents)); assertEquals(1.0f, getScaleOnUiThread(awContents));
} }
private boolean waitForScaleChange(final float previousScale, final AwContents awContents) private boolean waitUntilScaleBecomes(final float targetScale, final AwContents awContents)
throws Throwable { throws Throwable {
return CriteriaHelper.pollForCriteria(new Criteria() { return CriteriaHelper.pollForCriteria(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return previousScale != getPixelScaleOnUiThread(awContents); return targetScale == getScaleOnUiThread(awContents);
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
fail("Failed to getPixelScaleOnUiThread: " + t.toString()); fail("Failed to getScaleOnUiThread: " + t.toString());
return false; return false;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment