Elim cr-checkbox
[chromium-blink-merge.git] / ppapi / proxy / pdf_resource_unittest.cc
blob7bea178e172dbf296a3e4a096c105f29c476b4ee
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.
5 #include <cstring>
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"
21 namespace ppapi {
22 namespace proxy {
24 namespace {
26 typedef PluginProxyTest PDFResourceTest;
28 } // namespace
30 TEST_F(PDFResourceTest, SearchString) {
31 ProxyAutoLock lock;
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");
37 base::string16 input;
38 base::string16 term;
39 base::UTF8ToUTF16("abcdefabcdef", 12, &input);
40 base::UTF8ToUTF16("bc", 2, &term);
42 PP_PrivateFindResult* results;
43 int 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);
51 ASSERT_EQ(2, 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);
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;
67 IPC::Message msg;
68 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
69 PpapiHostMsg_PDF_DidStartLoading::ID, &params, &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;
78 IPC::Message msg;
79 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
80 PpapiHostMsg_PDF_DidStopLoading::ID, &params, &msg));
83 TEST_F(PDFResourceTest, SetContentRestriction) {
84 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
86 int restrictions = 5;
87 pdf_iface->SetContentRestriction(pp_instance(), restrictions);
89 ResourceMessageCallParams params;
90 IPC::Message msg;
91 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
92 PpapiHostMsg_PDF_SetContentRestriction::ID, &params, &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;
101 IPC::Message msg;
102 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
103 PpapiHostMsg_PDF_HasUnsupportedFeature::ID, &params, &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;
112 IPC::Message msg;
113 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
114 PpapiHostMsg_PDF_Print::ID, &params, &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;
123 IPC::Message msg;
124 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
125 PpapiHostMsg_PDF_SaveAs::ID, &params, &msg));
128 } // namespace proxy
129 } // namespace ppapi