WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
161451
Web Inspector: add Object.awaitEvent which is like singleFireEventListener but returns a promise
https://bugs.webkit.org/show_bug.cgi?id=161451
Summary
Web Inspector: add Object.awaitEvent which is like singleFireEventListener bu...
Blaze Burg
Reported
2016-08-31 12:27:09 PDT
This will make a bunch of tests easier to read.
Attachments
Patch
(2.28 KB, patch)
2016-08-31 14:25 PDT
,
Devin Rousso
no flags
Details
Formatted Diff
Diff
Patch
(4.70 KB, patch)
2016-08-31 15:36 PDT
,
Devin Rousso
no flags
Details
Formatted Diff
Diff
Archive of layout-test-results from ews100 for mac-yosemite
(845.19 KB, application/zip)
2016-08-31 16:26 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews106 for mac-yosemite-wk2
(1.13 MB, application/zip)
2016-08-31 16:26 PDT
,
Build Bot
no flags
Details
Archive of layout-test-results from ews112 for mac-yosemite
(1.50 MB, application/zip)
2016-08-31 16:33 PDT
,
Build Bot
no flags
Details
Patch
(5.02 KB, patch)
2016-08-31 17:22 PDT
,
Devin Rousso
no flags
Details
Formatted Diff
Diff
Patch
(5.57 KB, patch)
2016-09-01 00:04 PDT
,
Devin Rousso
no flags
Details
Formatted Diff
Diff
Show Obsolete
(6)
View All
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2016-08-31 12:28:22 PDT
<
rdar://problem/28100779
>
Devin Rousso
Comment 2
2016-08-31 14:25:50 PDT
Created
attachment 287542
[details]
Patch
Matt Baker
Comment 3
2016-08-31 14:43:25 PDT
Comment on
attachment 287542
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=287542&action=review
> Source/WebInspectorUI/UserInterface/Base/Object.js:105 > + resolve(...arguments);
This can be written with an arrow: this.singleFireEventListener(eventType, () => resolve(...arguments));
Blaze Burg
Comment 4
2016-08-31 15:10:00 PDT
Comment on
attachment 287542
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=287542&action=review
>> Source/WebInspectorUI/UserInterface/Base/Object.js:105 >> + resolve(...arguments); > > This can be written with an arrow: > this.singleFireEventListener(eventType, () => resolve(...arguments));
Resolve can only be passed one argument, the others are ignored. Please add a named argument 'event' and pass it.
Devin Rousso
Comment 5
2016-08-31 15:36:07 PDT
Created
attachment 287551
[details]
Patch
Blaze Burg
Comment 6
2016-08-31 16:13:21 PDT
Comment on
attachment 287551
[details]
Patch Regressions: Unexpected text-only failures (1) inspector/unit-tests/object.html [ Failure ]
Build Bot
Comment 7
2016-08-31 16:26:26 PDT
Comment on
attachment 287551
[details]
Patch
Attachment 287551
[details]
did not pass mac-ews (mac): Output:
http://webkit-queues.webkit.org/results/1982987
New failing tests: inspector/unit-tests/object.html
Build Bot
Comment 8
2016-08-31 16:26:29 PDT
Created
attachment 287556
[details]
Archive of layout-test-results from ews100 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews100 Port: mac-yosemite Platform: Mac OS X 10.10.5
Build Bot
Comment 9
2016-08-31 16:26:39 PDT
Comment on
attachment 287551
[details]
Patch
Attachment 287551
[details]
did not pass mac-wk2-ews (mac-wk2): Output:
http://webkit-queues.webkit.org/results/1982977
New failing tests: inspector/unit-tests/object.html
Build Bot
Comment 10
2016-08-31 16:26:42 PDT
Created
attachment 287558
[details]
Archive of layout-test-results from ews106 for mac-yosemite-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: ews106 Port: mac-yosemite-wk2 Platform: Mac OS X 10.10.5
Build Bot
Comment 11
2016-08-31 16:33:55 PDT
Comment on
attachment 287551
[details]
Patch
Attachment 287551
[details]
did not pass mac-debug-ews (mac): Output:
http://webkit-queues.webkit.org/results/1982990
New failing tests: inspector/unit-tests/object.html
Build Bot
Comment 12
2016-08-31 16:33:57 PDT
Created
attachment 287562
[details]
Archive of layout-test-results from ews112 for mac-yosemite The attached test failures were seen while running run-webkit-tests on the mac-debug-ews. Bot: ews112 Port: mac-yosemite Platform: Mac OS X 10.10.5
Joseph Pecoraro
Comment 13
2016-08-31 16:59:22 PDT
Comment on
attachment 287551
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=287551&action=review
> LayoutTests/inspector/unit-tests/object.html:38 > + object.awaitEvent(eventName).then(() => dispatchCount++);
In a Synchronous test suite this will not work, because any Promise's then microtask is guaranteed to run asynchronously. I'm not sure how you had gotten this to work locally. Either way, switching to an Async test suite (and updating all the tests to appropriately resolve/reject may do better. Maybe you could even have a synchronous suite runTestCasesAndNOTFinish() then run async tests right after.
Devin Rousso
Comment 14
2016-08-31 17:22:50 PDT
Created
attachment 287575
[details]
Patch
Joseph Pecoraro
Comment 15
2016-08-31 18:54:28 PDT
Comment on
attachment 287575
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=287575&action=review
r- only because I want to see a new test! Sorry for the back and forth on this =/
> LayoutTests/inspector/unit-tests/object.html:51 > + name: "Single Fire Promise", > + description: "awaitEvent should only trigger once", > + test(resolve, reject) { > + const eventName = "test"; > + let dispatchCount = 0; > + > + let object = new WebInspector.Object; > + > + object.awaitEvent(eventName).then(() => { > + dispatchCount++; > + > + InspectorTest.log("Dispatch count: " + dispatchCount); > + }); > + > + object.dispatchEventToListeners(eventName); > + object.dispatchEventToListeners(eventName); > + > + resolve(); > } > });
Err, resolve doesn't this call resolve before the awaitEvent's then block fires? There should probably be a separate event that ends up resolving. For example: (Assumes dispatchEvent is some microtask that happens before the Promise.resolve's) object.dispatchEventToListeners(eventName); object.dispatchEventToListeners(eventName); Promise.resolve().then(resolve, reject); Or: (assumes the timeout fires after all event listeners have fired) object.dispatchEventToListeners(eventName); object.dispatchEventToListeners(eventName); setTimeout(() => { resolve() }, 10); Or: (also best, this ensures the original is not dispatched more than once, and resolves the test after handling the second event) object.awaitEvent(eventName).then(() => { dispatchCount++; InspectorTest.expectThat(dispatchCount === 1, "Await event handler should be dispatched just once."); InspectorTest.log("Dispatch count: " + dispatchCount); object.awaitEvent(eventName).then(() => { resolve(); }); }); object.dispatchEventToListeners(eventName); object.dispatchEventToListeners(eventName); I prefer the last version, since it verifies both that the event is actually dispatched twice and that the original awaitEvent was dispatched just once.
Joseph Pecoraro
Comment 16
2016-08-31 18:55:43 PDT
Comment on
attachment 287575
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=287575&action=review
> LayoutTests/inspector/unit-tests/object.html:32 > + name: "Single Fire Promise",
And for Unit tests I've been giving the name the name of the method they test. This could be WebInspector.Object.prototype.awaitEvent. The one above could be dispatchEventToListeners.
Devin Rousso
Comment 17
2016-09-01 00:04:08 PDT
Created
attachment 287607
[details]
Patch
Blaze Burg
Comment 18
2016-09-01 10:44:15 PDT
Comment on
attachment 287607
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=287607&action=review
r=me
> LayoutTests/inspector/unit-tests/object.html:48 > + resolve();
You should add the dispatchCount === 1 assertion down here too, to check that the listener didn't fire a second time even though its a single fire event listener.
Joseph Pecoraro
Comment 19
2016-09-01 11:37:16 PDT
Comment on
attachment 287607
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=287607&action=review
>> LayoutTests/inspector/unit-tests/object.html:48 >> + resolve(); > > You should add the dispatchCount === 1 assertion down here too, to check that the listener didn't fire a second time even though its a single fire event listener.
Would the assertion down here matter? The only place dispatchCount changes is up above. If it changed again it would fail up above. Shrug.
WebKit Commit Bot
Comment 20
2016-09-01 15:05:03 PDT
Comment on
attachment 287607
[details]
Patch Clearing flags on attachment: 287607 Committed
r205319
: <
http://trac.webkit.org/changeset/205319
>
WebKit Commit Bot
Comment 21
2016-09-01 15:05:08 PDT
All reviewed patches have been landed. Closing bug.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug