Android NTP: Most visited tile clicks should have PageTransition.AUTO_BOOKMARK
[chromium-blink-merge.git] / ppapi / proxy / pdf_resource_unittest.cc
blob0b228722ff2cfd2288e6abd2ac98a11ef9254680
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, GetLocalizedString) {
31 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
33 std::string expected_string = "hello";
34 PpapiPluginMsg_PDF_GetLocalizedStringReply reply_msg(expected_string);
35 ResourceSyncCallHandler handler(
36 &sink(),
37 PpapiHostMsg_PDF_GetLocalizedString::ID,
38 PP_OK,
39 reply_msg);
40 sink().AddFilter(&handler);
42 PP_Var var = pdf_iface->GetLocalizedString(
43 pp_instance(), PP_RESOURCESTRING_PDFGETPASSWORD);
46 ProxyAutoLock lock;
47 ScopedPPVar release_var(ScopedPPVar::PassRef(), var);
48 StringVar* string_var = StringVar::FromPPVar(var);
49 ASSERT_TRUE(string_var != NULL);
50 std::string actual_string = string_var->value();
52 ASSERT_EQ(PpapiHostMsg_PDF_GetLocalizedString::ID,
53 handler.last_handled_msg().type());
54 ASSERT_EQ(expected_string, actual_string);
57 // Remove the filter or it will be destroyed before the sink() is destroyed.
58 sink().RemoveFilter(&handler);
61 TEST_F(PDFResourceTest, SearchString) {
62 ProxyAutoLock lock;
63 // Instantiate a resource explicitly so we can specify the locale.
64 scoped_refptr<PDFResource> pdf_resource(
65 new PDFResource(Connection(&sink(), &sink()), pp_instance()));
66 pdf_resource->SetLocaleForTest("en-US");
68 base::string16 input;
69 base::string16 term;
70 base::UTF8ToUTF16("abcdefabcdef", 12, &input);
71 base::UTF8ToUTF16("bc", 2, &term);
73 PP_PrivateFindResult* results;
74 int count = 0;
75 pdf_resource->SearchString(
76 reinterpret_cast<const unsigned short*>(input.c_str()),
77 reinterpret_cast<const unsigned short*>(term.c_str()),
78 true,
79 &results,
80 &count);
82 ASSERT_EQ(2, count);
83 ASSERT_EQ(1, results[0].start_index);
84 ASSERT_EQ(2, results[0].length);
85 ASSERT_EQ(7, results[1].start_index);
86 ASSERT_EQ(2, results[1].length);
88 const PPB_Memory_Dev* memory_iface = thunk::GetPPB_Memory_Dev_0_1_Thunk();
89 memory_iface->MemFree(results);
92 TEST_F(PDFResourceTest, DidStartLoading) {
93 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
95 pdf_iface->DidStartLoading(pp_instance());
97 ResourceMessageCallParams params;
98 IPC::Message msg;
99 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
100 PpapiHostMsg_PDF_DidStartLoading::ID, &params, &msg));
103 TEST_F(PDFResourceTest, DidStopLoading) {
104 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
106 pdf_iface->DidStopLoading(pp_instance());
108 ResourceMessageCallParams params;
109 IPC::Message msg;
110 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
111 PpapiHostMsg_PDF_DidStopLoading::ID, &params, &msg));
114 TEST_F(PDFResourceTest, SetContentRestriction) {
115 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
117 int restrictions = 5;
118 pdf_iface->SetContentRestriction(pp_instance(), restrictions);
120 ResourceMessageCallParams params;
121 IPC::Message msg;
122 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
123 PpapiHostMsg_PDF_SetContentRestriction::ID, &params, &msg));
126 TEST_F(PDFResourceTest, HasUnsupportedFeature) {
127 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
129 pdf_iface->HasUnsupportedFeature(pp_instance());
131 ResourceMessageCallParams params;
132 IPC::Message msg;
133 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
134 PpapiHostMsg_PDF_HasUnsupportedFeature::ID, &params, &msg));
137 TEST_F(PDFResourceTest, Print) {
138 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
140 pdf_iface->Print(pp_instance());
142 ResourceMessageCallParams params;
143 IPC::Message msg;
144 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
145 PpapiHostMsg_PDF_Print::ID, &params, &msg));
148 TEST_F(PDFResourceTest, SaveAs) {
149 const PPB_PDF* pdf_iface = thunk::GetPPB_PDF_Thunk();
151 pdf_iface->SaveAs(pp_instance());
153 ResourceMessageCallParams params;
154 IPC::Message msg;
155 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
156 PpapiHostMsg_PDF_SaveAs::ID, &params, &msg));
159 } // namespace proxy
160 } // namespace ppapi