-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
-import java.util.concurrent.Callable;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
-import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* AwContents tests.
*/
public class AwContentsTest extends AwTestBase {
- public static class OnDownloadStartHelper extends CallbackHelper {
+ private static class OnDownloadStartHelper extends CallbackHelper {
String mUrl;
String mUserAgent;
String mContentDisposition;
System.gc();
- assertTrue(pollOnUiThread(new Callable<Boolean>() {
+ pollOnUiThread(new Callable<Boolean>() {
@Override
public Boolean call() {
return AwContents.getNativeInstanceCount() <= MAX_IDLE_INSTANCES;
}
- }));
+ });
for (int i = 0; i < REPETITIONS; ++i) {
for (int j = 0; j < CONCURRENT_INSTANCES; ++j) {
AwTestContainerView view = createAwTestContainerViewOnMainSync(mContentsClient);
System.gc();
- assertTrue(pollOnUiThread(new Callable<Boolean>() {
+ pollOnUiThread(new Callable<Boolean>() {
@Override
public Boolean call() {
return AwContents.getNativeInstanceCount() <= MAX_IDLE_INSTANCES;
}
- }));
+ });
}
private int callDocumentHasImagesSync(final AwContents awContents)
awContents.documentHasImages(msg);
}
});
- assertTrue(s.tryAcquire(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS));
+ assertTrue(s.tryAcquire(WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS));
int result = val.get();
return result;
}
runTestOnUiThread(new Runnable() {
@Override
public void run() {
- for (int i = 0; i < 10; ++i) {
- awContents.clearCache(true);
- }
+ for (int i = 0; i < 10; ++i) {
+ awContents.clearCache(true);
+ }
}
});
}
- private static final long TEST_TIMEOUT = 20000L;
- private static final int CHECK_INTERVAL = 100;
-
@SmallTest
@Feature({"AndroidWebView"})
public void testGetFavicon() throws Throwable {
getAwSettingsOnUiThread(awContents).setImagesEnabled(true);
loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl);
- assertTrue(pollOnUiThread(new Callable<Boolean>() {
+ pollOnUiThread(new Callable<Boolean>() {
@Override
public Boolean call() {
return awContents.getFavicon() != null &&
!awContents.getFavicon().sameAs(defaultFavicon);
}
- }));
+ });
final Object originalFaviconSource = (new URL(faviconUrl)).getContent();
final Bitmap originalFavicon =
- BitmapFactory.decodeStream((InputStream)originalFaviconSource);
+ BitmapFactory.decodeStream((InputStream) originalFaviconSource);
assertNotNull(originalFavicon);
assertTrue(awContents.getFavicon().sameAs(originalFavicon));
SCRIPT));
// Forcing "offline".
- awContents.setNetworkAvailable(false);
+ setNetworkAvailableOnUiThread(awContents, false);
assertEquals("false", executeJavaScriptAndWaitForResult(awContents, mContentsClient,
SCRIPT));
// Forcing "online".
- awContents.setNetworkAvailable(true);
+ setNetworkAvailableOnUiThread(awContents, true);
assertEquals("true", executeJavaScriptAndWaitForResult(awContents, mContentsClient,
SCRIPT));
}
public void run() {
mCallbackHelper.notifyCalled();
}
- };
+ }
@Feature({"AndroidWebView", "JavaBridge"})
@SmallTest
"javascript:window.bridge.run();");
}
});
- callback.waitForCallback(0, 1, 20, TimeUnit.SECONDS);
+ callback.waitForCallback(0, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
+
+ @Feature({"AndroidWebView"})
+ @SmallTest
+ public void testEscapingOfErrorPage() throws Throwable {
+ AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient);
+ AwContents awContents = testView.getAwContents();
+ String SCRIPT = "window.failed == true";
+
+ enableJavaScriptOnUiThread(awContents);
+ CallbackHelper onPageFinishedHelper = mContentsClient.getOnPageFinishedHelper();
+ int currentCallCount = onPageFinishedHelper.getCallCount();
+ loadUrlAsync(awContents,
+ "file:///file-that-does-not-exist#<script>window.failed = true;</script>");
+ // We must wait for two onPageFinished callbacks. One for the original failing URL, and
+ // one for the error page that we then display to the user.
+ onPageFinishedHelper.waitForCallback(currentCallCount, 2, WAIT_TIMEOUT_MS,
+ TimeUnit.MILLISECONDS);
+
+ assertEquals("false", executeJavaScriptAndWaitForResult(awContents, mContentsClient,
+ SCRIPT));
+ }
+
}