tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Document-createEvent.https.html (5530B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>Document.createEvent</title>
      4 <link rel=help href="https://dom.spec.whatwg.org/#dom-document-createevent">
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="Document-createEvent.js"></script>
      8 <div id="log"></div>
      9 <script>
     10 function supportsTouchEvents(isTouchEvent) {
     11  if (isTouchEvent) {
     12    assert_implements_optional('ontouchstart' in document, "'expose legacy touch event APIs'");
     13  }
     14 }
     15 function testAlias(arg, iface, isTouchEvent) {
     16  var ev;
     17  test(function() {
     18    supportsTouchEvents(isTouchEvent);
     19    ev = document.createEvent(arg);
     20    assert_equals(Object.getPrototypeOf(ev), window[iface].prototype);
     21  }, arg + " should be an alias for " + iface + ".");
     22  test(function() {
     23    supportsTouchEvents(isTouchEvent);
     24    assert_equals(ev.type, "",
     25                  "type should be initialized to the empty string");
     26    assert_equals(ev.target, null,
     27                  "target should be initialized to null");
     28    assert_equals(ev.currentTarget, null,
     29                  "currentTarget should be initialized to null");
     30    assert_equals(ev.eventPhase, 0,
     31                  "eventPhase should be initialized to NONE (0)");
     32    assert_equals(ev.bubbles, false,
     33                  "bubbles should be initialized to false");
     34    assert_equals(ev.cancelable, false,
     35                  "cancelable should be initialized to false");
     36    assert_equals(ev.defaultPrevented, false,
     37                  "defaultPrevented should be initialized to false");
     38    assert_equals(ev.isTrusted, false,
     39                  "isTrusted should be initialized to false");
     40  }, "createEvent('" + arg + "') should be initialized correctly.");
     41 }
     42 aliases.TouchEvent = 'TouchEvent';
     43 for (var alias in aliases) {
     44  var isTouchEvent = alias === 'TouchEvent';
     45  var iface = aliases[alias];
     46  testAlias(alias, iface, isTouchEvent);
     47  testAlias(alias.toLowerCase(), iface, isTouchEvent);
     48  testAlias(alias.toUpperCase(), iface, isTouchEvent);
     49 
     50  if (alias[alias.length - 1] != "s") {
     51    var plural = alias + "s";
     52    if (!(plural in aliases)) {
     53      test(function () {
     54        assert_throws_dom("NOT_SUPPORTED_ERR", function () {
     55          var evt = document.createEvent(plural);
     56        });
     57      }, 'Should throw NOT_SUPPORTED_ERR for pluralized legacy event interface "' + plural + '"');
     58    }
     59  }
     60 }
     61 
     62 test(function() {
     63  assert_throws_dom("NOT_SUPPORTED_ERR", function() {
     64    var evt = document.createEvent("foo");
     65  });
     66  assert_throws_dom("NOT_SUPPORTED_ERR", function() {
     67    // 'LATIN CAPITAL LETTER I WITH DOT ABOVE' (U+0130)
     68    var evt = document.createEvent("U\u0130Event");
     69  });
     70  assert_throws_dom("NOT_SUPPORTED_ERR", function() {
     71    // 'LATIN SMALL LETTER DOTLESS I' (U+0131)
     72    var evt = document.createEvent("U\u0131Event");
     73  });
     74 }, "Should throw NOT_SUPPORTED_ERR for unrecognized arguments");
     75 
     76 /*
     77 * The following are event interfaces which do actually exist, but must still
     78 * throw since they're absent from the table in the spec for
     79 * document.createEvent().  This list is not exhaustive, but includes all
     80 * interfaces that it is known some UA does or did not throw for.
     81 */
     82 var someNonCreateableEvents = [
     83  "AnimationEvent",
     84  "AnimationPlaybackEvent",
     85  "AnimationPlayerEvent",
     86  "ApplicationCacheErrorEvent",
     87  "AudioProcessingEvent",
     88  "AutocompleteErrorEvent",
     89  "BeforeInstallPromptEvent",
     90  "BlobEvent",
     91  "ClipboardEvent",
     92  "CloseEvent",
     93  "CommandEvent",
     94  "DataContainerEvent",
     95  "ErrorEvent",
     96  "ExtendableEvent",
     97  "ExtendableMessageEvent",
     98  "FetchEvent",
     99  "FontFaceSetLoadEvent",
    100  "GamepadEvent",
    101  "GeofencingEvent",
    102  "IDBVersionChangeEvent",
    103  "InstallEvent",
    104  "KeyEvent",
    105  "MIDIConnectionEvent",
    106  "MIDIMessageEvent",
    107  "MediaEncryptedEvent",
    108  "MediaKeyEvent",
    109  "MediaKeyMessageEvent",
    110  "MediaQueryListEvent",
    111  "MediaStreamEvent",
    112  "MediaStreamTrackEvent",
    113  "MouseScrollEvent",
    114  "MutationEvent",
    115  "NotificationEvent",
    116  "NotifyPaintEvent",
    117  "OfflineAudioCompletionEvent",
    118  "OrientationEvent",
    119  "PageTransition", // Yes, with no "Event"
    120  "PageTransitionEvent",
    121  "PointerEvent",
    122  "PopStateEvent",
    123  "PopUpEvent",
    124  "PresentationConnectionAvailableEvent",
    125  "PresentationConnectionCloseEvent",
    126  "ProgressEvent",
    127  "PromiseRejectionEvent",
    128  "PushEvent",
    129  "RTCDTMFToneChangeEvent",
    130  "RTCDataChannelEvent",
    131  "RTCIceCandidateEvent",
    132  "RelatedEvent",
    133  "ResourceProgressEvent",
    134  "SVGEvent",
    135  "SVGZoomEvent",
    136  "ScrollAreaEvent",
    137  "SecurityPolicyViolationEvent",
    138  "ServicePortConnectEvent",
    139  "ServiceWorkerMessageEvent",
    140  "SimpleGestureEvent",
    141  "SpeechRecognitionError",
    142  "SpeechRecognitionEvent",
    143  "SpeechSynthesisEvent",
    144  "SyncEvent",
    145  "TimeEvent",
    146  "TrackEvent",
    147  "TransitionEvent",
    148  "WebGLContextEvent",
    149  "WebKitAnimationEvent",
    150  "WebKitTransitionEvent",
    151  "WheelEvent",
    152  "XULCommandEvent",
    153 ];
    154 someNonCreateableEvents.forEach(function (eventInterface) {
    155  test(function () {
    156    assert_throws_dom("NOT_SUPPORTED_ERR", function () {
    157      var evt = document.createEvent(eventInterface);
    158    });
    159  }, 'Should throw NOT_SUPPORTED_ERR for non-legacy event interface "' + eventInterface + '"');
    160 
    161  // SVGEvents is allowed, other plurals are not
    162  if (eventInterface !== "SVGEvent") {
    163    test(function () {
    164      assert_throws_dom("NOT_SUPPORTED_ERR", function () {
    165        var evt = document.createEvent(eventInterface + "s");
    166      });
    167    }, 'Should throw NOT_SUPPORTED_ERR for pluralized non-legacy event interface "' + eventInterface + 's"');
    168  }
    169 });
    170 </script>