Closed Bug 1373130 Opened 9 years ago Closed 8 years ago

[Form Autofill] Explicitly dispatch a notification after "identifyAutofillFields" invoked to ensure the tests have right timing to press down-key to avoid potential timeout

Categories

(Toolkit :: Form Manager, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
mozilla58
Tracking Status
firefox58 --- fixed

People

(Reporter: ralin, Assigned: ralin)

References

(Blocks 1 open bug)

Details

(Whiteboard: [form autofill])

Attachments

(1 file)

Right now, we defer the timing of invoking identifyAutofillFields at the point user "focusin" the element. It's intentional for performance improvement and doesn't harm normal usage. However, in our mochitest/bc tests, there's no delay between "focusin" and doKey("down")[1], and that potentially causes the timeout since no popup would show up until identifyAutofillFields is invoked. I think we should consider sending out a message like "FormAutofill:FieldsIdentified" to replace current workaround[2] as an accordance for our tests to wait for. [0] http://searchfox.org/mozilla-central/rev/d67ef71097da4d1aa344c9d9c672e49a7228e765/browser/extensions/formautofill/content/FormAutofillFrameScript.js#51 [1] http://searchfox.org/mozilla-central/rev/c49a70b53f67dd5550eec8a08793805f2aca8d42/browser/extensions/formautofill/test/mochitest/test_basic_autocomplete_form.html#107-108 [2] http://searchfox.org/mozilla-central/rev/d67ef71097da4d1aa344c9d9c672e49a7228e765/browser/extensions/formautofill/test/mochitest/formautofill_common.js#14-24
Whiteboard: [form autofill]
Not sure it's right way to go or is more reliable than setTimeout, will see the result on try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=0c01b9d259891f373e15c8c412b33af9b718a2d5
Take this bug since identifyAutofillFields is still bothering Bug 1300995 with timeout problem.
Assignee: nobody → ralin
Status: NEW → ASSIGNED
Blocks: 1300995
Comment on attachment 8878059 [details] Bug 1373130 - Send message after identifyAutofillFields being invoked to indicate that formautofill is ready to open popup. https://reviewboard.mozilla.org/r/149472/#review154238 ::: browser/extensions/formautofill/test/mochitest/formautofill_common.js:20 (Diff revision 2) > - input.focus(); > + input.focus(); > > - // "identifyAutofillFields" is invoked asynchronously in "focusin" event. We > - // should make sure fields are ready for popup before doing tests. > - // > - // TODO: "setTimeout" is used here temporarily because there's no event to > + if (docIdentified) { > + resolve(input); > + } else { > + formFillChromeScript.addMessageListener("FormAutofillTest:Identified", () => { I suppose we need to `removeMessageListener` as it should be invoked only once. ::: browser/extensions/formautofill/test/mochitest/formautofill_common.js:23 (Diff revision 2) > - // figure out a better way after the heuristics land. > - SimpleTest.requestFlakyTimeout("Guarantee asynchronous identifyAutofillFields is invoked"); > - return new Promise(resolve => setTimeout(() => { > - resolve(input); > + resolve(input); > - }, 500)); > + }); > + docIdentified = true; Since `docIdentified` actually happens after `FormAutofillTest:Identified`, it should be in the handler. However, according to your implementation, `FormAutofill:FieldsIdentified` is sent every time upon `focusin`, I think we don't need `docIdentified`.
Attachment #8878059 - Flags: review?(lchang)
Comment on attachment 8878059 [details] Bug 1373130 - Send message after identifyAutofillFields being invoked to indicate that formautofill is ready to open popup. https://reviewboard.mozilla.org/r/149472/#review154868 ::: browser/extensions/formautofill/content/FormAutofillFrameScript.js:52 (Diff revision 4) > return; > } > > - let doIdentifyAutofillFields = > - () => setTimeout(() => FormAutofillContent.identifyAutofillFields(doc)); > + let doIdentifyAutofillFields = () => setTimeout(() => { > + FormAutofillContent.identifyAutofillFields(doc); > + sendAsyncMessage("FormAutofill:FieldsIdentified"); Please comment on this that it's only used by tests for now.
Attachment #8878059 - Flags: review?(lchang) → review+
Thank you Luke, I was thinking to eliminate the setTimeout workaround in our tests, however, by looking at the latest try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=99d48f9d461dc81321f823a31e1eca73c20cd095, I doubt this is reliable enough. I'd like to leave setTimeout as-is if it doesn't bring up huge impact in the near future.
See Also: → 1406581
Hi Luke, Though you've r+'d the patch, could you help me to review again and see if it's still valid? Thanks.
https://treeherder.mozilla.org/#/jobs?repo=try&revision=c03aa8e523b891c095c35d1c8cf3d0ab63d49863 I think the TH result shows that this patch is reliable enough to settle some intermittent failures, including test_basic_creditcard_autocomplete_form.html.
Hey Luke, I've updated the patch according to what we discussed yesterday. Could you help me to review it again? Thanks.
Flags: needinfo?(lchang)
Comment on attachment 8878059 [details] Bug 1373130 - Send message after identifyAutofillFields being invoked to indicate that formautofill is ready to open popup. https://reviewboard.mozilla.org/r/149472/#review195774 ::: browser/extensions/formautofill/test/browser/head.js:103 (Diff revision 8) > await new Promise(resolve => setTimeout(resolve, ms)); > } > > +async function focusAndWaitForFieldsIdentified(browser, selector) { > + /* eslint no-shadow: ["error", { "allow": ["selector", "focused", "identified"] }] */ > + const {focused, identified} = await ContentTask.spawn(browser, {selector}, async function({selector}) { nit: `previouslyFocused` and `previouslyIdentified` ::: browser/extensions/formautofill/test/browser/head.js:119 (Diff revision 8) > + > + if (identified) { > + return; > + } > + > + if (!focused) { It would be clearer to leave some comments explaining `FormAutofill:FieldsIdentified` may not be triggered if an input has been focused previously. ::: browser/extensions/formautofill/test/browser/head.js:127 (Diff revision 8) > + Services.mm.removeMessageListener("FormAutofill:FieldsIdentified", onIdentified); > + resolve(); > + }); > + }); > + } > + // Wait 500ms for identifyAutofillFields if the form hasn't been identified yet. This comment may need some updates since it's mainly for inputs that were focused previously, isn't it? ::: browser/extensions/formautofill/test/mochitest/formautofill_common.js:19 (Diff revision 8) > await new Promise(resolve => setTimeout(resolve, ms)); > } > > -async function setInput(selector, value) { > - let input = document.querySelector("input" + selector); > - input.value = value; > +async function focusAndWaitForFieldsIdentified(input) { > + const rootElement = input.form || input.ownerDocument.documentElement; > + const focused = input != document.activeElement; nit: `previouslyFocused` ::: browser/extensions/formautofill/test/mochitest/formautofill_common.js:34 (Diff revision 8) > // "identifyAutofillFields" is invoked asynchronously in "focusin" event. We > // should make sure fields are ready for popup before doing tests. > // > // TODO: "sleep" is used here temporarily because there's no event to > // notify us of the state of "identifyAutofillFields" for now. We should > // figure out a better way after the heuristics land. Comments need to be updated, too. ::: browser/extensions/formautofill/test/mochitest/test_on_address_submission.html:35 (Diff revision 8) > + return Object.entries(profile) > + .map(([key, value]) => setInput("#" + key, value)) > + .reduce((p, c) => p.then(c), Promise.resolve()); Since for-loop does well, how about keep using it?
(In reply to Ray Lin[:ralin] from comment #17) > I've updated the patch according to what we discussed yesterday. Could you > help me to review it again? Thanks. Looks good to me. Only a few comments left. Thanks for addressing this.
Flags: needinfo?(lchang)
Comment on attachment 8878059 [details] Bug 1373130 - Send message after identifyAutofillFields being invoked to indicate that formautofill is ready to open popup. https://reviewboard.mozilla.org/r/149472/#review195774 Thanks for the review, the issues are fixed in the latest patch. > Since for-loop does well, how about keep using it? reverted the change, thanks.
Keywords: checkin-needed
Unmark checkin-needed, I didn't notice that: https://treeherder.mozilla.org/logviewer.html#?job_id=138105981&repo=try&lineNumber=2293, let me see why this patch causes new failure only on "test_on_address_submission.html"
Keywords: checkin-needed
Keywords: checkin-needed
Pushed by ryanvm@gmail.com: https://hg.mozilla.org/integration/autoland/rev/7649437b6b0c Send message after identifyAutofillFields being invoked to indicate that formautofill is ready to open popup. r=lchang
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: