browser_webconsole_output_02.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 = "http://example.com/browser/devtools/client/webconsole/" +
  7. "test/test-console-output-02.html";
  8. var inputTests = [
  9. // 0 - native named function
  10. {
  11. input: "document.getElementById",
  12. output: "function getElementById()",
  13. printOutput: "function getElementById() {\n [native code]\n}",
  14. inspectable: true,
  15. variablesViewLabel: "getElementById()",
  16. },
  17. // 1 - anonymous function
  18. {
  19. input: "(function() { return 42; })",
  20. output: "function ()",
  21. printOutput: "function() { return 42; }",
  22. suppressClick: true
  23. },
  24. // 2 - named function
  25. {
  26. input: "window.testfn1",
  27. output: "function testfn1()",
  28. printOutput: "function testfn1() { return 42; }",
  29. suppressClick: true
  30. },
  31. // 3 - anonymous function, but gets name.
  32. {
  33. input: "testobj1.testfn2",
  34. output: "function testfn2()",
  35. printOutput: "function() { return 42; }",
  36. suppressClick: true
  37. },
  38. // 4 - named function with custom display name
  39. {
  40. input: "window.testfn3",
  41. output: "function testfn3DisplayName()",
  42. printOutput: "function testfn3() { return 42; }",
  43. suppressClick: true
  44. },
  45. // 5 - basic array
  46. {
  47. input: "window.array1",
  48. output: 'Array [ 1, 2, 3, "a", "b", "c", "4", "5" ]',
  49. printOutput: "1,2,3,a,b,c,4,5",
  50. inspectable: true,
  51. variablesViewLabel: "Array[8]",
  52. },
  53. // 6 - array with objects
  54. {
  55. input: "window.array2",
  56. output: 'Array [ "a", HTMLDocument \u2192 test-console-output-02.html, ' +
  57. "<body>, DOMStringMap[0], DOMTokenList[0] ]",
  58. printOutput: '"a,[object HTMLDocument],[object HTMLBodyElement],' +
  59. '[object DOMStringMap],"',
  60. inspectable: true,
  61. variablesViewLabel: "Array[5]",
  62. },
  63. // 7 - array with more than 10 elements
  64. {
  65. input: "window.array3",
  66. output: "Array [ 1, Window \u2192 test-console-output-02.html, null, " +
  67. '"a", "b", undefined, false, "", -Infinity, ' +
  68. "testfn3DisplayName(), 3 more\u2026 ]",
  69. printOutput: '"1,[object Window],,a,b,,false,,-Infinity,' +
  70. 'function testfn3() { return 42; },[object Object],foo,bar"',
  71. inspectable: true,
  72. variablesViewLabel: "Array[13]",
  73. },
  74. // 8 - array with holes and a cyclic reference
  75. {
  76. input: "window.array4",
  77. output: 'Array [ <5 empty slots>, "test", Array[7] ]',
  78. printOutput: '",,,,,test,"',
  79. inspectable: true,
  80. variablesViewLabel: "Array[7]",
  81. },
  82. // 9
  83. {
  84. input: "window.typedarray1",
  85. output: "Int32Array [ 1, 287, 8651, 40983, 8754 ]",
  86. printOutput: "1,287,8651,40983,8754",
  87. inspectable: true,
  88. variablesViewLabel: "Int32Array[5]",
  89. },
  90. // 10 - Set with cyclic reference
  91. {
  92. input: "window.set1",
  93. output: 'Set [ 1, 2, null, Array[13], "a", "b", undefined, <head>, ' +
  94. "Set[9] ]",
  95. printOutput: "[object Set]",
  96. inspectable: true,
  97. variablesViewLabel: "Set[9]",
  98. },
  99. // 11 - Object with cyclic reference and a getter
  100. {
  101. input: "window.testobj2",
  102. output: 'Object { a: "b", c: "d", e: 1, f: "2", foo: Object, ' +
  103. "bar: Object, getterTest: Getter }",
  104. printOutput: "[object Object]",
  105. inspectable: true,
  106. variablesViewLabel: "Object",
  107. },
  108. // 12 - Object with more than 10 properties
  109. {
  110. input: "window.testobj3",
  111. output: 'Object { a: "b", c: "d", e: 1, f: "2", g: true, h: null, ' +
  112. 'i: undefined, j: "", k: StyleSheetList[0], l: NodeList[5], ' +
  113. "2 more\u2026 }",
  114. printOutput: "[object Object]",
  115. inspectable: true,
  116. variablesViewLabel: "Object",
  117. },
  118. // 13 - Object with a non-enumerable property that we do not show
  119. {
  120. input: "window.testobj4",
  121. output: 'Object { a: "b", c: "d", 1 more\u2026 }',
  122. printOutput: "[object Object]",
  123. inspectable: true,
  124. variablesViewLabel: "Object",
  125. },
  126. // 14 - Map with cyclic references
  127. {
  128. input: "window.map1",
  129. output: 'Map { a: "b", HTMLCollection[2]: Object, Map[3]: Set[9] }',
  130. printOutput: "[object Map]",
  131. inspectable: true,
  132. variablesViewLabel: "Map[3]",
  133. },
  134. // 15 - WeakSet
  135. {
  136. input: "window.weakset",
  137. // Need a regexp because the order may vary.
  138. output: new RegExp("WeakSet \\[ (String, <head>|<head>, String) \\]"),
  139. printOutput: "[object WeakSet]",
  140. inspectable: true,
  141. variablesViewLabel: "WeakSet[2]",
  142. },
  143. // 16 - WeakMap
  144. {
  145. input: "window.weakmap",
  146. // Need a regexp because the order may vary.
  147. output: new RegExp("WeakMap { (String: 23, HTMLCollection\\[2\\]: Object|HTMLCollection\\[2\\]: Object, String: 23) }"),
  148. printOutput: "[object WeakMap]",
  149. inspectable: true,
  150. variablesViewLabel: "WeakMap[2]",
  151. },
  152. ];
  153. function test() {
  154. requestLongerTimeout(2);
  155. Task.spawn(function* () {
  156. const {tab} = yield loadTab(TEST_URI);
  157. const hud = yield openConsole(tab);
  158. yield checkOutputForInputs(hud, inputTests);
  159. inputTests = null;
  160. }).then(finishTest);
  161. }