mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-cordova-android
This commit is contained in:
commit
aa45670d87
@ -256,10 +256,21 @@ public class DroidGap extends Activity implements CordovaInterface {
|
||||
LOG.d(TAG, "DroidGap.onCreate()");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
|
||||
if(!this.getBooleanProperty("showTitle", false))
|
||||
{
|
||||
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
||||
}
|
||||
|
||||
if(this.getBooleanProperty("setFullscreen", false))
|
||||
{
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
}
|
||||
// This builds the view. We could probably get away with NOT having a LinearLayout, but I like having a bucket!
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
|
@ -219,9 +219,11 @@ public class FileTransfer extends Plugin {
|
||||
|
||||
extraParams += LINE_START + BOUNDARY + LINE_END;
|
||||
extraParams += "Content-Disposition: form-data; name=\"" + fileKey + "\";" + " filename=\"";
|
||||
byte[] extraBytes = extraParams.getBytes("UTF-8");
|
||||
|
||||
String midParams = "\"" + LINE_END + "Content-Type: " + mimeType + LINE_END + LINE_END;
|
||||
String tailParams = LINE_END + LINE_START + BOUNDARY + LINE_START + LINE_END;
|
||||
byte[] fileNameBytes = fileName.getBytes("UTF-8");
|
||||
|
||||
// Should set this up as an option
|
||||
if (chunkedMode) {
|
||||
@ -229,7 +231,7 @@ public class FileTransfer extends Plugin {
|
||||
}
|
||||
else
|
||||
{
|
||||
int stringLength = extraParams.length() + midParams.length() + tailParams.length() + fileName.getBytes("UTF-8").length;
|
||||
int stringLength = extraBytes.length + midParams.length() + tailParams.length() + fileNameBytes.length;
|
||||
Log.d(LOG_TAG, "String Length: " + stringLength);
|
||||
int fixedLength = (int) fileInputStream.getChannel().size() + stringLength;
|
||||
Log.d(LOG_TAG, "Content Length: " + fixedLength);
|
||||
@ -238,9 +240,9 @@ public class FileTransfer extends Plugin {
|
||||
|
||||
|
||||
dos = new DataOutputStream( conn.getOutputStream() );
|
||||
dos.writeBytes(extraParams);
|
||||
//We don't want to chagne encoding, we just want this to write for all Unicode.
|
||||
dos.write(fileName.getBytes("UTF-8"));
|
||||
//We don't want to change encoding, we just want this to write for all Unicode.
|
||||
dos.write(extraBytes);
|
||||
dos.write(fileNameBytes);
|
||||
dos.writeBytes(midParams);
|
||||
|
||||
// create a buffer of maximum size
|
||||
|
78
test/src/org/apache/cordova/test/CordovaDriverAction.java
Normal file
78
test/src/org/apache/cordova/test/CordovaDriverAction.java
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
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.api.CordovaInterface;
|
||||
import org.apache.cordova.api.IPlugin;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
|
||||
public class CordovaDriverAction extends Activity implements CordovaInterface {
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindBackButton(boolean arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelLoadUrl() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBackButtonBound() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object onMessage(String arg0, Object arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityResultCallback(IPlugin arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startActivityForResult(IPlugin arg0, Intent arg1, int arg2) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
37
test/src/org/apache/cordova/test/CordovaViewFactory.java
Normal file
37
test/src/org/apache/cordova/test/CordovaViewFactory.java
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.ViewAdapter;
|
||||
import org.openqa.selenium.android.library.ViewFactory;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class CordovaViewFactory implements ViewFactory {
|
||||
|
||||
public ViewAdapter createNewView(Activity arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
return new ViewAdapter("org.apache.cordova.CordovaWebView", new CordovaWebView(arg0));
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package org.apache.cordova.test;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class LoadTimeoutTest extends ActivityInstrumentationTestCase2<loading> {
|
||||
private loading testActivity;
|
||||
private FrameLayout containerView;
|
||||
private LinearLayout innerContainer;
|
||||
private CordovaWebView testView;
|
||||
private long TIMEOUT = 1000;
|
||||
|
||||
public LoadTimeoutTest()
|
||||
{
|
||||
super("org.apache.cordova.test",loading.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 = (CordovaWebView) innerContainer.getChildAt(0);
|
||||
}
|
||||
|
||||
public void testPreconditions(){
|
||||
assertNotNull(innerContainer);
|
||||
assertNotNull(testView);
|
||||
}
|
||||
|
||||
public void testUrl()
|
||||
{
|
||||
sleep();
|
||||
String good_url = "http://www.google.com";
|
||||
String url = testView.getUrl();
|
||||
assertNotNull(url);
|
||||
assertFalse(url.equals(good_url));
|
||||
}
|
||||
|
||||
private void sleep() {
|
||||
try {
|
||||
Thread.sleep(TIMEOUT );
|
||||
} catch (InterruptedException e) {
|
||||
fail("Unexpected Timeout");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,12 @@
|
||||
package org.apache.cordova.test;
|
||||
|
||||
import org.apache.cordova.CordovaWebView;
|
||||
import org.apache.cordova.CordovaWebViewClient;
|
||||
import org.apache.cordova.CordovaChromeClient;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class UserWebViewTest extends ActivityInstrumentationTestCase2<userwebview> {
|
||||
|
||||
@ -8,4 +14,41 @@ public class UserWebViewTest extends ActivityInstrumentationTestCase2<userwebvie
|
||||
{
|
||||
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 customTest()
|
||||
{
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
90
test/src/org/apache/cordova/test/WebDriverTest.java
Normal file
90
test/src/org/apache/cordova/test/WebDriverTest.java
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
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 org.openqa.selenium.android.library.ChromeClientWrapper;
|
||||
import org.openqa.selenium.android.library.ViewClientWrapper;
|
||||
|
||||
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;
|
||||
private ViewClientWrapper viewClientWrapper;
|
||||
private ChromeClientWrapper chromeClientWrapper;
|
||||
|
||||
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);
|
||||
viewClientWrapper = new ViewClientWrapper("org.apache.cordova.CordovaWebViewClient", viewHandler);
|
||||
chromeClientWrapper = new ChromeClientWrapper("org.apache.cordova.CordovaChromeClient", appCode);
|
||||
testDriver = new AndroidWebDriver(testActivity, viewFactory, viewClientWrapper, chromeClientWrapper);
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package org.apache.cordova.test;
|
||||
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
|
||||
public class WhitelistTest extends ActivityInstrumentationTestCase2<whitelist> {
|
||||
|
||||
public WhitelistTest()
|
||||
{
|
||||
super(whitelist.class);
|
||||
}
|
||||
|
||||
}
|
@ -26,9 +26,15 @@ import org.apache.cordova.*;
|
||||
import org.apache.cordova.api.LOG;
|
||||
|
||||
public class userwebview extends DroidGap {
|
||||
|
||||
public TestViewClient testViewClient;
|
||||
public TestChromeClient testChromeClient;
|
||||
|
||||
@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));
|
||||
super.loadUrl("file:///android_asset/www/userwebview/index.html");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user