summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/print_preview/print_preview_utils_unittest.gtestjs
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/resources/print_preview/print_preview_utils_unittest.gtestjs')
-rw-r--r--chrome/browser/resources/print_preview/print_preview_utils_unittest.gtestjs113
1 files changed, 113 insertions, 0 deletions
diff --git a/chrome/browser/resources/print_preview/print_preview_utils_unittest.gtestjs b/chrome/browser/resources/print_preview/print_preview_utils_unittest.gtestjs
new file mode 100644
index 0000000..620fcfb
--- /dev/null
+++ b/chrome/browser/resources/print_preview/print_preview_utils_unittest.gtestjs
@@ -0,0 +1,113 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Test fixture for print preview utils.
+ * @constructor
+ * @extends {testing.Test}
+ */
+function PrintPreviewUtilsUnitTest () {}
+
+PrintPreviewUtilsUnitTest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /** @inheritDoc */
+ extraLibraries: [
+ 'print_preview_utils.js',
+ ],
+};
+
+TEST_F('PrintPreviewUtilsUnitTest', 'IsInteger', function() {
+ assertFalse(isInteger(" abc "));
+ assertFalse(isInteger("-7"));
+ assertFalse(isInteger("7.0"));
+ assertFalse(isInteger("a7a"));
+
+ assertTrue(isInteger("0"));
+ assertTrue(isInteger(" 100 "));
+ assertTrue(isInteger("0055 "));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'IsPositiveInteger', function() {
+ assertTrue(isPositiveInteger("100"));
+ assertTrue(isPositiveInteger("0055"));
+
+ assertFalse(isPositiveInteger("0"));
+ assertFalse(isPositiveInteger("-100"));
+ assertFalse(isPositiveInteger("sdfs"));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'AreArraysEqual', function() {
+ assertTrue(areArraysEqual([2,4,6,8,10], [2,4,6,8,10]));
+ assertTrue(areArraysEqual([], []));
+
+ assertFalse(areArraysEqual([2,4,6,8,10,12], [2,4,6,8,10]));
+ assertFalse(areArraysEqual([], [2,4,6,8,10]));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'RemoveDuplicates', function() {
+ var array1 = [1,2,2,3,6,6,6,7,9,10];
+ assertTrue(areArraysEqual(removeDuplicates(array1), [1,2,3,6,7,9,10]));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'IsPageRangeTextValid1', function() {
+ var totalPageCount;
+ assertTrue(isPageRangeTextValid("1,2, 3,56,1000000", totalPageCount));
+ assertTrue(isPageRangeTextValid(", ,1,2,3,,1,, 56 ,", totalPageCount));
+ assertTrue(isPageRangeTextValid(",1-3,,6-9,6-10,", totalPageCount));
+ assertTrue(isPageRangeTextValid("10-", totalPageCount));
+ assertTrue(isPageRangeTextValid("10-10", totalPageCount));
+ assertTrue(isPageRangeTextValid(" 10-100000", totalPageCount));
+
+ assertFalse(isPageRangeTextValid("1,2,0,56,1000000", totalPageCount));
+ assertFalse(isPageRangeTextValid("-1,1,2,,56", totalPageCount));
+ assertFalse(isPageRangeTextValid("1,2,56-40", totalPageCount));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'IsPageRangeTextValid2', function() {
+ var totalPageCount = 100;
+ assertTrue(isPageRangeTextValid(",,1,2,3,,1,,56,", totalPageCount));
+ assertTrue(isPageRangeTextValid(",1-3,,6-9,6-10,", totalPageCount));
+ assertTrue(isPageRangeTextValid("10-", totalPageCount));
+ assertTrue(isPageRangeTextValid("10-100000", totalPageCount));
+
+ assertFalse(isPageRangeTextValid("1,2,3,56,1000000", totalPageCount));
+ assertFalse(isPageRangeTextValid("1,2,0,56", totalPageCount));
+ assertFalse(isPageRangeTextValid("-1,1,2,,56", totalPageCount));
+ assertFalse(isPageRangeTextValid("1,2,56-40", totalPageCount));
+ assertFalse(isPageRangeTextValid("101-110", totalPageCount));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'PageRangeTextToPageList', function() {
+ var totalPageCount = 10;
+ assertTrue(areArraysEqual([1,2,3,4],
+ pageRangeTextToPageList("1-4", totalPageCount)));
+ assertTrue(areArraysEqual([1,2,3,4,2,3,4],
+ pageRangeTextToPageList("1-4, 2-4", totalPageCount)));
+ assertTrue(areArraysEqual([1,2,5,7,8,9,10,2,2,3],
+ pageRangeTextToPageList("1-2, 5, 7-10, 2, 2, 3",
+ totalPageCount)));
+ assertTrue(areArraysEqual([5,6,7,8,9,10],
+ pageRangeTextToPageList("5-", totalPageCount)));
+ assertTrue(areArraysEqual([], pageRangeTextToPageList("1-4", undefined)));
+ assertTrue(areArraysEqual([],
+ pageRangeTextToPageList("1-abcd", totalPageCount)));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'PageListToPageSet', function() {
+ assertTrue(areArraysEqual([1,2,3,4], pageListToPageSet([4,3,2,1,1,1])));
+ assertTrue(areArraysEqual([1,2,3,4], pageListToPageSet([1,2,2,3,4,1,1,1])));
+ assertTrue(areArraysEqual([], pageListToPageSet([])));
+});
+
+TEST_F('PrintPreviewUtilsUnitTest', 'PageSetToPageRanges', function() {
+ var pageRanges = pageSetToPageRanges([1,2,3,7,8,9,11]);
+ assertEquals(pageRanges.length, 3);
+ assertEquals(pageRanges[0].from, 1);
+ assertEquals(pageRanges[0].to, 3);
+ assertEquals(pageRanges[1].from, 7);
+ assertEquals(pageRanges[1].to, 9);
+ assertEquals(pageRanges[2].from, 11);
+ assertEquals(pageRanges[2].to, 11);
+});