mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
Update unit tests to not use most deprecated things (e.g. DroidGap)
This commit is contained in:
parent
1c5b5e2ce6
commit
d8a19b5565
@ -99,7 +99,7 @@
|
||||
android:windowSoftInputMode="adjustPan"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:name="org.apache.cordova.test.CordovaActivity" >
|
||||
android:name="org.apache.cordova.test.MainTestActivity" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||
|
@ -22,13 +22,13 @@ package org.apache.cordova.test;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.cordova.Config;
|
||||
import org.apache.cordova.CordovaChromeClient;
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.CordovaInterface;
|
||||
import org.apache.cordova.CordovaPlugin;
|
||||
import org.apache.cordova.LOG;
|
||||
import org.apache.cordova.CordovaWebViewClient;
|
||||
import org.apache.cordova.test.R;
|
||||
import org.apache.cordova.test.R.id;
|
||||
import org.apache.cordova.test.R.layout;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
@ -48,6 +48,8 @@ public class CordovaWebViewTestActivity extends Activity implements CordovaInter
|
||||
setContentView(R.layout.main);
|
||||
|
||||
cordovaWebView = (CordovaWebView) findViewById(R.id.cordovaWebView);
|
||||
cordovaWebView.init(this, new CordovaWebViewClient(this, cordovaWebView), new CordovaChromeClient(this, cordovaWebView),
|
||||
Config.getPluginEntries(), Config.getWhitelist(), Config.getPreferences());
|
||||
|
||||
cordovaWebView.loadUrl("file:///android_asset/www/index.html");
|
||||
|
||||
|
@ -18,12 +18,11 @@
|
||||
*/
|
||||
package org.apache.cordova.test;
|
||||
|
||||
import org.apache.cordova.DroidGap;
|
||||
import org.apache.cordova.CordovaActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class CordovaActivity extends DroidGap {
|
||||
public class MainTestActivity extends CordovaActivity {
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
@ -21,7 +21,7 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class backbuttonmultipage extends DroidGap {
|
||||
public class backbuttonmultipage extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -22,12 +22,12 @@ import android.os.Bundle;
|
||||
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class background extends DroidGap {
|
||||
public class background extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//super.init(new FixWebView(this), new CordovaWebViewClient(this), new CordovaChromeClient(this));
|
||||
super.setBooleanProperty("keepRunning", false);
|
||||
preferences.set("keepRunning", false);
|
||||
super.loadUrl("file:///android_asset/www/background/index.html");
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,15 @@ import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class backgroundcolor extends DroidGap {
|
||||
public class backgroundcolor extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Properties must be set before init() is called, since some are processed during init().
|
||||
|
||||
// backgroundColor can also be set in cordova.xml, but you must use the number equivalent of the color. For example, Color.RED is
|
||||
// <preference name="backgroundColor" value="-65536" />
|
||||
super.setIntegerProperty("backgroundColor", Color.GREEN);
|
||||
preferences.set("backgroundColor", Color.GREEN);
|
||||
|
||||
super.init();
|
||||
super.loadUrl("file:///android_asset/www/backgroundcolor/index.html");
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,11 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class errorurl extends DroidGap {
|
||||
public class errorurl extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.init();
|
||||
this.setStringProperty("errorUrl", "file:///android_asset/www/htmlnotfound/error.html");
|
||||
preferences.set("errorUrl", "file:///android_asset/www/htmlnotfound/error.html");
|
||||
super.loadUrl("file:///android_asset/www/htmlnotfound/index.html");
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class fullscreen extends DroidGap {
|
||||
public class fullscreen extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -30,7 +30,7 @@ public class fullscreen extends DroidGap {
|
||||
|
||||
// fullscreen can also be set in cordova.xml. For example,
|
||||
// <preference name="fullscreen" value="true" />
|
||||
super.setBooleanProperty("fullscreen", true);
|
||||
preferences.set("fullscreen", true);
|
||||
|
||||
super.init();
|
||||
super.loadUrl("file:///android_asset/www/fullscreen/index.html");
|
||||
|
@ -21,7 +21,7 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class htmlnotfound extends DroidGap {
|
||||
public class htmlnotfound extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -21,7 +21,7 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class iframe extends DroidGap {
|
||||
public class iframe extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -85,9 +85,7 @@ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<ba
|
||||
{
|
||||
String url = testView.getUrl();
|
||||
assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html", url);
|
||||
testView.printBackForwardList();
|
||||
assertTrue(testView.backHistory());
|
||||
testView.printBackForwardList();
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
|
@ -21,16 +21,16 @@ package org.apache.cordova.test.junit;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.PluginManager;
|
||||
import org.apache.cordova.test.CordovaActivity;
|
||||
import org.apache.cordova.test.MainTestActivity;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class CordovaActivityTest extends ActivityInstrumentationTestCase2<CordovaActivity> {
|
||||
public class CordovaActivityTest extends ActivityInstrumentationTestCase2<MainTestActivity> {
|
||||
|
||||
private CordovaActivity testActivity;
|
||||
private MainTestActivity testActivity;
|
||||
private FrameLayout containerView;
|
||||
private LinearLayout innerContainer;
|
||||
private CordovaWebView testView;
|
||||
@ -40,7 +40,7 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
|
||||
@SuppressWarnings("deprecation")
|
||||
public CordovaActivityTest()
|
||||
{
|
||||
super("org.apache.cordova.test",CordovaActivity.class);
|
||||
super("org.apache.cordova.test",MainTestActivity.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
@ -68,33 +68,7 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2<Cordov
|
||||
String className = innerContainer.getClass().getSimpleName();
|
||||
assertTrue(className.equals("LinearLayoutSoftKeyboardDetect"));
|
||||
}
|
||||
|
||||
|
||||
public void testPauseAndResume() throws Throwable
|
||||
{
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
mInstr.callActivityOnPause(testActivity);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
assertTrue(testView.isPaused());
|
||||
mInstr.callActivityOnResume(testActivity);
|
||||
}
|
||||
});
|
||||
sleep();
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run()
|
||||
{
|
||||
assertFalse(testView.isPaused());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sleep() {
|
||||
try {
|
||||
Thread.sleep(TIMEOUT);
|
||||
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
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.test.junit;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.CordovaChromeClient;
|
||||
import org.apache.cordova.PluginManager;
|
||||
import org.apache.cordova.test.CordovaWebViewTestActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import android.content.res.Resources;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class GapClientTest extends ActivityInstrumentationTestCase2<CordovaWebViewTestActivity> {
|
||||
|
||||
private CordovaWebViewTestActivity testActivity;
|
||||
private FrameLayout containerView;
|
||||
private LinearLayout innerContainer;
|
||||
private View testView;
|
||||
private String rString;
|
||||
private CordovaChromeClient appCode;
|
||||
|
||||
public GapClientTest() {
|
||||
super("org.apache.cordova.test.activities",CordovaWebViewTestActivity.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception{
|
||||
super.setUp();
|
||||
testActivity = this.getActivity();
|
||||
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
|
||||
innerContainer = (LinearLayout) containerView.getChildAt(0);
|
||||
testView = innerContainer.getChildAt(0);
|
||||
|
||||
}
|
||||
|
||||
public void testPreconditions(){
|
||||
assertNotNull(innerContainer);
|
||||
assertNotNull(testView);
|
||||
}
|
||||
|
||||
public void testForCordovaView() {
|
||||
String className = testView.getClass().getSimpleName();
|
||||
assertTrue(className.equals("CordovaWebView"));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package org.apache.cordova.test.junit;
|
||||
/*
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.CordovaWebViewClient;
|
||||
import org.apache.cordova.CordovaChromeClient;
|
||||
import org.apache.cordova.test.userwebview;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class UserWebViewTest extends ActivityInstrumentationTestCase2<userwebview> {
|
||||
|
||||
public UserWebViewTest ()
|
||||
{
|
||||
super(userwebview.class);
|
||||
}
|
||||
|
||||
private int TIMEOUT = 1000;
|
||||
userwebview testActivity;
|
||||
private FrameLayout containerView;
|
||||
private LinearLayout innerContainer;
|
||||
private CordovaWebView testView;
|
||||
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
testActivity = this.getActivity();
|
||||
containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
|
||||
innerContainer = (LinearLayout) containerView.getChildAt(0);
|
||||
testView = (CordovaWebView) innerContainer.getChildAt(0);
|
||||
}
|
||||
|
||||
public void testPreconditions(){
|
||||
assertNotNull(innerContainer);
|
||||
assertNotNull(testView);
|
||||
}
|
||||
|
||||
public void testCustom()
|
||||
{
|
||||
assertTrue(CordovaWebView.class.isInstance(testView));
|
||||
assertTrue(CordovaWebViewClient.class.isInstance(testActivity.testViewClient));
|
||||
assertTrue(CordovaChromeClient.class.isInstance(testActivity.testChromeClient));
|
||||
}
|
||||
|
||||
|
||||
private void sleep() {
|
||||
try {
|
||||
Thread.sleep(TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
fail("Unexpected Timeout");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -21,7 +21,7 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class lifecycle extends DroidGap {
|
||||
public class lifecycle extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -21,11 +21,11 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class loading extends DroidGap {
|
||||
public class loading extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.setStringProperty("loadingDialog", "Testing,Loading...");
|
||||
preferences.set("loadingDialog", "Testing,Loading...");
|
||||
super.loadUrl("http://www.google.com");
|
||||
}
|
||||
}
|
||||
|
@ -20,17 +20,15 @@ package org.apache.cordova.test;
|
||||
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
import org.apache.cordova.test.R;
|
||||
import org.apache.cordova.test.R.drawable;
|
||||
|
||||
public class splashscreen extends DroidGap {
|
||||
public class splashscreen extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.init();
|
||||
|
||||
// Show splashscreen
|
||||
this.setIntegerProperty("splashscreen", R.drawable.sandy);
|
||||
preferences.set("splashscreen", "sandy");
|
||||
|
||||
super.loadUrl("file:///android_asset/www/splashscreen/index.html", 2000);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class tests extends DroidGap {
|
||||
public class tests extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -21,14 +21,14 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class timeout extends DroidGap {
|
||||
public class timeout extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.init();
|
||||
|
||||
// Short timeout to cause error
|
||||
this.setIntegerProperty("loadUrlTimeoutValue", 10);
|
||||
preferences.set("loadUrlTimeoutValue", 10);
|
||||
super.loadUrl("http://www.google.com");
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,8 @@ import android.webkit.WebView;
|
||||
import android.webkit.GeolocationPermissions.Callback;
|
||||
|
||||
import org.apache.cordova.*;
|
||||
import org.apache.cordova.LOG;
|
||||
|
||||
public class userwebview extends DroidGap {
|
||||
public class userwebview extends MainTestActivity {
|
||||
|
||||
public TestViewClient testViewClient;
|
||||
public TestChromeClient testChromeClient;
|
||||
@ -33,15 +32,17 @@ public class userwebview extends DroidGap {
|
||||
@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));
|
||||
testViewClient = new TestViewClient(this, appView);
|
||||
testChromeClient = new TestChromeClient(this, appView);
|
||||
super.init();
|
||||
appView.setWebViewClient(testViewClient);
|
||||
appView.setWebChromeClient(testChromeClient);
|
||||
super.loadUrl("file:///android_asset/www/userwebview/index.html");
|
||||
}
|
||||
|
||||
public class TestChromeClient extends CordovaChromeClient {
|
||||
public TestChromeClient(DroidGap arg0) {
|
||||
super(arg0);
|
||||
public TestChromeClient(CordovaInterface ctx, CordovaWebView app) {
|
||||
super(ctx, app);
|
||||
LOG.d("userwebview", "TestChromeClient()");
|
||||
}
|
||||
|
||||
@ -57,8 +58,8 @@ public class userwebview extends DroidGap {
|
||||
* This class can be used to override the GapViewClient and receive notification of webview events.
|
||||
*/
|
||||
public class TestViewClient extends CordovaWebViewClient {
|
||||
public TestViewClient(DroidGap arg0) {
|
||||
super(arg0);
|
||||
public TestViewClient(CordovaInterface ctx, CordovaWebView app) {
|
||||
super(ctx, app);
|
||||
LOG.d("userwebview", "TestViewClient()");
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,12 @@ import android.webkit.WebView;
|
||||
import org.apache.cordova.*;
|
||||
import org.apache.cordova.LOG;
|
||||
|
||||
public class whitelist extends DroidGap {
|
||||
public class whitelist extends MainTestActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
super.init(new CordovaWebView(this), new TestViewClient(this), new CordovaChromeClient(this));
|
||||
super.init();
|
||||
appView.setWebViewClient(new TestViewClient(this, appView));
|
||||
super.loadUrl("file:///android_asset/www/whitelist/index.html");
|
||||
}
|
||||
|
||||
@ -37,8 +38,8 @@ public class whitelist extends DroidGap {
|
||||
*/
|
||||
public class TestViewClient extends CordovaWebViewClient {
|
||||
|
||||
public TestViewClient(DroidGap arg0) {
|
||||
super(arg0);
|
||||
public TestViewClient(CordovaInterface ctx, CordovaWebView app) {
|
||||
super(ctx, app);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,7 +21,7 @@ package org.apache.cordova.test;
|
||||
import android.os.Bundle;
|
||||
import org.apache.cordova.*;
|
||||
|
||||
public class xhr extends DroidGap {
|
||||
public class xhr extends CordovaActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
Loading…
Reference in New Issue
Block a user