Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / print_preview_utils_unittest.gtestjs
blobde50bcbc6f2ee73dc43575bae8ffc3b5295d50dc
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.
5 /**
6  * Test fixture for print preview utils.
7  * @constructor
8  * @extends {testing.Test}
9  */
10 function PrintPreviewUtilsUnitTest () {
11   testing.Test.call(this);
14 PrintPreviewUtilsUnitTest.prototype = {
15   __proto__: testing.Test.prototype,
17   /** @override */
18   extraLibraries: [
19     'print_preview_utils.js',
20   ]
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 "));
32 });
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"));
41 });
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]));
49 });
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]));
54 });
56 TEST_F('PrintPreviewUtilsUnitTest', 'PageRanges', function() {
57   function assertRangesEqual(simpleRange1, range2) {
58     var range1 = []
59     for (var i = 0; i < simpleRange1.length; i++) {
60       var from;
61       var to;
62       if (Array.isArray(simpleRange1[i])) {
63         from = simpleRange1[i][0];
64         to = simpleRange1[i][1];
65       } else {
66         from = simpleRange1[i];
67         to = simpleRange1[i];
68       }
69       range1.push({'from': from, 'to': to});
70     }
71     assertTrue(areRangesEqual(range1, range2));
72   };
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));
89 });
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);
97 });
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",
108                                                     10)));
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([])));