cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject [20/50] git commit: Adding tests related to 3.5.1
Date Thu, 28 Aug 2014 19:03:34 GMT
Adding tests related to 3.5.1


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/0a53a0c7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/0a53a0c7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/0a53a0c7

Branch: refs/heads/master
Commit: 0a53a0c7a923152829a0b05fa39228db41305590
Parents: 96c6c52
Author: Joe Bowser <bowserj@apache.org>
Authored: Tue Aug 12 11:09:53 2014 -0700
Committer: Archana Naik <naika@lab126.com>
Committed: Mon Aug 18 12:33:46 2014 -0700

----------------------------------------------------------------------
 .../apache/cordova/test/SabotagedActivity.java  | 73 ++++++++++++++++++++
 .../test/junit/IntentUriOverrideTest.java       | 73 ++++++++++++++++++++
 2 files changed, 146 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/0a53a0c7/test/src/org/apache/cordova/test/SabotagedActivity.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/SabotagedActivity.java b/test/src/org/apache/cordova/test/SabotagedActivity.java
new file mode 100644
index 0000000..e1170ba
--- /dev/null
+++ b/test/src/org/apache/cordova/test/SabotagedActivity.java
@@ -0,0 +1,73 @@
+package org.apache.cordova.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.FileOutputStream;
+
+import org.apache.cordova.Config;
+import org.apache.cordova.CordovaActivity;
+
+import android.content.res.AssetManager;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+
+public class SabotagedActivity extends CordovaActivity {
+
+    private String BAD_ASSET = "www/error.html";
+    private String LOG_TAG = "SabotagedActivity";
+    
+    
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);        
+        
+//        copyErrorAsset();
+        super.init();
+        super.loadUrl(Config.getStartUrl());
+    }
+
+    /* 
+     * Sometimes we need to move code around before we can do anything.  This will
+     * copy the bad code out of the assets before we initalize Cordova so that when Cordova
actually
+     * initializes, we have something for it to navigate to.
+     */ 
+    
+    private void copyErrorAsset () {
+        AssetManager assetManager = getAssets();
+        String[] files = null;
+        try {
+            files = assetManager.list(BAD_ASSET);
+        } catch (IOException e) {
+            Log.e(LOG_TAG, e.getMessage());
+        }
+
+        for(String filename : files) {
+            InputStream in = null;
+            OutputStream out = null;
+            try {
+              in = assetManager.open(BAD_ASSET);
+              out = new FileOutputStream(Environment.getExternalStorageDirectory().toString()
+"/" + filename);
+              copy(in, out);
+              in.close();
+              in = null;
+              out.flush();
+              out.close();
+              out = null;
+            } catch(Exception e) {
+                Log.e("tag", e.getMessage());
+            }
+        }
+    }
+    
+    
+    //Quick and Dirty Copy! 
+    private void copy(InputStream in, OutputStream out) throws IOException {
+        byte[] buffer = new byte[1024];
+        int read;
+        while((read = in.read(buffer)) != -1){
+          out.write(buffer, 0, read);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/0a53a0c7/test/src/org/apache/cordova/test/junit/IntentUriOverrideTest.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/junit/IntentUriOverrideTest.java b/test/src/org/apache/cordova/test/junit/IntentUriOverrideTest.java
new file mode 100644
index 0000000..aea06af
--- /dev/null
+++ b/test/src/org/apache/cordova/test/junit/IntentUriOverrideTest.java
@@ -0,0 +1,73 @@
+package org.apache.cordova.test.junit;
+
+import org.apache.cordova.CordovaWebView;
+import org.apache.cordova.test.SabotagedActivity;
+import org.apache.cordova.test.splashscreen;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.AssetManager;
+import android.test.ActivityInstrumentationTestCase2;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+
+
+public class IntentUriOverrideTest extends ActivityInstrumentationTestCase2<SabotagedActivity>
{
+    
+    private int TIMEOUT = 1000;
+    
+    private SabotagedActivity testActivity;
+    private FrameLayout containerView;
+    private LinearLayout innerContainer;
+    private CordovaWebView testView;
+    private Instrumentation mInstr;
+    private String BAD_URL = "file:///sdcard/download/wl-exploit.htm";
+
+
+    public IntentUriOverrideTest()
+    {
+        super("org.apache.cordova.test",SabotagedActivity.class);
+    }
+    
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        mInstr = this.getInstrumentation();
+        Intent badIntent = new Intent();
+        badIntent.setClassName("org.apache.cordova.test", "org.apache.cordova.test.SabotagedActivity");
+        badIntent.putExtra("url", BAD_URL);
+        setActivityIntent(badIntent);
+        testActivity = 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 testChangeStartUrl() throws Throwable
+    {
+        runTestOnUiThread(new Runnable() {
+            public void run()
+            {
+                boolean isBadUrl = testView.getUrl().equals(BAD_URL);
+                assertFalse(isBadUrl);
+            }
+        });
+    }
+
+    private void sleep() {
+        try {
+          Thread.sleep(TIMEOUT);
+        } catch (InterruptedException e) {
+          fail("Unexpected Timeout");
+        }
+    }
+    
+
+}


Mime
View raw message