|
|
Description[NTP Client] Add tests for Tile and TileGroup
Adds tests focused around TileGroup#buildTiles and
TileGroup#renderTileViews.
Includes some modifications to the EnableFeatures annotation
to mock the FeatureList as soon as the rule is added, without
requiring to set the annotation on each test.
BUG=694297
Review-Url: https://codereview.chromium.org/2722243002
Cr-Commit-Position: refs/heads/master@{#454846}
Committed: https://chromium.googlesource.com/chromium/src/+/31e02521bed88cdfc15b76b2d24065eeda082faf
Patch Set 1 #Patch Set 2 : moar tests #
Total comments: 10
Patch Set 3 : Remove mock layout, address other comments #Patch Set 4 : Revert default Rule effect #
Dependent Patchsets: Messages
Total messages: 30 (20 generated)
Description was changed from ========== [NTP Client] Add tests for Tile and TileGroup Adds tests focused around TileGroup#buildTiles and TileGroup#renderTileViews. Includes some modifications to the EnableFeatures annotation to mock the FeatureList as soon as the rule is added, without requiring to set the annotation on each test. BUG=694297 ========== to ========== [NTP Client] Add tests for Tile and TileGroup Adds tests focused around TileGroup#buildTiles and TileGroup#renderTileViews. Includes some modifications to the EnableFeatures annotation to mock the FeatureList as soon as the rule is added, without requiring to set the annotation on each test. BUG=694297 ==========
The CQ bit was checked by dgn@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
dgn@chromium.org changed reviewers: + bauerb@chromium.org
PTAL
dgn@chromium.org changed reviewers: + mvanouwerkerk@chromium.org
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... File chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java (right): https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java:45: * choose which features to enable. All are disabled by default. Ooh, there is one thing I had been thinking of: would it be possible / worth it to use a Map<String, Boolean> for feature state? The idea being that tests would explicitly set any feature to enabled or disabled that is checked by the code under test, and the code would assert if an unknown feature is checked (as opposed to now, where all features get disabled as soon as you add the rule). We could do that in a followup though. https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... File chrome/android/junit/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java (right): https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... chrome/android/junit/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java:429: mLayout = mock(TileGridLayout.class); Can you use a custom subclass instead? https://codereview.chromium.org/2722243002/diff/20001/testing/android/junit/j... File testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java (right): https://codereview.chromium.org/2722243002/diff/20001/testing/android/junit/j... testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java:48: public AnnotationProcessor(Class<T> annotationClass, boolean alwaysApply) { I find it a bit strange to have AnnotationProcessor not always require an annotation, but I can't think of a much better way off the top of my head either. https://codereview.chromium.org/2722243002/diff/20001/testing/android/junit/j... testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java:56: mAnnotation = description.getAnnotation(mAnnotationClass); Maybe extract getting the annotation into a helper method, and then do if (mAnnotation != null || mAlwaysApply) return supper.apply(base, description);
PTAL https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... File chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java (right): https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java:45: * choose which features to enable. All are disabled by default. On 2017/03/03 11:54:38, Bernhard Bauer wrote: > Ooh, there is one thing I had been thinking of: would it be possible / worth it > to use a Map<String, Boolean> for feature state? The idea being that tests would > explicitly set any feature to enabled or disabled that is checked by the code > under test, and the code would assert if an unknown feature is checked (as > opposed to now, where all features get disabled as soon as you add the rule). We > could do that in a followup though. Yes we could do that. But I think it becomes interesting only when we define default states for features. Otherwise turning on only what you need is easy enough for unit tests, considering that we mock most things. Which features do you think would benefit most? I'll do it as follow up, yes. https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... File chrome/android/junit/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java (right): https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... chrome/android/junit/src/org/chromium/chrome/browser/suggestions/TileGroupTest.java:429: mLayout = mock(TileGridLayout.class); On 2017/03/03 11:54:38, Bernhard Bauer wrote: > Can you use a custom subclass instead? Used FrameLayout instead. https://codereview.chromium.org/2722243002/diff/20001/testing/android/junit/j... File testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java (right): https://codereview.chromium.org/2722243002/diff/20001/testing/android/junit/j... testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java:48: public AnnotationProcessor(Class<T> annotationClass, boolean alwaysApply) { On 2017/03/03 11:54:39, Bernhard Bauer wrote: > I find it a bit strange to have AnnotationProcessor not always require an > annotation, but I can't think of a much better way off the top of my head > either. Currently just adding @EnableFeatures at the class level would mean that the rule would set a default value for all the tests. So I could remove the alwaysApply argument. I just thought that adding @Rule should be already indicating intent, and it feels redundant to still have to set a default. But if you prefer I can do it that way. https://codereview.chromium.org/2722243002/diff/20001/testing/android/junit/j... testing/android/junit/java/src/org/chromium/testing/local/AnnotationProcessor.java:56: mAnnotation = description.getAnnotation(mAnnotationClass); On 2017/03/03 11:54:38, Bernhard Bauer wrote: > Maybe extract getting the annotation into a helper method, and then do > > if (mAnnotation != null || mAlwaysApply) return supper.apply(base, > description); Done.
The CQ bit was checked by dgn@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
lgtm https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... File chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java (right): https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java:45: * choose which features to enable. All are disabled by default. On 2017/03/03 13:48:30, dgn wrote: > On 2017/03/03 11:54:38, Bernhard Bauer wrote: > > Ooh, there is one thing I had been thinking of: would it be possible / worth > it > > to use a Map<String, Boolean> for feature state? The idea being that tests > would > > explicitly set any feature to enabled or disabled that is checked by the code > > under test, and the code would assert if an unknown feature is checked (as > > opposed to now, where all features get disabled as soon as you add the rule). > We > > could do that in a followup though. > > Yes we could do that. But I think it becomes interesting only when we define > default states for features. Otherwise turning on only what you need is easy > enough for unit tests, considering that we mock most things. Which features do > you think would benefit most? I'll do it as follow up, yes. Well, what I'm a bit worried about is if we make a change that makes our code check a feature it didn't check before. We will just default to off, which may not match the real-world behavior if the feature in Chrome defaults to on, so we would avoid catching a hypothetical bug that only happens if the feature is on. If we require the feature to be set, we would at least have to explicitly define the feature state we're assuming.
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
dgn@chromium.org changed reviewers: + dtrainor@chromium.org
Thanks! dtrainor@chromium.org: Please review changes in //testing/android https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... File chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java (right): https://codereview.chromium.org/2722243002/diff/20001/chrome/android/junit/sr... chrome/android/junit/src/org/chromium/chrome/browser/EnableFeatures.java:45: * choose which features to enable. All are disabled by default. On 2017/03/03 14:01:22, Bernhard Bauer wrote: > On 2017/03/03 13:48:30, dgn wrote: > > On 2017/03/03 11:54:38, Bernhard Bauer wrote: > > > Ooh, there is one thing I had been thinking of: would it be possible / worth > > it > > > to use a Map<String, Boolean> for feature state? The idea being that tests > > would > > > explicitly set any feature to enabled or disabled that is checked by the > code > > > under test, and the code would assert if an unknown feature is checked (as > > > opposed to now, where all features get disabled as soon as you add the > rule). > > We > > > could do that in a followup though. > > > > Yes we could do that. But I think it becomes interesting only when we define > > default states for features. Otherwise turning on only what you need is easy > > enough for unit tests, considering that we mock most things. Which features do > > you think would benefit most? I'll do it as follow up, yes. > > Well, what I'm a bit worried about is if we make a change that makes our code > check a feature it didn't check before. We will just default to off, which may > not match the real-world behavior if the feature in Chrome defaults to on, so we > would avoid catching a hypothetical bug that only happens if the feature is on. > If we require the feature to be set, we would at least have to explicitly define > the feature state we're assuming. Okay got it. In that case, I reverted the change that makes the rule have some effect by default, since it would not be useful for that later state. I just added the current empty annotation at the class level.
The CQ bit was checked by dgn@chromium.org to run a CQ dry run
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
The CQ bit was unchecked by commit-bot@chromium.org
Dry run: This issue passed the CQ dry run.
testing/android lgtm
The CQ bit was checked by dgn@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from bauerb@chromium.org Link to the patchset: https://codereview.chromium.org/2722243002/#ps60001 (title: "Revert default Rule effect")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.or...
CQ is committing da patch. Bot data: {"patchset_id": 60001, "attempt_start_ts": 1488793785931380, "parent_rev": "42bd5bf1a4db228077a4b44c70bff956470f0a75", "commit_rev": "31e02521bed88cdfc15b76b2d24065eeda082faf"}
Message was sent while issue was closed.
Description was changed from ========== [NTP Client] Add tests for Tile and TileGroup Adds tests focused around TileGroup#buildTiles and TileGroup#renderTileViews. Includes some modifications to the EnableFeatures annotation to mock the FeatureList as soon as the rule is added, without requiring to set the annotation on each test. BUG=694297 ========== to ========== [NTP Client] Add tests for Tile and TileGroup Adds tests focused around TileGroup#buildTiles and TileGroup#renderTileViews. Includes some modifications to the EnableFeatures annotation to mock the FeatureList as soon as the rule is added, without requiring to set the annotation on each test. BUG=694297 Review-Url: https://codereview.chromium.org/2722243002 Cr-Commit-Position: refs/heads/master@{#454846} Committed: https://chromium.googlesource.com/chromium/src/+/31e02521bed88cdfc15b76b2d240... ==========
Message was sent while issue was closed.
Committed patchset #4 (id:60001) as https://chromium.googlesource.com/chromium/src/+/31e02521bed88cdfc15b76b2d240...
Message was sent while issue was closed.
post-commit lgtm Thanks! |