cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / ppapi / proxy / file_chooser_resource_unittest.cc
bloba5801eed161c00a9055c220832fc529aee08d9b3
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 "base/message_loop/message_loop.h"
6 #include "ppapi/c/dev/ppb_file_chooser_dev.h"
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/proxy/file_chooser_resource.h"
9 #include "ppapi/proxy/locking_resource_releaser.h"
10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/proxy/ppapi_proxy_test.h"
12 #include "ppapi/shared_impl/proxy_lock.h"
13 #include "ppapi/shared_impl/scoped_pp_var.h"
14 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/thunk/thunk.h"
17 namespace ppapi {
18 namespace proxy {
20 namespace {
22 typedef PluginProxyTest FileChooserResourceTest;
24 void* GetFileRefDataBuffer(void* user_data,
25 uint32_t element_count,
26 uint32_t element_size) {
27 EXPECT_TRUE(element_size == sizeof(PP_Resource));
28 std::vector<PP_Resource>* output =
29 static_cast<std::vector<PP_Resource>*>(user_data);
30 output->resize(element_count);
31 if (element_count > 0)
32 return &(*output)[0];
33 return NULL;
36 void DoNothingCallback(void* user_data, int32_t result) {
39 // Calls PopulateAcceptTypes and verifies that the resulting array contains
40 // the given values. The values may be NULL if there aren't expected to be
41 // that many results.
42 bool CheckParseAcceptType(const std::string& input,
43 const char* expected1,
44 const char* expected2) {
45 std::vector<std::string> output;
46 FileChooserResource::PopulateAcceptTypes(input, &output);
48 const size_t kCount = 2;
49 const char* expected[kCount] = { expected1, expected2 };
51 for (size_t i = 0; i < kCount; i++) {
52 if (!expected[i])
53 return i == output.size();
54 if (output.size() <= i)
55 return false;
56 if (output[i] != expected[i])
57 return false;
60 return output.size() == kCount;
63 } // namespace
65 // Does a full test of Show() and reply functionality in the plugin side using
66 // the public C interfaces.
67 TEST_F(FileChooserResourceTest, Show) {
68 const PPB_FileChooser_Dev_0_6* chooser_iface =
69 thunk::GetPPB_FileChooser_Dev_0_6_Thunk();
70 LockingResourceReleaser res(
71 chooser_iface->Create(pp_instance(), PP_FILECHOOSERMODE_OPEN,
72 PP_MakeUndefined()));
74 std::vector<PP_Resource> dest;
75 PP_ArrayOutput output;
76 output.GetDataBuffer = &GetFileRefDataBuffer;
77 output.user_data = &dest;
79 int32_t result = chooser_iface->Show(
80 res.get(), output, PP_MakeCompletionCallback(&DoNothingCallback, NULL));
81 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result);
83 // Should have sent a "show" message.
84 ResourceMessageCallParams params;
85 IPC::Message msg;
86 ASSERT_TRUE(sink().GetFirstResourceCallMatching(
87 PpapiHostMsg_FileChooser_Show::ID, &params, &msg));
89 ResourceMessageReplyParams reply_params(params.pp_resource(),
90 params.sequence());
91 reply_params.set_result(PP_OK);
93 // Synthesize a response with one file ref in it. Note that it must have a
94 // host resource value set or deserialization will fail. Since there isn't
95 // actually a host, this can be whatever we want.
96 std::vector<PPB_FileRef_CreateInfo> create_info_array;
97 PPB_FileRef_CreateInfo create_info;
98 create_info.resource.SetHostResource(pp_instance(), 123);
99 create_info.path = "foo/bar";
100 create_info.name = "baz";
101 create_info_array.push_back(create_info);
102 ASSERT_TRUE(plugin_dispatcher()->OnMessageReceived(
103 PpapiPluginMsg_ResourceReply(reply_params,
104 PpapiPluginMsg_FileChooser_ShowReply(create_info_array))));
106 // Should have populated our vector.
107 ASSERT_EQ(1u, dest.size());
108 LockingResourceReleaser dest_deletor(dest[0]); // Ensure it's cleaned up.
110 const PPB_FileRef_1_0* file_ref_iface = thunk::GetPPB_FileRef_1_0_Thunk();
111 EXPECT_EQ(PP_FILESYSTEMTYPE_EXTERNAL,
112 file_ref_iface->GetFileSystemType(dest[0]));
114 PP_Var name_var(file_ref_iface->GetName(dest[0]));
116 ProxyAutoLock lock;
117 ScopedPPVar release_name_var(ScopedPPVar::PassRef(), name_var);
118 EXPECT_VAR_IS_STRING(create_info.name, name_var);
120 // Path should be undefined since it's external filesystem.
121 PP_Var path_var(file_ref_iface->GetPath(dest[0]));
123 ProxyAutoLock lock;
124 ScopedPPVar release_path_var(ScopedPPVar::PassRef(), path_var);
125 EXPECT_EQ(PP_VARTYPE_UNDEFINED, path_var.type);
129 TEST_F(FileChooserResourceTest, PopulateAcceptTypes) {
130 EXPECT_TRUE(CheckParseAcceptType(std::string(), NULL, NULL));
131 EXPECT_TRUE(CheckParseAcceptType("/", NULL, NULL));
132 EXPECT_TRUE(CheckParseAcceptType(".", NULL, NULL));
133 EXPECT_TRUE(CheckParseAcceptType(",, , ", NULL, NULL));
135 EXPECT_TRUE(CheckParseAcceptType("app/txt", "app/txt", NULL));
136 EXPECT_TRUE(CheckParseAcceptType("app/txt,app/pdf", "app/txt", "app/pdf"));
137 EXPECT_TRUE(CheckParseAcceptType(" app/txt , app/pdf ",
138 "app/txt", "app/pdf"));
140 // No dot or slash ones should be skipped.
141 EXPECT_TRUE(CheckParseAcceptType("foo", NULL, NULL));
142 EXPECT_TRUE(CheckParseAcceptType("foo,.txt", ".txt", NULL));
145 } // namespace proxy
146 } // namespace ppapi