Closed Bug 1083094 Opened 10 years ago Closed 10 years ago

Add events for content loaded when changing the category in preferences

Categories

(Firefox :: Settings UI, defect)

defect
Not set
normal
Points:
1

Tracking

()

RESOLVED WORKSFORME
Iteration:
36.2

People

(Reporter: danisielm, Assigned: jaws)

References

Details

(Whiteboard: [qa-automation-blocked])

Attachments

(4 obsolete files)

While working on mozmill automated tests for the in-content preferences, I often get failures when trying to change the category and access an element really fast.

This is the bug we filed for our tests: bug 1073483.

So what we need is event/events we could wait for that tell us the content of a category is completely loaded.
No longer blocks: 1005811
Blocks: 1005811
Jared, as we talked two days ago it would be great if we could get such an event. Right now this is kinda blocking us from getting in-content preferences tests implemented via Mozmill. Would there be a chance for you to get this added in the next time?
Flags: needinfo?(jaws)
Whiteboard: [mozmill] → [qa-automation-blocked]
Flags: needinfo?(jaws)
Assignee: nobody → jaws
Status: NEW → ASSIGNED
Iteration: --- → 36.1
Points: --- → 1
Flags: firefox-backlog+
Flags: qe-verify?
Attached patch WIP Patch (obsolete) — Splinter Review
Attached patch WIP Patch (with actual patch) (obsolete) — Splinter Review
Attachment #8508292 - Attachment is obsolete: true
Attached patch Patch (obsolete) — Splinter Review
Attachment #8508295 - Attachment is obsolete: true
Attachment #8509005 - Flags: review?(bmcbride)
remote: You can view the progress of your build at the following URL:
remote:   https://treeherder.mozilla.org/ui/#/jobs?repo=try&revision=dc0e05b09f13
remote: Alternatively, view them on TBPL (soon to be deprecated):
remote:   https://tbpl.mozilla.org/?tree=Try&rev=dc0e05b09f13
Comment on attachment 8509005 [details] [diff] [review]
Patch

>+  let event = new CustomEvent("PreferencesSearchEvent", {});

Event names don't usually contain the term "event".
(In reply to Dão Gottwald [:dao] from comment #6)
> Comment on attachment 8509005 [details] [diff] [review]
> Patch
> 
> >+  let event = new CustomEvent("PreferencesSearchEvent", {});
> 
> Event names don't usually contain the term "event".

I used the same naming convention as http://mxr.mozilla.org/mozilla-central/source/browser/base/content/abouthome/aboutHome.js#323 ("AboutHomeSearchEvent"). I can remove the "Event" suffix though.
(In reply to Jared Wein [:jaws] (please needinfo? me) from comment #7)
> (In reply to Dão Gottwald [:dao] from comment #6)
> > Comment on attachment 8509005 [details] [diff] [review]
> > Patch
> > 
> > >+  let event = new CustomEvent("PreferencesSearchEvent", {});
> > 
> > Event names don't usually contain the term "event".
> 
> I used the same naming convention as
> http://mxr.mozilla.org/mozilla-central/source/browser/base/content/abouthome/
> aboutHome.js#323 ("AboutHomeSearchEvent").

Which is not at all a convention. :) By the way, the second CustomEvent parameter is optional.
Attached patch Patch v1.1 (obsolete) — Splinter Review
Attachment #8509005 - Attachment is obsolete: true
Attachment #8509005 - Flags: review?(bmcbride)
Attachment #8509033 - Flags: review?(dao)
Comment on attachment 8509033 [details] [diff] [review]
Patch v1.1

It's not clear to me how you ended up implementing a search event while this bug was about category switching. gotoPref seems like the natural place for dispatching such an event. However, maybe mozmill could just listen to the select event?
Attachment #8509033 - Flags: review?(dao)
Henrik, can you try listening for the 'select' event and then running your test after a setTimeout(0)? The setTimeout may be necessary to ensure that all 'select' listeners have completed before you run your mozmill test code.
Flags: needinfo?(hskupin)
Moving the flag over to Daniel since he has worked on this.
Flags: needinfo?(hskupin) → needinfo?(daniel.gherasim)
(In reply to Jared Wein [:jaws] (please needinfo? me) from comment #11)
> Henrik, can you try listening for the 'select' event and then running your
> test after a setTimeout(0)? The setTimeout may be necessary to ensure that
> all 'select' listeners have completed before you run your mozmill test code.

Would you mind to be more specific in which kind of other select events we should expect and have to wait for? Maybe some pointers to the code might also be helpful. Thanks.
http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/in-content/preferences.js#41 shows an event listener being added to the `categories` element. You can add the same event listener, but you should run your test in a setTimeout to make sure that it is delayed until all of the listeners have completed.

> categories.addEventListener("select", function categoriesSelect() {
>   categories.removeEventListener("select", categoriesSelect);
>   setTimeout(function() {
>     // add test code here
>   }, 0);
> });

Does that help?
(In reply to Jared Wein [:jaws] (please needinfo? me) from comment #14)
> http://mxr.mozilla.org/mozilla-central/source/browser/components/preferences/
> in-content/preferences.js#41 shows an event listener being added to the
> `categories` element. You can add the same event listener, but you should
> run your test in a setTimeout to make sure that it is delayed until all of
> the listeners have completed.
> 
> > categories.addEventListener("select", function categoriesSelect() {
> >   categories.removeEventListener("select", categoriesSelect);
> >   setTimeout(function() {
> >     // add test code here
> >   }, 0);
> > });
> 
> Does that help?

Hi Jared. I think the real problem we've got in mozmill is related to the elements in the sync category. For the "Sign In", "Create Account" and "Using an older...|, the click event fails sometime if we do it really fast after accessing the category.

Basically we do
==== 
Access 'Sync' > Click on 'Sign In'/'Create Account'/... > wait for the new tab (fails sometime)
====
This is reproducible locally if I slow down my proccessor speed.

I believe that those are the only affected as I ran
===== 
Access 'category-privacy' > Click on 'Learn More' > wait for the new tab 
====
with no events waiting when switching the category and never failed in 100 runs.
Flags: needinfo?(daniel.gherasim)
Flags: needinfo?(jaws)
For the Sync pane, you need to add a "weave:service:ready" observer. You'll have to wait for the "weave:service:ready" notification before interacting with the items on the Sync pane.

browser/components/preferences/in-content/sync.js does this in init():
> let onReady = function () {
>   Services.obs.removeObserver(onReady, "weave:service:ready");
>   window.removeEventListener("unload", onUnload, false);
>   this._init();
> }.bind(this);
> Services.obs.addObserver(onReady, "weave:service:ready", false);

The other potential fix that we could do is to have preferences.js delay dispatching the "Initialized" event until it has observed the "weave:service:ready" notification, but I'm not sure what else that may impact.

Dao, what do you think about delaying the "Initialized" event?
Flags: needinfo?(jaws)
Flags: needinfo?(dao)
Flags: needinfo?(daniel.gherasim)
(In reply to Jared Wein [:jaws] (please needinfo? me) from comment #16)
> For the Sync pane, you need to add a "weave:service:ready" observer. You'll
> have to wait for the "weave:service:ready" notification before interacting
> with the items on the Sync pane.

Is that event always sent when opening the category? I don't think so. AFAIK while working on the TPS tests, this event is sent once at the beginning when you actually have logged in. Is it also sent if you are not logged in? Also when we switch between categories, come back to Sync and the event is not getting send again, we will timeout waiting for it.
(In reply to Jared Wein [:jaws] (please needinfo? me) from comment #16)
> For the Sync pane, you need to add a "weave:service:ready" observer. You'll
> have to wait for the "weave:service:ready" notification before interacting
> with the items on the Sync pane.
> 

So I see it works waiting for that event when we access about:preferences, but that doesn't help us here. As Henrik stated, it doesn't help us when switching to the sync category, stll fails. Maybe the elements are somehow loaded different then the other categories ? Given that the content depends on if we are logged in or not.
Flags: needinfo?(daniel.gherasim)
Hi Jared, can you mark this bug for QE verification.
Flags: needinfo?(jaws)
Flags: qe-verify?
Flags: qe-verify-
Flags: needinfo?(jaws)
Iteration: 36.1 → 36.2
Iteration: 36.2 → ---
Flags: needinfo?(dao)
(In reply to Henrik Skupin (:whimboo) from comment #17)
> (In reply to Jared Wein [:jaws] (please needinfo? me) from comment #16)
> > For the Sync pane, you need to add a "weave:service:ready" observer. You'll
> > have to wait for the "weave:service:ready" notification before interacting
> > with the items on the Sync pane.
> 
> Is that event always sent when opening the category? I don't think so. AFAIK
> while working on the TPS tests, this event is sent once at the beginning
> when you actually have logged in. Is it also sent if you are not logged in?
> Also when we switch between categories, come back to Sync and the event is
> not getting send again, we will timeout waiting for it.

(In reply to Daniel Gherasim from comment #18)
> (In reply to Jared Wein [:jaws] (please needinfo? me) from comment #16)
> > For the Sync pane, you need to add a "weave:service:ready" observer. You'll
> > have to wait for the "weave:service:ready" notification before interacting
> > with the items on the Sync pane.
> > 
> 
> So I see it works waiting for that event when we access about:preferences,
> but that doesn't help us here. As Henrik stated, it doesn't help us when
> switching to the sync category, stll fails. Maybe the elements are somehow
> loaded different then the other categories ? Given that the content depends
> on if we are logged in or not.

So this is what needs to be done:
When opening the in-content preferences, you should wait for the "Initialized" event, which is sent after all of the panes are loaded. Further, you will need to wait for the "weave:service:ready" observer notification to know that the Sync pane has finished loading. This notification will fire whether the user is logged in to Sync or not.

After waiting for the above two events to happen (you can probably *just* wait for "weave:service:ready"), then you will need to listen for the "select" event on the #categories element. After the "select" event, the desired pane will be showing and you can interact with it.

The "weave:service:ready" notification will only fire once, when the in-content preferences are loaded. It will not fire again when the Sync pane is visited.

Does that help you?
Flags: needinfo?(danisielm)
mozmill test breakages don't normally cause backouts of patches, and are not run through TBPL. As such, the in-content prefs triage today decided to remove this as a blocker from shipping in-content preferences.
Blocks: 718011
No longer blocks: ship-incontent-prefs
(In reply to Jared Wein [:jaws] (please needinfo? me) from comment #20)
> So this is what needs to be done:
> When opening the in-content preferences, you should wait for the
> "Initialized" event, which is sent after all of the panes are loaded.
> Further, you will need to wait for the "weave:service:ready" observer
> notification to know that the Sync pane has finished loading. This
> notification will fire whether the user is logged in to Sync or not.
True, this fires once you open the about:preferences the first time, waiting for this and for Initilized event in open method should be enough.
> After waiting for the above two events to happen (you can probably *just*
> wait for "weave:service:ready"), then you will need to listen for the
> "select" event on the #categories element. After the "select" event, the
> desired pane will be showing and you can interact with it.
Waiting only for the first two events when opening the preferences pane was enough for me.

> Does that help you?
Yes, I ran the testcase in a loop for 2000 times and didn't failed. 

Though this needs to be implemented in bug 1005811, I'll close this as Fixed and bug 1073483 as invalid.
Flags: needinfo?(danisielm)
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Iteration: --- → 36.2
Nothing landed here.
Resolution: FIXED → WORKSFORME
Attachment #8509033 - Attachment is obsolete: true
The proposed patch never landed because it was trying to do something else, as what I can read via the comments. So the way right now is somewhat a workaround but we could live with it, as it looks like. It may be good to have a dedicated event when panes are getting switched, but it looks like that beside our tests, no other add-on is affected yet. So not sure if having it makes sense.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: