browser_webconsole_output_06.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. "use strict";
  5. // Test the webconsole output for various arrays.
  6. const TEST_URI = "data:text/html;charset=utf8,test for console output - 06";
  7. const {ELLIPSIS} = require("devtools/shared/l10n");
  8. const testStrIn = "SHOW\\nALL\\nOF\\nTHIS\\nON\\nA\\nSINGLE" +
  9. "\\nLINE ONLY. ESCAPE ALL NEWLINE";
  10. const testStrOut = "SHOW ALL OF THIS ON A SINGLE LINE O" + ELLIPSIS;
  11. var inputTests = [
  12. // 1 - array with empty slots only
  13. {
  14. input: "Array(5)",
  15. output: "Array [ <5 empty slots> ]",
  16. printOutput: ",,,,",
  17. inspectable: true,
  18. variablesViewLabel: "Array[5]",
  19. },
  20. // 2 - array with one empty slot at the beginning
  21. {
  22. input: "[,1,2,3]",
  23. output: "Array [ <1 empty slot>, 1, 2, 3 ]",
  24. printOutput: ",1,2,3",
  25. inspectable: true,
  26. variablesViewLabel: "Array[4]",
  27. },
  28. // 3 - array with multiple consecutive empty slots at the beginning
  29. {
  30. input: "[,,,3,4,5]",
  31. output: "Array [ <3 empty slots>, 3, 4, 5 ]",
  32. printOutput: ",,,3,4,5",
  33. inspectable: true,
  34. variablesViewLabel: "Array[6]",
  35. },
  36. // 4 - array with one empty slot at the middle
  37. {
  38. input: "[0,1,,3,4,5]",
  39. output: "Array [ 0, 1, <1 empty slot>, 3, 4, 5 ]",
  40. printOutput: "0,1,,3,4,5",
  41. inspectable: true,
  42. variablesViewLabel: "Array[6]",
  43. },
  44. // 5 - array with multiple successive empty slots at the middle
  45. {
  46. input: "[0,1,,,,5]",
  47. output: "Array [ 0, 1, <3 empty slots>, 5 ]",
  48. printOutput: "0,1,,,,5",
  49. inspectable: true,
  50. variablesViewLabel: "Array[6]",
  51. },
  52. // 6 - array with multiple non successive single empty slots
  53. {
  54. input: "[0,,2,,4,5]",
  55. output: "Array [ 0, <1 empty slot>, 2, <1 empty slot>, 4, 5 ]",
  56. printOutput: "0,,2,,4,5",
  57. inspectable: true,
  58. variablesViewLabel: "Array[6]",
  59. },
  60. // 7 - array with multiple multi-slot holes
  61. {
  62. input: "[0,,,3,,,,7,8]",
  63. output: "Array [ 0, <2 empty slots>, 3, <3 empty slots>, 7, 8 ]",
  64. printOutput: "0,,,3,,,,7,8",
  65. inspectable: true,
  66. variablesViewLabel: "Array[9]",
  67. },
  68. // 8 - array with a single slot hole at the end
  69. {
  70. input: "[0,1,2,3,4,,]",
  71. output: "Array [ 0, 1, 2, 3, 4, <1 empty slot> ]",
  72. printOutput: "0,1,2,3,4,",
  73. inspectable: true,
  74. variablesViewLabel: "Array[6]",
  75. },
  76. // 9 - array with multiple consecutive empty slots at the end
  77. {
  78. input: "[0,1,2,,,,]",
  79. output: "Array [ 0, 1, 2, <3 empty slots> ]",
  80. printOutput: "0,1,2,,,",
  81. inspectable: true,
  82. variablesViewLabel: "Array[6]",
  83. },
  84. // 10 - array with members explicitly set to null
  85. {
  86. input: "[0,null,null,3,4,5]",
  87. output: "Array [ 0, null, null, 3, 4, 5 ]",
  88. printOutput: "0,,,3,4,5",
  89. inspectable: true,
  90. variablesViewLabel: "Array[6]"
  91. },
  92. // 11 - array with members explicitly set to undefined
  93. {
  94. input: "[0,undefined,undefined,3,4,5]",
  95. output: "Array [ 0, undefined, undefined, 3, 4, 5 ]",
  96. printOutput: "0,,,3,4,5",
  97. inspectable: true,
  98. variablesViewLabel: "Array[6]"
  99. },
  100. // 12 - array with long strings as elements
  101. {
  102. input: '["' + testStrIn + '", "' + testStrIn + '", "' + testStrIn + '"]',
  103. output: 'Array [ "' + testStrOut + '", "' + testStrOut + '", "' +
  104. testStrOut + '" ]',
  105. inspectable: true,
  106. printOutput: "SHOW\nALL\nOF\nTHIS\nON\nA\nSINGLE\nLINE ONLY. ESCAPE " +
  107. "ALL NEWLINE,SHOW\nALL\nOF\nTHIS\nON\nA\nSINGLE\nLINE ONLY. " +
  108. "ESCAPE ALL NEWLINE,SHOW\nALL\nOF\nTHIS\nON\nA\nSINGLE\n" +
  109. "LINE ONLY. ESCAPE ALL NEWLINE",
  110. variablesViewLabel: "Array[3]"
  111. },
  112. // 13
  113. {
  114. input: '({0: "a", 1: "b"})',
  115. output: 'Object [ "a", "b" ]',
  116. printOutput: "[object Object]",
  117. inspectable: true,
  118. variablesViewLabel: "Object[2]",
  119. },
  120. // 14
  121. {
  122. input: '({0: "a", 42: "b"})',
  123. output: '[ "a", <9 empty slots>, 33 more\u2026 ]',
  124. printOutput: "[object Object]",
  125. inspectable: true,
  126. variablesViewLabel: "Object[43]",
  127. },
  128. // 15
  129. {
  130. input: '({0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", 6: "g", ' +
  131. '7: "h", 8: "i", 9: "j", 10: "k", 11: "l"})',
  132. output: 'Object [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", ' +
  133. "2 more\u2026 ]",
  134. printOutput: "[object Object]",
  135. inspectable: true,
  136. variablesViewLabel: "Object[12]",
  137. },
  138. // 16
  139. {
  140. input: '({0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", 6: "g", ' +
  141. '7: "h", 8: "i", 9: "j", 10: "k", 11: "l", m: "n"})',
  142. output: 'Object { 0: "a", 1: "b", 2: "c", 3: "d", 4: "e", 5: "f", ' +
  143. '6: "g", 7: "h", 8: "i", 9: "j", 3 more\u2026 }',
  144. printOutput: "[object Object]",
  145. inspectable: true,
  146. variablesViewLabel: "Object",
  147. },
  148. // 17
  149. {
  150. input: '({" ": "a"})',
  151. output: 'Object { : "a" }',
  152. printOutput: "[object Object]",
  153. inspectable: true,
  154. variablesViewLabel: "Object",
  155. },
  156. // 18
  157. {
  158. input: '({})',
  159. output: 'Object { }',
  160. printOutput: "[object Object]",
  161. inspectable: true,
  162. variablesViewLabel: "Object",
  163. },
  164. // 19
  165. {
  166. input: '({length: 0})',
  167. output: 'Object [ ]',
  168. printOutput: "[object Object]",
  169. inspectable: true,
  170. variablesViewLabel: "Object[0]",
  171. },
  172. // 20
  173. {
  174. input: '({length: 1})',
  175. output: '[ <1 empty slot> ]',
  176. printOutput: "[object Object]",
  177. inspectable: true,
  178. variablesViewLabel: "Object[1]",
  179. },
  180. // 21
  181. {
  182. input: '({0: "a", 1: "b", length: 1})',
  183. output: 'Object { 0: "a", 1: "b", length: 1 }',
  184. printOutput: "[object Object]",
  185. inspectable: true,
  186. variablesViewLabel: "Object",
  187. },
  188. // 22
  189. {
  190. input: '({0: "a", 1: "b", length: 2})',
  191. output: 'Object [ "a", "b" ]',
  192. printOutput: "[object Object]",
  193. inspectable: true,
  194. variablesViewLabel: "Object[2]",
  195. },
  196. // 23
  197. {
  198. input: '({0: "a", 1: "b", length: 3})',
  199. output: '[ "a", "b", <1 empty slot> ]',
  200. printOutput: "[object Object]",
  201. inspectable: true,
  202. variablesViewLabel: "Object[3]",
  203. },
  204. // 24
  205. {
  206. input: '({0: "a", 2: "b", length: 2})',
  207. output: 'Object { 0: "a", 2: "b", length: 2 }',
  208. printOutput: "[object Object]",
  209. inspectable: true,
  210. variablesViewLabel: "Object",
  211. },
  212. // 25
  213. {
  214. input: '({0: "a", 2: "b", length: 3})',
  215. output: '[ "a", <1 empty slot>, "b" ]',
  216. printOutput: "[object Object]",
  217. inspectable: true,
  218. variablesViewLabel: "Object[3]",
  219. },
  220. // 26
  221. {
  222. input: '({0: "a", b: "b", length: 1})',
  223. output: 'Object { 0: "a", b: "b", length: 1 }',
  224. printOutput: "[object Object]",
  225. inspectable: true,
  226. variablesViewLabel: "Object",
  227. },
  228. // 27
  229. {
  230. input: '({0: "a", b: "b", length: 2})',
  231. output: 'Object { 0: "a", b: "b", length: 2 }',
  232. printOutput: "[object Object]",
  233. inspectable: true,
  234. variablesViewLabel: "Object",
  235. },
  236. // 28
  237. {
  238. input: '({42: "a"})',
  239. output: 'Object { 42: "a" }',
  240. printOutput: "[object Object]",
  241. inspectable: true,
  242. variablesViewLabel: "Object",
  243. },
  244. ];
  245. function test() {
  246. requestLongerTimeout(2);
  247. Task.spawn(function* () {
  248. let {tab} = yield loadTab(TEST_URI);
  249. let hud = yield openConsole(tab);
  250. return checkOutputForInputs(hud, inputTests);
  251. }).then(finishUp);
  252. }
  253. function finishUp() {
  254. inputTests = null;
  255. finishTest();
  256. }