Closed Bug 567522 Opened 15 years ago Closed 15 years ago

onMouseover and onMouseOut called twice with different event targets (jetpack 0.4 rc1 widget)

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: david, Assigned: dietrich)

References

Details

Attachments

(1 file, 1 obsolete file)

With the new Widget API in 0.4 RC1, when I register an onMouseover/onMouseout I get called back twice for each with different event targets. STR const widgets = require("widget"); widgets.add(widgets.Widget({ label: "Widget with changing image on mouseover", content: "<img src=http://www.yahoo.com/favicon.ico>", onMouseover: function(e) { console.log("over "+e.target); e.target.src = "http://www.bing.com/favicon.ico"; }, onMouseout: function(e) { console.log("out "+e.target) e.target.src = "http://www.yahoo.com/favicon.ico"; } })); Actual Results: info: over [object XULElement] info: over [object XPCNativeWrapper [object HTMLImageElement]] info: out [object XPCNativeWrapper [object HTMLImageElement]] info: out [object XULElement] Expected results: A single call to over/out as implied by the docs.
Assignee: nobody → dietrich
OS: Mac OS X → All
Hardware: x86 → All
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attached patch v1 (obsolete) — Splinter Review
- only fire events for the content document, not for the xul iframe - update tests to ensure only one call to the listener per event fired
Attachment #447119 - Flags: review?(myk)
Comment on attachment 447119 [details] [diff] [review] v1 >diff --git a/packages/jetpack-core/lib/widget.js b/packages/jetpack-core/lib/widget.js > let listener = function(e) { >+ if (e.target.tagName && e.target.tagName == "iframe" && >+ e.target.toString() == "[object XULElement]") >+ return; Nit: this'll work, but it'd be better to do |e.target == item.node.firstElementChild|, which is both simpler and more robust. > // URL-specific handling > if (e.type == "load" && > contentType == CONTENT_TYPE_URI || contentType == CONTENT_TYPE_IMAGE) { > if (!loadURIIsMatch(e.target.location, item.widget)) > return; > } While you're making changes to this area of the code, can you fix a bug in this conditional? It evaluates to true when contentType == CONTENT_TYPE_IMAGE, even when e.type != "load", because && has higher precedence than ||, leading to exceptions because loadURIIsMatch gets called with a null e.target.location when mousing over/out of an image: Error: uncaught exception: [Exception... "Component returned failure code: 0x804b000a (NS_ERROR_MALFORMED_URI) [nsIIOService.newURI]" nsresult: "0x804b000a (NS_ERROR_MALFORMED_URI)" location: "JS frame :: file:///mnt/hgfs/myk/Projects/jetpack-sdk-widget/packages/jetpack-core/lib/securable-module.js -> resource://widgets-jetpack-core-lib/widget.js :: loadURIIsMatch :: line 428" data: no] >diff --git a/packages/jetpack-core/tests/test-widget.js b/packages/jetpack-core/tests/test-widget.js >- content: "<div id='me'>foo</div>", >+ content: "0", > onReady: function(e) { >- if (e.target.defaultView) >- sendMouseEvent({type:"click"}, "me", e.target.defaultView); >+ // ignore subsequent loads >+ if (this.content > 0) >+ return; >+ // send click once, and later check that it only fired once. >+ sendMouseEvent({type:"click"}, null, e.target.defaultView); >+ let self = this; >+ require("timer").setTimeout(function() { >+ test.assertEqual(self.content, 1, "onClick only called once per event fired"); >+ widgets.remove(self); >+ doneTest(); >+ }, 100); These tests don't seem to test the behavior in question, as they pass even if I remove the change to widget.js. I suspect "content" has to contain something like the <img> tag in comment 0. However, when I make it something like "<img src=http://www.yahoo.com/favicon.ico>", I get a bunch of exceptions thrown to the console, perhaps because "content" is no longer something that can be incremented like a number. However, using a variable to track the call count like in the following example doesn't fail the tests either, so I'm not sure what's going on: tests.push(function() { let count = 0; testSingleWidget(widgets.Widget({ label: "mouseover test widget", content: "<img src=http://www.yahoo.com/favicon.ico>", onReady: function(e) { // ignore subsequent loads if (count > 0) return; // send mouseover once, and later check that it only fired once. sendMouseEvent({type:"mouseover"}, null, e.target.defaultView); let self = this; require("timer").setTimeout(function() { test.assertEqual(count, 1, "onMouseover only called once per event fired"); widgets.remove(self); doneTest(); }, 100); }, onMouseover: function(e) { test.pass("onMouseover called"); count++; } }))});
Attachment #447119 - Flags: review?(myk) → review-
> While you're making changes to this area of the code, can you fix a bug in this > conditional? It evaluates to true when contentType == CONTENT_TYPE_IMAGE, even should be fixed from the check-in for bug 567505.
(In reply to comment #3) > should be fixed from the check-in for bug 567505. Ah, yes, of course!
Blocks: 566904
Version: unspecified → Trunk
This was driving me crazy, because I can reproduce the original bug in a separate addon via cfx run, but not in the unit tests. Current theory is that while moving the mouse to the widget, it passes over the iframe, while in the test i trigger the event manually, directly on the target element (no pass-over!). I confirmed manually that this patch fixes the problem (and with Myk's change also), so going to not include the hacky unit test bits.
Attached patch v2Splinter Review
Attachment #447119 - Attachment is obsolete: true
Attachment #447278 - Flags: review?(myk)
Attachment #447278 - Flags: review?(myk) → review+
Comment on attachment 447278 [details] [diff] [review] v2 Ah, Mozilla, so much fun to debug. r=myk
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
The Add-on SDK is no longer a Mozilla Labs experiment and has become a big enough project to warrant its own Bugzilla product, so the "Add-on SDK" product has been created for it, and I am moving its bugs to that product. To filter bugmail related to this change, filter on the word "looptid".
Component: Jetpack SDK → General
Product: Mozilla Labs → Add-on SDK
QA Contact: jetpack-sdk → general
Version: Trunk → unspecified
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: