Changeset 205319 in webkit


Ignore:
Timestamp:
Sep 1, 2016 3:03:10 PM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: add Object.awaitEvent which is like singleFireEventListener but returns a promise
https://bugs.webkit.org/show_bug.cgi?id=161451

Patch by Devin Rousso <Devin Rousso> on 2016-09-01
Reviewed by Brian Burg.

Source/WebInspectorUI:

  • UserInterface/Base/Object.js:

(WebInspector.Object.awaitEvent):
(WebInspector.Object.prototype.awaitEvent):

LayoutTests:

  • inspector/unit-tests/object-expected.txt:
  • inspector/unit-tests/object.html:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r205316 r205319  
     12016-09-01  Devin Rousso  <dcrousso+webkit@gmail.com>
     2
     3        Web Inspector: add Object.awaitEvent which is like singleFireEventListener but returns a promise
     4        https://bugs.webkit.org/show_bug.cgi?id=161451
     5
     6        Reviewed by Brian Burg.
     7
     8        * inspector/unit-tests/object-expected.txt:
     9        * inspector/unit-tests/object.html:
     10
    1112016-09-01  Ryosuke Niwa  <rniwa@webkit.org>
    212
  • trunk/LayoutTests/inspector/unit-tests/object-expected.txt

    r195442 r205319  
    33
    44== Running test suite: Object
    5 -- Running test case: Events propagation
     5-- Running test case: WebInspector.Object.prototype.dispatchEventToListeners
    66Dispatch count: 1
    77
     8-- Running test case: WebInspector.Object.prototype.awaitEvent
     9PASS: Await event handler should be dispatched just once.
     10Dispatch count: 1
     11
  • trunk/LayoutTests/inspector/unit-tests/object.html

    r195442 r205319  
    66function test()
    77{
    8     let suite = InspectorTest.createSyncSuite("Object");
     8    let suite = InspectorTest.createAsyncSuite("Object");
    99
    1010    suite.addTestCase({
    11         name: "Events propagation",
     11        name: "WebInspector.Object.prototype.dispatchEventToListeners",
    1212        description: "WebInspector.Object shouldn't dispatch constructor-level events multiple times",
    13         test: function() {
     13        test(resolve, reject) {
    1414            class Parent extends WebInspector.Object {}
    1515            class Child extends Parent {}
     
    2424
    2525            InspectorTest.log("Dispatch count: " + dispatchCount);
     26
     27            resolve();
     28        }
     29    });
     30
     31    suite.addTestCase({
     32        name: "WebInspector.Object.prototype.awaitEvent",
     33        description: "awaitEvent should only trigger once",
     34        test(resolve, reject) {
     35            const eventName = "test";
     36            let dispatchCount = 0;
     37
     38            let object = new WebInspector.Object;
     39
     40            object.awaitEvent(eventName).then(() => {
     41                dispatchCount++;
     42
     43                InspectorTest.expectThat(dispatchCount === 1, "Await event handler should be dispatched just once.");
     44                InspectorTest.log("Dispatch count: " + dispatchCount);
     45
     46                // Resolve test on second event dispatch.
     47                object.awaitEvent(eventName).then(() => {
     48                    resolve();
     49                });
     50
     51                object.dispatchEventToListeners(eventName);
     52            });
     53
     54            object.dispatchEventToListeners(eventName);
    2655        }
    2756    });
  • trunk/Source/WebInspectorUI/ChangeLog

    r205314 r205319  
     12016-09-01  Devin Rousso  <dcrousso+webkit@gmail.com>
     2
     3        Web Inspector: add Object.awaitEvent which is like singleFireEventListener but returns a promise
     4        https://bugs.webkit.org/show_bug.cgi?id=161451
     5
     6        Reviewed by Brian Burg.
     7
     8        * UserInterface/Base/Object.js:
     9        (WebInspector.Object.awaitEvent):
     10        (WebInspector.Object.prototype.awaitEvent):
     11
    1122016-09-01  Nikita Vasilyev  <nvasilyev@apple.com>
    213
  • trunk/Source/WebInspectorUI/UserInterface/Base/Object.js

    r202784 r205319  
    9999    }
    100100
     101    static awaitEvent(eventType)
     102    {
     103        return new Promise((resolve, reject) => {
     104            this.singleFireEventListener(eventType, (event) => resolve(event), null);
     105        });
     106    }
     107
    101108    // Only used by tests.
    102109    static hasEventListeners(eventType)
     
    132139    singleFireEventListener() { return WebInspector.Object.singleFireEventListener.apply(this, arguments); }
    133140    removeEventListener() { return WebInspector.Object.removeEventListener.apply(this, arguments); }
     141    awaitEvent() { return WebInspector.Object.awaitEvent.apply(this, arguments); }
    134142    hasEventListeners() { return WebInspector.Object.hasEventListeners.apply(this, arguments); }
    135143    retainedObjectsWithPrototype() { return WebInspector.Object.retainedObjectsWithPrototype.apply(this, arguments); }
Note: See TracChangeset for help on using the changeset viewer.