Search in sources :

Example 6 with CordovaWebView

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());
        }
    });
}
Also used : CordovaWebView(org.apache.cordova.CordovaWebView) Test(org.junit.Test)

Example 7 with CordovaWebView

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);
}
Also used : PluginManager(org.apache.cordova.PluginManager) Field(java.lang.reflect.Field) CallbackContext(org.apache.cordova.CallbackContext) CordovaWebView(org.apache.cordova.CordovaWebView) Method(java.lang.reflect.Method) CordovaWebViewImpl(org.apache.cordova.CordovaWebViewImpl) Test(org.junit.Test)

Example 8 with CordovaWebView

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);
}
Also used : SystemWebView(org.apache.cordova.engine.SystemWebView) CordovaWebView(org.apache.cordova.CordovaWebView) CordovaPreferences(org.apache.cordova.CordovaPreferences) Test(org.junit.Test)

Example 9 with CordovaWebView

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");
}
Also used : CordovaWebView(org.apache.cordova.CordovaWebView)

Aggregations

CordovaWebView (org.apache.cordova.CordovaWebView)9 Test (org.junit.Test)6 SuppressLint (android.annotation.SuppressLint)1 Resources (android.content.res.Resources)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 LayoutParams (android.view.WindowManager.LayoutParams)1 WebSettings (android.webkit.WebSettings)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 RelativeLayout (android.widget.RelativeLayout)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 CallbackContext (org.apache.cordova.CallbackContext)1