Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import org.junit.runner.Description; | 7 import org.junit.runner.Description; |
| 8 import org.junit.runners.model.Statement; | 8 import org.junit.runners.model.Statement; |
| 9 | 9 |
| 10 import org.chromium.base.test.SetUpTestRule; | |
| 10 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 11 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
| 11 import org.chromium.content_shell_apk.ContentShellActivity; | 12 import org.chromium.content_shell_apk.ContentShellActivity; |
| 12 import org.chromium.content_shell_apk.ContentShellActivityTestRule; | 13 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| 13 import org.chromium.content_shell_apk.ContentShellTestCommon.TestCommonCallback; | 14 import org.chromium.content_shell_apk.ContentShellTestCommon.TestCommonCallback; |
| 14 | 15 |
| 15 import java.lang.annotation.Annotation; | 16 import java.lang.annotation.Annotation; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * ActivityTestRule with common functionality for testing the Java Bridge. | 19 * ActivityTestRule with common functionality for testing the Java Bridge. |
| 19 */ | 20 */ |
| 20 public class JavaBridgeActivityTestRule | 21 public class JavaBridgeActivityTestRule |
| 21 extends ContentShellActivityTestRule implements TestCommonCallback<Conte ntShellActivity> { | 22 extends ContentShellActivityTestRule implements TestCommonCallback<Conte ntShellActivity>, |
| 22 private JavaBridgeTestCommon mTestCommon; | 23 SetUpTestRule<JavaBridge ActivityTestRule> { |
| 23 | 24 private JavaBridgeTestCommon mTestCommon = new JavaBridgeTestCommon(this); |
| 24 public JavaBridgeActivityTestRule() { | 25 private boolean mRunSetUp = false; |
| 25 super(); | |
| 26 mTestCommon = new JavaBridgeTestCommon(this); | |
| 27 } | |
| 28 | 26 |
| 29 /** | 27 /** |
| 30 * Sets up the ContentView. Intended to be called from setUp(). | 28 * Sets up the ContentView. Intended to be called from setUp(). |
| 31 */ | 29 */ |
| 32 private void setUpContentView() { | 30 private void setUpContentView() { |
| 33 mTestCommon.setUpContentView(); | 31 mTestCommon.setUpContentView(); |
| 34 } | 32 } |
| 35 | 33 |
| 36 public TestCallbackHelperContainer getTestCallBackHelperContainer() { | 34 public TestCallbackHelperContainer getTestCallBackHelperContainer() { |
| 37 return mTestCommon.getTestCallBackHelperContainer(); | 35 return mTestCommon.getTestCallBackHelperContainer(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 55 final Class<? extends Annotation> requiredAnnotation) throws Excepti on { | 53 final Class<? extends Annotation> requiredAnnotation) throws Excepti on { |
| 56 mTestCommon.injectObjectsAndReload(object1, name1, object2, name2, requi redAnnotation); | 54 mTestCommon.injectObjectsAndReload(object1, name1, object2, name2, requi redAnnotation); |
| 57 } | 55 } |
| 58 | 56 |
| 59 public void synchronousPageReload() throws Throwable { | 57 public void synchronousPageReload() throws Throwable { |
| 60 mTestCommon.synchronousPageReload(); | 58 mTestCommon.synchronousPageReload(); |
| 61 } | 59 } |
| 62 | 60 |
| 63 @Override | 61 @Override |
| 64 public Statement apply(final Statement base, Description desc) { | 62 public Statement apply(final Statement base, Description desc) { |
| 65 return super.apply(new Statement() { | 63 return super.apply(new SetUpTestRule.SetUpStatement(base, this, mRunSetU p), desc); |
| 66 @Override | 64 } |
| 67 public void evaluate() throws Throwable { | 65 |
| 68 setUpContentView(); | 66 @Override |
| 69 base.evaluate(); | 67 public JavaBridgeActivityTestRule shouldSetUp(boolean shouldSetUp) { |
|
jbudorick
2017/03/28 01:13:28
So every rule supporting this behavior would need
the real yoland
2017/03/28 01:32:50
ya, one way to decrease the boilerplate code is to
jbudorick
2017/03/28 01:36:59
Let's talk about this offline.
| |
| 70 } | 68 mRunSetUp = shouldSetUp; |
| 71 }, desc); | 69 return this; |
| 70 } | |
| 71 | |
| 72 @Override | |
| 73 public void setUp() { | |
| 74 setUpContentView(); | |
| 72 } | 75 } |
| 73 } | 76 } |
| OLD | NEW |