You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2013/01/30 00:21:01 UTC

[1/5] android commit: Adding purity to the test suite. Purity is a test class that may be renamed later

Adding purity to the test suite.  Purity is a test class that may be renamed later


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

Branch: refs/heads/master
Commit: 66f15fdd3758331f7fffd7f3dd83a8d528a9b925
Parents: 038f0e4
Author: Joe Bowser <bo...@apache.org>
Authored: Fri Jan 18 15:00:02 2013 -0800
Committer: Joe Bowser <bo...@apache.org>
Committed: Fri Jan 18 15:00:02 2013 -0800

----------------------------------------------------------------------
 test/src/org/apache/cordova/test/JQMTabTest.java  |   24 ++++
 test/src/org/apache/cordova/test/util/Purity.java |  101 ++++++++++++++++
 2 files changed, 125 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/66f15fdd/test/src/org/apache/cordova/test/JQMTabTest.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/JQMTabTest.java b/test/src/org/apache/cordova/test/JQMTabTest.java
index 8d01ff2..1e58dee 100644
--- a/test/src/org/apache/cordova/test/JQMTabTest.java
+++ b/test/src/org/apache/cordova/test/JQMTabTest.java
@@ -21,15 +21,39 @@ package org.apache.cordova.test;
 */
 
 
+import org.apache.cordova.CordovaWebView;
+import org.apache.cordova.test.util.Purity;
 import org.apache.cordova.test.actions.jqmtabbackbutton;
 
+import android.app.Instrumentation;
 import android.test.ActivityInstrumentationTestCase2;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
 
 public class JQMTabTest extends ActivityInstrumentationTestCase2<jqmtabbackbutton> {
 
+  private Instrumentation mInstr;
+  private jqmtabbackbutton testActivity;
+  private FrameLayout containerView; 
+  private LinearLayout innerContainer;
+  private CordovaWebView testView;
+  private Purity touchTool;
+
   public JQMTabTest(Class<jqmtabbackbutton> activityClass) {
     super(activityClass);
     // TODO Auto-generated constructor stub
   }
+  
+  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);
+      touchTool = new Purity(testActivity, getInstrumentation());
+  }
+  
+  
 
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/66f15fdd/test/src/org/apache/cordova/test/util/Purity.java
----------------------------------------------------------------------
diff --git a/test/src/org/apache/cordova/test/util/Purity.java b/test/src/org/apache/cordova/test/util/Purity.java
new file mode 100644
index 0000000..0cee494
--- /dev/null
+++ b/test/src/org/apache/cordova/test/util/Purity.java
@@ -0,0 +1,101 @@
+/*
+       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.
+*/
+
+/*
+ * Purity is a small set of Android utility methods that allows us to simulate touch events on 
+ * Android applications.  This is important for simulating some of the most annoying tests.
+ */
+
+package org.apache.cordova.test.util;
+
+import android.app.Instrumentation;
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Picture;
+import android.os.SystemClock;
+import android.util.DisplayMetrics;
+import android.view.MotionEvent;
+import android.webkit.WebView;
+
+
+public class Purity {
+
+    Instrumentation inst;
+    int width, height;
+    float density;
+    Bitmap state;
+   
+    public Purity(Context ctx, Instrumentation i)
+    {
+        inst = i;
+        DisplayMetrics display = ctx.getResources().getDisplayMetrics();
+        density = display.density;
+        width = display.widthPixels;
+        height = display.heightPixels;
+        
+    }
+    
+    /*
+     * WebKit doesn't give you real pixels anymore, this is done for subpixel fonts to appear on
+     * iOS and Android.  However, Android automation requires real pixels
+     */
+    private int getRealCoord(int coord)
+    {
+        return (int) (coord * density);
+    }
+
+    public void touch(int x, int y)
+    {
+        int realX = getRealCoord(x);
+        int realY = getRealCoord(y);
+        long downTime = SystemClock.uptimeMillis();
+        // event time MUST be retrieved only by this way!
+        long eventTime = SystemClock.uptimeMillis();
+        MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, realX, realY, 0);
+        inst.sendPointerSync(event);
+    }
+    
+    public void setBitmap(WebView view)
+    {
+        Picture p = view.capturePicture();
+        state = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
+    }
+    
+    public boolean checkRenderView(WebView view)
+    {
+        if(state == null)
+        {
+            setBitmap(view);
+            return false;
+        }
+        else
+        {
+            Picture p = view.capturePicture();
+            Bitmap newState = Bitmap.createBitmap(p.getWidth(), p.getHeight(), Bitmap.Config.ARGB_8888);
+            boolean result = newState.equals(state);
+            newState.recycle();
+            return result;
+        }
+    }
+    
+    public void clearBitmap()
+    {
+        state.recycle();
+    }
+}