mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
Removing tests that don't work and modifying CordovaWebView so it works as a stand-alone component again. Mobile-spec currently doesn't work
This commit is contained in:
parent
295b9f4f5b
commit
afa1ecf3c5
@ -38,6 +38,7 @@ import android.content.res.XmlResourceParser;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
@ -73,22 +74,38 @@ public class CordovaWebView extends WebView {
|
|||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
*/
|
*/
|
||||||
public CordovaWebView(CordovaInterface context) {
|
public CordovaWebView(Context context) {
|
||||||
super(context.getActivity());
|
super(context);
|
||||||
this.mCtx = context;
|
if(CordovaInterface.class.isInstance(context))
|
||||||
|
{
|
||||||
|
this.mCtx = (CordovaInterface) context;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.d(TAG, "Your activity must implement CordovaInterface to work");
|
||||||
|
}
|
||||||
this.loadConfiguration();
|
this.loadConfiguration();
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context
|
||||||
* @param attrs
|
* @param attrs
|
||||||
*/
|
*/
|
||||||
public CordovaWebView(CordovaInterface context, AttributeSet attrs) {
|
public CordovaWebView(Context context, AttributeSet attrs) {
|
||||||
super(context.getActivity(), attrs);
|
super(context, attrs);
|
||||||
this.mCtx = context;
|
if(CordovaInterface.class.isInstance(context))
|
||||||
|
{
|
||||||
|
this.mCtx = (CordovaInterface) context;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.d(TAG, "Your activity must implement CordovaInterface to work");
|
||||||
|
}
|
||||||
|
|
||||||
this.loadConfiguration();
|
this.loadConfiguration();
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
@ -99,10 +116,18 @@ public class CordovaWebView extends WebView {
|
|||||||
* @param context
|
* @param context
|
||||||
* @param attrs
|
* @param attrs
|
||||||
* @param defStyle
|
* @param defStyle
|
||||||
|
* @throws CordovaException
|
||||||
*/
|
*/
|
||||||
public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle) {
|
public CordovaWebView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context.getActivity(), attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
this.mCtx = context;
|
if(CordovaInterface.class.isInstance(context))
|
||||||
|
{
|
||||||
|
this.mCtx = (CordovaInterface) context;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.d(TAG, "Your activity must implement CordovaInterface to work");
|
||||||
|
}
|
||||||
this.loadConfiguration();
|
this.loadConfiguration();
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
@ -115,9 +140,16 @@ public class CordovaWebView extends WebView {
|
|||||||
* @param defStyle
|
* @param defStyle
|
||||||
* @param privateBrowsing
|
* @param privateBrowsing
|
||||||
*/
|
*/
|
||||||
public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
|
public CordovaWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
|
||||||
super(context.getActivity(), attrs, defStyle, privateBrowsing);
|
super(context, attrs, defStyle, privateBrowsing);
|
||||||
this.mCtx = context;
|
if(CordovaInterface.class.isInstance(context))
|
||||||
|
{
|
||||||
|
this.mCtx = (CordovaInterface) context;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.d(TAG, "Your activity must implement CordovaInterface to work");
|
||||||
|
}
|
||||||
this.loadConfiguration();
|
this.loadConfiguration();
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
@ -153,7 +185,12 @@ public class CordovaWebView extends WebView {
|
|||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
|
|
||||||
//Start up the plugin manager
|
//Start up the plugin manager
|
||||||
this.pluginManager = new PluginManager(this, this.mCtx);
|
try {
|
||||||
|
this.pluginManager = new PluginManager(this, mCtx);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,32 +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;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
|
|
||||||
public class CordovaDriverAction extends Activity {
|
|
||||||
/** Called when the activity is first created. */
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +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;
|
|
||||||
|
|
||||||
import org.openqa.selenium.android.library.WebViewFactory;
|
|
||||||
|
|
||||||
import org.apache.cordova.CordovaWebView;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
public class CordovaViewFactory implements WebViewFactory {
|
|
||||||
|
|
||||||
public WebView createNewView(Activity arg0) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return new CordovaWebView(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,84 +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;
|
|
||||||
|
|
||||||
import org.apache.cordova.CordovaWebViewClient;
|
|
||||||
import org.apache.cordova.CordovaWebView;
|
|
||||||
import org.apache.cordova.CordovaChromeClient;
|
|
||||||
|
|
||||||
import org.apache.cordova.test.CordovaViewFactory;
|
|
||||||
import org.openqa.selenium.By;
|
|
||||||
import org.openqa.selenium.WebElement;
|
|
||||||
import org.openqa.selenium.android.library.AndroidWebDriver;
|
|
||||||
|
|
||||||
import android.test.ActivityInstrumentationTestCase2;
|
|
||||||
|
|
||||||
public class WebDriverTest extends ActivityInstrumentationTestCase2<CordovaDriverAction> {
|
|
||||||
|
|
||||||
private static final long TIMEOUT = 5000;
|
|
||||||
private CordovaDriverAction testActivity;
|
|
||||||
private CordovaWebView testView;
|
|
||||||
private CordovaViewFactory viewFactory;
|
|
||||||
private CordovaChromeClient appCode;
|
|
||||||
private CordovaWebViewClient viewHandler;
|
|
||||||
private AndroidWebDriver testDriver;
|
|
||||||
|
|
||||||
public WebDriverTest() {
|
|
||||||
super("com.phonegap.test.activities",CordovaDriverAction.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setUp() throws Exception{
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
testActivity = this.getActivity();
|
|
||||||
viewFactory = new CordovaViewFactory();
|
|
||||||
appCode = new CordovaChromeClient(testActivity);
|
|
||||||
viewHandler = new CordovaWebViewClient(testActivity);
|
|
||||||
testDriver = new AndroidWebDriver(testActivity, viewFactory, viewHandler, appCode);
|
|
||||||
testView = (CordovaWebView) testDriver.getWebView();
|
|
||||||
viewHandler.setWebView(testView);
|
|
||||||
appCode.setWebView(testView);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPreconditions(){
|
|
||||||
assertNotNull(testView);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWebLoad() {
|
|
||||||
testDriver.get("file:///android_asset/www/index.html");
|
|
||||||
sleep();
|
|
||||||
String url = testView.getUrl();
|
|
||||||
//Check the sanity!
|
|
||||||
boolean result = url.equals("file:///android_asset/www/index.html");
|
|
||||||
assertTrue(result);
|
|
||||||
WebElement platformSpan = testDriver.findElement(By.id("platform"));
|
|
||||||
String text = platformSpan.getText();
|
|
||||||
assertTrue(text.equals("Android"));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void sleep() {
|
|
||||||
try {
|
|
||||||
Thread.sleep(TIMEOUT);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
fail("Unexpected Timeout");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user