Commit e4a7e916 authored by Eric Seckler's avatar Eric Seckler Committed by Commit Bot

[headless] Allow print page ranges with range.to > page count.

Bug: 603559
Change-Id: Ib9316295cee0226fe19c966e47b0c5a6a730db44
Reviewed-on: https://chromium-review.googlesource.com/567504
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Reviewed-by: default avatarAlex Clarke <alexclarke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485914}
parent aff24926
......@@ -107,8 +107,10 @@ HeadlessPrintManager::PageRangeTextToPages(base::StringPiece page_range_text,
if (range.from < 1 || range.from > range.to)
return SYNTAX_ERROR;
if (range.to > pages_count)
if (range.from > pages_count)
return LIMIT_ERROR;
if (range.to > pages_count)
range.to = pages_count;
// Page numbers are 1-based in the dictionary.
// Page numbers are 0-based for the print settings.
......
......@@ -154,37 +154,51 @@ TEST(PageRangeTextToPagesTest, General) {
std::vector<int> pages;
std::vector<int> expected_pages;
// "-" is full range of pages.
PM::PageRangeStatus status = PM::PageRangeTextToPages("-", 10, &pages);
expected_pages = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
EXPECT_EQ(expected_pages, pages);
EXPECT_EQ(PM::PRINT_NO_ERROR, status);
// If no start page is specified, we start at first page.
status = PM::PageRangeTextToPages("-5", 10, &pages);
expected_pages = {0, 1, 2, 3, 4};
EXPECT_EQ(expected_pages, pages);
EXPECT_EQ(PM::PRINT_NO_ERROR, status);
// If no end page is specified, we end at last page.
status = PM::PageRangeTextToPages("5-", 10, &pages);
expected_pages = {4, 5, 6, 7, 8, 9};
EXPECT_EQ(expected_pages, pages);
EXPECT_EQ(PM::PRINT_NO_ERROR, status);
// Multiple ranges are separated by commas.
status = PM::PageRangeTextToPages("1-3,9-10,4-6", 10, &pages);
expected_pages = {0, 1, 2, 3, 4, 5, 8, 9};
EXPECT_EQ(expected_pages, pages);
EXPECT_EQ(PM::PRINT_NO_ERROR, status);
// White space is ignored.
status = PM::PageRangeTextToPages("1- 3, 9-10,4 -6", 10, &pages);
expected_pages = {0, 1, 2, 3, 4, 5, 8, 9};
EXPECT_EQ(expected_pages, pages);
EXPECT_EQ(PM::PRINT_NO_ERROR, status);
// End page beyond number of pages is supported and capped to number of pages.
status = PM::PageRangeTextToPages("1-10", 5, &pages);
expected_pages = {0, 1, 2, 3, 4};
EXPECT_EQ(expected_pages, pages);
EXPECT_EQ(PM::PRINT_NO_ERROR, status);
// Start page beyond number of pages results in error.
status = PM::PageRangeTextToPages("1-3,9-10,4-6", 5, &pages);
EXPECT_EQ(PM::LIMIT_ERROR, status);
// Invalid input results in error.
status = PM::PageRangeTextToPages("abcd", 10, &pages);
EXPECT_EQ(PM::SYNTAX_ERROR, status);
// Invalid input results in error.
status = PM::PageRangeTextToPages("1-3,9-a10,4-6", 10, &pages);
EXPECT_EQ(PM::SYNTAX_ERROR, status);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment