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:
Joe Bowser 2012-05-15 13:24:43 -07:00
parent 295b9f4f5b
commit afa1ecf3c5
4 changed files with 52 additions and 167 deletions

View File

@ -38,6 +38,7 @@ import android.content.res.XmlResourceParser;
import android.net.Uri;
import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
@ -73,22 +74,38 @@ public class CordovaWebView extends WebView {
*
* @param context
*/
public CordovaWebView(CordovaInterface context) {
super(context.getActivity());
this.mCtx = context;
public CordovaWebView(Context context) {
super(context);
if(CordovaInterface.class.isInstance(context))
{
this.mCtx = (CordovaInterface) context;
}
else
{
Log.d(TAG, "Your activity must implement CordovaInterface to work");
}
this.loadConfiguration();
this.setup();
}
/**
* Constructor.
*
* @param context
* @param attrs
*/
public CordovaWebView(CordovaInterface context, AttributeSet attrs) {
super(context.getActivity(), attrs);
this.mCtx = context;
public CordovaWebView(Context context, AttributeSet attrs) {
super(context, attrs);
if(CordovaInterface.class.isInstance(context))
{
this.mCtx = (CordovaInterface) context;
}
else
{
Log.d(TAG, "Your activity must implement CordovaInterface to work");
}
this.loadConfiguration();
this.setup();
}
@ -99,10 +116,18 @@ public class CordovaWebView extends WebView {
* @param context
* @param attrs
* @param defStyle
* @throws CordovaException
*/
public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle) {
super(context.getActivity(), attrs, defStyle);
this.mCtx = context;
public CordovaWebView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if(CordovaInterface.class.isInstance(context))
{
this.mCtx = (CordovaInterface) context;
}
else
{
Log.d(TAG, "Your activity must implement CordovaInterface to work");
}
this.loadConfiguration();
this.setup();
}
@ -115,9 +140,16 @@ public class CordovaWebView extends WebView {
* @param defStyle
* @param privateBrowsing
*/
public CordovaWebView(CordovaInterface context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
super(context.getActivity(), attrs, defStyle, privateBrowsing);
this.mCtx = context;
public CordovaWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
super(context, attrs, defStyle, privateBrowsing);
if(CordovaInterface.class.isInstance(context))
{
this.mCtx = (CordovaInterface) context;
}
else
{
Log.d(TAG, "Your activity must implement CordovaInterface to work");
}
this.loadConfiguration();
this.setup();
}
@ -153,7 +185,12 @@ public class CordovaWebView extends WebView {
settings.setGeolocationEnabled(true);
//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();
}
}
/**

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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");
}
}
}