Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(674)

Side by Side Diff: printing/page_overlays_unittest.cc

Issue 7585015: Printing: Remove unused PageOverlay since header/footers are drawn in PrintWebViewHelper. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix win Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/page_overlays.cc ('k') | printing/print_settings.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 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.
4
5 #include "base/message_loop.h"
6 #include "base/string16.h"
7 #include "base/stringprintf.h"
8 #include "base/utf_string_conversions.h"
9 #include "printing/page_overlays.h"
10 #include "printing/print_settings.h"
11 #include "printing/printed_document.h"
12 #include "printing/printed_page.h"
13 #include "printing/printed_pages_source.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace {
17
18 struct Keys {
19 const wchar_t* key;
20 const wchar_t* expected;
21 };
22
23 const Keys kOverlayKeys[] = {
24 { printing::PageOverlays::kTitle, L"Foobar Document" },
25 { printing::PageOverlays::kTime, L"" },
26 { printing::PageOverlays::kDate, L"" },
27 { printing::PageOverlays::kPage, L"1" },
28 { printing::PageOverlays::kPageCount, L"2" },
29 { printing::PageOverlays::kPageOnTotal, L"1/2" },
30 { printing::PageOverlays::kUrl, L"http://www.perdu.com/" },
31 };
32
33 class PagesSource : public printing::PrintedPagesSource {
34 public:
35 virtual string16 RenderSourceName() {
36 return ASCIIToUTF16("Foobar Document");
37 }
38
39 virtual GURL RenderSourceUrl() {
40 return GURL("http://www.perdu.com");
41 }
42 };
43
44 } // namespace
45
46 class PageOverlaysTest : public testing::Test {
47 private:
48 MessageLoop message_loop_;
49 };
50
51 TEST_F(PageOverlaysTest, StringConversion) {
52 printing::PageOverlays overlays;
53 overlays.GetOverlay(printing::PageOverlays::LEFT,
54 printing::PageOverlays::BOTTOM);
55 printing::PrintSettings settings;
56 PagesSource source;
57 int cookie = 1;
58 scoped_refptr<printing::PrintedDocument> doc(
59 new printing::PrintedDocument(settings, &source, cookie));
60 doc->set_page_count(2);
61 gfx::Size page_size(100, 100);
62 gfx::Rect page_content_area(5, 5, 90, 90);
63 scoped_refptr<printing::PrintedPage> page(
64 new printing::PrintedPage(1, NULL, page_size, page_content_area, true));
65
66 std::wstring input;
67 std::wstring out;
68 for (size_t i = 0; i < arraysize(kOverlayKeys); ++i) {
69 input = base::StringPrintf(L"foo%lsbar", kOverlayKeys[i].key);
70 out = printing::PageOverlays::ReplaceVariables(input, *doc.get(),
71 *page.get());
72 EXPECT_FALSE(out.empty());
73 if (wcslen(kOverlayKeys[i].expected) == 0)
74 continue;
75 std::wstring expected =
76 base::StringPrintf(L"foo%lsbar", kOverlayKeys[i].expected);
77 EXPECT_EQ(expected, out) << kOverlayKeys[i].key;
78 }
79
80 // Check if SetOverlay really sets the page overlay.
81 overlays.SetOverlay(printing::PageOverlays::LEFT,
82 printing::PageOverlays::TOP,
83 L"Page {page}");
84 input = overlays.GetOverlay(printing::PageOverlays::LEFT,
85 printing::PageOverlays::TOP);
86 EXPECT_EQ(input, L"Page {page}");
87
88 // Replace the variables to see if the page number is correct.
89 out = printing::PageOverlays::ReplaceVariables(input, *doc.get(),
90 *page.get());
91 EXPECT_EQ(out, L"Page 1");
92 }
OLDNEW
« no previous file with comments | « printing/page_overlays.cc ('k') | printing/print_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698