Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / printing / pdf_metafile_cg_mac_unittest.cc
1 // Copyright (c) 2011 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 "printing/pdf_metafile_cg_mac.h"
6
7 #import <ApplicationServices/ApplicationServices.h>
8 #include <stdint.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/gfx/geometry/rect.h"
15
16 namespace printing {
17
18 TEST(PdfMetafileCgTest, Pdf) {
19   // Test in-renderer constructor.
20   PdfMetafileCg pdf;
21   EXPECT_TRUE(pdf.Init());
22   EXPECT_TRUE(pdf.context() != NULL);
23
24   // Render page 1.
25   gfx::Rect rect_1(10, 10, 520, 700);
26   gfx::Size size_1(540, 720);
27   pdf.StartPage(size_1, rect_1, 1.25);
28   pdf.FinishPage();
29
30   // Render page 2.
31   gfx::Rect rect_2(10, 10, 520, 700);
32   gfx::Size size_2(720, 540);
33   pdf.StartPage(size_2, rect_2, 2.0);
34   pdf.FinishPage();
35
36   pdf.FinishDocument();
37
38   // Check data size.
39   uint32_t size = pdf.GetDataSize();
40   EXPECT_GT(size, 0U);
41
42   // Get resulting data.
43   std::vector<char> buffer(size, 0);
44   pdf.GetData(&buffer.front(), size);
45
46   // Test browser-side constructor.
47   PdfMetafileCg pdf2;
48   EXPECT_TRUE(pdf2.InitFromData(&buffer.front(), size));
49
50   // Get the first 4 characters from pdf2.
51   std::vector<char> buffer2(4, 0);
52   pdf2.GetData(&buffer2.front(), 4);
53
54   // Test that the header begins with "%PDF".
55   std::string header(&buffer2.front(), 4);
56   EXPECT_EQ(0U, header.find("%PDF", 0));
57
58   // Test that the PDF is correctly reconstructed.
59   EXPECT_EQ(2U, pdf2.GetPageCount());
60   gfx::Size page_size = pdf2.GetPageBounds(1).size();
61   EXPECT_EQ(540, page_size.width());
62   EXPECT_EQ(720, page_size.height());
63   page_size = pdf2.GetPageBounds(2).size();
64   EXPECT_EQ(720, page_size.width());
65   EXPECT_EQ(540, page_size.height());
66 }
67
68 }  // namespace printing