| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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 <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(kString, | |
| 203 strlen(kString)); | |
| 204 PPBPDF()->UserMetricsRecordAction(action); | |
| 205 | |
| 206 PPBVar()->Release(action); | |
| 207 | |
| 208 return TEST_PASSED; | |
| 209 } | |
| 210 | |
| 211 void TestHasUnsupportedFeature() { | |
| 212 PPBPDF()->HasUnsupportedFeature(pp_instance()); | |
| 213 | |
| 214 return TEST_PASSED; | |
| 215 } | |
| 216 | |
| 217 void TestSaveAs() { | |
| 218 // This test pops up a file 'SaveAs' dialog, which will cause | |
| 219 // automated browser tests to hang. Un-comment to test manually. | |
| 220 /* | |
| 221 PPBPDF()->SaveAs(pp_instance()); | |
| 222 */ | |
| 223 | |
| 224 return TEST_PASSED; | |
| 225 } | |
| 226 | |
| 227 } // namespace | |
| 228 | |
| 229 void SetupTests() { | |
| 230 RegisterTest("TestGetLocalizedString", | |
| 231 TestGetLocalizedString); | |
| 232 RegisterTest("TestGetResourceImage", | |
| 233 TestGetResourceImage); | |
| 234 RegisterTest("TestGetFontFileWithFallback", | |
| 235 TestGetFontFileWithFallback); | |
| 236 RegisterTest("TestGetFontTableForPrivateFontFile", | |
| 237 TestGetFontTableForPrivateFontFile); | |
| 238 RegisterTest("TestSearchString", | |
| 239 TestSearchString); | |
| 240 RegisterTest("TestDidStartLoading", | |
| 241 TestDidStartLoading); | |
| 242 RegisterTest("TestDidStopLoading", | |
| 243 TestDidStopLoading); | |
| 244 RegisterTest("TestSetContentRestriction", | |
| 245 TestSetContentRestriction); | |
| 246 RegisterTest("TestHistogramPDFPageCount", | |
| 247 TestHistogramPDFPageCount); | |
| 248 RegisterTest("TestUserMetricsRecordAction", | |
| 249 TestUserMetricsRecordAction); | |
| 250 RegisterTest("TestHasUnsupportedFeature", | |
| 251 TestHasUnsupportedFeature); | |
| 252 RegisterTest("TestSaveAs", | |
| 253 TestSaveAs); | |
| 254 } | |
| 255 | |
| 256 void SetupPluginInterfaces() { | |
| 257 } | |
| 258 | |
| OLD | NEW |