Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / android_webview / javatests / src / org / chromium / android_webview / test / AwTestBase.java
index d8dfe07..6bcbd44 100644 (file)
@@ -24,6 +24,8 @@ import org.chromium.content.browser.test.util.Criteria;
 import org.chromium.content.browser.test.util.CriteriaHelper;
 import org.chromium.content_public.browser.LoadUrlParams;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.FutureTask;
@@ -47,16 +49,20 @@ public class AwTestBase
     protected void setUp() throws Exception {
         super.setUp();
         if (needsBrowserProcessStarted()) {
-            final Context context = getActivity();
-            getInstrumentation().runOnMainSync(new Runnable() {
-                @Override
-                public void run() {
-                    AwBrowserProcess.start(context);
-                }
-            });
+            startBrowserProcess();
         }
     }
 
+    protected void startBrowserProcess() throws Exception {
+        final Context context = getActivity();
+        getInstrumentation().runOnMainSync(new Runnable() {
+            @Override
+            public void run() {
+                AwBrowserProcess.start(context);
+            }
+        });
+    }
+
     /* Override this to return false if the test doesn't want the browser startup sequence to
      * be run automatically.
      */
@@ -267,14 +273,32 @@ public class AwTestBase
     }
 
     /**
+     * Checks the current test has |clazz| annotation. Note this swallows NoSuchMethodException
+     * and returns false in that case.
+     */
+    private boolean testMethodHasAnnotation(Class<? extends Annotation> clazz) {
+        String testName = getName();
+        Method method = null;
+        try {
+            method = getClass().getMethod(testName);
+        } catch (NoSuchMethodException e) {
+            Log.w(TAG, "Test method name not found.", e);
+            return false;
+        }
+
+        return method.isAnnotationPresent(clazz);
+    }
+
+    /**
      * Factory class used in creation of test AwContents instances.
      *
      * Test cases can provide subclass instances to the createAwTest* methods in order to create an
      * AwContents instance with injected test dependencies.
      */
     public static class TestDependencyFactory extends AwContents.DependencyFactory {
-        public AwTestContainerView createAwTestContainerView(AwTestRunnerActivity activity) {
-            return new AwTestContainerView(activity, false);
+        public AwTestContainerView createAwTestContainerView(AwTestRunnerActivity activity,
+                boolean allowHardwareAcceleration) {
+            return new AwTestContainerView(activity, allowHardwareAcceleration);
         }
         public AwSettings createAwSettings(Context context, boolean supportsLegacyQuirks) {
             return new AwSettings(context, false, supportsLegacyQuirks);
@@ -311,8 +335,12 @@ public class AwTestBase
     public AwTestContainerView createDetachedAwTestContainerView(
             final AwContentsClient awContentsClient, boolean supportsLegacyQuirks) {
         final TestDependencyFactory testDependencyFactory = createTestDependencyFactory();
+
+        boolean allowHardwareAcceleration = isHardwareAcceleratedTest();
         final AwTestContainerView testContainerView =
-            testDependencyFactory.createAwTestContainerView(getActivity());
+                testDependencyFactory.createAwTestContainerView(getActivity(),
+                        allowHardwareAcceleration);
+
         AwSettings awSettings = testDependencyFactory.createAwSettings(getActivity(),
                 supportsLegacyQuirks);
         testContainerView.initialize(new AwContents(
@@ -323,6 +351,10 @@ public class AwTestBase
         return testContainerView;
     }
 
+    protected boolean isHardwareAcceleratedTest() {
+        return !testMethodHasAnnotation(DisableHardwareAccelerationForTest.class);
+    }
+
     public AwTestContainerView createAwTestContainerViewOnMainSync(
             final AwContentsClient client) throws Exception {
         return createAwTestContainerViewOnMainSync(client, false);