browser_scratchpad_inspect_primitives.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. // Test that inspecting primitive values uses the object inspector, not an
  4. // inline comment.
  5. var {Task} = require("devtools/shared/task");
  6. function test() {
  7. const options = {
  8. tabContent: "test inspecting primitive values"
  9. };
  10. openTabAndScratchpad(options)
  11. .then(Task.async(runTests))
  12. .then(finish, console.error);
  13. }
  14. function* runTests([win, sp]) {
  15. // Inspect a number.
  16. yield checkResults(sp, 7);
  17. // Inspect a string.
  18. yield checkResults(sp, "foobar", true);
  19. // Inspect a boolean.
  20. yield checkResults(sp, true);
  21. }
  22. // Helper function that does the actual testing.
  23. var checkResults = Task.async(function* (sp, value, isString = false) {
  24. let sourceValue = value;
  25. if (isString) {
  26. sourceValue = '"' + value + '"';
  27. }
  28. let source = "var foobar = " + sourceValue + "; foobar";
  29. sp.setText(source);
  30. yield sp.inspect();
  31. let sidebar = sp.sidebar;
  32. ok(sidebar.visible, "sidebar is open");
  33. let found = false;
  34. outer: for (let scope of sidebar.variablesView) {
  35. for (let [, obj] of scope) {
  36. for (let [, prop] of obj) {
  37. if (prop.name == "value" && prop.value == value) {
  38. found = true;
  39. break outer;
  40. }
  41. }
  42. }
  43. }
  44. ok(found, "found the value of " + value);
  45. let tabbox = sidebar._sidebar._tabbox;
  46. ok(!tabbox.hasAttribute("hidden"), "Scratchpad sidebar visible");
  47. sidebar.hide();
  48. ok(tabbox.hasAttribute("hidden"), "Scratchpad sidebar hidden");
  49. });