use of org.apache.cordova.CordovaWebView in project cordova-android by apache.
the class BackButtonMultipageTest method testViaLoadUrl.
@Test
public void testViaLoadUrl() throws Throwable {
final CordovaWebView webInterface = mActivity.getWebInterface();
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
webInterface.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", mActivity.onPageFinishedUrl.take());
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
}
});
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take());
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertTrue(webInterface.backHistory());
}
});
assertEquals(START_URL, mActivity.onPageFinishedUrl.take());
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
assertFalse(webInterface.backHistory());
}
});
}
use of org.apache.cordova.CordovaWebView in project cordova-android by apache.
the class MessageChannelMultipageTest method testThatCachedCallbackIdIsValid.
//test that after a page load the cached callback id and the live callback id match
//this is to prevent a regression
//the issue was that CordovaWebViewImpl's cached instance of CoreAndroid would become stale on page load
//this is because the cached instance was not being cleared when the pluginManager was reset on page load
//the plugin manager would get a new instance which would be updated with a new callback id
//the cached instance's message channel callback id would become stale
//effectively this caused message channel events to not be delivered
@Test
public void testThatCachedCallbackIdIsValid() throws Throwable {
final CordovaWebView cordovaWebView = testActivity.getWebInterface();
Class cordovaWebViewImpl = CordovaWebViewImpl.class;
//send a test event - this initializes cordovaWebViewImpl.appPlugin (the cached instance of CoreAndroid)
Method method = cordovaWebViewImpl.getDeclaredMethod("sendJavascriptEvent", String.class);
method.setAccessible(true);
method.invoke(cordovaWebView, "testEvent");
sleep(1000);
//load a page - this resets the plugin manager and nulls cordovaWebViewImpl.appPlugin
//(previously this resets plugin manager but did not null cordovaWebViewImpl.appPlugin, leading to the issue)
mActivityRule.runOnUiThread(new Runnable() {
public void run() {
cordovaWebView.loadUrl(START_URL);
}
});
assertEquals(START_URL, testActivity.onPageFinishedUrl.take());
//send a test event - this initializes cordovaWebViewImpl.appPlugin (the cached instance of CoreAndroid)
method.invoke(cordovaWebView, "testEvent");
sleep(1000);
//get reference to package protected class CoreAndroid
Class coreAndroid = Class.forName("org.apache.cordova.CoreAndroid");
//get cached CoreAndroid
Field appPluginField = cordovaWebViewImpl.getDeclaredField("appPlugin");
appPluginField.setAccessible(true);
Object cachedAppPlugin = appPluginField.get(cordovaWebView);
//get cached CallbackContext
Field messageChannelField = coreAndroid.getDeclaredField("messageChannel");
messageChannelField.setAccessible(true);
CallbackContext cachedCallbackContext = (CallbackContext) messageChannelField.get(cachedAppPlugin);
//get live CoreAndroid
PluginManager pluginManager = cordovaWebView.getPluginManager();
Field coreAndroidPluginNameField = coreAndroid.getField("PLUGIN_NAME");
String coreAndroidPluginName = (String) coreAndroidPluginNameField.get(null);
Object liveAppPlugin = pluginManager.getPlugin(coreAndroidPluginName);
//get live CallbackContext
CallbackContext liveCallbackContext = (CallbackContext) messageChannelField.get(liveAppPlugin);
//get callback id from live callbackcontext
String liveCallbackId = (liveCallbackContext != null) ? liveCallbackContext.getCallbackId() : null;
//get callback id from cached callbackcontext
String cachedCallbackId = (cachedCallbackContext != null) ? cachedCallbackContext.getCallbackId() : null;
//verify that the live message channel has been initialized
assertNotNull(liveCallbackId);
//verify that the cached message channel and the live message channel have the same id
assertEquals(liveCallbackId, cachedCallbackId);
}
use of org.apache.cordova.CordovaWebView in project cordova-android by apache.
the class StandardActivityTest method checkBackgroundIntentCheck.
@Test
public void checkBackgroundIntentCheck() {
StandardActivity activity = (StandardActivity) mActivityRule.getActivity();
final SystemWebView webView = (SystemWebView) activity.getWindow().getCurrentFocus();
CordovaWebView webInterface = webView.getCordovaWebView();
CordovaPreferences prefs = webInterface.getPreferences();
assertFalse(prefs.getInteger("backgroundcolor", Color.BLACK) == Color.GREEN);
}
use of org.apache.cordova.CordovaWebView in project cordova-android-chromeview by thedracle.
the class userwebview method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
testViewClient = new TestViewClient(this);
testChromeClient = new TestChromeClient(this);
super.init(new CordovaWebView(this), new TestViewClient(this), new TestChromeClient(this));
super.loadUrl("file:///android_asset/www/userwebview/index.html");
}
Aggregations