Closed Bug 1144869 Opened 9 years ago Closed 9 years ago

Add BrowserTestUtils.withNewTab

Categories

(Testing :: General, defect)

defect
Not set
normal
Points:
1

Tracking

(firefox39 fixed)

RESOLVED FIXED
mozilla39
Iteration:
39.2 - 23 Mar
Tracking Status
firefox39 --- fixed

People

(Reporter: Paolo, Assigned: Paolo)

References

Details

Attachments

(1 file)

This is an utility function to execute a test on a web page.
Blocks: 1143903
Attached patch The patchSplinter Review
The first user would be the login tests:

yield BrowserTestUtils.withNewTab({
  gBrowser,
  url: "https://example.com/browser/toolkit/components/" +
       "passwordmgr/test/browser/form_basic.html",
}, function* (browser) {
  // ...
  yield ContentTask.spawn(browser, null, function* () { /*...*/ });
});
Assignee: nobody → paolo.mozmail
Status: NEW → ASSIGNED
Attachment #8579604 - Flags: review?(smacleod)
Iteration: --- → 39.2 - 23 Mar
Points: --- → 1
Flags: firefox-backlog+
Comment on attachment 8579604 [details] [diff] [review]
The patch

Review of attachment 8579604 [details] [diff] [review]:
-----------------------------------------------------------------

::: testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ +52,5 @@
> +   */
> +  withNewTab: Task.async(function* (options, taskFn) {
> +    // In theory we may be subject to a race condition here, since we cannot set
> +    // up the browserLoaded listener before calling addTab. In practice this is
> +    // how most tests currently do their setup, so this is expected to work.

So I believe this is guaranteed to work because the way we're listening for the load is in the content-utils.js framescript, and then sending an async message up. Since we don't yield the event loop before setting up our listener for that message (in browserLoaded) we can't miss it.

That being said I don't think we need this comment about a possible race condition. What I said above should probably be documented in browserLoaded though.

If you still think this comment is needed, I'm fine with that too though.
Attachment #8579604 - Flags: review?(smacleod) → review+
(In reply to Steven MacLeod [:smacleod] from comment #2)
> So I believe this is guaranteed to work because the way we're listening for
> the load is in the content-utils.js framescript, and then sending an async
> message up. Since we don't yield the event loop before setting up our
> listener for that message (in browserLoaded) we can't miss it.

You're right, I've documented this as you suggested and pushed to fx-team:

https://hg.mozilla.org/integration/fx-team/rev/477656ff3fc5
https://hg.mozilla.org/mozilla-central/rev/477656ff3fc5
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: