Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
4,735 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
bin/templates/project/assets/www/cordova.js | ||
test/app | ||
test/android/app | ||
test/androidx/app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
--> | ||
|
||
# Cordova Android Test Project | ||
|
||
The project in this directory is an Android Test project that enables those | ||
interested in further developing `cordova-android` to validate their changes. | ||
|
||
## Requirements | ||
|
||
The requirements in the [top-level README](../README.md) still apply. In | ||
addition, ensure you have installed Gradle, and that it is (at the time of this | ||
writing) at least version 3.3 or newer. | ||
|
||
## Getting Started | ||
|
||
You can run this test project from both the command line as well as from | ||
Android Studio: | ||
|
||
### Command Line | ||
|
||
Ensure you have the gradle wrapper script, `gradlew`, in this directory. If | ||
you do not, you can run the following to generate it: | ||
|
||
$ cd cordova-android/test | ||
$ gradle :wrapper -b build.gradle | ||
|
||
You can then see a list of all tasks available to run with `gradlew tasks`. | ||
|
||
The two different kinds of tests one typically wants to run are unit tests and | ||
end-to-end, or instrumented, tests. Unit tests do not require any particular | ||
environment to run in, but the instrumented tests, however, require a connected | ||
Android device or emulator to run in. | ||
|
||
- To run the unit tests, run: `gradlew test`. | ||
- To run the instrumented tests, run: `gradlew connectedAndroidTest`. | ||
|
||
To make sure all tests are run, add the `--rerun-tasks` parameter. | ||
|
||
### Android Studio | ||
|
||
Import this `test/` directory into Android Studio, and hit the Play button. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.2" | ||
|
||
defaultConfig { | ||
applicationId "org.apache.cordova.unittests" | ||
minSdkVersion 19 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation project(path: ':CordovaLib') | ||
implementation 'androidx.appcompat:appcompat:1.0.2' | ||
|
||
testImplementation 'org.json:json:20140107' | ||
testImplementation 'junit:junit:4.12' | ||
|
||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1', { | ||
exclude group: 'androidx.test.espresso', module: 'androidx.annotation' | ||
}) | ||
|
||
androidTestImplementation('androidx.test.espresso:espresso-web:3.1.1', { | ||
exclude group: 'androidx.test.espresso', module: 'androidx.annotation' | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/jbowser/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
158 changes: 158 additions & 0 deletions
158
...droidx/app/src/androidTest/java/org/apache/cordova/unittests/BackButtonMultipageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
/* | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
*/ | ||
|
||
package org.apache.cordova.unittests; | ||
|
||
import android.content.Intent; | ||
import androidx.test.rule.ActivityTestRule; | ||
import androidx.test.runner.AndroidJUnit4; | ||
|
||
import org.apache.cordova.CordovaWebView; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static androidx.test.espresso.Espresso.onView; | ||
import static androidx.test.espresso.action.ViewActions.pressBack; | ||
import static androidx.test.espresso.matcher.ViewMatchers.withId; | ||
import static androidx.test.espresso.web.sugar.Web.onWebView; | ||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertFalse; | ||
import static junit.framework.Assert.assertTrue; | ||
|
||
|
||
import static org.apache.cordova.unittests.R.id.cordovaWebView; | ||
|
||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class BackButtonMultipageTest { | ||
|
||
private static final String START_URL = "file:///android_asset/www/backbuttonmultipage/index.html"; | ||
//I have no idea why we picked 100, but we did. | ||
private static final int WEBVIEW_ID = 100; | ||
private TestActivity mActivity; | ||
|
||
// Don't launch the activity, we're going to send it intents | ||
@Rule | ||
public ActivityTestRule mActivityRule = new ActivityTestRule<>( | ||
TestActivity.class, true, false); | ||
|
||
@Before | ||
public void launchApplicationWithIntent() { | ||
Intent intent = new Intent(); | ||
intent.putExtra("startUrl", START_URL); | ||
mActivity = (TestActivity) mActivityRule.launchActivity(intent); | ||
} | ||
|
||
@Test | ||
public void testViaHref() throws Throwable { | ||
final CordovaWebView webInterface = mActivity.getWebInterface(); | ||
assertEquals(START_URL, mActivity.onPageFinishedUrl.take()); | ||
|
||
mActivityRule.runOnUiThread(new Runnable() { | ||
public void run() { | ||
webInterface.sendJavascript("window.location = 'sample2.html';"); | ||
} | ||
}); | ||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take()); | ||
mActivityRule.runOnUiThread(new Runnable() { | ||
public void run() { | ||
webInterface.sendJavascript("window.location = '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()); | ||
} | ||
}); | ||
} | ||
|
||
@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()); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testViaBackButtonOnView() 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()); | ||
onView(withId(WEBVIEW_ID)).perform(pressBack()); | ||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html", mActivity.onPageFinishedUrl.take()); | ||
onView(withId(WEBVIEW_ID)).perform(pressBack()); | ||
assertEquals(START_URL, mActivity.onPageFinishedUrl.take()); | ||
} | ||
} |
Oops, something went wrong.