1 // Copyright (c) 2012 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 "ppapi/tests/test_printing.h" 6 7 #include "ppapi/cpp/dev/printing_dev.h" 8 #include "ppapi/cpp/instance.h" 9 #include "ppapi/tests/testing_instance.h" 10 11 namespace { 12 bool g_callback_triggered; 13 int32_t g_callback_result; 14 PP_PrintSettings_Dev g_print_settings; 15 } // namespace 16 17 REGISTER_TEST_CASE(Printing); 18 19 class TestPrinting_Dev : public pp::Printing_Dev { 20 public: 21 explicit TestPrinting_Dev(pp::Instance* instance) : 22 pp::Printing_Dev(instance) {} 23 virtual ~TestPrinting_Dev() {} 24 virtual uint32_t QuerySupportedPrintOutputFormats() { return 0; } 25 virtual int32_t PrintBegin( 26 const PP_PrintSettings_Dev& print_settings) { return 0; } 27 virtual pp::Resource PrintPages( 28 const PP_PrintPageNumberRange_Dev* page_ranges, 29 uint32_t page_range_count) { 30 return pp::Resource(); 31 } 32 virtual void PrintEnd() {} 33 virtual bool IsPrintScalingDisabled() { return false; } 34 }; 35 36 TestPrinting::TestPrinting(TestingInstance* instance) 37 : TestCase(instance), 38 nested_event_(instance->pp_instance()) { 39 callback_factory_.Initialize(this); 40 } 41 42 void TestPrinting::RunTests(const std::string& filter) { 43 RUN_TEST(GetDefaultPrintSettings, filter); 44 } 45 46 std::string TestPrinting::TestGetDefaultPrintSettings() { 47 g_callback_triggered = false; 48 TestPrinting_Dev test_printing(instance_); 49 pp::CompletionCallbackWithOutput<PP_PrintSettings_Dev> cb = 50 callback_factory_.NewCallbackWithOutput(&TestPrinting::Callback); 51 test_printing.GetDefaultPrintSettings(cb); 52 nested_event_.Wait(); 53 54 ASSERT_EQ(PP_OK, g_callback_result); 55 ASSERT_TRUE(g_callback_triggered); 56 57 // Sanity check the |printable_area|, |content_area| and |paper_size| members. 58 // It is possible these values are outside these ranges but it shouldn't 59 // happen in practice and probably means there is an error in computing 60 // the default print settings. These values are in points. 61 ASSERT_TRUE(g_print_settings.printable_area.point.x < 200); 62 ASSERT_TRUE(g_print_settings.printable_area.point.y < 200); 63 ASSERT_TRUE(g_print_settings.printable_area.size.width < 2000); 64 ASSERT_TRUE(g_print_settings.printable_area.size.height < 2000); 65 66 ASSERT_TRUE(g_print_settings.content_area.point.x < 200); 67 ASSERT_TRUE(g_print_settings.content_area.point.y < 200); 68 ASSERT_TRUE(g_print_settings.content_area.size.width < 2000); 69 ASSERT_TRUE(g_print_settings.content_area.size.height< 2000); 70 71 ASSERT_TRUE(g_print_settings.paper_size.width < 2000); 72 ASSERT_TRUE(g_print_settings.paper_size.height < 2000); 73 74 PASS(); 75 } 76 77 void TestPrinting::Callback(int32_t result, 78 PP_PrintSettings_Dev& print_settings) { 79 g_callback_triggered = true; 80 g_callback_result = result; 81 g_print_settings = print_settings; 82 nested_event_.Signal(); 83 } 84