1c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// found in the LICENSE file.
4c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
5c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ppapi/tests/test_pdf.h"
6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
7c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ppapi/c/private/ppb_pdf.h"
8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ppapi/cpp/image_data.h"
9c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ppapi/cpp/point.h"
10c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ppapi/cpp/private/pdf.h"
11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ppapi/cpp/var.h"
12c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ppapi/tests/testing_instance.h"
13c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)REGISTER_TEST_CASE(PDF);
15c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TestPDF::TestPDF(TestingInstance* instance)
17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    : TestCase(instance) {
18c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)void TestPDF::RunTests(const std::string& filter) {
21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RUN_TEST(GetLocalizedString, filter);
22c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  RUN_TEST(GetResourceImage, filter);
23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)std::string TestPDF::TestGetLocalizedString() {
26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  pp::Var string = pp::PDF::GetLocalizedString(instance_,
27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      PP_RESOURCESTRING_PDFGETPASSWORD);
28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_TRUE(string.is_string());
29c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_EQ("This document is password protected.  Please enter a password.",
30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)            string.AsString());
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  PASS();
32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)std::string TestPDF::TestGetResourceImage() {
35c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  pp::ImageData data =
36c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      pp::PDF::GetResourceImage(instance_, PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN);
37c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_EQ(43, data.size().width());
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ASSERT_EQ(42, data.size().height());
39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  for (int i = 0; i < data.size().width(); ++i) {
40c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    for (int j = 0; j < data.size().height(); ++j) {
41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      pp::Point point(i, j);
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      ASSERT_NE(0, *data.GetAddr32(point));
43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  PASS();
46c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
47