diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c17a9b2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,26 @@ +language: android +jdk: oraclejdk8 +android: + components: + - platform-tools + - tools + + # The BuildTools version used by your project + - build-tools-25.0.0 + + + # The SDK version used to compile your project + - android-23 + + # Support library + - extra-android-support + - extra-android-m2repository + - sys-img-x86_64-android-22 + licenses: + - 'android-sdk-preview-license-52d11cd2' + - 'android-sdk-license-.+' + - 'google-gdk-license-.+' + +script: + - android list target + diff --git a/app/build.gradle b/app/build.gradle index 5be5d2c..c9a39c1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,6 +16,12 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + debug { + testCoverageEnabled true + } + } + testOptions { + unitTests.returnDefaultValues = true } } diff --git a/app/src/androidTest/java/wendu/jsbdemo/CallJavascriptActivityTest.java b/app/src/androidTest/java/wendu/jsbdemo/CallJavascriptActivityTest.java new file mode 100644 index 0000000..0224e03 --- /dev/null +++ b/app/src/androidTest/java/wendu/jsbdemo/CallJavascriptActivityTest.java @@ -0,0 +1,58 @@ +package wendu.jsbdemo; + +import android.os.SystemClock; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; +import android.test.ActivityInstrumentationTestCase2; +import android.view.View; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import wendu.dsbridge.DWebView; +import wendu.dsbridge.OnReturnValue; + +/** + * Created by du on 2018/2/5. + */ +@RunWith (AndroidJUnit4.class) +public class CallJavascriptActivityTest extends ActivityInstrumentationTestCase2 { + + private DWebView dWebView; + + public CallJavascriptActivityTest() { + super(CallJavascriptActivity.class); + } + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + // Injecting the Instrumentation instance is required + // for your test to run with AndroidJUnitRunner. + injectInstrumentation(InstrumentationRegistry.getInstrumentation()); + CallJavascriptActivity activity=getActivity(); + dWebView= (DWebView) getActivity().findViewById(R.id.webview); + //dWebView.loadUrl("file:///android_asset/js-call-native.html"); + DWebView.setWebContentsDebuggingEnabled(true); + } + + @After + public void tearDown() throws Exception { + + } + + @Test + public void onClick(View v) throws Exception { + dWebView.callHandler("addValue", new Object[]{3, 4}, new OnReturnValue() { + @Override + public void onValue(Integer retValue) { + assertEquals(7,retValue.intValue()); + } + }); + SystemClock.sleep(5000); + } + +} \ No newline at end of file diff --git a/app/src/main/assets/js-call-native.html b/app/src/main/assets/js-call-native.html index 2cebf69..e59ddc6 100644 --- a/app/src/main/assets/js-call-native.html +++ b/app/src/main/assets/js-call-native.html @@ -92,6 +92,7 @@ function callProgress() { dsBridge.call("callProgress", function (value) { + if(value==0) value=""; document.getElementById("progress").innerText = value }) } diff --git a/app/src/main/java/wendu/jsbdemo/JsApi.java b/app/src/main/java/wendu/jsbdemo/JsApi.java index fdb8bcd..74bb94d 100644 --- a/app/src/main/java/wendu/jsbdemo/JsApi.java +++ b/app/src/main/java/wendu/jsbdemo/JsApi.java @@ -55,7 +55,7 @@ public void onTick(long millisUntilFinished) { @Override public void onFinish() { //complete the js invocation with data; handler will be invalid when complete is called - handler.complete(); + handler.complete(0); } }.start(); diff --git a/app/src/test/java/wendu/jsbdemo/ExampleUnitTest.java b/app/src/test/java/wendu/jsbdemo/ExampleUnitTest.java deleted file mode 100644 index ec9d1e1..0000000 --- a/app/src/test/java/wendu/jsbdemo/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package wendu.jsbdemo; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/readme-chs.md b/readme-chs.md index 4b1a5e2..2e4d14c 100644 --- a/readme-chs.md +++ b/readme-chs.md @@ -1,7 +1,7 @@ # DSBridge -[![](https://jitpack.io/v/wendux/DSBridge-Android.svg)](https://jitpack.io/#wendux/DSBridge-Android) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/mit-license.php) +[![](https://jitpack.io/v/wendux/DSBridge-Android.svg)](https://jitpack.io/#wendux/DSBridge-Android) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/mit-license.php) [![](https://travis-ci.org/wendux/DSBridge-Android.svg?branch=x5-3.0)](https://travis-ci.org/wendux/DSBridge-Android) > 三端易用的现代跨平台的 Javascript bridge, 通过它,你可以在Javascript和原生之间同步或异步的调用彼此的函数. @@ -192,7 +192,7 @@ public void callProgress(Object args, final CompletionHandler handler) public void onFinish() { //complete the js invocation with data; //handler will invalid when complete is called - handler.complete(); + handler.complete(0); } }.start(); } diff --git a/readme.md b/readme.md index 9899cdb..e6cecd1 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ # DSBridge -[![](https://jitpack.io/v/wendux/DSBridge-Android.svg)](https://jitpack.io/#wendux/DSBridge-Android) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/mit-license.php) +[![](https://jitpack.io/v/wendux/DSBridge-Android.svg)](https://jitpack.io/#wendux/DSBridge-Android) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/mit-license.php) [![](https://travis-ci.org/wendux/DSBridge-Android.svg?branch=x5-3.0)](https://travis-ci.org/wendux/DSBridge-Android) >Modern cross-platform JavaScript bridge, through which you can invoke each other's functions synchronously or asynchronously between JavaScript and native applications. @@ -55,7 +55,7 @@ DSBridge v3.0 is a milestone version. Compared with v2.0, we have made a lot of See the `wendu.jsbdemo/` package. run the `app` project and to see it in action. -To use a dsBridge in your own project: +To use dsBridge in your own project: ## Usage @@ -179,7 +179,7 @@ public void callProgress(Object args, final CompletionHandler handler) public void onFinish() { //complete the js invocation with data; //handler will be invalid when complete is called - handler.complete(); + handler.complete(0); } }.start(); }