Closed Bug 1273654 Opened 8 years ago Closed 8 years ago

Refactor common APZ mochitest code

Categories

(Core :: Panning and Zooming, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: kats, Assigned: kats)

Details

(Whiteboard: [gfx-noted])

Attachments

(8 files)

58 bytes, text/x-review-board-request
botond
: review+
Details
58 bytes, text/x-review-board-request
botond
: review+
Details
58 bytes, text/x-review-board-request
botond
: review+
Details
58 bytes, text/x-review-board-request
botond
: review+
Details
58 bytes, text/x-review-board-request
botond
: review+
Details
58 bytes, text/x-review-board-request
botond
: review+
Details
58 bytes, text/x-review-board-request
botond
: review+
Details
58 bytes, text/x-review-board-request
botond
: review+
Details
Bug 1264017 did a little bit of refactoring, by creating a runSubtestsSeriallyInFreshWindows function that was reused across some tests. However there's a lot more common code that can be extracted and refactored. I haz patches.
Try is looking green, patches incoming.
The set of changes in this patch removes all waitForFocus calls in the test
folder, except for the one in apz_test_utils.js. This results in less
boilerplate and more consistent test state initialization.

Review commit: https://reviewboard.mozilla.org/r/53412/diff/#index_header
See other reviews: https://reviewboard.mozilla.org/r/53412/
https://reviewboard.mozilla.org/r/53412/#review50252

::: gfx/layers/apz/test/mochitest/apz_test_utils.js:213
(Diff revision 1)
> +  return new Promise(function(resolve, reject) {
> +    SpecialPowers.pushPrefEnv({'set': prefs}, resolve);
> +  });

In light of bug 1197310 I'll just change this to be:

function pushPrefs(prefs) {
  return SpecialPowers.pushPrefEnv({'set': prefs});
}

or I can just inline it to the call sites if you don't mind the extra 'set' boilerplate.
Comment on attachment 8753623 [details]
MozReview Request: Bug 1273654 - Merge the subtests from test_basic_pan into test_group_touchevents. r?botond

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53406/diff/1-2/
Comment on attachment 8753624 [details]
MozReview Request: Bug 1273654 - Remove redundant function wrapper. r?botond

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53408/diff/1-2/
Comment on attachment 8753625 [details]
MozReview Request: Bug 1273654 - Extract a waitUntilApzStable helper function for tests. r?botond

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53410/diff/1-2/
Comment on attachment 8753626 [details]
MozReview Request: Bug 1273654 - Extract a pushPrefs helper function to simplify test setup. r?botond

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53412/diff/1-2/
Comment on attachment 8753627 [details]
MozReview Request: Bug 1273654 - Extract a helper to check if APZ is enabled or not. r?botond

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53414/diff/1-2/
Comment on attachment 8753628 [details]
MozReview Request: Bug 1273654 - Reuse the apz test utils in a few more places. r?botond

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53416/diff/1-2/
Comment on attachment 8753629 [details]
MozReview Request: Bug 1273654 - Extract a helper function to run continuation-style tests. r?botond

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53418/diff/1-2/
Attachment #8753623 - Flags: review?(botond) → review+
Comment on attachment 8753623 [details]
MozReview Request: Bug 1273654 - Merge the subtests from test_basic_pan into test_group_touchevents. r?botond

https://reviewboard.mozilla.org/r/53406/#review51814

I'm fine with this, but I have a general concern about this consolidation of tests into test groups: when we get a test failure, is it sufficiently clear which subtest failed? (In particular, does the error output mention the subtest by name?)

For example, I'd view it as an unfortunate consequence of this change if failures in a subtest formerly part of test_basic_pan will now start to get starred on Treeherder as the same bug as failures in another subtest in test_group_touchevents.
Comment on attachment 8753624 [details]
MozReview Request: Bug 1273654 - Remove redundant function wrapper. r?botond

https://reviewboard.mozilla.org/r/53408/#review51816
Attachment #8753624 - Flags: review?(botond) → review+
Attachment #8753625 - Flags: review?(botond) → review+
Comment on attachment 8753625 [details]
MozReview Request: Bug 1273654 - Extract a waitUntilApzStable helper function for tests. r?botond

https://reviewboard.mozilla.org/r/53410/#review51820

So we're switching from "window.onload = " to "SimpleTest.waitForFocus()". I assume the latter is equivalent (or better)?

::: gfx/layers/apz/test/mochitest/helper_basic_pan.html:30
(Diff revision 2)
>  function checkScroll() {
>    is(window.scrollY, 50, "check that the window scrolled");
>    subtestDone();
>  }
>  
> -window.onload = function() {
> +waitUntilApzStable().then(scrollPage);

I can see why people like Promises so much: they make code read very nicely ("wait until APZ is stable, then scroll the page").
Comment on attachment 8753626 [details]
MozReview Request: Bug 1273654 - Extract a pushPrefs helper function to simplify test setup. r?botond

https://reviewboard.mozilla.org/r/53412/#review51830

Very nice :)
Attachment #8753626 - Flags: review?(botond) → review+
Comment on attachment 8753627 [details]
MozReview Request: Bug 1273654 - Extract a helper to check if APZ is enabled or not. r?botond

https://reviewboard.mozilla.org/r/53414/#review51836
Attachment #8753627 - Flags: review?(botond) → review+
Attachment #8753628 - Flags: review?(botond) → review+
Comment on attachment 8753628 [details]
MozReview Request: Bug 1273654 - Reuse the apz test utils in a few more places. r?botond

https://reviewboard.mozilla.org/r/53416/#review51838
Attachment #8753629 - Flags: review?(botond) → review+
Comment on attachment 8753629 [details]
MozReview Request: Bug 1273654 - Extract a helper function to run continuation-style tests. r?botond

https://reviewboard.mozilla.org/r/53418/#review51840

Getting nicer and nicer!

::: gfx/layers/apz/test/mochitest/apz_test_utils.js:254
(Diff revision 2)
> +  // if we didn't have this extra function, the promise would start running
> +  // during construction of the promise chain, concurrently with the first
> +  // promise in the chain.
> +  return function() {
> +    return new Promise(function(resolve, reject) {
> +      var gTestContinuation = null;

Not much point prefixing this with 'g' if it's not a global any more.
Attachment #8756372 - Flags: review?(botond) → review+
Comment on attachment 8756372 [details]
MozReview Request: Bug 1273654 - Update a new test to use the new helpers. r?botond

https://reviewboard.mozilla.org/r/55118/#review51848
(In reply to Botond Ballo [:botond] from comment #19)
> Comment on attachment 8753623 [details]
> MozReview Request: Bug 1273654 - Merge the subtests from test_basic_pan into
> test_group_touchevents. r?botond
> 
> https://reviewboard.mozilla.org/r/53406/#review51814
> 
> I'm fine with this, but I have a general concern about this consolidation of
> tests into test groups: when we get a test failure, is it sufficiently clear
> which subtest failed? (In particular, does the error output mention the
> subtest by name?)
> 
> For example, I'd view it as an unfortunate consequence of this change if
> failures in a subtest formerly part of test_basic_pan will now start to get
> starred on Treeherder as the same bug as failures in another subtest in
> test_group_touchevents.

Ah, that's a good point. I can fix this easily enough, by injecting the subtest name into the message passed to the is/ok functions at [1]. I just verified locally that it works as intended, I'll update the patch to do that.

(In reply to Botond Ballo [:botond] from comment #21)
> Comment on attachment 8753625 [details]
> MozReview Request: Bug 1273654 - Extract a waitUntilApzStable helper
> function for tests. r?botond
> 
> https://reviewboard.mozilla.org/r/53410/#review51820
> 
> So we're switching from "window.onload = " to "SimpleTest.waitForFocus()". I
> assume the latter is equivalent (or better)?

Yeah, I looked at the code for waitForFocus [2] and that also waits for load, as well as waits for focus. So it's strictly better I think.

(In reply to Botond Ballo [:botond] from comment #25)
> > +      var gTestContinuation = null;
> 
> Not much point prefixing this with 'g' if it's not a global any more.

True, I'll rename that.

I have more refactorings in mind, but they're much smaller and sometimes local to specific tests. I'll do those too at some point, in another bug, since I wanted to get these larger-scope refactorings done first.

[1] http://mxr.mozilla.org/mozilla-central/source/gfx/layers/apz/test/mochitest/apz_test_utils.js?rev=47b83c8478a0#192
[2] http://mxr.mozilla.org/mozilla-central/source/testing/mochitest/tests/SimpleTest/SimpleTest.js?rev=8710b9ecc282#665
The try push at https://treeherder.mozilla.org/#/jobs?repo=try&revision=d8a80c00d94d&group_state=expanded has the rebased patches (the ones posted to this bug, plus some WIPs for bug 1275604), I'll wait for that before landing.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: