OLD | NEW |
---|---|
(Empty) | |
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 "content/browser/renderer_host/pepper/browser_ppapi_host_test.h" | |
6 #include "content/browser/renderer_host/pepper/pepper_print_settings_manager.h" | |
7 #include "content/browser/renderer_host/pepper/pepper_printing_host.h" | |
8 #include "ppapi/c/pp_errors.h" | |
9 #include "ppapi/host/host_message_context.h" | |
10 #include "ppapi/host/ppapi_host.h" | |
11 #include "ppapi/proxy/ppapi_messages.h" | |
12 #include "ppapi/proxy/resource_message_params.h" | |
13 #include "ppapi/proxy/resource_message_test_sink.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 namespace content { | |
17 | |
18 namespace { | |
19 | |
20 class PepperPrintingHostTest | |
21 : public testing::Test, | |
22 public BrowserPpapiHostTest { | |
23 public: | |
24 PepperPrintingHostTest() { | |
25 } | |
26 | |
27 ~PepperPrintingHostTest() { | |
28 } | |
29 | |
30 DISALLOW_COPY_AND_ASSIGN(PepperPrintingHostTest); | |
31 }; | |
32 | |
33 bool PP_SizeEqual(const PP_Size& lhs, const PP_Size& rhs) { | |
34 return lhs.width == rhs.width && lhs.height == rhs.height; | |
brettw
2012/09/18 21:41:38
Check indenting for these functions.
raymes
2012/09/18 23:43:57
Done.
| |
35 } | |
36 | |
37 bool PP_RectEqual(const PP_Rect& lhs, const PP_Rect& rhs) { | |
38 return lhs.point.x == rhs.point.x && | |
39 lhs.point.y == rhs.point.y && | |
40 PP_SizeEqual(lhs.size, rhs.size); | |
41 } | |
42 | |
43 } // namespace | |
44 | |
45 TEST_F(PepperPrintingHostTest, GetDefaultPrintSettings) { | |
46 PP_Instance pp_instance = 12345; | |
47 PP_Resource pp_resource = 67890; | |
48 PP_PrintSettings_Dev expected_settings = { | |
49 { { 0, 0 }, { 500, 515 } }, | |
50 { { 25, 35 }, { 300, 720 } }, | |
51 { 600, 700 }, | |
52 200, | |
53 PP_PRINTORIENTATION_NORMAL, | |
54 PP_PRINTSCALINGOPTION_NONE, | |
55 PP_FALSE, | |
56 PP_PRINTOUTPUTFORMAT_PDF | |
57 }; | |
58 | |
59 // Construct the resource host. | |
60 scoped_ptr<PepperPrintSettingsManager> manager( | |
61 new MockPepperPrintSettingsManager(expected_settings)); | |
62 PepperPrintingHost printing(GetBrowserPpapiHost()->GetPpapiHost(), | |
63 pp_instance, pp_resource, manager.Pass()); | |
64 | |
65 // Simulate a message being received. | |
66 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 1); | |
67 ppapi::host::HostMessageContext context(call_params); | |
68 int32 result = printing.OnResourceMessageReceived( | |
69 PpapiHostMsg_Printing_GetDefaultPrintSettings(), &context); | |
70 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result); | |
71 | |
72 // This should have sent the Pepper reply to our test sink. | |
73 ppapi::proxy::ResourceMessageReplyParams reply_params; | |
74 IPC::Message reply_msg; | |
75 ASSERT_TRUE(sink().GetFirstResourceReplyMatching( | |
76 PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply::ID, &reply_params, | |
77 &reply_msg)); | |
78 | |
79 // Validation of reply. | |
80 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); | |
81 EXPECT_EQ(PP_OK, reply_params.result()); | |
82 PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply::Schema::Param | |
83 reply_msg_param; | |
84 ASSERT_TRUE(PpapiPluginMsg_Printing_GetDefaultPrintSettingsReply::Read( | |
85 &reply_msg, &reply_msg_param)); | |
86 PP_PrintSettings_Dev actual_settings = reply_msg_param.a; | |
87 | |
88 EXPECT_TRUE(PP_RectEqual(expected_settings.printable_area, | |
89 actual_settings.printable_area)); | |
90 EXPECT_TRUE(PP_RectEqual(expected_settings.content_area, | |
91 actual_settings.content_area)); | |
92 EXPECT_TRUE(PP_SizeEqual(expected_settings.paper_size, | |
93 actual_settings.paper_size)); | |
94 EXPECT_EQ(expected_settings.dpi, actual_settings.dpi); | |
95 EXPECT_EQ(expected_settings.orientation, actual_settings.orientation); | |
96 EXPECT_EQ(expected_settings.print_scaling_option, | |
97 actual_settings.print_scaling_option); | |
98 EXPECT_EQ(expected_settings.grayscale, actual_settings.grayscale); | |
99 EXPECT_EQ(expected_settings.format, actual_settings.format); | |
100 } | |
101 | |
102 } // namespace content | |
OLD | NEW |