Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: ppapi/native_client/tests/ppapi_browser/ppb_pdf/ppapi_ppb_pdf.cc

Issue 7740013: Cloning a bunch of stuff from the native_client repository at r6528 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client 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 <string.h>
6 #include <string>
7
8 #include "native_client/src/include/nacl_macros.h"
9 #include "native_client/src/shared/platform/nacl_check.h"
10 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h"
11 #include "native_client/tests/ppapi_test_lib/test_interface.h"
12 #include "ppapi/c/dev/ppb_font_dev.h"
13 #include "ppapi/c/dev/ppb_memory_dev.h"
14 #include "ppapi/c/pp_bool.h"
15 #include "ppapi/c/pp_errors.h"
16 #include "ppapi/c/pp_rect.h"
17 #include "ppapi/c/ppb_core.h"
18 #include "ppapi/c/ppb_image_data.h"
19 #include "ppapi/c/ppb_var.h"
20 #include "ppapi/c/ppp_messaging.h"
21 #include "ppapi/c/private/ppb_pdf.h"
22
23 namespace {
24
25 const bool kCaseSensitive = true;
26 const bool kCaseInsensitive = false;
27
28 const PPB_PDF* PPBPDF() {
29 return reinterpret_cast<const PPB_PDF*>(
30 GetBrowserInterface(PPB_PDF_INTERFACE));
31 }
32
33 void TestGetLocalizedString() {
34 // Create a vertical scrollbar.
35 PP_Var string = PPBPDF()->GetLocalizedString(
36 pp_instance(),
37 PP_RESOURCESTRING_PDFGETPASSWORD);
38 EXPECT(string.type == PP_VARTYPE_STRING);
39
40 TEST_PASSED;
41 }
42
43 void TestGetResourceImage() {
44 // Get an image.
45 PP_Resource image = PPBPDF()->GetResourceImage(
46 pp_instance(),
47 PP_RESOURCEIMAGE_PDF_BUTTON_FTP);
48 EXPECT(image != kInvalidResource);
49 EXPECT(PPBImageData()->IsImageData(image));
50
51 PPBCore()->ReleaseResource(image);
52
53 return TEST_PASSED;
54 }
55
56 void TestGetFontFileWithFallback() {
57 PP_FontDescription_Dev description;
58 PP_Resource font_file = PPBPDF()->GetFontFileWithFallback(
59 pp_instance(),
60 &description,
61 PP_PRIVATEFONTCHARSET_ANSI);
62 EXPECT(font_file == kInvalidResource);
63
64 TEST_PASSED;
65 }
66
67 void TestGetFontTableForPrivateFontFile() {
68 uint32_t output_length;
69 bool success = PPBPDF()->GetFontTableForPrivateFontFile(
70 kInvalidResource, // font
71 0, // uint32_t table
72 NULL, // void* output
73 &output_length);
74 EXPECT(!success);
75
76 return TEST_PASSED;
77 }
78
79 typedef std::basic_string<unsigned short> Utf16String;
80
81 Utf16String CreateWString(const std::string& string) {
82 Utf16String utf16String = Utf16String();
83 for (std::string::const_iterator it = string.begin();
84 it != string.end(); ++it) {
85 utf16String.push_back(static_cast<unsigned short>(*it));
86 }
87 return utf16String;
88 }
89
90 void TestSearchString() {
91 int count;
92 PP_PrivateFindResult* results;
93 Utf16String string = CreateWString("Hello World");
94 {
95 Utf16String term = CreateWString("Hello");
96 PPBPDF()->SearchString(
97 pp_instance(),
98 string.c_str(),
99 term.c_str(),
100 kCaseSensitive,
101 &results,
102 &count);
103 EXPECT(count == 1);
104 EXPECT(results[0].start_index == 0 && results[0].length == 5);
105 PPBMemoryDev()->MemFree(results);
106 }
107 {
108 Utf16String term = CreateWString("l");
109 PPBPDF()->SearchString(
110 pp_instance(),
111 string.c_str(),
112 term.c_str(),
113 kCaseSensitive,
114 &results,
115 &count);
116 EXPECT(count == 3);
117 EXPECT(results[0].start_index == 2 && results[0].length == 1);
118 EXPECT(results[1].start_index == 3 && results[1].length == 1);
119 EXPECT(results[2].start_index == 9 && results[2].length == 1);
120 PPBMemoryDev()->MemFree(results);
121 }
122 {
123 Utf16String term = CreateWString("Hel");
124 PPBPDF()->SearchString(
125 pp_instance(),
126 string.c_str(),
127 term.c_str(),
128 kCaseSensitive,
129 &results,
130 &count);
131 EXPECT(count == 1);
132 EXPECT(results[0].start_index == 0 && results[0].length == 3);
133 PPBMemoryDev()->MemFree(results);
134 }
135 {
136 Utf16String term = CreateWString("h");
137 PPBPDF()->SearchString(
138 pp_instance(),
139 string.c_str(),
140 term.c_str(),
141 kCaseInsensitive,
142 &results,
143 &count);
144 EXPECT(count == 1);
145 EXPECT(results[0].start_index == 0 && results[0].length == 1);
146 PPBMemoryDev()->MemFree(results);
147 }
148 {
149 Utf16String term = CreateWString("h");
150 PPBPDF()->SearchString(
151 pp_instance(),
152 string.c_str(),
153 term.c_str(),
154 kCaseSensitive,
155 &results,
156 &count);
157 EXPECT(count == 0);
158 PPBMemoryDev()->MemFree(results);
159 }
160 {
161 Utf16String term = CreateWString("");
162 PPBPDF()->SearchString(
163 pp_instance(),
164 string.c_str(),
165 term.c_str(),
166 kCaseInsensitive,
167 &results,
168 &count);
169 EXPECT(count == 0);
170 PPBMemoryDev()->MemFree(results);
171 }
172
173 TEST_PASSED;
174 }
175
176 void TestDidStartLoading() {
177 PPBPDF()->DidStartLoading(pp_instance());
178
179 return TEST_PASSED;
180 }
181
182 void TestDidStopLoading() {
183 PPBPDF()->DidStopLoading(pp_instance());
184
185 return TEST_PASSED;
186 }
187
188 void TestSetContentRestriction() {
189 PPBPDF()->SetContentRestriction(pp_instance(), 0);
190
191 return TEST_PASSED;
192 }
193
194 void TestHistogramPDFPageCount() {
195 PPBPDF()->HistogramPDFPageCount(1);
196
197 return TEST_PASSED;
198 }
199
200 void TestUserMetricsRecordAction() {
201 const char* kString = "Action!";
202 PP_Var action = PPBVar()->VarFromUtf8(pp_module(),
203 kString,
204 strlen(kString));
205 PPBPDF()->UserMetricsRecordAction(action);
206
207 PPBVar()->Release(action);
208
209 return TEST_PASSED;
210 }
211
212 void TestHasUnsupportedFeature() {
213 PPBPDF()->HasUnsupportedFeature(pp_instance());
214
215 return TEST_PASSED;
216 }
217
218 void TestSaveAs() {
219 // This test pops up a file 'SaveAs' dialog, which will cause
220 // automated browser tests to hang. Un-comment to test manually.
221 /*
222 PPBPDF()->SaveAs(pp_instance());
223 */
224
225 return TEST_PASSED;
226 }
227
228 } // namespace
229
230 void SetupTests() {
231 RegisterTest("TestGetLocalizedString",
232 TestGetLocalizedString);
233 RegisterTest("TestGetResourceImage",
234 TestGetResourceImage);
235 RegisterTest("TestGetFontFileWithFallback",
236 TestGetFontFileWithFallback);
237 RegisterTest("TestGetFontTableForPrivateFontFile",
238 TestGetFontTableForPrivateFontFile);
239 RegisterTest("TestSearchString",
240 TestSearchString);
241 RegisterTest("TestDidStartLoading",
242 TestDidStartLoading);
243 RegisterTest("TestDidStopLoading",
244 TestDidStopLoading);
245 RegisterTest("TestSetContentRestriction",
246 TestSetContentRestriction);
247 RegisterTest("TestHistogramPDFPageCount",
248 TestHistogramPDFPageCount);
249 RegisterTest("TestUserMetricsRecordAction",
250 TestUserMetricsRecordAction);
251 RegisterTest("TestHasUnsupportedFeature",
252 TestHasUnsupportedFeature);
253 RegisterTest("TestSaveAs",
254 TestSaveAs);
255 }
256
257 void SetupPluginInterfaces() {
258 }
259
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698