19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// Copyright (c) 2012 The Chromium Authors. All rights reserved.
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// Use of this source code is governed by a BSD-style license that can be
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall// found in the LICENSE file.
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ppapi/tests/test_pdf.h"
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ppapi/c/private/ppb_pdf.h"
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ppapi/cpp/image_data.h"
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ppapi/cpp/point.h"
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ppapi/cpp/private/pdf.h"
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ppapi/cpp/var.h"
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "ppapi/tests/testing_instance.h"
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallREGISTER_TEST_CASE(PDF);
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallTestPDF::TestPDF(TestingInstance* instance)
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    : TestCase(instance) {
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid TestPDF::RunTests(const std::string& filter) {
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RUN_TEST(GetLocalizedString, filter);
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  RUN_TEST(GetResourceImage, filter);
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstd::string TestPDF::TestGetLocalizedString() {
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pp::Var string = pp::PDF::GetLocalizedString(instance_,
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      PP_RESOURCESTRING_PDFGETPASSWORD);
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  ASSERT_TRUE(string.is_string());
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  ASSERT_EQ("This document is password protected.  Please enter a password.",
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall            string.AsString());
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  PASS();
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstd::string TestPDF::TestGetResourceImage() {
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  pp::ImageData data =
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pp::PDF::GetResourceImage(instance_, PP_RESOURCEIMAGE_PDF_BUTTON_ZOOMIN);
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  ASSERT_EQ(43, data.size().width());
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  ASSERT_EQ(42, data.size().height());
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  for (int i = 0; i < data.size().width(); ++i) {
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    for (int j = 0; j < data.size().height(); ++j) {
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      pp::Point point(i, j);
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall      ASSERT_NE(0, *data.GetAddr32(point));
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    }
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  }
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall  PASS();
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall}
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall