chromium/third_party/blink/web_tests/fast/events/event-creation.html

<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<script>
    description("This tests that document.createEvent is hooked up for all Event interfaces (and alternatives) and creates the right instance.")

    // AnimationEvent
    shouldBeTrue("document.createEvent('AnimationEvent') instanceof window.AnimationEvent");
    shouldBeTrue("document.createEvent('AnimationEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('AnimationEvent').constructor === window.AnimationEvent");

    // Event
    shouldBeTrue("document.createEvent('Event') instanceof window.Event");
    shouldBeTrue("document.createEvent('Event').constructor === window.Event");
    shouldBeTrue("document.createEvent('EvENt') instanceof window.Event");
    shouldBeTrue("document.createEvent('EvENt').constructor === window.Event");

    // Events (Event alternative)
    shouldBeTrue("document.createEvent('Events') instanceof window.Event");
    shouldBeTrue("document.createEvent('Events').constructor === window.Event");
    shouldBeTrue("document.createEvent('EvENts') instanceof window.Event");
    shouldBeTrue("document.createEvent('EvENts').constructor === window.Event");

    // HTMLEvents (Event alternative)
    shouldBeTrue("document.createEvent('HTMLEvents') instanceof window.Event");
    shouldBeTrue("document.createEvent('HTMLEvents').constructor === window.Event");
    shouldBeTrue("document.createEvent('HTMLEvENts') instanceof window.Event");
    shouldBeTrue("document.createEvent('HTMLEvENts').constructor === window.Event");

    // CompositionEvent
    shouldBeTrue("document.createEvent('CompositionEvent') instanceof window.CompositionEvent");
    shouldBeTrue("document.createEvent('CompositionEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('CompositionEvent').constructor === window.CompositionEvent");

    // CustomEvent
    shouldBeTrue("document.createEvent('CustomEvent') instanceof window.CustomEvent");
    shouldBeTrue("document.createEvent('CustomEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('CustomEvent').constructor === window.CustomEvent");
    shouldBeTrue("document.createEvent('CustomEvENt') instanceof window.CustomEvent");
    shouldBeTrue("document.createEvent('CustomEvENt') instanceof window.Event");
    shouldBeTrue("document.createEvent('CustomEvENt').constructor === window.CustomEvent");

    // ErrorEvent
    shouldBeTrue("document.createEvent('ErrorEvent') instanceof window.ErrorEvent");
    shouldBeTrue("document.createEvent('ErrorEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('ErrorEvent').constructor === window.ErrorEvent");

    // HashChangeEvent
    shouldBeTrue("document.createEvent('HashChangeEvent') instanceof window.HashChangeEvent");
    shouldBeTrue("document.createEvent('HashChangeEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('HashChangeEvent').constructor === window.HashChangeEvent");

    // KeyboardEvent
    shouldBeTrue("document.createEvent('KeyboardEvent') instanceof window.KeyboardEvent");
    shouldBeTrue("document.createEvent('KeyboardEvent') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('KeyboardEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('KeyboardEvent').constructor === window.KeyboardEvent");

    // KeyboardEvents (KeyboardEvent alternative)
    shouldBeTrue("document.createEvent('KeyboardEvents') instanceof window.KeyboardEvent");
    shouldBeTrue("document.createEvent('KeyboardEvents') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('KeyboardEvents') instanceof window.Event");
    shouldBeTrue("document.createEvent('KeyboardEvents').constructor === window.KeyboardEvent");

    // MessageEvent
    shouldBeTrue("document.createEvent('MessageEvent') instanceof window.MessageEvent");
    shouldBeTrue("document.createEvent('MessageEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('MessageEvent').constructor === window.MessageEvent");

    // MouseEvent
    shouldBeTrue("document.createEvent('MouseEvent') instanceof window.MouseEvent");
    shouldBeTrue("document.createEvent('MouseEvent') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('MouseEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('MouseEvent').constructor === window.MouseEvent");
    shouldBeTrue("document.createEvent('MouseEvENt') instanceof window.MouseEvent");
    shouldBeTrue("document.createEvent('MouseEvENt') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('MouseEvENt') instanceof window.Event");
    shouldBeTrue("document.createEvent('MouseEvENt').constructor === window.MouseEvent");

    // MouseEvents (MouseEvent alternative)
    shouldBeTrue("document.createEvent('MouseEvents') instanceof window.MouseEvent");
    shouldBeTrue("document.createEvent('MouseEvents') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('MouseEvents') instanceof window.Event");
    shouldBeTrue("document.createEvent('MouseEvents').constructor === window.MouseEvent");
    shouldBeTrue("document.createEvent('MouseEvENts') instanceof window.MouseEvent");
    shouldBeTrue("document.createEvent('MouseEvENts') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('MouseEvENts') instanceof window.Event");
    shouldBeTrue("document.createEvent('MouseEvENts').constructor === window.MouseEvent");

    // MutationEvent
    shouldBeTrue("document.createEvent('MutationEvent') instanceof window.MutationEvent");
    shouldBeTrue("document.createEvent('MutationEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('MutationEvent').constructor === window.MutationEvent");

    // MutationEvents (MutationEvent alternative)
    shouldBeTrue("document.createEvent('MutationEvents') instanceof window.MutationEvent");
    shouldBeTrue("document.createEvent('MutationEvents') instanceof window.Event");
    shouldBeTrue("document.createEvent('MutationEvents').constructor === window.MutationEvent");

    // PageTransitionEvent
    shouldBeTrue("document.createEvent('PageTransitionEvent') instanceof window.PageTransitionEvent");
    shouldBeTrue("document.createEvent('PageTransitionEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('PageTransitionEvent').constructor === window.PageTransitionEvent");

    // PopStateEvent
    shouldBeTrue("document.createEvent('PopStateEvent') instanceof window.PopStateEvent");
    shouldBeTrue("document.createEvent('PopStateEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('PopStateEvent').constructor === window.PopStateEvent");

    // TextEvent
    shouldBeTrue("document.createEvent('TextEvent') instanceof window.TextEvent");
    shouldBeTrue("document.createEvent('TextEvent') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('TextEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('TextEvent').constructor === window.TextEvent");

    // UIEvent
    shouldBeTrue("document.createEvent('UIEvent') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('UIEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('UIEvent').constructor === window.UIEvent");
    shouldBeTrue("document.createEvent('UIEvENt') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('UIEvENt') instanceof window.Event");
    shouldBeTrue("document.createEvent('UIEvENt').constructor === window.UIEvent");

    // UIEvents (UIEvent alternative)
    shouldBeTrue("document.createEvent('UIEvents') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('UIEvents') instanceof window.Event");
    shouldBeTrue("document.createEvent('UIEvents').constructor === window.UIEvent");
    shouldBeTrue("document.createEvent('UIEvENts') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('UIEvENts') instanceof window.Event");
    shouldBeTrue("document.createEvent('UIEvENts').constructor === window.UIEvent");

    // TransitionEvent
    shouldBeTrue("document.createEvent('TransitionEvent') instanceof window.TransitionEvent");
    shouldBeTrue("document.createEvent('TransitionEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('TransitionEvent').constructor === window.TransitionEvent");

    // WheelEvent
    shouldBeTrue("document.createEvent('WheelEvent') instanceof window.WheelEvent");
    shouldBeTrue("document.createEvent('WheelEvent') instanceof window.MouseEvent");
    shouldBeTrue("document.createEvent('WheelEvent') instanceof window.UIEvent");
    shouldBeTrue("document.createEvent('WheelEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('WheelEvent').constructor === window.WheelEvent");

    // StorageEvent
    shouldBeTrue("document.createEvent('StorageEvent') instanceof window.StorageEvent");
    shouldBeTrue("document.createEvent('StorageEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('StorageEvent').constructor === window.StorageEvent");

    // SVGEvents (Event alternative)
    shouldBeTrue("document.createEvent('SVGEvents') instanceof window.Event");
    shouldBeTrue("document.createEvent('SVGEvents').constructor === window.Event");

    // CloseEvent
    shouldBeTrue("document.createEvent('CloseEvent') instanceof window.CloseEvent");
    shouldBeTrue("document.createEvent('CloseEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('CloseEvent').constructor === window.CloseEvent");

    // The following are here for completeness, but won't until there is more widespread support for them.

    // #if ENABLE(WEBGL)
    // WebGLContextEvent
    // shouldBeTrue("document.createEvent('WebGLContextEvent') instanceof window.WebGLContextEvent");
    // shouldBeTrue("document.createEvent('WebGLContextEvent') instanceof window.Event");
    // shouldBeTrue("document.createEvent('WebGLContextEvent').constructor === window.WebGLContextEvent");

    // TouchEvent
    shouldBeTrue("document.createEvent('TouchEvent') instanceof window.TouchEvent");
    shouldBeTrue("document.createEvent('TouchEvent') instanceof window.Event");
    shouldBeTrue("document.createEvent('TouchEvent').constructor === window.TouchEvent");

    // DeviceMotionEvent
    // shouldBeTrue("document.createEvent('DeviceMotionEvent') instanceof window.DeviceMotionEvent");
    // shouldBeTrue("document.createEvent('DeviceMotionEvent') instanceof window.Event");
    // shouldBeTrue("document.createEvent('DeviceMotionEvent').constructor === window.DeviceMotionEvent");

    // DeviceOrientationEvent
    // shouldBeTrue("document.createEvent('DeviceOrientationEvent') instanceof window.DeviceOrientationEvent");
    // shouldBeTrue("document.createEvent('DeviceOrientationEvent') instanceof window.Event");
    // shouldBeTrue("document.createEvent('DeviceOrientationEvent').constructor === window.DeviceOrientationEvent");

    // We test both a hard coded set and the automated set below (using enumeration) to ensure that a constructor being removed
    // from the window is caught a regression.

    var allEventInterfacesCreateEvents = true;
    for (var propertyName in window) {
        if (propertyName.match(/Event$/) && window[propertyName].toString().match(/EventConstructor\]$/)) {
            try {
                if (!(document.createEvent(propertyName) instanceof window.Event)) {
                    allEventInterfacesCreateEvents = false;
                    debug("'document.createEvent(propertyName) instanceof window.Event' with propertyName: " + propertyName + " should be true but isn't");
                }
            } catch (e) {
                allEventInterfacesCreateEvents = false;
                debug("'document.createEvent(propertyName) instanceof window.Event' with propertyName: " + propertyName + " threw an exception: " + e);
            }

            try {
                if (!(document.createEvent(propertyName) instanceof window[propertyName])) {
                    allEventInterfacesCreateEvents = false;
                    debug("'document.createEvent(propertyName) instanceof window[propertyName]' with propertyName: " + propertyName + " should be true but isn't");
                }
            } catch (e) {
                allEventInterfacesCreateEvents = false;
                debug("'document.createEvent(propertyName) instanceof window[propertyName]' with propertyName: " + propertyName + " threw an exception: " + e);
            }

            try {
                if (!(document.createEvent(propertyName).constructor === window[propertyName])) {
                    allEventInterfacesCreateEvents = false;
                    debug("'document.createEvent(propertyName).constructor === window[propertyName]' with propertyName: " + propertyName + " should be true but isn't");
                }
            } catch (e) {
                allEventInterfacesCreateEvents = false;
                debug("'document.createEvent(propertyName).constructor === window[propertyName]' with propertyName: " + propertyName + " threw an exception: " + e);
            }
        }
    }
    shouldBeTrue('allEventInterfacesCreateEvents');
</script>



</body>