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.
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"
26 typedef PluginProxyTest PDFResourceTest
;
30 TEST_F(PDFResourceTest
, SearchString
) {
32 // Instantiate a resource explicitly so we can specify the locale.
33 scoped_refptr
<PDFResource
> pdf_resource(
34 new PDFResource(Connection(&sink(), &sink()), pp_instance()));
35 pdf_resource
->SetLocaleForTest("en-US");
39 base::UTF8ToUTF16("abcdefabcdef", 12, &input
);
40 base::UTF8ToUTF16("bc", 2, &term
);
42 PP_PrivateFindResult
* results
;
44 pdf_resource
->SearchString(
45 reinterpret_cast<const unsigned short*>(input
.c_str()),
46 reinterpret_cast<const unsigned short*>(term
.c_str()),
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
);
57 const PPB_Memory_Dev
* memory_iface
= thunk::GetPPB_Memory_Dev_0_1_Thunk();
58 memory_iface
->MemFree(results
);
61 TEST_F(PDFResourceTest
, DidStartLoading
) {
62 const PPB_PDF
* pdf_iface
= thunk::GetPPB_PDF_Thunk();
64 pdf_iface
->DidStartLoading(pp_instance());
66 ResourceMessageCallParams params
;
68 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
69 PpapiHostMsg_PDF_DidStartLoading::ID
, ¶ms
, &msg
));
72 TEST_F(PDFResourceTest
, DidStopLoading
) {
73 const PPB_PDF
* pdf_iface
= thunk::GetPPB_PDF_Thunk();
75 pdf_iface
->DidStopLoading(pp_instance());
77 ResourceMessageCallParams params
;
79 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
80 PpapiHostMsg_PDF_DidStopLoading::ID
, ¶ms
, &msg
));
83 TEST_F(PDFResourceTest
, SetContentRestriction
) {
84 const PPB_PDF
* pdf_iface
= thunk::GetPPB_PDF_Thunk();
87 pdf_iface
->SetContentRestriction(pp_instance(), restrictions
);
89 ResourceMessageCallParams params
;
91 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
92 PpapiHostMsg_PDF_SetContentRestriction::ID
, ¶ms
, &msg
));
95 TEST_F(PDFResourceTest
, HasUnsupportedFeature
) {
96 const PPB_PDF
* pdf_iface
= thunk::GetPPB_PDF_Thunk();
98 pdf_iface
->HasUnsupportedFeature(pp_instance());
100 ResourceMessageCallParams params
;
102 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
103 PpapiHostMsg_PDF_HasUnsupportedFeature::ID
, ¶ms
, &msg
));
106 TEST_F(PDFResourceTest
, Print
) {
107 const PPB_PDF
* pdf_iface
= thunk::GetPPB_PDF_Thunk();
109 pdf_iface
->Print(pp_instance());
111 ResourceMessageCallParams params
;
113 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
114 PpapiHostMsg_PDF_Print::ID
, ¶ms
, &msg
));
117 TEST_F(PDFResourceTest
, SaveAs
) {
118 const PPB_PDF
* pdf_iface
= thunk::GetPPB_PDF_Thunk();
120 pdf_iface
->SaveAs(pp_instance());
122 ResourceMessageCallParams params
;
124 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
125 PpapiHostMsg_PDF_SaveAs::ID
, ¶ms
, &msg
));