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

Side by Side Diff: content/renderer/pepper/pepper_file_chooser_host_unittest.cc

Issue 10815073: Refactoring of new IPC-only pepper implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "content/common/view_messages.h" 7 #include "content/common/view_messages.h"
8 #include "content/public/test/render_view_test.h" 8 #include "content/public/test/render_view_test.h"
9 #include "content/public/common/file_chooser_params.h" 9 #include "content/public/common/file_chooser_params.h"
10 #include "content/renderer/pepper/mock_renderer_ppapi_host.h"
10 #include "content/renderer/pepper/pepper_file_chooser_host.h" 11 #include "content/renderer/pepper/pepper_file_chooser_host.h"
11 #include "content/renderer/pepper/pepper_instance_state_accessor.h" 12 //#include "content/renderer/pepper/pepper_instance_state_accessor.h"
12 #include "content/renderer/render_view_impl.h" 13 #include "content/renderer/render_view_impl.h"
13 #include "content/test/test_content_client.h" 14 #include "content/test/test_content_client.h"
14 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/host/host_message_context.h" 16 #include "ppapi/host/host_message_context.h"
16 #include "ppapi/host/ppapi_host.h" 17 #include "ppapi/host/ppapi_host.h"
17 #include "ppapi/proxy/ppapi_messages.h" 18 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/proxy/resource_message_params.h" 19 #include "ppapi/proxy/resource_message_params.h"
19 #include "ppapi/proxy/resource_message_test_sink.h" 20 #include "ppapi/proxy/resource_message_test_sink.h"
20 #include "ppapi/shared_impl/ppapi_permissions.h" 21 #include "ppapi/shared_impl/ppapi_permissions.h"
21 #include "ppapi/shared_impl/ppb_file_ref_shared.h" 22 #include "ppapi/shared_impl/ppb_file_ref_shared.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 63
63 // For testing to convert our hardcoded file paths to 8-bit. 64 // For testing to convert our hardcoded file paths to 8-bit.
64 std::string FilePathToUTF8(const FilePath::StringType& path) { 65 std::string FilePathToUTF8(const FilePath::StringType& path) {
65 #if defined(OS_WIN) 66 #if defined(OS_WIN)
66 return UTF16ToUTF8(path); 67 return UTF16ToUTF8(path);
67 #else 68 #else
68 return path; 69 return path;
69 #endif 70 #endif
70 } 71 }
71 72
72 class MockInstanceState : public PepperInstanceStateAccessor {
73 public:
74 MockInstanceState() : has_user_gesture_(true) {}
75 virtual ~MockInstanceState() {}
76
77 void set_has_user_gesture(bool has) { has_user_gesture_ = has; }
78
79 // PepperInstanceStateAccessor.
80 virtual bool IsValidInstance(PP_Instance instance) OVERRIDE {
81 return true;
82 }
83 virtual bool HasUserGesture(PP_Instance instance) OVERRIDE {
84 return has_user_gesture_;
85 }
86
87 private:
88 bool has_user_gesture_;
89 };
90
91 } // namespace 73 } // namespace
92 74
93 TEST_F(PepperFileChooserHostTest, Show) { 75 TEST_F(PepperFileChooserHostTest, Show) {
94 PP_Resource pp_resource = 123; 76 PP_Resource pp_resource = 123;
95 77
96 MockInstanceState state; 78 MockRendererPpapiHost host(view_, pp_instance());
97 ppapi::proxy::ResourceMessageTestSink sink; 79 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource);
98 ppapi::host::PpapiHost host(&sink, NULL, ppapi::PpapiPermissions());
99 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
100 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource, view_impl,
101 &state);
102 80
103 std::vector<std::string> accept; 81 std::vector<std::string> accept;
104 accept.push_back("text/plain"); 82 accept.push_back("text/plain");
105 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); 83 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
106 84
107 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); 85 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
108 ppapi::host::HostMessageContext context(call_params); 86 ppapi::host::HostMessageContext context(call_params);
109 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); 87 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
110 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result); 88 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result);
111 89
(...skipping 11 matching lines...) Expand all
123 ASSERT_EQ(1u, chooser_params.accept_types.size()); 101 ASSERT_EQ(1u, chooser_params.accept_types.size());
124 EXPECT_EQ(accept[0], UTF16ToUTF8(chooser_params.accept_types[0])); 102 EXPECT_EQ(accept[0], UTF16ToUTF8(chooser_params.accept_types[0]));
125 103
126 // Send a chooser reply to the render view. Note our reply path has to have a 104 // Send a chooser reply to the render view. Note our reply path has to have a
127 // path separator so we include both a Unix and a Windows one. 105 // path separator so we include both a Unix and a Windows one.
128 ui::SelectedFileInfo selected_info; 106 ui::SelectedFileInfo selected_info;
129 selected_info.display_name = FILE_PATH_LITERAL("Hello, world"); 107 selected_info.display_name = FILE_PATH_LITERAL("Hello, world");
130 selected_info.local_path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo")); 108 selected_info.local_path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo"));
131 std::vector<ui::SelectedFileInfo> selected_info_vector; 109 std::vector<ui::SelectedFileInfo> selected_info_vector;
132 selected_info_vector.push_back(selected_info); 110 selected_info_vector.push_back(selected_info);
111 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
133 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(), 112 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(),
134 selected_info_vector); 113 selected_info_vector);
135 EXPECT_TRUE(view_impl->OnMessageReceived(response)); 114 EXPECT_TRUE(view_impl->OnMessageReceived(response));
136 115
137 // This should have sent the Pepper reply to our test sink. 116 // This should have sent the Pepper reply to our test sink.
138 ppapi::proxy::ResourceMessageReplyParams reply_params; 117 ppapi::proxy::ResourceMessageReplyParams reply_params;
139 IPC::Message reply_msg; 118 IPC::Message reply_msg;
140 ASSERT_TRUE(sink.GetFirstResourceReplyMatching( 119 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching(
141 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); 120 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg));
142 121
143 // Basic validation of reply. 122 // Basic validation of reply.
144 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); 123 EXPECT_EQ(call_params.sequence(), reply_params.sequence());
145 EXPECT_EQ(PP_OK, reply_params.result()); 124 EXPECT_EQ(PP_OK, reply_params.result());
146 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; 125 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param;
147 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, 126 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg,
148 &reply_msg_param)); 127 &reply_msg_param));
149 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results = 128 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results =
150 reply_msg_param.a; 129 reply_msg_param.a;
151 ASSERT_EQ(1u, chooser_results.size()); 130 ASSERT_EQ(1u, chooser_results.size());
152 // Note path is empty because this is an external filesystem. 131 // Note path is empty because this is an external filesystem.
153 EXPECT_EQ(std::string(), chooser_results[0].path); 132 EXPECT_EQ(std::string(), chooser_results[0].path);
154 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), 133 EXPECT_EQ(FilePathToUTF8(selected_info.display_name),
155 chooser_results[0].name); 134 chooser_results[0].name);
156 } 135 }
157 136
158 TEST_F(PepperFileChooserHostTest, NoUserGesture) { 137 TEST_F(PepperFileChooserHostTest, NoUserGesture) {
159 PP_Resource pp_resource = 123; 138 PP_Resource pp_resource = 123;
160 139
161 MockInstanceState state; 140 MockRendererPpapiHost host(view_, pp_instance());
162 ppapi::proxy::ResourceMessageTestSink sink; 141 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource);
163 ppapi::host::PpapiHost host(&sink, NULL, ppapi::PpapiPermissions());
164 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
165 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource, view_impl,
166 &state);
167 142
168 // Say there's no user gesture. 143 // Say there's no user gesture.
169 state.set_has_user_gesture(false); 144 host.set_has_user_gesture(false);
170 145
171 std::vector<std::string> accept; 146 std::vector<std::string> accept;
172 accept.push_back("text/plain"); 147 accept.push_back("text/plain");
173 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); 148 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
174 149
175 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); 150 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
176 ppapi::host::HostMessageContext context(call_params); 151 ppapi::host::HostMessageContext context(call_params);
177 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); 152 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
178 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); 153 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result);
179 } 154 }
180 155
181 } // namespace content 156 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_file_chooser_host.cc ('k') | content/renderer/pepper/pepper_in_process_resource_creation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698