1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 * Test fixture for print preview utils.
8 * @extends {testing.Test}
10 function PrintPreviewUtilsUnitTest () {
11 testing.Test.call(this);
14 PrintPreviewUtilsUnitTest.prototype = {
15 __proto__: testing.Test.prototype,
19 'print_preview_utils.js',
23 TEST_F('PrintPreviewUtilsUnitTest', 'IsInteger', function() {
24 assertFalse(isInteger(" abc "));
25 assertFalse(isInteger("-7"));
26 assertFalse(isInteger("7.0"));
27 assertFalse(isInteger("a7a"));
29 assertTrue(isInteger("0"));
30 assertTrue(isInteger(" 100 "));
31 assertTrue(isInteger("0055 "));
34 TEST_F('PrintPreviewUtilsUnitTest', 'IsPositiveInteger', function() {
35 assertTrue(isPositiveInteger("100"));
36 assertTrue(isPositiveInteger("0055"));
38 assertFalse(isPositiveInteger("0"));
39 assertFalse(isPositiveInteger("-100"));
40 assertFalse(isPositiveInteger("sdfs"));
43 TEST_F('PrintPreviewUtilsUnitTest', 'AreArraysEqual', function() {
44 assertTrue(areArraysEqual([2,4,6,8,10], [2,4,6,8,10]));
45 assertTrue(areArraysEqual([], []));
47 assertFalse(areArraysEqual([2,4,6,8,10,12], [2,4,6,8,10]));
48 assertFalse(areArraysEqual([], [2,4,6,8,10]));
51 TEST_F('PrintPreviewUtilsUnitTest', 'RemoveDuplicates', function() {
52 var array1 = [1,2,2,3,6,6,6,7,9,10];
53 assertTrue(areArraysEqual(removeDuplicates(array1), [1,2,3,6,7,9,10]));
56 TEST_F('PrintPreviewUtilsUnitTest', 'PageRanges', function() {
57 function assertRangesEqual(simpleRange1, range2) {
59 for (var i = 0; i < simpleRange1.length; i++) {
62 if (Array.isArray(simpleRange1[i])) {
63 from = simpleRange1[i][0];
64 to = simpleRange1[i][1];
66 from = simpleRange1[i];
69 range1.push({'from': from, 'to': to});
71 assertTrue(areRangesEqual(range1, range2));
73 assertRangesEqual([1, 2, 3, 1, 56],
74 pageRangeTextToPageRanges("1,2,3,1,56", 100));
75 assertRangesEqual([[1, 3],[6, 9], [6, 10]],
76 pageRangeTextToPageRanges("1-3, 6-9,6-10 ", 100));
77 assertRangesEqual([[10, 100]],
78 pageRangeTextToPageRanges("10-", 100));
79 assertRangesEqual([[10, 100000]],
80 pageRangeTextToPageRanges("10-100000", 100));
81 assertRangesEqual([[1, 100]],
82 pageRangeTextToPageRanges("-", 100));
83 assertRangesEqual([1, 2],
84 pageRangeTextToPageRanges("1,2", undefined));
85 assertRangesEqual([[1, 1000000000]],
86 pageRangeTextToPageRanges("-", null));
87 assertRangesEqual([[1, 1000000000]],
88 pageRangeTextToPageRanges("-", 0));
91 TEST_F('PrintPreviewUtilsUnitTest', 'InvalidPageRanges', function() {
92 assertTrue(pageRangeTextToPageRanges("1,100000", 100) == null);
93 assertTrue(pageRangeTextToPageRanges("1,2,0,56", 100) == null);
94 assertTrue(pageRangeTextToPageRanges("-1,1,2,,56", 100) == null);
95 assertTrue(pageRangeTextToPageRanges("1,2,56-40", 100) == null);
96 assertTrue(pageRangeTextToPageRanges("101-110", 100) == null);
99 TEST_F('PrintPreviewUtilsUnitTest', 'PageRangeTextToPageList', function() {
100 assertTrue(areArraysEqual([1],
101 pageRangeTextToPageList("1", 10)));
102 assertTrue(areArraysEqual([1,2,3,4],
103 pageRangeTextToPageList("1-4", 10)));
104 assertTrue(areArraysEqual([1,2,3,4,2,3,4],
105 pageRangeTextToPageList("1-4, 2-4", 10)));
106 assertTrue(areArraysEqual([1,2,5,7,8,9,10,2,2,3],
107 pageRangeTextToPageList("1-2, 5, 7-10, 2, 2, 3",
109 assertTrue(areArraysEqual([5,6,7,8,9,10],
110 pageRangeTextToPageList("5-", 10)));
111 assertTrue(areArraysEqual([],
112 pageRangeTextToPageList("1-4", undefined)));
113 assertTrue(areArraysEqual([1,2,3,4,5,6,7,8,9,10],
114 pageRangeTextToPageList("1-abcd", 10)));
117 TEST_F('PrintPreviewUtilsUnitTest', 'PageListToPageSet', function() {
118 assertTrue(areArraysEqual([1,2,3,4], pageListToPageSet([4,3,2,1,1,1])));
119 assertTrue(areArraysEqual([1,2,3,4], pageListToPageSet([1,2,2,3,4,1,1,1])));
120 assertTrue(areArraysEqual([], pageListToPageSet([])));