setters_tests.json 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. {
  2. "comment": [
  3. "## Tests for setters of https://url.spec.whatwg.org/#urlutils-members",
  4. "",
  5. "This file contains a JSON object.",
  6. "Other than 'comment', each key is an attribute of the `URL` interface",
  7. "defined in WHATWG’s URL Standard.",
  8. "The values are arrays of test case objects for that attribute.",
  9. "",
  10. "To run a test case for the attribute `attr`:",
  11. "",
  12. "* Create a new `URL` object with the value for the 'href' key",
  13. " the constructor single parameter. (Without a base URL.)",
  14. " This must not throw.",
  15. "* Set the attribute `attr` to (invoke its setter with)",
  16. " with the value of for 'new_value' key.",
  17. "* The value for the 'expected' key is another object.",
  18. " For each `key` / `value` pair of that object,",
  19. " get the attribute `key` (invoke its getter).",
  20. " The returned string must be equal to `value`.",
  21. "",
  22. "Note: the 'href' setter is already covered by urltestdata.json."
  23. ],
  24. "protocol": [
  25. {
  26. "comment": "The empty string is not a valid scheme. Setter leaves the URL unchanged.",
  27. "href": "a://example.net",
  28. "new_value": "",
  29. "expected": {
  30. "href": "a://example.net/",
  31. "protocol": "a:"
  32. }
  33. },
  34. {
  35. "href": "a://example.net",
  36. "new_value": "b",
  37. "expected": {
  38. "href": "b://example.net/",
  39. "protocol": "b:"
  40. }
  41. },
  42. {
  43. "comment": "Upper-case ASCII is lower-cased",
  44. "href": "a://example.net",
  45. "new_value": "B",
  46. "expected": {
  47. "href": "b://example.net/",
  48. "protocol": "b:"
  49. }
  50. },
  51. {
  52. "comment": "Non-ASCII is rejected",
  53. "href": "a://example.net",
  54. "new_value": "é",
  55. "expected": {
  56. "href": "a://example.net/",
  57. "protocol": "a:"
  58. }
  59. },
  60. {
  61. "comment": "No leading digit",
  62. "href": "a://example.net",
  63. "new_value": "0b",
  64. "expected": {
  65. "href": "a://example.net/",
  66. "protocol": "a:"
  67. }
  68. },
  69. {
  70. "comment": "No leading punctuation",
  71. "href": "a://example.net",
  72. "new_value": "+b",
  73. "expected": {
  74. "href": "a://example.net/",
  75. "protocol": "a:"
  76. }
  77. },
  78. {
  79. "href": "a://example.net",
  80. "new_value": "bC0+-.",
  81. "expected": {
  82. "href": "bc0+-.://example.net/",
  83. "protocol": "bc0+-.:"
  84. }
  85. },
  86. {
  87. "comment": "Non-ASCII is rejected",
  88. "href": "a://example.net",
  89. "new_value": "bé",
  90. "expected": {
  91. "href": "a://example.net/",
  92. "protocol": "a:"
  93. }
  94. },
  95. {
  96. "comment": "Spec deviation: from special scheme to not is not problematic. https://github.com/whatwg/url/issues/104",
  97. "href": "http://example.net",
  98. "new_value": "b",
  99. "expected": {
  100. "href": "b://example.net/",
  101. "protocol": "b:"
  102. }
  103. },
  104. {
  105. "comment": "Cannot-be-a-base URL doesn’t have a host, but URL in a special scheme must.",
  106. "href": "mailto:me@example.net",
  107. "new_value": "http",
  108. "expected": {
  109. "href": "mailto:me@example.net",
  110. "protocol": "mailto:"
  111. }
  112. },
  113. {
  114. "comment": "Spec deviation: from non-special scheme with a host to special is not problematic. https://github.com/whatwg/url/issues/104",
  115. "href": "ssh://me@example.net",
  116. "new_value": "http",
  117. "expected": {
  118. "href": "http://me@example.net/",
  119. "protocol": "http:"
  120. }
  121. },
  122. {
  123. "comment": "Stuff after the first ':' is ignored",
  124. "href": "http://example.net",
  125. "new_value": "https:foo : bar",
  126. "expected": {
  127. "href": "https://example.net/",
  128. "protocol": "https:"
  129. }
  130. },
  131. {
  132. "comment": "Stuff after the first ':' is ignored",
  133. "href": "data:text/html,<p>Test",
  134. "new_value": "view-source+data:foo : bar",
  135. "expected": {
  136. "href": "view-source+data:text/html,<p>Test",
  137. "protocol": "view-source+data:"
  138. }
  139. }
  140. ],
  141. "username": [],
  142. "password": [],
  143. "host": [],
  144. "hostname": [],
  145. "port": [],
  146. "pathname": [],
  147. "search": [],
  148. "hash": []
  149. }