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 <cstring> 6 7 #include "base/message_loop/message_loop.h" 8 #include "ppapi/c/dev/ppb_printing_dev.h" 9 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/proxy/locking_resource_releaser.h" 11 #include "ppapi/proxy/plugin_message_filter.h" 12 #include "ppapi/proxy/ppapi_messages.h" 13 #include "ppapi/proxy/ppapi_proxy_test.h" 14 #include "ppapi/proxy/printing_resource.h" 15 #include "ppapi/thunk/thunk.h" 16 17 namespace ppapi { 18 namespace proxy { 19 20 namespace { 21 22 typedef PluginProxyTest PrintingResourceTest; 23 24 bool g_callback_called; 25 int32_t g_callback_result; 26 27 void Callback(void* user_data, int32_t result) { 28 g_callback_called = true; 29 g_callback_result = result; 30 } 31 32 bool PP_SizeEqual(const PP_Size& lhs, const PP_Size& rhs) { 33 return lhs.width == rhs.width && lhs.height == rhs.height; 34 } 35 36 bool PP_RectEqual(const PP_Rect& lhs, const PP_Rect& rhs) { 37 return lhs.point.x == rhs.point.x && 38 lhs.point.y == rhs.point.y && 39 PP_SizeEqual(lhs.size, rhs.size); 40 } 41 42 } // namespace 43 44 // Does a full test of GetDefaultPrintSettings() and reply functionality in the 45 // plugin side using the public C interfaces. 46 TEST_F(PrintingResourceTest, GetDefaultPrintSettings) { 47 g_callback_called = false; 48 49 const PPB_Printing_Dev_0_7* printing_iface = 50 thunk::GetPPB_Printing_Dev_0_7_Thunk(); 51 LockingResourceReleaser res(printing_iface->Create(pp_instance())); 52 53 PP_PrintSettings_Dev output_settings; 54 55 int32_t result = printing_iface->GetDefaultPrintSettings( 56 res.get(), &output_settings, PP_MakeCompletionCallback(&Callback, NULL)); 57 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); 58 59 // Should have sent a "GetDefaultPrintSettings" message. 60 ResourceMessageCallParams params; 61 IPC::Message msg; 62 ASSERT_TRUE(sink().GetFirstResourceCallMatching( 63 PpapiHostMsg_Printing_GetDefaultPrintSettings::ID, ¶ms, &msg)); 64 65 // Synthesize a response with some random print settings. 66 ResourceMessageReplyParams reply_params(params.pp_resource(), 67 params.sequence()); 68 reply_params.set_result(PP_OK); 69 70 PP_PrintSettings_Dev reply_settings = { 71 { { 0, 0 }, { 500, 515 } }, 72 { { 25, 35 }, { 300, 720 } }, 73 { 600, 700 }, 74 200, 75 PP_PRINTORIENTATION_NORMAL, 76 PP_PRINTSCALINGOPTION_NONE, 77 PP_FALSE, 78 PP_PRINTOUTPUTFORMAT_PDF 79 }; 80 PluginMessageFilter::DispatchResourceReplyForTest( 81 reply_params, 82 PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply( 83 reply_settings)); 84 85 EXPECT_TRUE(PP_RectEqual(reply_settings.printable_area, 86 output_settings.printable_area)); 87 EXPECT_TRUE(PP_RectEqual(reply_settings.content_area, 88 output_settings.content_area)); 89 EXPECT_TRUE(PP_SizeEqual(reply_settings.paper_size, 90 output_settings.paper_size)); 91 EXPECT_EQ(reply_settings.dpi, output_settings.dpi); 92 EXPECT_EQ(reply_settings.orientation, output_settings.orientation); 93 EXPECT_EQ(reply_settings.print_scaling_option, 94 output_settings.print_scaling_option); 95 EXPECT_EQ(reply_settings.grayscale, output_settings.grayscale); 96 EXPECT_EQ(reply_settings.format, output_settings.format); 97 98 EXPECT_EQ(g_callback_result, PP_OK); 99 EXPECT_EQ(g_callback_called, true); 100 } 101 102 } // namespace proxy 103 } // namespace ppapi 104