pdf_history_spec.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright 2017 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. import { isDestArraysEqual, isDestHashesEqual } from "../../web/pdf_history.js";
  16. describe("pdf_history", function () {
  17. describe("isDestHashesEqual", function () {
  18. it("should reject non-equal destination hashes", function () {
  19. expect(isDestHashesEqual(null, "page.157")).toEqual(false);
  20. expect(isDestHashesEqual("title.0", "page.157")).toEqual(false);
  21. expect(isDestHashesEqual("page=1&zoom=auto", "page.157")).toEqual(false);
  22. expect(isDestHashesEqual("nameddest-page.157", "page.157")).toEqual(
  23. false
  24. );
  25. expect(isDestHashesEqual("page.157", "nameddest=page.157")).toEqual(
  26. false
  27. );
  28. const destArrayString = JSON.stringify([
  29. { num: 3757, gen: 0 },
  30. { name: "XYZ" },
  31. 92.918,
  32. 748.972,
  33. null,
  34. ]);
  35. expect(isDestHashesEqual(destArrayString, "page.157")).toEqual(false);
  36. expect(isDestHashesEqual("page.157", destArrayString)).toEqual(false);
  37. });
  38. it("should accept equal destination hashes", function () {
  39. expect(isDestHashesEqual("page.157", "page.157")).toEqual(true);
  40. expect(isDestHashesEqual("nameddest=page.157", "page.157")).toEqual(true);
  41. expect(
  42. isDestHashesEqual("nameddest=page.157&zoom=100", "page.157")
  43. ).toEqual(true);
  44. });
  45. });
  46. describe("isDestArraysEqual", function () {
  47. const firstDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 0, 375, null];
  48. const secondDest = [{ num: 5, gen: 0 }, { name: "XYZ" }, 0, 375, null];
  49. const thirdDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 750, 0, null];
  50. const fourthDest = [{ num: 1, gen: 0 }, { name: "XYZ" }, 0, 375, 1.0];
  51. const fifthDest = [{ gen: 0, num: 1 }, { name: "XYZ" }, 0, 375, null];
  52. it("should reject non-equal destination arrays", function () {
  53. expect(isDestArraysEqual(firstDest, undefined)).toEqual(false);
  54. expect(isDestArraysEqual(firstDest, [1, 2, 3, 4, 5])).toEqual(false);
  55. expect(isDestArraysEqual(firstDest, secondDest)).toEqual(false);
  56. expect(isDestArraysEqual(firstDest, thirdDest)).toEqual(false);
  57. expect(isDestArraysEqual(firstDest, fourthDest)).toEqual(false);
  58. });
  59. it("should accept equal destination arrays", function () {
  60. expect(isDestArraysEqual(firstDest, firstDest)).toEqual(true);
  61. expect(isDestArraysEqual(firstDest, fifthDest)).toEqual(true);
  62. const firstDestCopy = firstDest.slice();
  63. expect(firstDest).not.toBe(firstDestCopy);
  64. expect(isDestArraysEqual(firstDest, firstDestCopy)).toEqual(true);
  65. });
  66. });
  67. });