test_breakpoint-actor-map.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/ */
  4. "use strict";
  5. // Test the functionality of the BreakpointActorMap object.
  6. const { BreakpointActorMap } = require("devtools/server/actors/script");
  7. function run_test() {
  8. test_get_actor();
  9. test_set_actor();
  10. test_delete_actor();
  11. test_find_actors();
  12. test_duplicate_actors();
  13. }
  14. function test_get_actor() {
  15. let bpStore = new BreakpointActorMap();
  16. let location = {
  17. originalSourceActor: { actor: "actor1" },
  18. originalLine: 3
  19. };
  20. let columnLocation = {
  21. originalSourceActor: { actor: "actor2" },
  22. originalLine: 5,
  23. originalColumn: 15
  24. };
  25. // Shouldn't have breakpoint
  26. do_check_eq(null, bpStore.getActor(location),
  27. "Breakpoint not added and shouldn't exist.");
  28. bpStore.setActor(location, {});
  29. do_check_true(!!bpStore.getActor(location),
  30. "Breakpoint added but not found in Breakpoint Store.");
  31. bpStore.deleteActor(location);
  32. do_check_eq(null, bpStore.getActor(location),
  33. "Breakpoint removed but still exists.");
  34. // Same checks for breakpoint with a column
  35. do_check_eq(null, bpStore.getActor(columnLocation),
  36. "Breakpoint with column not added and shouldn't exist.");
  37. bpStore.setActor(columnLocation, {});
  38. do_check_true(!!bpStore.getActor(columnLocation),
  39. "Breakpoint with column added but not found in Breakpoint Store.");
  40. bpStore.deleteActor(columnLocation);
  41. do_check_eq(null, bpStore.getActor(columnLocation),
  42. "Breakpoint with column removed but still exists in Breakpoint Store.");
  43. }
  44. function test_set_actor() {
  45. // Breakpoint with column
  46. let bpStore = new BreakpointActorMap();
  47. let location = {
  48. originalSourceActor: { actor: "actor1" },
  49. originalLine: 10,
  50. originalColumn: 9
  51. };
  52. bpStore.setActor(location, {});
  53. do_check_true(!!bpStore.getActor(location),
  54. "We should have the column breakpoint we just added");
  55. // Breakpoint without column (whole line breakpoint)
  56. location = {
  57. originalSourceActor: { actor: "actor2" },
  58. originalLine: 103
  59. };
  60. bpStore.setActor(location, {});
  61. do_check_true(!!bpStore.getActor(location),
  62. "We should have the whole line breakpoint we just added");
  63. }
  64. function test_delete_actor() {
  65. // Breakpoint with column
  66. let bpStore = new BreakpointActorMap();
  67. let location = {
  68. originalSourceActor: { actor: "actor1" },
  69. originalLine: 10,
  70. originalColumn: 9
  71. };
  72. bpStore.setActor(location, {});
  73. bpStore.deleteActor(location);
  74. do_check_eq(bpStore.getActor(location), null,
  75. "We should not have the column breakpoint anymore");
  76. // Breakpoint without column (whole line breakpoint)
  77. location = {
  78. originalSourceActor: { actor: "actor2" },
  79. originalLine: 103
  80. };
  81. bpStore.setActor(location, {});
  82. bpStore.deleteActor(location);
  83. do_check_eq(bpStore.getActor(location), null,
  84. "We should not have the whole line breakpoint anymore");
  85. }
  86. function test_find_actors() {
  87. let bps = [
  88. { originalSourceActor: { actor: "actor1" }, originalLine: 10 },
  89. { originalSourceActor: { actor: "actor1" }, originalLine: 10, originalColumn: 3 },
  90. { originalSourceActor: { actor: "actor1" }, originalLine: 10, originalColumn: 10 },
  91. { originalSourceActor: { actor: "actor1" }, originalLine: 23, originalColumn: 89 },
  92. { originalSourceActor: { actor: "actor2" }, originalLine: 10, originalColumn: 1 },
  93. { originalSourceActor: { actor: "actor2" }, originalLine: 20, originalColumn: 5 },
  94. { originalSourceActor: { actor: "actor2" }, originalLine: 30, originalColumn: 34 },
  95. { originalSourceActor: { actor: "actor2" }, originalLine: 40, originalColumn: 56 }
  96. ];
  97. let bpStore = new BreakpointActorMap();
  98. for (let bp of bps) {
  99. bpStore.setActor(bp, bp);
  100. }
  101. // All breakpoints
  102. let bpSet = new Set(bps);
  103. for (let bp of bpStore.findActors()) {
  104. bpSet.delete(bp);
  105. }
  106. do_check_eq(bpSet.size, 0,
  107. "Should be able to iterate over all breakpoints");
  108. // Breakpoints by URL
  109. bpSet = new Set(bps.filter(bp => { return bp.originalSourceActor.actorID === "actor1"; }));
  110. for (let bp of bpStore.findActors({ originalSourceActor: { actorID: "actor1" } })) {
  111. bpSet.delete(bp);
  112. }
  113. do_check_eq(bpSet.size, 0,
  114. "Should be able to filter the iteration by url");
  115. // Breakpoints by URL and line
  116. bpSet = new Set(bps.filter(bp => { return bp.originalSourceActor.actorID === "actor1" && bp.originalLine === 10; }));
  117. let first = true;
  118. for (let bp of bpStore.findActors({ originalSourceActor: { actorID: "actor1" }, originalLine: 10 })) {
  119. if (first) {
  120. do_check_eq(bp.originalColumn, undefined,
  121. "Should always get the whole line breakpoint first");
  122. first = false;
  123. } else {
  124. do_check_neq(bp.originalColumn, undefined,
  125. "Should not get the whole line breakpoint any time other than first.");
  126. }
  127. bpSet.delete(bp);
  128. }
  129. do_check_eq(bpSet.size, 0,
  130. "Should be able to filter the iteration by url and line");
  131. }
  132. function test_duplicate_actors() {
  133. let bpStore = new BreakpointActorMap();
  134. // Breakpoint with column
  135. let location = {
  136. originalSourceActor: { actorID: "foo-actor" },
  137. originalLine: 10,
  138. originalColumn: 9
  139. };
  140. bpStore.setActor(location, {});
  141. bpStore.setActor(location, {});
  142. do_check_eq(bpStore.size, 1, "We should have only 1 column breakpoint");
  143. bpStore.deleteActor(location);
  144. // Breakpoint without column (whole line breakpoint)
  145. location = {
  146. originalSourceActor: { actorID: "foo-actor" },
  147. originalLine: 15
  148. };
  149. bpStore.setActor(location, {});
  150. bpStore.setActor(location, {});
  151. do_check_eq(bpStore.size, 1, "We should have only 1 whole line breakpoint");
  152. bpStore.deleteActor(location);
  153. }