cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [13/14] android commit: Merge branch 'master' into 4.0.x (gradlify tests)
Date Tue, 20 Jan 2015 20:04:20 GMT
Merge branch 'master' into 4.0.x (gradlify tests)

Conflicts:
	test/androidTest/src/org/apache/cordova/test/junit/MenuTest.java


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/c352b296
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/c352b296
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/c352b296

Branch: refs/heads/4.0.x
Commit: c352b296da717e1dd824d90a17b7b97b1aed71ac
Parents: 587488a 9e04eec
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Tue Jan 20 14:55:44 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Tue Jan 20 14:55:44 2015 -0500

----------------------------------------------------------------------
 .gitignore                                      |   34 +-
 bin/lib/check_reqs.js                           |    6 +-
 bin/lib/create.js                               |    2 +-
 bin/templates/project/build.gradle              |   17 +-
 bin/templates/project/cordova.gradle            |  161 --
 framework/build.gradle                          |   32 +-
 framework/cordova.gradle                        |  165 ++
 test/README.md                                  |   55 +-
 .../test/junit/BackButtonMultiPageTest.java     |  278 +++
 .../cordova/test/junit/CordovaActivityTest.java |   79 +
 .../test/junit/CordovaResourceApiTest.java      |  281 +++
 .../apache/cordova/test/junit/CordovaTest.java  |  116 ++
 .../apache/cordova/test/junit/ErrorUrlTest.java |   82 +
 .../apache/cordova/test/junit/FixWebView.java   |   43 +
 .../cordova/test/junit/HtmlNotFoundTest.java    |   80 +
 .../apache/cordova/test/junit/IFrameTest.java   |  128 ++
 .../test/junit/IntentUriOverrideTest.java       |   94 +
 .../cordova/test/junit/LifecycleTest.java       |   34 +
 .../cordova/test/junit/PluginManagerTest.java   |   70 +
 .../cordova/test/junit/SplashscreenTest.java    |   49 +
 .../org/apache/cordova/test/junit/XhrTest.java  |   34 +
 .../org/apache/cordova/test/util/Purity.java    |  171 ++
 test/ant.properties                             |   17 -
 test/build.gradle                               |   75 +
 test/build.xml                                  |  110 -
 test/cordova/android_sdk_version                |   29 -
 test/cordova/build                              |   37 -
 test/cordova/build.bat                          |   26 -
 test/cordova/check_reqs                         |   28 -
 test/cordova/clean                              |   36 -
 test/cordova/clean.bat                          |   26 -
 test/cordova/lib/android_sdk_version.js         |   65 -
 test/cordova/lib/appinfo.js                     |   41 -
 test/cordova/lib/build.js                       |   87 -
 test/cordova/lib/check_reqs.js                  |   94 -
 test/cordova/lib/clean.js                       |   38 -
 test/cordova/lib/device.js                      |   86 -
 test/cordova/lib/emulator.js                    |  330 ---
 test/cordova/lib/exec.js                        |   43 -
 test/cordova/lib/install-device                 |   42 -
 test/cordova/lib/install-device.bat             |   26 -
 test/cordova/lib/install-emulator               |   38 -
 test/cordova/lib/install-emulator.bat           |   26 -
 test/cordova/lib/list-devices                   |   33 -
 test/cordova/lib/list-devices.bat               |   26 -
 test/cordova/lib/list-emulator-images           |   32 -
 test/cordova/lib/list-emulator-images.bat       |   26 -
 test/cordova/lib/list-started-emulators         |   32 -
 test/cordova/lib/list-started-emulators.bat     |   26 -
 test/cordova/lib/log.js                         |   57 -
 test/cordova/lib/run.js                         |  139 --
 test/cordova/lib/start-emulator                 |   39 -
 test/cordova/lib/start-emulator.bat             |   26 -
 test/cordova/log                                |   36 -
 test/cordova/log.bat                            |   26 -
 test/cordova/node_modules/.bin/shjs             |    1 -
 test/cordova/node_modules/q/CONTRIBUTING.md     |   40 -
 test/cordova/node_modules/q/LICENSE             |   19 -
 test/cordova/node_modules/q/README.md           |  813 --------
 .../q/benchmark/compare-with-callbacks.js       |   71 -
 .../node_modules/q/benchmark/scenarios.js       |   36 -
 test/cordova/node_modules/q/package.json        |   93 -
 test/cordova/node_modules/q/q.js                | 1937 ------------------
 test/cordova/node_modules/q/queue.js            |   35 -
 .../node_modules/shelljs/.documentup.json       |    6 -
 test/cordova/node_modules/shelljs/.jshintrc     |    7 -
 test/cordova/node_modules/shelljs/.npmignore    |    2 -
 test/cordova/node_modules/shelljs/.travis.yml   |    5 -
 test/cordova/node_modules/shelljs/LICENSE       |   26 -
 test/cordova/node_modules/shelljs/README.md     |  552 -----
 test/cordova/node_modules/shelljs/bin/shjs      |   51 -
 test/cordova/node_modules/shelljs/global.js     |    3 -
 test/cordova/node_modules/shelljs/make.js       |   47 -
 test/cordova/node_modules/shelljs/package.json  |   48 -
 .../shelljs/scripts/generate-docs.js            |   21 -
 .../node_modules/shelljs/scripts/run-tests.js   |   50 -
 test/cordova/node_modules/shelljs/shell.js      |  153 --
 test/cordova/node_modules/shelljs/src/cat.js    |   43 -
 test/cordova/node_modules/shelljs/src/cd.js     |   19 -
 test/cordova/node_modules/shelljs/src/chmod.js  |  208 --
 test/cordova/node_modules/shelljs/src/common.js |  189 --
 test/cordova/node_modules/shelljs/src/cp.js     |  200 --
 test/cordova/node_modules/shelljs/src/dirs.js   |  191 --
 test/cordova/node_modules/shelljs/src/echo.js   |   20 -
 test/cordova/node_modules/shelljs/src/error.js  |   10 -
 test/cordova/node_modules/shelljs/src/exec.js   |  181 --
 test/cordova/node_modules/shelljs/src/find.js   |   51 -
 test/cordova/node_modules/shelljs/src/grep.js   |   52 -
 test/cordova/node_modules/shelljs/src/ls.js     |  126 --
 test/cordova/node_modules/shelljs/src/mkdir.js  |   68 -
 test/cordova/node_modules/shelljs/src/mv.js     |   80 -
 test/cordova/node_modules/shelljs/src/popd.js   |    1 -
 test/cordova/node_modules/shelljs/src/pushd.js  |    1 -
 test/cordova/node_modules/shelljs/src/pwd.js    |   11 -
 test/cordova/node_modules/shelljs/src/rm.js     |  145 --
 test/cordova/node_modules/shelljs/src/sed.js    |   43 -
 .../cordova/node_modules/shelljs/src/tempdir.js |   56 -
 test/cordova/node_modules/shelljs/src/test.js   |   85 -
 test/cordova/node_modules/shelljs/src/to.js     |   29 -
 test/cordova/node_modules/shelljs/src/toEnd.js  |   29 -
 test/cordova/node_modules/shelljs/src/which.js  |   79 -
 test/cordova/run                                |   37 -
 test/cordova/run.bat                            |   26 -
 test/cordova/version                            |   25 -
 test/cordova/version.bat                        |   26 -
 test/proguard.cfg                               |   57 -
 test/project.properties                         |    2 +-
 test/settings.gradle                            |    4 +
 .../test/junit/BackButtonMultiPageTest.java     |  272 ---
 .../cordova/test/junit/CordovaActivityTest.java |   79 -
 .../test/junit/CordovaResourceApiTest.java      |  281 ---
 .../apache/cordova/test/junit/CordovaTest.java  |  116 --
 .../apache/cordova/test/junit/ErrorUrlTest.java |   82 -
 .../apache/cordova/test/junit/FixWebView.java   |   43 -
 .../cordova/test/junit/HtmlNotFoundTest.java    |   80 -
 .../apache/cordova/test/junit/IFrameTest.java   |  128 --
 .../test/junit/IntentUriOverrideTest.java       |   94 -
 .../cordova/test/junit/LifecycleTest.java       |   34 -
 .../cordova/test/junit/PluginManagerTest.java   |   70 -
 .../cordova/test/junit/SplashscreenTest.java    |   49 -
 .../org/apache/cordova/test/junit/XhrTest.java  |   34 -
 .../org/apache/cordova/test/util/Purity.java    |  171 --
 122 files changed, 1861 insertions(+), 9591 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c352b296/bin/lib/create.js
----------------------------------------------------------------------
diff --cc bin/lib/create.js
index 1414c4a,5471bb4..e983fa4
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@@ -119,9 -120,9 +120,8 @@@ function writeProjectProperties(project
  
  function copyBuildRules(projectPath) {
      var srcDir = path.join(ROOT, 'bin', 'templates', 'project');
 -    shell.cp('-f', path.join(srcDir, 'custom_rules.xml'), projectPath);
  
      shell.cp('-f', path.join(srcDir, 'build.gradle'), projectPath);
-     shell.cp('-f', path.join(srcDir, 'cordova.gradle'), projectPath);
  }
  
  function copyScripts(projectPath) {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c352b296/test/androidTest/src/org/apache/cordova/test/junit/BackButtonMultiPageTest.java
----------------------------------------------------------------------
diff --cc test/androidTest/src/org/apache/cordova/test/junit/BackButtonMultiPageTest.java
index 0000000,9a73384..cc90538
mode 000000,100644..100644
--- a/test/androidTest/src/org/apache/cordova/test/junit/BackButtonMultiPageTest.java
+++ b/test/androidTest/src/org/apache/cordova/test/junit/BackButtonMultiPageTest.java
@@@ -1,0 -1,277 +1,278 @@@
+ 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.test.backbuttonmultipage;
+ 
+ import android.test.ActivityInstrumentationTestCase2;
+ import android.test.UiThreadTest;
+ import android.view.KeyEvent;
++import android.view.View;
+ import android.view.inputmethod.BaseInputConnection;
+ import android.widget.FrameLayout;
+ import android.widget.LinearLayout;
+ 
+ public class BackButtonMultiPageTest extends ActivityInstrumentationTestCase2<backbuttonmultipage>
{
+ 
+   private int TIMEOUT = 2000;
+   backbuttonmultipage testActivity;
+   private FrameLayout containerView;
+   private LinearLayout innerContainer;
+   private CordovaWebView testView;
+   
+ 
+   public BackButtonMultiPageTest() {
+     super(backbuttonmultipage.class);
+   }
+ 
+   @Override
+   public void setUp() {
+       testActivity = getActivity();
+       containerView = (FrameLayout) testActivity.findViewById(android.R.id.content);
+       innerContainer = (LinearLayout) containerView.getChildAt(0);
+       testView = (CordovaWebView) innerContainer.getChildAt(0);
+   }
+ 
+   void loadTestPage() {
+      testView.loadUrl("file:///android_asset/www/backbuttonmultipage/index.html");
+      sleep();
+   }
+ 
+   @UiThreadTest
+   public void testPreconditions(){
+       loadTestPage();
+       assertNotNull(innerContainer);
+       assertNotNull(testView);
+       String url = testView.getUrl();
+       assertTrue(url.endsWith("index.html"));
+   }
+   
+   public void testViaHref() throws Throwable {
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               loadTestPage();
+               testView.sendJavascript("window.location = 'sample2.html';");
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html",
url);
+               testView.sendJavascript("window.location = 'sample3.html';");          }
+       });
+      
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertEquals("file:///android_asset/www/backbuttonmultipage/sample3.html",
url);
+               assertTrue(testView.backHistory());
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertEquals("file:///android_asset/www/backbuttonmultipage/sample2.html",
url);
+               assertTrue(testView.backHistory());
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertEquals("file:///android_asset/www/backbuttonmultipage/index.html", url);
+           }
+       });
+   }
+   
+   public void testViaLoadUrl() throws Throwable {
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               loadTestPage();
+               testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample2.html"));
+               testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample3.html"));
+               testView.backHistory();
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample2.html"));
+               testView.backHistory();
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("index.html"));
+               testView.backHistory();
+           }
+       });
+   }
+ 
+   public void testViaBackButtonOnView() throws Throwable {
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               loadTestPage();
+               testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample2.html"));
+               testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample3.html"));
 -              BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
++              BaseInputConnection viewConnection = new BaseInputConnection((View) testView,
true);
+               KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
+               KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
+               viewConnection.sendKeyEvent(backDown);
+               viewConnection.sendKeyEvent(backUp);
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample2.html"));
 -              BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
++              BaseInputConnection viewConnection = new BaseInputConnection((View) testView,
true);
+               KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
+               KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
+               viewConnection.sendKeyEvent(backDown);
+               viewConnection.sendKeyEvent(backUp);
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("index.html"));
+           }
+       });
+       
+   }
+   
+   public void testViaBackButtonOnLayout() throws Throwable {
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               loadTestPage();
+               testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample2.html"));
+               testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample3.html"));
+               BaseInputConnection viewConnection = new BaseInputConnection(containerView,
true);
+               KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
+               KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
+               viewConnection.sendKeyEvent(backDown);
+               viewConnection.sendKeyEvent(backUp);
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("sample2.html"));
+               BaseInputConnection viewConnection = new BaseInputConnection(containerView,
true);
+               KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
+               KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
+               viewConnection.sendKeyEvent(backDown);
+               viewConnection.sendKeyEvent(backUp);
+           }
+       });
+       sleep();
+       runTestOnUiThread(new Runnable() {
+           public void run()
+           {
+               String url = testView.getUrl();
+               assertTrue(url.endsWith("index.html"));
+           }
+       });
+       
+   }
+ 
+   private void sleep() {
+       try {
+           Thread.sleep(TIMEOUT);
+       } catch (InterruptedException e) {
+           fail("Unexpected Timeout");
+       }
+   }
+ 
+ }
+ 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c352b296/test/androidTest/src/org/apache/cordova/test/junit/CordovaActivityTest.java
----------------------------------------------------------------------
diff --cc test/androidTest/src/org/apache/cordova/test/junit/CordovaActivityTest.java
index 0000000,883a0f7..08590be
mode 000000,100644..100644
--- a/test/androidTest/src/org/apache/cordova/test/junit/CordovaActivityTest.java
+++ b/test/androidTest/src/org/apache/cordova/test/junit/CordovaActivityTest.java
@@@ -1,0 -1,79 +1,79 @@@
+ /*
+        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.PluginManager;
+ 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<MainTestActivity>
{
+ 
+     private MainTestActivity testActivity;
+     private FrameLayout containerView;
+     private LinearLayout innerContainer;
+     private CordovaWebView testView;
+     private Instrumentation mInstr;
+     private int TIMEOUT = 1000;
+     
+     @SuppressWarnings("deprecation")
+     public CordovaActivityTest()
+     {
+         super("org.apache.cordova.test",MainTestActivity.class);
+     }
+     
+     protected void setUp() throws Exception {
+         super.setUp();
+         mInstr = this.getInstrumentation();
+         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 testForCordovaView() {
++    public void testForAndroidWebView() {
+         String className = testView.getClass().getSimpleName();
 -        assertTrue(className.equals("CordovaWebView"));
++        assertTrue(className.equals("AndroidWebView"));
+     }
+     
+     public void testForLinearLayout() {
+         String className = innerContainer.getClass().getSimpleName();
+         assertTrue(className.equals("LinearLayoutSoftKeyboardDetect"));
+     }
+ 
+     private void sleep() {
+         try {
+           Thread.sleep(TIMEOUT);
+         } catch (InterruptedException e) {
+           fail("Unexpected Timeout");
+         }
+     }
+ }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c352b296/test/androidTest/src/org/apache/cordova/test/junit/CordovaResourceApiTest.java
----------------------------------------------------------------------
diff --cc test/androidTest/src/org/apache/cordova/test/junit/CordovaResourceApiTest.java
index 0000000,1c91922..a8a5370
mode 000000,100644..100644
--- a/test/androidTest/src/org/apache/cordova/test/junit/CordovaResourceApiTest.java
+++ b/test/androidTest/src/org/apache/cordova/test/junit/CordovaResourceApiTest.java
@@@ -1,0 -1,281 +1,281 @@@
+ 
+ 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 android.graphics.Bitmap;
+ import android.graphics.BitmapFactory;
+ import android.net.Uri;
+ import android.os.Environment;
+ import android.provider.MediaStore;
+ import android.test.ActivityInstrumentationTestCase2;
+ 
+ import org.apache.cordova.CallbackContext;
+ import org.apache.cordova.CordovaPlugin;
+ import org.apache.cordova.CordovaResourceApi;
+ import org.apache.cordova.CordovaResourceApi.OpenForReadResult;
+ import org.apache.cordova.CordovaWebView;
+ import org.apache.cordova.PluginEntry;
+ import org.apache.cordova.test.CordovaWebViewTestActivity;
+ import org.apache.cordova.test.R;
+ import org.json.JSONArray;
+ import org.json.JSONException;
+ 
+ import java.io.File;
+ import java.io.IOException;
+ import java.io.OutputStream;
+ import java.util.Scanner;
+ 
+ public class CordovaResourceApiTest extends ActivityInstrumentationTestCase2<CordovaWebViewTestActivity>
{
+ 
+     public CordovaResourceApiTest()
+     {
+         super(CordovaWebViewTestActivity.class);
+     }
+ 
+     CordovaWebView cordovaWebView;
+     CordovaResourceApi resourceApi;
+ 
+     private CordovaWebViewTestActivity activity;
+     String execPayload;
+     Integer execStatus;
+ 
+     protected void setUp() throws Exception {
+         super.setUp();
+         activity = this.getActivity();
+         cordovaWebView = activity.cordovaWebView;
+         resourceApi = cordovaWebView.getResourceApi();
+         resourceApi.setThreadCheckingEnabled(false);
 -        cordovaWebView.pluginManager.addService(new PluginEntry("CordovaResourceApiTestPlugin1",
new CordovaPlugin() {
++        cordovaWebView.getPluginManager().addService(new PluginEntry("CordovaResourceApiTestPlugin1",
new CordovaPlugin() {
+             @Override
+             public Uri remapUri(Uri uri) {
+                 if (uri.getQuery() != null && uri.getQuery().contains("pluginRewrite"))
{
+                     return cordovaWebView.getResourceApi().remapUri(
+                             Uri.parse("data:text/plain;charset=utf-8,pass"));
+                 }
+                 return null;
+             }
+             public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
throws JSONException {
+                 synchronized (CordovaResourceApiTest.this) {
+                     execPayload = args.getString(0);
+                     execStatus = args.getInt(1);
+                     CordovaResourceApiTest.this.notify();
+                 }
+                 return true;
+             }
+         }));
+     }
+ 
+     private Uri createTestImageContentUri() {
+         Bitmap imageBitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.icon);
+         String stored = MediaStore.Images.Media.insertImage(activity.getContentResolver(),
+                 imageBitmap, "app-icon", "desc");
+         return Uri.parse(stored);
+     }
+ 
+     private void performApiTest(Uri uri, String expectedMimeType, File expectedLocalFile,
+             boolean expectRead, boolean expectWrite) throws IOException {
+         uri = resourceApi.remapUri(uri);
+         assertEquals(expectedLocalFile, resourceApi.mapUriToFile(uri));
+         
+         try {
+             OpenForReadResult readResult = resourceApi.openForRead(uri);
+             String mimeType2 = resourceApi.getMimeType(uri);
+             assertEquals("openForRead mime-type", expectedMimeType, readResult.mimeType);
+             assertEquals("getMimeType mime-type", expectedMimeType, mimeType2);
+             readResult.inputStream.read();
+             if (!expectRead) {
+                 fail("Expected getInputStream to throw.");
+             }
+         } catch (IOException e) {
+             if (expectRead) {
+                 throw e;
+             }
+         }
+         try {
+             OutputStream outStream = resourceApi.openOutputStream(uri);
+             outStream.write(123);
+             if (!expectWrite) {
+                 fail("Expected getOutputStream to throw.");
+             }
+             outStream.close();
+         } catch (IOException e) {
+             if (expectWrite) {
+                 throw e;
+             }
+         }
+     }
+ 
+     public void testValidContentUri() throws IOException
+     {
+         Uri contentUri = createTestImageContentUri();
+         File localFile = resourceApi.mapUriToFile(contentUri);
+         assertNotNull(localFile);
+         performApiTest(contentUri, "image/jpeg", localFile, true, true);
+     }
+ 
+     public void testInvalidContentUri() throws IOException
+     {
+         Uri contentUri = Uri.parse("content://media/external/images/media/999999999");
+         performApiTest(contentUri, null, null, false, false);
+     }
+ 
+     public void testValidAssetUri() throws IOException
+     {
+         Uri assetUri = Uri.parse("file:///android_asset/www/index.html?foo#bar"); // Also
check for stripping off ? and # correctly.
+         performApiTest(assetUri, "text/html", null, true, false);
+     }
+ 
+     public void testInvalidAssetUri() throws IOException
+     {
+         Uri assetUri = Uri.parse("file:///android_asset/www/missing.html");
+         performApiTest(assetUri, "text/html", null, false, false);
+     }
+ 
+     public void testFileUriToExistingFile() throws IOException
+     {
+         File f = File.createTempFile("te s t", ".txt"); // Also check for dealing with spaces.
+         try {
+             Uri fileUri = Uri.parse(f.toURI().toString() + "?foo#bar"); // Also check for
stripping off ? and # correctly.
+             performApiTest(fileUri, "text/plain", f, true, true);
+         } finally {
+             f.delete();
+         }
+     }
+ 
+     public void testFileUriToMissingFile() throws IOException
+     {
+         File f = new File(Environment.getExternalStorageDirectory() + "/somefilethatdoesntexist");
+         Uri fileUri = Uri.parse(f.toURI().toString());
+         try {
+             performApiTest(fileUri, null, f, false, true);
+         } finally {
+             f.delete();
+         }
+     }
+     
+     public void testFileUriToMissingFileWithMissingParent() throws IOException
+     {
+         File f = new File(Environment.getExternalStorageDirectory() + "/somedirthatismissing"
+ System.currentTimeMillis() + "/somefilethatdoesntexist");
+         Uri fileUri = Uri.parse(f.toURI().toString());
+         performApiTest(fileUri, null, f, false, true);
+     }
+ 
+     public void testUnrecognizedUri() throws IOException
+     {
+         Uri uri = Uri.parse("somescheme://foo");
+         performApiTest(uri, null, null, false, false);
+     }
+ 
+     public void testRelativeUri()
+     {
+         try {
+             resourceApi.openForRead(Uri.parse("/foo"));
+             fail("Should have thrown for relative URI 1.");
+         } catch (Throwable t) {
+         }
+         try {
+             resourceApi.openForRead(Uri.parse("//foo/bar"));
+             fail("Should have thrown for relative URI 2.");
+         } catch (Throwable t) {
+         }
+         try {
+             resourceApi.openForRead(Uri.parse("foo.png"));
+             fail("Should have thrown for relative URI 3.");
+         } catch (Throwable t) {
+         }
+     }
+     
+     public void testPluginOverride() throws IOException
+     {
+         Uri uri = Uri.parse("plugin-uri://foohost/android_asset/www/index.html?pluginRewrite=yes");
+         performApiTest(uri, "text/plain", null, true, false);
+     }
+ 
+     public void testMainThreadUsage() throws IOException
+     {
+         Uri assetUri = Uri.parse("file:///android_asset/www/index.html");
+         resourceApi.setThreadCheckingEnabled(true);
+         try {
+             resourceApi.openForRead(assetUri);
+             fail("Should have thrown for main thread check.");
+         } catch (Throwable t) {
+         }
+     }
+     
+     
+     public void testDataUriPlain() throws IOException
+     {
+         Uri uri = Uri.parse("data:text/plain;charset=utf-8,pa%20ss");
+         OpenForReadResult readResult = resourceApi.openForRead(uri);
+         assertEquals("text/plain", readResult.mimeType);
+         String data = new Scanner(readResult.inputStream, "UTF-8").useDelimiter("\\A").next();
+         assertEquals("pa ss", data);
+     }
+     
+     public void testDataUriBase64() throws IOException
+     {
+         Uri uri = Uri.parse("data:text/js;charset=utf-8;base64,cGFzcw==");
+         OpenForReadResult readResult = resourceApi.openForRead(uri);
+         assertEquals("text/js", readResult.mimeType);
+         String data = new Scanner(readResult.inputStream, "UTF-8").useDelimiter("\\A").next();
+         assertEquals("pass", data);
+     }
+     
+     public void testWebViewRequestIntercept() throws IOException
+     {
+         cordovaWebView.sendJavascript(
+             "var x = new XMLHttpRequest;\n" +
+             "x.open('GET', 'file://foo?pluginRewrite=1', false);\n" + 
+             "x.send();\n" + 
+             "cordova.require('cordova/exec')(null,null,'CordovaResourceApiTestPlugin1',
'foo', [x.responseText, x.status])");
+         execPayload = null;
+         execStatus = null;
+         try {
+             synchronized (this) {
+                 this.wait(2000);
+             }
+         } catch (InterruptedException e) {
+         }
+         assertEquals("pass", execPayload);
+         assertEquals(execStatus.intValue(), 200);
+     }
+     
+     public void testWebViewWhiteListRejection() throws IOException
+     {
+         cordovaWebView.sendJavascript(
+             "var x = new XMLHttpRequest;\n" +
+             "x.open('GET', 'http://foo/bar', false);\n" + 
+             "x.send();\n" + 
+             "cordova.require('cordova/exec')(null,null,'CordovaResourceApiTestPlugin1',
'foo', [x.responseText, x.status])");
+         execPayload = null;
+         execStatus = null;
+         try {
+             synchronized (this) {
+                 this.wait(2000);
+             }
+         } catch (InterruptedException e) {
+         }
+         assertEquals("", execPayload);
+         assertEquals(execStatus.intValue(), 404);
+     }    
+ }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/c352b296/test/androidTest/src/org/apache/cordova/test/junit/CordovaTest.java
----------------------------------------------------------------------
diff --cc test/androidTest/src/org/apache/cordova/test/junit/CordovaTest.java
index 0000000,02f4ee6..2e09611
mode 000000,100644..100644
--- a/test/androidTest/src/org/apache/cordova/test/junit/CordovaTest.java
+++ b/test/androidTest/src/org/apache/cordova/test/junit/CordovaTest.java
@@@ -1,0 -1,116 +1,116 @@@
+ /*
+        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.PluginManager;
+ import org.apache.cordova.test.CordovaWebViewTestActivity;
+ import org.apache.cordova.test.R;
+ 
+ import android.app.Instrumentation;
+ import android.test.ActivityInstrumentationTestCase2;
+ import android.view.View;
+ 
+ public class CordovaTest extends
+     ActivityInstrumentationTestCase2<CordovaWebViewTestActivity> {
+ 
+   private static final long TIMEOUT = 1000;
+   private CordovaWebViewTestActivity testActivity;
+   private View testView;
+   private String rString;
+ 
+   public CordovaTest() {
+     super("org.apache.cordova.test.activities", CordovaWebViewTestActivity.class);
+   }
+ 
+   protected void setUp() throws Exception {
+     super.setUp();
+     testActivity = this.getActivity();
+     testView = testActivity.findViewById(R.id.cordovaWebView);
+   }
+ 
+   public void testPreconditions() {
+     assertNotNull(testView);
+   }
+ 
 -  public void testForCordovaView() {
++  public void testForAndroidWebView() {
+     //Sleep for no reason!!!!
 -    sleep();
++    sleep();        
+     String className = testView.getClass().getSimpleName();
 -    assertTrue(className.equals("CordovaWebView"));
++    assertTrue(className.equals("AndroidWebView"));
+   }
+ 
+   /*
+   public void testForPluginManager() {
+     CordovaWebView v = (CordovaWebView) testView;
+     PluginManager p = v.getPluginManager();
+     assertNotNull(p);
+     String className = p.getClass().getSimpleName();
+     assertTrue(className.equals("PluginManager"));
+   }
+ 
+   public void testBackButton() {
+     CordovaWebView v = (CordovaWebView) testView;
+     assertFalse(v.checkBackKey());
+   }
+ 
+   public void testLoadUrl() {
+     CordovaWebView v = (CordovaWebView) testView;
+     v.loadUrlIntoView("file:///android_asset/www/index.html");
+     sleep();
+     String url = v.getUrl();
+     boolean result = url.equals("file:///android_asset/www/index.html");
+     assertTrue(result);
+     int visible = v.getVisibility();
+     assertTrue(visible == View.VISIBLE);
+   }
+ 
+   public void testBackHistoryFalse() {
+     CordovaWebView v = (CordovaWebView) testView;
+     // Move back in the history
+     boolean test = v.backHistory();
+     assertFalse(test);
+   }
+ 
+   // Make sure that we can go back
+   public void testBackHistoryTrue() {
+     this.testLoadUrl();
+     CordovaWebView v = (CordovaWebView) testView;
+     v.loadUrlIntoView("file:///android_asset/www/compass/index.html");
+     sleep();
+     String url = v.getUrl();
+     assertTrue(url.equals("file:///android_asset/www/compass/index.html"));
+     // Move back in the history
+     boolean test = v.backHistory();
+     assertTrue(test);
+     sleep();
+     url = v.getUrl();
+     assertTrue(url.equals("file:///android_asset/www/index.html"));
+   }
+   */
+   
+ 
+   private void sleep() {
+     try {
+       Thread.sleep(TIMEOUT);
+     } catch (InterruptedException e) {
+       fail("Unexpected Timeout");
+     }
+   }
+ }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message