This source file includes following definitions.
- setUp
- Feature
- testFindAddress
- Feature
- testEnableDisablePlatformNotifications
package org.chromium.android_webview.test;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Proxy;
import android.test.mock.MockContext;
import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.android_webview.AwContents;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.ContentViewStatics;
import org.chromium.net.ProxyChangeListener;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
public class ContentViewMiscTest extends AwTestBase {
private TestAwContentsClient mContentsClient;
private AwContents mAwContents;
private ContentViewCore mContentViewCore;
@Override
public void setUp() throws Exception {
super.setUp();
mContentsClient = new TestAwContentsClient();
final AwTestContainerView testContainerView =
createAwTestContainerViewOnMainSync(mContentsClient);
mAwContents = testContainerView.getAwContents();
mContentViewCore = testContainerView.getContentViewCore();
}
@SmallTest
@Feature({"AndroidWebView"})
public void testFindAddress() {
assertNull(ContentViewStatics.findAddress("This is some random text"));
String googleAddr = "1600 Amphitheatre Pkwy, Mountain View, CA 94043";
String testString = "Address: " + googleAddr + " in a string";
assertEquals(googleAddr, ContentViewStatics.findAddress(testString));
}
@SmallTest
@Feature({"AndroidWebView"})
public void testEnableDisablePlatformNotifications() {
final AtomicReference<BroadcastReceiver> receiverRef =
new AtomicReference<BroadcastReceiver>();
final MockContext appContext = new MockContext() {
@Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
receiverRef.set(receiver);
return null;
}
};
final MockContext context = new MockContext() {
@Override
public Context getApplicationContext() {
return appContext;
}
};
final AtomicBoolean proxyChanged = new AtomicBoolean();
final ProxyChangeListener.Delegate delegate = new ProxyChangeListener.Delegate() {
@Override
public void proxySettingsChanged() {
proxyChanged.set(true);
}
};
Intent intent = new Intent();
intent.setAction(Proxy.PROXY_CHANGE_ACTION);
ProxyChangeListener listener = ProxyChangeListener.create(context);
listener.setDelegateForTesting(delegate);
listener.start(0);
proxyChanged.set(false);
receiverRef.get().onReceive(context, intent);
assertEquals(true, proxyChanged.get());
proxyChanged.set(false);
ContentViewStatics.disablePlatformNotifications();
receiverRef.get().onReceive(context, intent);
assertEquals(false, proxyChanged.get());
ContentViewStatics.enablePlatformNotifications();
receiverRef.get().onReceive(context, intent);
assertEquals(true, proxyChanged.get());
}
}