| OLD | NEW |
| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 // For testing to convert our hardcoded file paths to 8-bit. | 63 // For testing to convert our hardcoded file paths to 8-bit. |
| 64 std::string FilePathToUTF8(const FilePath::StringType& path) { | 64 std::string FilePathToUTF8(const FilePath::StringType& path) { |
| 65 #if defined(OS_WIN) | 65 #if defined(OS_WIN) |
| 66 return UTF16ToUTF8(path); | 66 return UTF16ToUTF8(path); |
| 67 #else | 67 #else |
| 68 return path; | 68 return path; |
| 69 #endif | 69 #endif |
| 70 } | 70 } |
| 71 | 71 |
| 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 | 72 } // namespace |
| 92 | 73 |
| 93 TEST_F(PepperFileChooserHostTest, Show) { | 74 TEST_F(PepperFileChooserHostTest, Show) { |
| 94 PP_Resource pp_resource = 123; | 75 PP_Resource pp_resource = 123; |
| 95 | 76 |
| 96 MockInstanceState state; | 77 MockRendererPpapiHost host(view_, pp_instance()); |
| 97 ppapi::proxy::ResourceMessageTestSink sink; | 78 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 | 79 |
| 103 std::vector<std::string> accept; | 80 std::vector<std::string> accept; |
| 104 accept.push_back("text/plain"); | 81 accept.push_back("text/plain"); |
| 105 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); | 82 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); |
| 106 | 83 |
| 107 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); | 84 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); |
| 108 ppapi::host::HostMessageContext context(call_params); | 85 ppapi::host::HostMessageContext context(call_params); |
| 109 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); | 86 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); |
| 110 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result); | 87 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 111 | 88 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 130 selected_info.path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo")); | 107 selected_info.path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo")); |
| 131 std::vector<ui::SelectedFileInfo> selected_info_vector; | 108 std::vector<ui::SelectedFileInfo> selected_info_vector; |
| 132 selected_info_vector.push_back(selected_info); | 109 selected_info_vector.push_back(selected_info); |
| 133 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(), | 110 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(), |
| 134 selected_info_vector); | 111 selected_info_vector); |
| 135 EXPECT_TRUE(view_impl->OnMessageReceived(response)); | 112 EXPECT_TRUE(view_impl->OnMessageReceived(response)); |
| 136 | 113 |
| 137 // This should have sent the Pepper reply to our test sink. | 114 // This should have sent the Pepper reply to our test sink. |
| 138 ppapi::proxy::ResourceMessageReplyParams reply_params; | 115 ppapi::proxy::ResourceMessageReplyParams reply_params; |
| 139 IPC::Message reply_msg; | 116 IPC::Message reply_msg; |
| 140 ASSERT_TRUE(sink.GetFirstResourceReplyMatching( | 117 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching( |
| 141 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); | 118 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); |
| 142 | 119 |
| 143 // Basic validation of reply. | 120 // Basic validation of reply. |
| 144 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); | 121 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); |
| 145 EXPECT_EQ(PP_OK, reply_params.result()); | 122 EXPECT_EQ(PP_OK, reply_params.result()); |
| 146 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; | 123 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; |
| 147 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, | 124 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, |
| 148 &reply_msg_param)); | 125 &reply_msg_param)); |
| 149 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results = | 126 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results = |
| 150 reply_msg_param.a; | 127 reply_msg_param.a; |
| 151 ASSERT_EQ(1u, chooser_results.size()); | 128 ASSERT_EQ(1u, chooser_results.size()); |
| 152 // Note path is empty because this is an external filesystem. | 129 // Note path is empty because this is an external filesystem. |
| 153 EXPECT_EQ(std::string(), chooser_results[0].path); | 130 EXPECT_EQ(std::string(), chooser_results[0].path); |
| 154 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), | 131 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), |
| 155 chooser_results[0].name); | 132 chooser_results[0].name); |
| 156 } | 133 } |
| 157 | 134 |
| 158 TEST_F(PepperFileChooserHostTest, NoUserGesture) { | 135 TEST_F(PepperFileChooserHostTest, NoUserGesture) { |
| 159 PP_Resource pp_resource = 123; | 136 PP_Resource pp_resource = 123; |
| 160 | 137 |
| 161 MockInstanceState state; | 138 MockRendererPpapiHost host(view_, pp_instance()); |
| 162 ppapi::proxy::ResourceMessageTestSink sink; | 139 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 | 140 |
| 168 // Say there's no user gesture. | 141 // Say there's no user gesture. |
| 169 state.set_has_user_gesture(false); | 142 host.set_has_user_gesture(false); |
| 170 | 143 |
| 171 std::vector<std::string> accept; | 144 std::vector<std::string> accept; |
| 172 accept.push_back("text/plain"); | 145 accept.push_back("text/plain"); |
| 173 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); | 146 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); |
| 174 | 147 |
| 175 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); | 148 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); |
| 176 ppapi::host::HostMessageContext context(call_params); | 149 ppapi::host::HostMessageContext context(call_params); |
| 177 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); | 150 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); |
| 178 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); | 151 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); |
| 179 } | 152 } |
| 180 | 153 |
| 181 } // namespace content | 154 } // namespace content |
| OLD | NEW |