Merge "Fix calculation for swipe margin of error"
diff --git a/suite/pts/deviceTests/opengl/jni/contextswitch/ContextSwitchRenderer.cpp b/suite/pts/deviceTests/opengl/jni/contextswitch/ContextSwitchRenderer.cpp
index df31cbc..d64ca3f 100644
--- a/suite/pts/deviceTests/opengl/jni/contextswitch/ContextSwitchRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/contextswitch/ContextSwitchRenderer.cpp
@@ -26,14 +26,17 @@
 static const EGLint contextAttribs[] =
         { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
 
-static const float csVertices[] = {
+static const int CS_NUM_VERTICES = 6;
+
+static const float CS_VERTICES[CS_NUM_VERTICES * 3] = {
         1.0f, 1.0f, -1.0f,
         -1.0f, 1.0f, -1.0f,
         -1.0f, -1.0f, -1.0f,
         -1.0f, -1.0f, -1.0f,
         1.0f, -1.0f, -1.0f,
         1.0f, 1.0f, -1.0f };
-static const float csTexCoords[] = {
+
+static const float CS_TEX_COORDS[CS_NUM_VERTICES * 2] = {
         1.0f, 1.0f,
         0.0f, 1.0f,
         0.0f, 0.0f,
@@ -41,7 +44,7 @@
         1.0f, 0.0f,
         1.0f, 1.0f };
 
-static const char* csVertex =
+static const char* CS_VERTEX =
         "attribute vec4 a_Position;"
         "attribute vec2 a_TexCoord;"
         "varying vec2 v_TexCoord;"
@@ -50,7 +53,7 @@
         "  gl_Position = a_Position;"
         "}";
 
-static const char* csFragment =
+static const char* CS_FRAGMENT =
         "precision mediump float;"
         "uniform sampler2D u_Texture;"
         "varying vec2 v_TexCoord;"
@@ -96,7 +99,7 @@
     }
 
     // Create program.
-    mProgram = GLUtils::createProgram(&csVertex, &csFragment);
+    mProgram = GLUtils::createProgram(&CS_VERTEX, &CS_FRAGMENT);
     if (mProgram == 0)
         return false;
     // Bind attributes.
@@ -142,11 +145,11 @@
         glEnableVertexAttribArray(mPositionHandle);
         glEnableVertexAttribArray(mTexCoordHandle);
         glVertexAttribPointer(mPositionHandle, 3, GL_FLOAT, false, 0,
-                csVertices);
+                CS_VERTICES);
         glVertexAttribPointer(mTexCoordHandle, 2, GL_FLOAT, false, 0,
-                csTexCoords);
+                CS_TEX_COORDS);
 
-        glDrawArrays(GL_TRIANGLES, 0, 6);
+        glDrawArrays(GL_TRIANGLES, 0, CS_NUM_VERTICES);
     }
     return eglSwapBuffers(mEglDisplay, mEglSurface);
 }
diff --git a/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineMesh.cpp b/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineMesh.cpp
index 895df9f..097dcdd 100644
--- a/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineMesh.cpp
+++ b/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineMesh.cpp
@@ -30,9 +30,12 @@
     glUniform1i(prog.mTextureUniformHandle, 0);
 
     glEnableVertexAttribArray(prog.mPositionHandle);
+    glEnableVertexAttribArray(prog.mNormalHandle);
     glEnableVertexAttribArray(prog.mTexCoordHandle);
     glVertexAttribPointer(prog.mPositionHandle, 3, GL_FLOAT, false, 0,
             mMesh->mVertices);
+    glVertexAttribPointer(prog.mNormalHandle, 3, GL_FLOAT, false, 0,
+            mMesh->mNormals);
     glVertexAttribPointer(prog.mTexCoordHandle, 2, GL_FLOAT, false, 0,
             mMesh->mTexCoords);
 
diff --git a/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineRenderer.cpp b/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineRenderer.cpp
index 1769701..f85a173 100644
--- a/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/fullpipeline/FullPipelineRenderer.cpp
@@ -11,7 +11,7 @@
  * or implied. See the License for the specific language governing permissions and limitations under
  * the License.
  */
-
+#include <math.h>
 #include <EGL/egl.h>
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
@@ -23,21 +23,25 @@
 #include <graphics/TransformationNode.h>
 #include <GLUtils.h>
 
-static const float fullVertices[] = {
-        1.0f, 1.0f, -1.0f,
-        -1.0f, 1.0f, -1.0f,
-        -1.0f, -1.0f, -1.0f,
-        -1.0f, -1.0f, -1.0f,
-        1.0f, -1.0f, -1.0f,
-        1.0f, 1.0f, -1.0f };
-static const float fullNormals[] = {
+static const int FP_NUM_VERTICES = 6;
+
+static const float FP_VERTICES[FP_NUM_VERTICES * 3] = {
+        1.0f, 1.0f, 0.0f,
+        0.0f, 1.0f, 0.0f,
+        0.0f, 0.0f, 0.0f,
+        0.0f, 0.0f, 0.0f,
+        1.0f, 0.0f, 0.0f,
+        1.0f, 1.0f, 0.0f };
+
+static const float FP_NORMALS[FP_NUM_VERTICES * 3] = {
         0.0f, 0.0f, 1.0f,
         0.0f, 0.0f, 1.0f,
         0.0f, 0.0f, 1.0f,
         0.0f, 0.0f, 1.0f,
         0.0f, 0.0f, 1.0f,
         0.0f, 0.0f, 1.0f };
-static const float fullTexCoords[] = {
+
+static const float FP_TEX_COORDS[FP_NUM_VERTICES * 2] = {
         1.0f, 1.0f,
         0.0f, 1.0f,
         0.0f, 0.0f,
@@ -45,7 +49,7 @@
         1.0f, 0.0f,
         1.0f, 1.0f };
 
-static const char* fullVertex =
+static const char* FP_VERTEX =
         "uniform mat4 u_MVPMatrix;"
         "uniform mat4 u_MVMatrix;"
         "attribute vec4 a_Position;"
@@ -65,7 +69,7 @@
         "  gl_Position = u_MVPMatrix * a_Position;\n"
         "}";
 
-static const char* fullFragment =
+static const char* FP_FRAGMENT =
         "precision mediump float;"
         "uniform vec3 u_LightPos;"
         "uniform sampler2D u_Texture;"
@@ -96,7 +100,7 @@
     if (!Renderer::setUp()) {
         return false;
     }
-    GLuint programId = GLUtils::createProgram(&fullVertex, &fullFragment);
+    GLuint programId = GLUtils::createProgram(&FP_VERTEX, &FP_FRAGMENT);
     if (programId == 0)
         return false;
     mProgram = new FullPipelineProgram(programId);
@@ -107,15 +111,12 @@
     // Use culling to remove back faces.
     glEnable (GL_CULL_FACE);
 
-    // Enable depth testing
-    glEnable (GL_DEPTH_TEST);
-
     mModelMatrix = new Matrix();
 
     // Position the eye in front of the origin.
     float eyeX = 0.0f;
     float eyeY = 0.0f;
-    float eyeZ = 6.0f;
+    float eyeZ = 2.0f;
 
     // We are looking at the origin
     float centerX = 0.0f;
@@ -139,7 +140,7 @@
     float bottom = -1.0f;
     float top = 1.0f;
     float near = 1.0f;
-    float far = 10.0f;
+    float far = 3.0f;
 
     mProjectionMatrix = Matrix::newFrustum(left, right, bottom, top, near, far);
 
@@ -148,15 +149,22 @@
         return false;
     }
 
+    float count = pow(2, mWorkload-1);
+    float middle = count / 2.0f;
+    float scale = 1.0f / count;
+
+    mMesh = new Mesh(FP_VERTICES, FP_NORMALS, FP_TEX_COORDS, FP_NUM_VERTICES, textureId);
     mSceneGraph = new ProgramNode();
-    mMesh = new Mesh(fullVertices, fullNormals, fullTexCoords, 6, textureId);
-    for (int i = 0; i < mWorkload; i++) {
-        Matrix* transformMatrix = Matrix::newRotate(45.0f, 0.0f, 1.0f, 0.0f);
-        TransformationNode* transformNode = new TransformationNode(
-                transformMatrix);
-        mSceneGraph->addChild(transformNode);
-        FullPipelineMesh* meshNode = new FullPipelineMesh(mMesh);
-        transformNode->addChild(meshNode);
+
+    for (int i = 0; i < count; i++) {
+        for (int j = 0; j < count; j++) {
+            Matrix* transformMatrix = Matrix::newScale(scale, scale, scale);
+            transformMatrix->translate(i - middle, j - middle, 0.0f);
+            TransformationNode* transformNode = new TransformationNode(transformMatrix);
+            mSceneGraph->addChild(transformNode);
+            FullPipelineMesh* meshNode = new FullPipelineMesh(mMesh);
+            transformNode->addChild(meshNode);
+        }
     }
     return true;
 }
@@ -183,7 +191,6 @@
 bool FullPipelineRenderer::draw() {
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
     mModelMatrix->identity();
-    mSceneGraph->draw(*mProgram, *mModelMatrix, *mViewMatrix,
-            *mProjectionMatrix);
+    mSceneGraph->draw(*mProgram, *mModelMatrix, *mViewMatrix, *mProjectionMatrix);
     return eglSwapBuffers(mEglDisplay, mEglSurface);
 }
diff --git a/suite/pts/deviceTests/opengl/jni/graphics/Matrix.cpp b/suite/pts/deviceTests/opengl/jni/graphics/Matrix.cpp
index a23326b..83591e8 100644
--- a/suite/pts/deviceTests/opengl/jni/graphics/Matrix.cpp
+++ b/suite/pts/deviceTests/opengl/jni/graphics/Matrix.cpp
@@ -16,6 +16,10 @@
 #include <string.h>
 #include <math.h>
 
+#define LOG_TAG "PTS_OPENGL"
+#define LOG_NDEBUG 0
+#include "utils/Log.h"
+
 Matrix::Matrix() {
     identity();
 }
@@ -24,6 +28,14 @@
     loadWith(src);
 }
 
+void Matrix::print(const char* label) {
+    ALOGI("%c", *label);
+    for (int i = 0; i < 4; i++) {
+        const float* d = &(mData[i * 4]);
+        ALOGI("%f %f %f %f\n", d[0], d[1], d[2], d[3]);
+    }
+}
+
 bool Matrix::equals(const Matrix& src) {
     bool equals = true;
     const float* d = src.mData;
@@ -214,9 +226,9 @@
     Matrix* m = new Matrix();
     if (m != NULL) {
         float* d = m->mData;
-        d[3] = x;
-        d[7] = y;
-        d[11] = z;
+        d[12] = x;
+        d[13] = y;
+        d[14] = z;
     }
     return m;
 }
diff --git a/suite/pts/deviceTests/opengl/jni/graphics/Matrix.h b/suite/pts/deviceTests/opengl/jni/graphics/Matrix.h
index 1586ed0..3484266 100644
--- a/suite/pts/deviceTests/opengl/jni/graphics/Matrix.h
+++ b/suite/pts/deviceTests/opengl/jni/graphics/Matrix.h
@@ -35,6 +35,8 @@
     // Sets this matrix to be the result of multiplying the given matrices.
     void multiply(const Matrix& l, const Matrix& r);
 
+    void print(const char* label);
+
     // Returns a new matrix representing the camera.
     static Matrix* newLookAt(float eyeX, float eyeY, float eyeZ, float centerX,
             float centerY, float centerZ, float upX, float upY, float upZ);
diff --git a/suite/pts/deviceTests/opengl/jni/pixeloutput/PixelOutputRenderer.cpp b/suite/pts/deviceTests/opengl/jni/pixeloutput/PixelOutputRenderer.cpp
index 968fa26..c97b860 100644
--- a/suite/pts/deviceTests/opengl/jni/pixeloutput/PixelOutputRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/pixeloutput/PixelOutputRenderer.cpp
@@ -14,14 +14,16 @@
 #include "PixelOutputRenderer.h"
 #include <GLUtils.h>
 
-static const float poVertices[] = {
+static const int PO_NUM_VERTICES = 6;
+
+static const float PO_VERTICES[PO_NUM_VERTICES * 3] = {
         1.0f, 1.0f, -1.0f,
         -1.0f, 1.0f, -1.0f,
         -1.0f, -1.0f, -1.0f,
         -1.0f, -1.0f, -1.0f,
         1.0f, -1.0f, -1.0f,
         1.0f, 1.0f, -1.0f };
-static const float poTexCoords[] = {
+static const float PO_TEX_COORDS[PO_NUM_VERTICES * 2] = {
         1.0f, 1.0f,
         0.0f, 1.0f,
         0.0f, 0.0f,
@@ -29,7 +31,7 @@
         1.0f, 0.0f,
         1.0f, 1.0f };
 
-static const char* poVertex =
+static const char* PO_VERTEX =
         "attribute vec4 a_Position;"
         "attribute vec2 a_TexCoord;"
         "varying vec2 v_TexCoord;"
@@ -38,7 +40,7 @@
         "  gl_Position = a_Position;"
         "}";
 
-static const char* poFragment =
+static const char* PO_FRAGMENT =
         "precision mediump float;"
         "uniform sampler2D u_Texture;"
         "varying vec2 v_TexCoord;"
@@ -56,7 +58,7 @@
     }
 
     // Create program.
-    mProgram = GLUtils::createProgram(&poVertex, &poFragment);
+    mProgram = GLUtils::createProgram(&PO_VERTEX, &PO_FRAGMENT);
     if (mProgram == 0)
         return false;
     // Bind attributes.
@@ -97,11 +99,11 @@
 
     glEnableVertexAttribArray(mPositionHandle);
     glEnableVertexAttribArray(mTexCoordHandle);
-    glVertexAttribPointer(mPositionHandle, 3, GL_FLOAT, false, 0, poVertices);
-    glVertexAttribPointer(mTexCoordHandle, 2, GL_FLOAT, false, 0, poTexCoords);
+    glVertexAttribPointer(mPositionHandle, 3, GL_FLOAT, false, 0, PO_VERTICES);
+    glVertexAttribPointer(mTexCoordHandle, 2, GL_FLOAT, false, 0, PO_TEX_COORDS);
 
     for (int i = 0; i < mWorkload; i++) {
-        glDrawArrays(GL_TRIANGLES, 0, 6);
+        glDrawArrays(GL_TRIANGLES, 0, PO_NUM_VERTICES);
     }
 
     return eglSwapBuffers(mEglDisplay, mEglSurface);
diff --git a/suite/pts/deviceTests/opengl/jni/shaderperf/ShaderPerfRenderer.cpp b/suite/pts/deviceTests/opengl/jni/shaderperf/ShaderPerfRenderer.cpp
index a7f07ba..11ca0a4 100644
--- a/suite/pts/deviceTests/opengl/jni/shaderperf/ShaderPerfRenderer.cpp
+++ b/suite/pts/deviceTests/opengl/jni/shaderperf/ShaderPerfRenderer.cpp
@@ -14,7 +14,9 @@
 #include "ShaderPerfRenderer.h"
 #include <GLUtils.h>
 
-static const float spVertices[] = {
+static const int SP_NUM_VERTICES = 6;
+
+static const float SP_VERTICES[SP_NUM_VERTICES * 3] = {
         1.0f, 1.0f, -1.0f,
         -1.0f, 1.0f, -1.0f,
         -1.0f, -1.0f, -1.0f,
@@ -22,7 +24,7 @@
         1.0f, -1.0f, -1.0f,
         1.0f, 1.0f, -1.0f };
 
-static const char* spVertex = "attribute vec4 a_Position;"
+static const char* SP_VERTEX = "attribute vec4 a_Position;"
                               "varying vec4 v_Position;"
                               "void main() {"
                               "  v_Position = a_Position;"
@@ -30,7 +32,7 @@
                               "}";
 
 // TODO At the moment this a very simple shader. Later on this will get more complex.
-static const char* spFragment = "precision mediump float;"
+static const char* SP_FRAGMENT = "precision mediump float;"
                                 "varying vec4 v_Position;"
                                 "void main() {"
                                 "  gl_FragColor = v_Position;"
@@ -45,7 +47,7 @@
         return false;
     }
     // Create program.
-    mProgram = GLUtils::createProgram(&spVertex, &spFragment);
+    mProgram = GLUtils::createProgram(&SP_VERTEX, &SP_FRAGMENT);
     if (mProgram == 0)
         return false;
     // Bind attributes.
@@ -65,9 +67,9 @@
     glDisable (GL_DEPTH_TEST);
 
     glEnableVertexAttribArray(mPositionHandle);
-    glVertexAttribPointer(mPositionHandle, 3, GL_FLOAT, false, 0, spVertices);
+    glVertexAttribPointer(mPositionHandle, 3, GL_FLOAT, false, 0, SP_VERTICES);
 
-    glDrawArrays(GL_TRIANGLES, 0, 6);
+    glDrawArrays(GL_TRIANGLES, 0, SP_NUM_VERTICES);
 
     return eglSwapBuffers(mEglDisplay, mEglSurface);
 }
diff --git a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLActivity.java b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLActivity.java
index 0caa576..5f75cbb 100644
--- a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLActivity.java
+++ b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLActivity.java
@@ -119,7 +119,6 @@
         public void run() {
             // Creates a watchdog to ensure a iteration doesn't exceed the timeout.
             watchDog = new WatchDog(mTimeout);
-            watchDog.start();
             // Used to record the start and end time of the iteration.
             double[] times = new double[2];
             while (repeat) {
@@ -140,8 +139,11 @@
                         setupContextSwitchBenchmark(mSurface, wl);
                         break;
                 }
+                watchDog.start();
+                boolean success = startBenchmark(mNumFrames, times);
+                watchDog.stop();
                 // Start benchmark.
-                if (!startBenchmark(mNumFrames, times)) {
+                if (!success) {
                     mException = new Exception("Could not run benchmark");
                     repeat = false;
                 } else {
@@ -149,7 +151,7 @@
                     double totalTimeTaken = times[1] - times[0];
                     double meanFps = mNumFrames * 1000.0f / totalTimeTaken;
                     Log.i(TAG, "Workload: " + wl);
-                    Log.i(TAG, "MeanFPS: " + meanFps);
+                    Log.i(TAG, "Mean FPS: " + meanFps);
                     if (meanFps >= mMinFps) {
                         // Iteration passed, proceed to next one.
                         mWorkload++;
@@ -158,10 +160,7 @@
                         repeat = false;
                     }
                 }
-                // Resets the watchdog for the next iteration.
-                watchDog.reset();
             }
-            watchDog.stop();
         }
 
     }
diff --git a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLBenchmark.java b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLBenchmark.java
index ad3159f..e944b9a 100644
--- a/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLBenchmark.java
+++ b/suite/pts/deviceTests/opengl/src/com/android/pts/opengl/primitive/GLBenchmark.java
@@ -19,6 +19,9 @@
 import com.android.pts.util.ResultType;
 import com.android.pts.util.ResultUnit;
 
+import android.opengl.Matrix;
+import android.util.Log;
+import java.util.Arrays;
 /**
  * Runs the Primitive OpenGL ES 2.0 Benchmarks.
  */
@@ -36,7 +39,7 @@
      * @throws Exception If the benchmark could not be run.
      */
     public void testFullPipeline() throws Exception {
-        runBenchmark(Benchmark.FullPipeline, 500, 10000);
+        runBenchmark(Benchmark.FullPipeline, 500, 50000, 1);
     }
 
     /**
@@ -45,7 +48,7 @@
      * @throws Exception If the benchmark could not be run.
      */
     public void testPixelOutput() throws Exception {
-        runBenchmark(Benchmark.PixelOutput, 500, 10000);
+        runBenchmark(Benchmark.PixelOutput, 500, 50000, 1);
     }
 
     /**
@@ -55,7 +58,7 @@
      */
     public void testShaderPerf() throws Exception {
         // TODO(stuartscott): Not yet implemented
-        // runBenchmark(Benchmark.ShaderPerf, 500, 10000);
+        // runBenchmark(Benchmark.ShaderPerf, 500, 50000, 1);
     }
 
     /**
@@ -64,7 +67,7 @@
      * @throws Exception If the benchmark could not be run.
      */
     public void testContextSwitch() throws Exception {
-        runBenchmark(Benchmark.ContextSwitch, 500, 10000);
+        runBenchmark(Benchmark.ContextSwitch, 500, 50000, 1);
     }
 
     /**
@@ -75,7 +78,8 @@
      * @param timeout The milliseconds to wait for an iteration of the benchmark before timing out.
      * @throws Exception If the benchmark could not be run.
      */
-    private void runBenchmark(Benchmark benchmark, int numFrames, int timeout) throws Exception {
+    private void runBenchmark(Benchmark benchmark, int numFrames, int timeout, int target)
+            throws Exception {
         String benchmarkName = benchmark.toString();
         Intent intent = new Intent();
         intent.putExtra(GLActivity.INTENT_EXTRA_BENCHMARK_NAME, benchmarkName);
@@ -87,8 +91,12 @@
         setActivityIntent(intent);
         try {
             activity = getActivity();
+            // Represents the maximum workload it can do whilst maintaining MIN_FPS.
             int workload = activity.waitForCompletion();
-            // represents the maximum workload it can do whilst maintaining MIN_FPS.
+            if (workload < target) {
+                throw new Exception("Benchmark did not reach target. Got " + workload
+                        + ", target was " + target);
+            }
             getReportLog()
                     .printSummary("Workload", workload, ResultType.HIGHER_BETTER, ResultUnit.SCORE);
         } finally {
diff --git a/suite/pts/deviceTests/opengl/test/MatrixTest.cpp b/suite/pts/deviceTests/opengl/test/MatrixTest.cpp
index b94f133..d78dfc4 100644
--- a/suite/pts/deviceTests/opengl/test/MatrixTest.cpp
+++ b/suite/pts/deviceTests/opengl/test/MatrixTest.cpp
@@ -157,8 +157,8 @@
     float expected[] = {
         1.0f, 0.0f, 0.0f, 0.0f,
         0.0f, 1.0f, 0.0f, 0.0f,
-        0.0f, 0.0f, 1.0f, -6.0f,
-        0.0f, 0.0f, 0.0f, 1.0f};
+        0.0f, 0.0f, 1.0f, 0.0f,
+        0.0f, 0.0f, -6.0f, 1.0f};
     // Check values
     checkValues(m->mData, expected, Matrix::MATRIX_SIZE);
     delete m;
@@ -189,10 +189,10 @@
     Matrix* m = Matrix::newTranslate(5, 6, 8);
     ASSERT_TRUE(m != NULL);
     float expected[] = {
-        1.0f, 0.0f, 0.0f, 5.0f,
-        0.0f, 1.0f, 0.0f, 6.0f,
-        0.0f, 0.0f, 1.0f, 8.0f,
-        0.0f, 0.0f, 0.0f, 1.0f};
+        1.0f, 0.0f, 0.0f, 0.0f,
+        0.0f, 1.0f, 0.0f, 0.0f,
+        0.0f, 0.0f, 1.0f, 0.0f,
+        5.0f, 6.0f, 8.0f, 1.0f};
     // Check values
     checkValues(m->mData, expected, Matrix::MATRIX_SIZE);
     delete m;
diff --git a/tests/assets/webkit/jswindow.html b/tests/assets/webkit/jswindow.html
index 534a683..7075d6e 100644
--- a/tests/assets/webkit/jswindow.html
+++ b/tests/assets/webkit/jswindow.html
@@ -23,7 +23,6 @@
             childWindow = window.open();
             childWindow.document.title = "javascript child window";
             childWindow.document.write("javascript child window");
-            childWindow.focus();
             setTimeout(function(){childWindow.close();}, 2000);
         }
     </script>
diff --git a/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java b/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java
index d58336d..beb3621 100644
--- a/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/AvoidXfermodeTest.java
@@ -62,7 +62,7 @@
 
         assertEquals(Color.GREEN, b.getPixel(BASE_SIZE / 2, BASE_SIZE / 2));
         assertEquals(Color.RED, b.getPixel(BASE_SIZE + BASE_SIZE / 2, BASE_SIZE / 2));
-        assertEquals(Color.CYAN, b.getPixel(BASE_SIZE / 2, BASE_SIZE + BASE_SIZE / 2));
+        assertEquals(Color.BLUE, b.getPixel(BASE_SIZE / 2, BASE_SIZE + BASE_SIZE / 2));
         assertEquals(Color.BLACK, b.getPixel(BASE_SIZE + BASE_SIZE / 2, BASE_SIZE + BASE_SIZE / 2));
     }
 }
diff --git a/tests/tests/graphics/src/android/graphics/cts/MatrixTest.java b/tests/tests/graphics/src/android/graphics/cts/MatrixTest.java
index ebe20a2..29e4f5f 100644
--- a/tests/tests/graphics/src/android/graphics/cts/MatrixTest.java
+++ b/tests/tests/graphics/src/android/graphics/cts/MatrixTest.java
@@ -302,7 +302,7 @@
         values[0] = 1000f;
         matrix.setValues(values);
         assertTrue(mMatrix.invert(matrix));
-        String expect = "[1.0, -0.0, 0.0][-0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
+        String expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
         assertEquals(expect, matrix.toShortString());
         expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
         assertEquals(expect, mMatrix.toShortString());
diff --git a/tests/tests/os/src/android/os/cts/UsbDebuggingTest.java b/tests/tests/os/src/android/os/cts/UsbDebuggingTest.java
new file mode 100644
index 0000000..60583e7
--- /dev/null
+++ b/tests/tests/os/src/android/os/cts/UsbDebuggingTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed 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 android.os.cts;
+
+import android.os.Build;
+import android.os.SystemProperties;
+import android.test.AndroidTestCase;
+import java.io.File;
+
+public class UsbDebuggingTest extends AndroidTestCase {
+
+    public void testUsbDebugging() {
+        // Secure USB debugging must be enabled
+        assertEquals("1", SystemProperties.get("ro.adb.secure"));
+
+        // Don't ship vendor keys in user build
+        if ("user".equals(Build.TYPE)) {
+            File keys = new File("/adb_keys");
+            assertFalse(keys.exists());
+        }
+    }
+
+}
diff --git a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
index 2fcf53c..52e9278 100644
--- a/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/HttpAuthHandlerTest.java
@@ -28,6 +28,11 @@
 
     private static final long TIMEOUT = 10000;
 
+    private static final String WRONG_USERNAME = "wrong_user";
+    private static final String WRONG_PASSWORD = "wrong_password";
+    private static final String CORRECT_USERNAME = CtsTestServer.AUTH_USER;
+    private static final String CORRECT_PASSWORD = CtsTestServer.AUTH_PASS;
+
     private CtsTestServer mWebServer;
     private WebViewOnUiThread mOnUiThread;
 
@@ -50,64 +55,18 @@
         super.tearDown();
     }
 
-    public void testProceed() throws Exception {
-        mWebServer = new CtsTestServer(getActivity());
-        String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
-
-        // wrong credentials
-        MyWebViewClient client = new MyWebViewClient(true, "FakeUser", "FakePass");
-        mOnUiThread.setWebViewClient(client);
-
-        mOnUiThread.loadUrlAndWaitForCompletion(url);
-        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
-        assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
-        assertTrue(client.useHttpAuthUsernamePassword);
-
-        // missing credentials
-        client = new MyWebViewClient(true, null, null);
-        mOnUiThread.setWebViewClient(client);
-
-        mOnUiThread.loadUrlAndWaitForCompletion(url);
-        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
-        assertEquals(
-                CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
-        assertTrue(client.useHttpAuthUsernamePassword);
-
-        // correct credentials
-        client = new MyWebViewClient(true, CtsTestServer.AUTH_USER, CtsTestServer.AUTH_PASS);
-        mOnUiThread.setWebViewClient(client);
-
-        mOnUiThread.loadUrlAndWaitForCompletion(url);
-        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
-        assertEquals(TestHtmlConstants.HELLO_WORLD_TITLE, mOnUiThread.getTitle());
-        assertTrue(client.useHttpAuthUsernamePassword);
-    }
-
-    public void testCancel() throws Exception {
-        mWebServer = new CtsTestServer(getActivity());
-
-        String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
-        MyWebViewClient client = new MyWebViewClient(false, null, null);
-        mOnUiThread.setWebViewClient(client);
-
-        mOnUiThread.loadUrlAndWaitForCompletion(url);
-        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
-        assertEquals(
-                CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
-    }
-
-    private class MyWebViewClient extends WaitForLoadedClient {
+    private class ProceedHttpAuthClient extends WaitForLoadedClient {
         String realm;
         boolean useHttpAuthUsernamePassword;
 
-        private boolean mProceed;
+        private int mMaxAuthAttempts;
         private String mUser;
         private String mPassword;
         private int mAuthCount;
 
-        MyWebViewClient(boolean proceed, String user, String password) {
+        ProceedHttpAuthClient(int maxAuthAttempts, String user, String password) {
             super(mOnUiThread);
-            mProceed = proceed;
+            mMaxAuthAttempts = maxAuthAttempts;
             mUser = user;
             mPassword = password;
         }
@@ -115,18 +74,113 @@
         @Override
         public void onReceivedHttpAuthRequest(WebView view,
                 HttpAuthHandler handler, String host, String realm) {
-            ++mAuthCount;
-            if (mAuthCount > 1) {
+            if (++mAuthCount > mMaxAuthAttempts) {
                 handler.cancel();
                 return;
             }
+
             this.realm = realm;
             this.useHttpAuthUsernamePassword = handler.useHttpAuthUsernamePassword();
-            if (mProceed) {
-                handler.proceed(mUser, mPassword);
-            } else {
-                handler.cancel();
-            }
+
+            handler.proceed(mUser, mPassword);
         }
     }
+
+    private class CancelHttpAuthClient extends WaitForLoadedClient {
+        String realm;
+
+        CancelHttpAuthClient() {
+            super(mOnUiThread);
+        }
+
+        @Override
+        public void onReceivedHttpAuthRequest(WebView view,
+                HttpAuthHandler handler, String host, String realm) {
+            this.realm = realm;
+            handler.cancel();
+        }
+    }
+
+    private void incorrectCredentialsAccessDenied(String url) throws Throwable {
+        ProceedHttpAuthClient client = new ProceedHttpAuthClient(1, WRONG_USERNAME, WRONG_PASSWORD);
+        mOnUiThread.setWebViewClient(client);
+
+        // As we're providing incorrect credentials, the page should complete but at
+        // an access denied page.
+        mOnUiThread.loadUrlAndWaitForCompletion(url);
+
+        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
+        assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
+    }
+
+    private void missingCredentialsAccessDenied(String url) throws Throwable {
+        ProceedHttpAuthClient client = new ProceedHttpAuthClient(1, null, null);
+        mOnUiThread.setWebViewClient(client);
+
+        // As we're providing no credentials, the page should complete but at
+        // an access denied page.
+        mOnUiThread.loadUrlAndWaitForCompletion(url);
+
+        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
+        assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
+    }
+
+    private void correctCredentialsAccessGranted(String url) throws Throwable {
+        ProceedHttpAuthClient client = new ProceedHttpAuthClient(1, CORRECT_USERNAME, CORRECT_PASSWORD);
+        mOnUiThread.setWebViewClient(client);
+
+        // As we're providing valid credentials, the page should complete and
+        // at the page we requested.
+        mOnUiThread.loadUrlAndWaitForCompletion(url);
+
+        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
+        assertEquals(TestHtmlConstants.HELLO_WORLD_TITLE, mOnUiThread.getTitle());
+    }
+
+    public void testProceed() throws Throwable {
+        mWebServer = new CtsTestServer(getActivity());
+        String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
+
+        incorrectCredentialsAccessDenied(url);
+        missingCredentialsAccessDenied(url);
+        correctCredentialsAccessGranted(url);
+    }
+
+    public void testCancel() throws Throwable {
+        mWebServer = new CtsTestServer(getActivity());
+        String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
+
+        CancelHttpAuthClient client = new CancelHttpAuthClient();
+        mOnUiThread.setWebViewClient(client);
+
+        mOnUiThread.loadUrlAndWaitForCompletion(url);
+        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
+        assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
+    }
+
+    public void testUseHttpAuthUsernamePassword() throws Throwable {
+        mWebServer = new CtsTestServer(getActivity());
+        String url = mWebServer.getAuthAssetUrl(TestHtmlConstants.HELLO_WORLD_URL);
+
+        // Try to login once with incorrect credentials. This should cause
+        // useHttpAuthUsernamePassword to be true in the callback, as at that point
+        // we don't yet know that the credentials we will use are invalid.
+        ProceedHttpAuthClient client = new ProceedHttpAuthClient(1, WRONG_USERNAME, WRONG_PASSWORD);
+        mOnUiThread.setWebViewClient(client);
+        mOnUiThread.loadUrlAndWaitForCompletion(url);
+        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
+        assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
+        assertTrue(client.useHttpAuthUsernamePassword);
+
+        // Try to login twice with invalid credentials. This should cause
+        // useHttpAuthUsernamePassword to return false, as the credentials
+        // we would have stored on the first auth request
+        // are not suitable for use the second time.
+        client = new ProceedHttpAuthClient(2, WRONG_USERNAME, WRONG_PASSWORD);
+        mOnUiThread.setWebViewClient(client);
+        mOnUiThread.loadUrlAndWaitForCompletion(url);
+        assertEquals(CtsTestServer.AUTH_REALM, client.realm);
+        assertEquals(CtsTestServer.getReasonString(HttpStatus.SC_UNAUTHORIZED), mOnUiThread.getTitle());
+        assertFalse(client.useHttpAuthUsernamePassword);
+    }
 }
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
index 4a536b8..422c8fb 100644
--- a/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebChromeClientTest.java
@@ -20,6 +20,7 @@
 import android.graphics.Bitmap;
 import android.os.Message;
 import android.test.ActivityInstrumentationTestCase2;
+import android.view.ViewGroup;
 import android.webkit.JsPromptResult;
 import android.webkit.JsResult;
 import android.webkit.WebIconDatabase;
@@ -27,7 +28,6 @@
 import android.webkit.WebView;
 import android.webkit.cts.WebViewOnUiThread.WaitForProgressClient;
 
-
 public class WebChromeClientTest extends ActivityInstrumentationTestCase2<WebViewStubActivity> {
     private static final long TEST_TIMEOUT = 5000L;
 
@@ -132,8 +132,8 @@
 
         assertFalse(webChromeClient.hadOnCreateWindow());
 
-        // load a page that opens a child window, requests focus for the child and sets a timeout
-        // after which the child will be closed
+        // Load a page that opens a child window and sets a timeout after which the child
+        // will be closed.
         mOnUiThread.loadUrlAndWaitForCompletion(mWebServer.
                 getAssetUrl(TestHtmlConstants.JS_WINDOW_URL));
 
@@ -143,7 +143,6 @@
                 return webChromeClient.hadOnCreateWindow();
             }
         }.run();
-        assertFalse(webChromeClient.hadOnRequestFocus());
         new PollingCheck(TEST_TIMEOUT) {
             @Override
             protected boolean check() {
@@ -388,6 +387,8 @@
             transport.setWebView(childView);
             resultMsg.sendToTarget();
             mHadOnCreateWindow = true;
+            getActivity().addContentView(childView, new ViewGroup.LayoutParams(
+                    ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
             return true;
         }
 
diff --git a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
index eff9640..05b2d6e 100755
--- a/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
+++ b/tests/tests/webkit/src/android/webkit/cts/WebViewTest.java
@@ -606,7 +606,7 @@
             }
         }.run();
         assertEquals(mWebView, listener.webView);
-        assertNotNull(listener.picture);
+        assertNull(listener.picture);
 
         final int oldCallCount = listener.callCount;
         final String newUrl = mWebServer.getAssetUrl(TestHtmlConstants.SMALL_IMG_URL);