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

Side by Side Diff: tests/ppapi_file_system/ppapi_file_system.cc

Issue 7167018: Migrating test/ppapi_file_system to messaging (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 6 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
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdio.h> 5 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h"
6 #include <stdlib.h> 6 #include "native_client/tests/ppapi_test_lib/test_interface.h"
7 #include <string.h> 7 #include "native_client/src/shared/platform/nacl_check.h"
8 8 #include "ppapi/c/dev/ppb_file_system_dev.h"
9 #include "native_client/src/include/portability.h" 9 #include "ppapi/c/ppb_core.h"
10 #include "ppapi/c/dev/ppb_var_deprecated.h" 10 #include "ppapi/c/ppb_url_request_info.h"
11 #include "ppapi/c/pp_errors.h" 11 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/c/pp_module.h"
13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/c/ppb.h"
15 #include "ppapi/c/ppp_instance.h"
16 #include "ppapi/c/ppp.h"
17
18
19 // Defined in scriptable_object.c
20 extern "C" struct PP_Var GetScriptableObject(PP_Instance plugin_instance);
21
22 // Global variables
23 extern PPB_GetInterface get_browser_interface_func;
24 extern PP_Module module;
25 12
26 namespace { 13 namespace {
27 14
28 PP_Bool DidCreate(PP_Instance /*instance*/, 15 void OpenCallback(void* /*data*/, int32_t /*result*/) {
29 uint32_t /*argc*/, 16 }
30 const char** /*argn*/, 17
31 const char** /*argv*/) { 18 const PP_FileSystemType_Dev kFileSystemTypes[] = {
32 return PP_TRUE; 19 PP_FILESYSTEMTYPE_EXTERNAL,
33 } 20 PP_FILESYSTEMTYPE_LOCALPERSISTENT,
34 21 PP_FILESYSTEMTYPE_LOCALTEMPORARY
35 void DidDestroy(PP_Instance /*instance*/) { 22 };
36 } 23
37 24 const size_t kNumFileSystemTypes =
38 void DidChangeView(PP_Instance /*instance*/, 25 sizeof(kFileSystemTypes) / sizeof(kFileSystemTypes[0]);
39 const struct PP_Rect* /*position*/, 26
40 const struct PP_Rect* /*clip*/) { 27 void TestCreate() {
41 } 28 PP_Resource file_system = kInvalidResource;
42 29 const struct PPB_Core* const ppb_core = PPBCore();
43 void DidChangeFocus(PP_Instance /*instance*/, 30 const struct PPB_FileSystem_Dev* const ppb_file_system = PPBFileSystemDev();
44 PP_Bool /*has_focus*/) { 31 /*
45 } 32 * Test to see if PPB_FileSystem_Dev::Create returns PP_Resource value of 0
46 33 * if the instance parameter is invalid.
47 PP_Bool HandleInputEvent(PP_Instance /*instance*/, 34 */
48 const struct PP_InputEvent* /*event*/) { 35 file_system = ppb_file_system->Create(kInvalidInstance,
49 return PP_TRUE; 36 PP_FILESYSTEMTYPE_EXTERNAL);
50 } 37 EXPECT_ASYNC(file_system == kInvalidResource);
51 38 file_system = ppb_file_system->Create(kInvalidInstance,
52 static PP_Bool HandleDocumentLoad(PP_Instance /*instance*/, 39 PP_FILESYSTEMTYPE_LOCALPERSISTENT);
53 PP_Resource /*url_loader*/) { 40 EXPECT_ASYNC(file_system == kInvalidResource);
54 return PP_TRUE; 41 file_system = ppb_file_system->Create(kInvalidInstance,
55 } 42 PP_FILESYSTEMTYPE_LOCALTEMPORARY);
56 43 EXPECT_ASYNC(file_system == kInvalidResource);
57 struct PP_Var GetInstanceObject(PP_Instance instance) { 44
58 return GetScriptableObject(instance); 45 /* Test for failure when an invalid file system type is requested. */
46 file_system = ppb_file_system->Create(pp_instance(),
47 PP_FILESYSTEMTYPE_INVALID);
48 EXPECT_ASYNC(file_system == kInvalidResource);
49
50 /*
51 * Test to see if PPB_FileSystem_Dev::Create returns a valid PP_Resource
52 * value when given a valid PP_Instance value parameter. Test for all
53 * three file system types PPB_FileSystem_Dev supports.
54 */
55 for (size_t j = 0; j < kNumFileSystemTypes; ++j) {
56 file_system =
57 ppb_file_system->Create(pp_instance(), kFileSystemTypes[j]);
58 EXPECT_ASYNC(file_system != kInvalidResource);
59 ppb_core->ReleaseResource(file_system);
60 }
61 TEST_PASSED_ASYNC;
62 }
63
64 void TestIsFileSystem() {
65 const struct PPB_Core* const ppb_core = PPBCore();
66 const struct PPB_FileSystem_Dev* const ppb_file_system = PPBFileSystemDev();
67 const struct PPB_URLRequestInfo* const ppb_url_request_info =
68 PPBURLRequestInfo();
69 PP_Resource url_request_info = kInvalidResource;
70 PP_Resource file_system = kInvalidResource;
71 size_t j = 0;
72 PP_Bool is_file_system = PP_FALSE;
73
74 /* Test fail for invalid resource. */
75 EXPECT_ASYNC(ppb_file_system->IsFileSystem(kInvalidResource) != PP_TRUE);
76
77 /*
78 * Test pass for the different valid system types, and test fail against a
79 * resource that has been released.
80 */
81 for (j = 0; j < kNumFileSystemTypes; ++j) {
82 file_system = ppb_file_system->Create(pp_instance(),
83 kFileSystemTypes[j]);
84 CHECK(file_system != kInvalidResource);
85
86 is_file_system = ppb_file_system->IsFileSystem(file_system);
87 ppb_core->ReleaseResource(file_system);
88
89 EXPECT_ASYNC(is_file_system == PP_TRUE);
90
91 is_file_system = ppb_file_system->IsFileSystem(file_system);
92 EXPECT_ASYNC(is_file_system == PP_FALSE);
93 }
94
95 /* Test fail against a non-filesystem resource */
96 url_request_info = ppb_url_request_info->Create(pp_instance());
97 CHECK(url_request_info != kInvalidResource);
98 is_file_system = ppb_file_system->IsFileSystem(url_request_info);
99 ppb_core->ReleaseResource(url_request_info);
100 EXPECT_ASYNC(is_file_system == PP_FALSE);
101
102 TEST_PASSED_ASYNC;
103 }
104
105 void TestOpen() {
106 size_t j = 0;
107 PP_Resource file_system = 0;
108 const struct PP_CompletionCallback open_callback =
109 MakeTestableCompletionCallback(
110 "OpenCallback",
111 OpenCallback,
112 NULL); // user data
113 const struct PPB_Core* const ppb_core = PPBCore();
114 const struct PPB_FileSystem_Dev* const ppb_file_system = PPBFileSystemDev();
115
116 /* Test to make sure opening an invalid file system fails. */
117 int32_t pp_error = ppb_file_system->Open(kInvalidResource,
118 1024, /* Dummy value */
119 open_callback);
120 EXPECT_ASYNC(pp_error == PP_ERROR_BADRESOURCE);
121
122 /*
123 * Test to make sure external file system is not supported.
124 * TODO(sanga): Once Chrome supports external file systems, change this test
125 * to reflect the change.
126 */
127 file_system = ppb_file_system->Create(pp_instance(),
128 PP_FILESYSTEMTYPE_EXTERNAL);
129 pp_error = ppb_file_system->Open(file_system,
130 1024, /* Dummy value */
131 open_callback);
132 ppb_core->ReleaseResource(file_system);
133 EXPECT_ASYNC(pp_error != PP_OK);
134 EXPECT_ASYNC(pp_error != PP_OK_COMPLETIONPENDING);
135
136 /* Test local temporary and local persistant file systems */
137 for (j = 1; j < kNumFileSystemTypes; ++j) {
138 #ifdef __native_client__
139 /* Test fail for blocking open */
140 /*
141 * Only conduct this test with nexe. Trusted ppapi plugin does not work
142 * with synchronous Open call.
143 * See http://code.google.com/p/chromium/issues/detail?id=78449
144 */
145 file_system = ppb_file_system->Create(pp_instance(),
146 kFileSystemTypes[j]);
147 pp_error = ppb_file_system->Open(file_system,
148 1024, /* Dummy value */
149 PP_BlockUntilComplete());
150 ppb_core->ReleaseResource(file_system);
151 EXPECT_ASYNC(pp_error == PP_ERROR_BADARGUMENT);
152 #endif
153
154 /* Test success for asynchronous open */
155 file_system = ppb_file_system->Create(pp_instance(),
156 kFileSystemTypes[j]);
157 pp_error = ppb_file_system->Open(file_system,
158 1024, /* Dummy value */
159 open_callback);
160 ppb_core->ReleaseResource(file_system);
161 EXPECT_ASYNC(pp_error == PP_OK_COMPLETIONPENDING);
162
163 /* Test fail for multiple opens */
164 file_system = ppb_file_system->Create(pp_instance(),
165 kFileSystemTypes[j]);
166 pp_error = ppb_file_system->Open(file_system,
167 1024, /* Dummy value */
168 open_callback);
169 CHECK(pp_error == PP_OK_COMPLETIONPENDING); /* Previously tested */
170 pp_error = ppb_file_system->Open(file_system,
171 1024, /* Dummy value */
172 open_callback);
173 ppb_core->ReleaseResource(file_system);
174 EXPECT_ASYNC(pp_error == PP_ERROR_FAILED);
175 }
176 TEST_PASSED_ASYNC;
177 }
178
179 void TestGetType() {
180 #if 1
181 printf("WHAAAAAAA?!?!?!\n");
David Springer 2011/06/15 21:40:27 Are you sure that this is useful test output?
Sang Ahn 2011/06/15 22:27:42 That's too funny. On 2011/06/15 21:40:27, David S
182 TEST_PASSED_ASYNC;
183 #else
184 const struct PPB_Core* const ppb_core = PPBCore();
David Springer 2011/06/15 21:40:27 It seems like this code inside the #else clause sh
Sang Ahn 2011/06/15 22:27:42 Done.
185 const struct PPB_FileSystem_Dev* const ppb_file_system = PPBFileSystemDev();
186 const struct PPB_URLRequestInfo* const ppb_url_request_info =
187 PPBURLRequestInfo();
188 PP_Resource url_request_info = kInvalidResource;
189 PP_Resource file_system = kInvalidResource;
190 size_t j = 0;
191 PP_FileSystemType_Dev type = PP_FILESYSTEMTYPE_INVALID;
192
193 /* Test for invalid resource. */
194 EXPECT_ASYNC(PP_FILESYSTEMTYPE_INVALID == ppb_file_system->GetType(0));
195
196 /* Test pass for the different valid system types */
197 for (j = 0; j < kNumFileSystemTypes; ++j) {
198 file_system = ppb_file_system->Create(pp_instance(),
199 kFileSystemTypes[j]);
200 CHECK(file_system != kInvalidResource);
201
202 type = ppb_file_system->GetType(file_system);
203 ppb_core->ReleaseResource(file_system);
204
205 EXPECT_ASYNC(type == kFileSystemTypes[j]);
206 }
207
208 /* Test fail against a non-filesystem resource */
209 url_request_info = ppb_url_request_info->Create(pp_instance());
210 CHECK(url_request_info != kInvalidResource);
211
212 type = ppb_file_system->GetType(url_request_info);
213 ppb_core->ReleaseResource(url_request_info);
214 EXPECT_ASYNC(type == PP_FILESYSTEMTYPE_INVALID);
215
216 TEST_PASSED_ASYNC;
217 #endif
59 } 218 }
60 219
61 } // namespace 220 } // namespace
62 221
63 // Implementations of the PPP entry points expected by the browser 222 void SetupTests() {
64 extern "C" { 223 RegisterTest("TestCreate", TestCreate);
65 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module_id, 224 RegisterTest("TestIsFileSystem", TestIsFileSystem);
66 PPB_GetInterface get_browser_interface) { 225 RegisterTest("TestOpen", TestOpen);
67 module = module_id; 226 RegisterTest("TestGetType", TestGetType);
68 get_browser_interface_func = get_browser_interface; 227 }
69 return PP_OK; 228
70 } 229 void SetupPluginInterfaces() {
71 230 /* No PPP interface to test. */
72 PP_EXPORT void PPP_ShutdownModule() { 231 }
73 }
74
75 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
76 if (0 == strncmp(PPP_INSTANCE_INTERFACE, interface_name,
77 strlen(PPP_INSTANCE_INTERFACE))) {
78 static struct PPP_Instance instance_interface = {
79 DidCreate,
80 DidDestroy,
81 DidChangeView,
82 DidChangeFocus,
83 HandleInputEvent,
84 HandleDocumentLoad,
85 GetInstanceObject
86 };
87 return &instance_interface;
88 }
89 return NULL;
90 }
91 } // extern "C"
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698