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

Side by Side Diff: content/renderer/pepper/pepper_file_chooser_host_browsertest.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/public/test/render_view_test.h" 7 #include "content/public/test/render_view_test.h"
8 #include "content/common/view_messages.h" 8 #include "content/common/view_messages.h"
9 #include "content/public/common/file_chooser_params.h" 9 #include "content/public/common/file_chooser_params.h"
10 #include "content/renderer/pepper/pepper_file_chooser_host.h" 10 #include "content/renderer/pepper/pepper_file_chooser_host.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 // For testing to convert our hardcoded file paths to 8-bit. 57 // For testing to convert our hardcoded file paths to 8-bit.
58 std::string FilePathToUTF8(const FilePath::StringType& path) { 58 std::string FilePathToUTF8(const FilePath::StringType& path) {
59 #if defined(OS_WIN) 59 #if defined(OS_WIN)
60 return UTF16ToUTF8(path); 60 return UTF16ToUTF8(path);
61 #else 61 #else
62 return path; 62 return path;
63 #endif 63 #endif
64 } 64 }
65 65
66 class MockInstanceState : public PepperInstanceStateAccessor {
67 public:
68 MockInstanceState() : has_user_gesture_(true) {}
69 virtual ~MockInstanceState() {}
70
71 void set_has_user_gesture(bool has) { has_user_gesture_ = has; }
72
73 // PepperInstanceStateAccessor.
74 virtual bool IsValidInstance(PP_Instance instance) OVERRIDE {
75 return true;
76 }
77 virtual bool HasUserGesture(PP_Instance instance) OVERRIDE {
78 return has_user_gesture_;
79 }
80
81 private:
82 bool has_user_gesture_;
83 };
84
85 } // namespace 66 } // namespace
86 67
87 TEST_F(PepperFileChooserHostTest, Show) { 68 TEST_F(PepperFileChooserHostTest, Show) {
88 PP_Resource pp_resource = 123; 69 PP_Resource pp_resource = 123;
89 70
90 MockInstanceState state; 71 MockRendererPpapiHost host(view_, pp_instance());
91 ppapi::proxy::ResourceMessageTestSink sink; 72 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource);
92 ppapi::host::PpapiHost host(&sink, NULL, ppapi::PpapiPermissions());
93 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
94 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource, view_impl,
95 &state);
96 73
97 std::vector<std::string> accept; 74 std::vector<std::string> accept;
98 accept.push_back("text/plain"); 75 accept.push_back("text/plain");
99 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); 76 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
100 77
101 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); 78 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
102 ppapi::host::HostMessageContext context(call_params); 79 ppapi::host::HostMessageContext context(call_params);
103 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); 80 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
104 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result); 81 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result);
105 82
(...skipping 18 matching lines...) Expand all
124 selected_info.path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo")); 101 selected_info.path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo"));
125 std::vector<ui::SelectedFileInfo> selected_info_vector; 102 std::vector<ui::SelectedFileInfo> selected_info_vector;
126 selected_info_vector.push_back(selected_info); 103 selected_info_vector.push_back(selected_info);
127 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(), 104 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(),
128 selected_info_vector); 105 selected_info_vector);
129 EXPECT_TRUE(view_impl->OnMessageReceived(response)); 106 EXPECT_TRUE(view_impl->OnMessageReceived(response));
130 107
131 // This should have sent the Pepper reply to our test sink. 108 // This should have sent the Pepper reply to our test sink.
132 ppapi::proxy::ResourceMessageReplyParams reply_params; 109 ppapi::proxy::ResourceMessageReplyParams reply_params;
133 IPC::Message reply_msg; 110 IPC::Message reply_msg;
134 ASSERT_TRUE(sink.GetFirstResourceReplyMatching( 111 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching(
135 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); 112 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg));
136 113
137 // Basic validation of reply. 114 // Basic validation of reply.
138 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); 115 EXPECT_EQ(call_params.sequence(), reply_params.sequence());
139 EXPECT_EQ(PP_OK, reply_params.result()); 116 EXPECT_EQ(PP_OK, reply_params.result());
140 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; 117 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param;
141 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, 118 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg,
142 &reply_msg_param)); 119 &reply_msg_param));
143 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results = 120 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results =
144 reply_msg_param.a; 121 reply_msg_param.a;
145 ASSERT_EQ(1u, chooser_results.size()); 122 ASSERT_EQ(1u, chooser_results.size());
146 // Note path is empty because this is an external filesystem. 123 // Note path is empty because this is an external filesystem.
147 EXPECT_EQ(std::string(), chooser_results[0].path); 124 EXPECT_EQ(std::string(), chooser_results[0].path);
148 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), 125 EXPECT_EQ(FilePathToUTF8(selected_info.display_name),
149 chooser_results[0].name); 126 chooser_results[0].name);
150 } 127 }
151 128
152 TEST_F(PepperFileChooserHostTest, NoUserGesture) { 129 TEST_F(PepperFileChooserHostTest, NoUserGesture) {
153 PP_Resource pp_resource = 123; 130 PP_Resource pp_resource = 123;
154 131
155 MockInstanceState state; 132 MockRendererPpapiHost host(view_, pp_instance());
156 ppapi::proxy::ResourceMessageTestSink sink; 133 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource);
157 ppapi::host::PpapiHost host(&sink, NULL, ppapi::PpapiPermissions());
158 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
159 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource, view_impl,
160 &state);
161 134
162 // Say there's no user gesture. 135 // Say there's no user gesture.
163 state.set_has_user_gesture(false); 136 host.set_has_user_gesture(false);
164 137
165 std::vector<std::string> accept; 138 std::vector<std::string> accept;
166 accept.push_back("text/plain"); 139 accept.push_back("text/plain");
167 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); 140 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
168 141
169 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); 142 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
170 ppapi::host::HostMessageContext context(call_params); 143 ppapi::host::HostMessageContext context(call_params);
171 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); 144 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
172 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); 145 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result);
173 } 146 }
174 147
175 } // namespace content 148 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698