browser_webconsole_output_05.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. // Test the webconsole output for various types of objects.
  5. "use strict";
  6. const TEST_URI = "data:text/html;charset=utf8,test for console output - 05";
  7. const {ELLIPSIS} = require("devtools/shared/l10n");
  8. // March, 1960: The first implementation of Lisp. From Wikipedia:
  9. //
  10. // > Lisp was first implemented by Steve Russell on an IBM 704 computer. Russell
  11. // > had read McCarthy's paper, and realized (to McCarthy's surprise) that the
  12. // > Lisp eval function could be implemented in machine code. The result was a
  13. // > working Lisp interpreter which could be used to run Lisp programs, or more
  14. // > properly, 'evaluate Lisp expressions.'
  15. var testDate = -310435200000;
  16. var inputTests = [
  17. // 0
  18. {
  19. input: "/foo?b*\\s\"ar/igym",
  20. output: "/foo?b*\\s\"ar/gimy",
  21. printOutput: "/foo?b*\\s\"ar/gimy",
  22. inspectable: true,
  23. },
  24. // 1
  25. {
  26. input: "null",
  27. output: "null",
  28. },
  29. // 2
  30. {
  31. input: "undefined",
  32. output: "undefined",
  33. },
  34. // 3
  35. {
  36. input: "true",
  37. output: "true",
  38. },
  39. // 4
  40. {
  41. input: "new Boolean(false)",
  42. output: "Boolean { false }",
  43. printOutput: "false",
  44. inspectable: true,
  45. variablesViewLabel: "Boolean { false }"
  46. },
  47. // 5
  48. {
  49. input: "new Date(" + testDate + ")",
  50. output: "Date " + (new Date(testDate)).toISOString(),
  51. printOutput: (new Date(testDate)).toString(),
  52. inspectable: true,
  53. },
  54. // 6
  55. {
  56. input: "new Date('test')",
  57. output: "Invalid Date",
  58. printOutput: "Invalid Date",
  59. inspectable: true,
  60. variablesViewLabel: "Invalid Date",
  61. },
  62. // 7
  63. {
  64. input: "Date.prototype",
  65. output: /Object \{.*\}/,
  66. printOutput: "Invalid Date",
  67. inspectable: true,
  68. variablesViewLabel: "Object",
  69. },
  70. // 8
  71. {
  72. input: "new Number(43)",
  73. output: "Number { 43 }",
  74. printOutput: "43",
  75. inspectable: true,
  76. variablesViewLabel: "Number { 43 }"
  77. },
  78. // 9
  79. {
  80. input: "new String('hello')",
  81. output: /String { "hello", 6 more.* }/,
  82. printOutput: "hello",
  83. inspectable: true,
  84. variablesViewLabel: "String"
  85. },
  86. // 10
  87. {
  88. input: "(function () { var s = new String('hello'); s.whatever = 23; " +
  89. " return s;})()",
  90. output: /String { "hello", whatever: 23, 6 more.* }/,
  91. printOutput: "hello",
  92. inspectable: true,
  93. variablesViewLabel: "String"
  94. },
  95. // 11
  96. {
  97. input: "(function () { var s = new String('hello'); s[8] = 'x'; " +
  98. " return s;})()",
  99. output: /String { "hello", 8: "x", 6 more.* }/,
  100. printOutput: "hello",
  101. inspectable: true,
  102. variablesViewLabel: "String"
  103. },
  104. // 12
  105. {
  106. // XXX: Can't test fulfilled and rejected promises, because promises get
  107. // settled on the next tick of the event loop.
  108. input: "new Promise(function () {})",
  109. output: 'Promise { <state>: "pending" }',
  110. printOutput: "[object Promise]",
  111. inspectable: true,
  112. variablesViewLabel: "Promise"
  113. },
  114. // 13
  115. {
  116. input: "(function () { var p = new Promise(function () {}); " +
  117. "p.foo = 1; return p; }())",
  118. output: 'Promise { <state>: "pending", foo: 1 }',
  119. printOutput: "[object Promise]",
  120. inspectable: true,
  121. variablesViewLabel: "Promise"
  122. },
  123. // 14
  124. {
  125. input: "new Object({1: 'this\\nis\\nsupposed\\nto\\nbe\\na\\nvery" +
  126. "\\nlong\\nstring\\n,shown\\non\\na\\nsingle\\nline', " +
  127. "2: 'a shorter string', 3: 100})",
  128. output: '[ <1 empty slot>, "this is supposed to be a very long ' + ELLIPSIS +
  129. '", "a shorter string", 100 ]',
  130. printOutput: "[object Object]",
  131. inspectable: true,
  132. variablesViewLabel: "Object[4]"
  133. },
  134. // 15
  135. {
  136. input: "new Proxy({a:1},[1,2,3])",
  137. output: 'Proxy { <target>: Object, <handler>: Array[3] }',
  138. printOutput: "[object Object]",
  139. inspectable: true,
  140. variablesViewLabel: "Proxy"
  141. }
  142. ];
  143. function test() {
  144. requestLongerTimeout(2);
  145. Task.spawn(function* () {
  146. let {tab} = yield loadTab(TEST_URI);
  147. let hud = yield openConsole(tab);
  148. return checkOutputForInputs(hud, inputTests);
  149. }).then(finishUp);
  150. }
  151. function finishUp() {
  152. inputTests = testDate = null;
  153. finishTest();
  154. }