ink_editor_spec.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Copyright 2022 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. const {
  16. closePages,
  17. getSelectedEditors,
  18. loadAndWait,
  19. } = require("./test_utils.js");
  20. describe("Editor", () => {
  21. describe("Ink", () => {
  22. let pages;
  23. beforeAll(async () => {
  24. pages = await loadAndWait("aboutstacks.pdf", ".annotationEditorLayer");
  25. });
  26. afterAll(async () => {
  27. await closePages(pages);
  28. });
  29. it("must draw, undo a deletion and check that the editors are not selected", async () => {
  30. await Promise.all(
  31. pages.map(async ([browserName, page]) => {
  32. await page.click("#editorInk");
  33. const rect = await page.$eval(".annotationEditorLayer", el => {
  34. // With Chrome something is wrong when serializing a DomRect,
  35. // hence we extract the values and just return them.
  36. const { x, y } = el.getBoundingClientRect();
  37. return { x, y };
  38. });
  39. for (let i = 0; i < 3; i++) {
  40. const x = rect.x + 100 + i * 100;
  41. const y = rect.y + 100 + i * 100;
  42. await page.mouse.move(x, y);
  43. await page.mouse.down();
  44. await page.mouse.move(x + 50, y + 50);
  45. await page.mouse.up();
  46. await page.keyboard.press("Escape");
  47. }
  48. await page.keyboard.down("Control");
  49. await page.keyboard.press("a");
  50. await page.keyboard.up("Control");
  51. expect(await getSelectedEditors(page))
  52. .withContext(`In ${browserName}`)
  53. .toEqual([0, 1, 2]);
  54. await page.keyboard.press("Backspace");
  55. await page.keyboard.down("Control");
  56. await page.keyboard.press("z");
  57. await page.keyboard.up("Control");
  58. expect(await getSelectedEditors(page))
  59. .withContext(`In ${browserName}`)
  60. .toEqual([]);
  61. })
  62. );
  63. });
  64. it("must draw, undo/redo and check that the editor don't move", async () => {
  65. await Promise.all(
  66. pages.map(async ([browserName, page]) => {
  67. await page.keyboard.down("Control");
  68. await page.keyboard.press("a");
  69. await page.keyboard.up("Control");
  70. await page.keyboard.press("Backspace");
  71. const rect = await page.$eval(".annotationEditorLayer", el => {
  72. // With Chrome something is wrong when serializing a DomRect,
  73. // hence we extract the values and just return them.
  74. const { x, y } = el.getBoundingClientRect();
  75. return { x, y };
  76. });
  77. const xStart = rect.x + 300;
  78. const yStart = rect.y + 300;
  79. await page.mouse.move(xStart, yStart);
  80. await page.mouse.down();
  81. await page.mouse.move(xStart + 50, yStart + 50);
  82. await page.mouse.up();
  83. await page.keyboard.press("Escape");
  84. const rectBefore = await page.$eval(".inkEditor canvas", el => {
  85. const { x, y } = el.getBoundingClientRect();
  86. return { x, y };
  87. });
  88. for (let i = 0; i < 30; i++) {
  89. await page.keyboard.down("Control");
  90. await page.keyboard.press("z");
  91. await page.keyboard.up("Control");
  92. await page.waitForTimeout(10);
  93. await page.keyboard.down("Control");
  94. await page.keyboard.press("y");
  95. await page.keyboard.up("Control");
  96. await page.waitForTimeout(10);
  97. }
  98. const rectAfter = await page.$eval(".inkEditor canvas", el => {
  99. const { x, y } = el.getBoundingClientRect();
  100. return { x, y };
  101. });
  102. expect(Math.round(rectBefore.x))
  103. .withContext(`In ${browserName}`)
  104. .toEqual(Math.round(rectAfter.x));
  105. expect(Math.round(rectBefore.y))
  106. .withContext(`In ${browserName}`)
  107. .toEqual(Math.round(rectAfter.y));
  108. })
  109. );
  110. });
  111. });
  112. });