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/strings/utf_string_conversions.h"
8 #include "ppapi/c/dev/ppb_memory_dev.h"
9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/c/ppb_image_data.h"
11 #include "ppapi/proxy/pdf_resource.h"
12 #include "ppapi/proxy/ppapi_messages.h"
13 #include "ppapi/proxy/ppapi_proxy_test.h"
14 #include "ppapi/proxy/ppb_image_data_proxy.h"
15 #include "ppapi/proxy/serialized_handle.h"
16 #include "ppapi/shared_impl/proxy_lock.h"
17 #include "ppapi/shared_impl/scoped_pp_var.h"
18 #include "ppapi/shared_impl/var.h"
19 #include "ppapi/thunk/thunk.h"
20
21 namespace ppapi {
22 namespace proxy {
23
24 namespace {
25
26 typedef PluginProxyTest PDFResourceTest;
27
28 } // namespace
29
TEST_F(PDFResourceTest,SearchString)30 TEST_F(PDFResourceTest, SearchString) {
31 ProxyAutoLock lock;
32 // Instantiate a resource explicitly so we can specify the locale.
33 auto pdf_resource = base::MakeRefCounted<PDFResource>(
34 Connection(&sink(), &sink(), 0), pp_instance());
35 pdf_resource->SetLocaleForTest("en-US@collation=search");
36
37 base::string16 input;
38 base::string16 term;
39 base::UTF8ToUTF16("abcdefabcdef", 12, &input);
40 base::UTF8ToUTF16("bc", 2, &term);
41
42 PP_PrivateFindResult* results;
43 uint32_t count = 0;
44 pdf_resource->SearchString(
45 reinterpret_cast<const unsigned short*>(input.c_str()),
46 reinterpret_cast<const unsigned short*>(term.c_str()),
47 true,
48 &results,
49 &count);
50
51 ASSERT_EQ(2U, count);
52 ASSERT_EQ(1, results[0].start_index);
53 ASSERT_EQ(2, results[0].length);
54 ASSERT_EQ(7, results[1].start_index);
55 ASSERT_EQ(2, results[1].length);
56
57 const PPB_Memory_Dev* memory_iface = thunk::GetPPB_Memory_Dev_0_1_Thunk();
58 memory_iface->MemFree(results);
59 }
60
TEST_F(PDFResourceTest,DidStartLoading)61 TEST_F(PDFResourceTest, DidStartLoading) {
62 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
63
64 pdf_iface->DidStartLoading(pp_instance());
65
66 ResourceMessageCallParams params;
67 IPC::Message msg;
68 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
69 PpapiHostMsg_PDF_DidStartLoading::ID, ¶ms, &msg));
70 }
71
TEST_F(PDFResourceTest,DidStopLoading)72 TEST_F(PDFResourceTest, DidStopLoading) {
73 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
74
75 pdf_iface->DidStopLoading(pp_instance());
76
77 ResourceMessageCallParams params;
78 IPC::Message msg;
79 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
80 PpapiHostMsg_PDF_DidStopLoading::ID, ¶ms, &msg));
81 }
82
TEST_F(PDFResourceTest,SetContentRestriction)83 TEST_F(PDFResourceTest, SetContentRestriction) {
84 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
85
86 int restrictions = 5;
87 pdf_iface->SetContentRestriction(pp_instance(), restrictions);
88
89 ResourceMessageCallParams params;
90 IPC::Message msg;
91 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
92 PpapiHostMsg_PDF_SetContentRestriction::ID, ¶ms, &msg));
93 }
94
TEST_F(PDFResourceTest,HasUnsupportedFeature)95 TEST_F(PDFResourceTest, HasUnsupportedFeature) {
96 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
97
98 pdf_iface->HasUnsupportedFeature(pp_instance());
99
100 ResourceMessageCallParams params;
101 IPC::Message msg;
102 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
103 PpapiHostMsg_PDF_HasUnsupportedFeature::ID, ¶ms, &msg));
104 }
105
TEST_F(PDFResourceTest,Print)106 TEST_F(PDFResourceTest, Print) {
107 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
108
109 pdf_iface->Print(pp_instance());
110
111 ResourceMessageCallParams params;
112 IPC::Message msg;
113 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
114 PpapiHostMsg_PDF_Print::ID, ¶ms, &msg));
115 }
116
TEST_F(PDFResourceTest,SaveAs)117 TEST_F(PDFResourceTest, SaveAs) {
118 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
119
120 pdf_iface->SaveAs(pp_instance());
121
122 ResourceMessageCallParams params;
123 IPC::Message msg;
124 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
125 PpapiHostMsg_PDF_SaveAs::ID, ¶ms, &msg));
126 }
127
TEST_F(PDFResourceTest,SelectionChanged)128 TEST_F(PDFResourceTest, SelectionChanged) {
129 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
130
131 PP_FloatPoint left = PP_MakeFloatPoint(0.0f, 0.0f);
132 PP_FloatPoint right = PP_MakeFloatPoint(1.0f, 1.0f);
133 pdf_iface->SelectionChanged(pp_instance(), &left, 0, &right, 0);
134
135 ResourceMessageCallParams params;
136 IPC::Message msg;
137 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
138 PpapiHostMsg_PDF_SelectionChanged::ID, ¶ms, &msg));
139 }
140
TEST_F(PDFResourceTest,SetPluginCanSave)141 TEST_F(PDFResourceTest, SetPluginCanSave) {
142 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
143
144 pdf_iface->SetPluginCanSave(pp_instance(), true);
145
146 ResourceMessageCallParams params;
147 IPC::Message msg;
148 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
149 PpapiHostMsg_PDF_SetPluginCanSave::ID, ¶ms, &msg));
150 }
151
152 } // namespace proxy
153 } // namespace ppapi
154