| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <tuple> |
| 6 | 7 |
| 7 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 9 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 10 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
| 11 #include "content/public/common/file_chooser_file_info.h" | 12 #include "content/public/common/file_chooser_file_info.h" |
| 12 #include "content/public/common/file_chooser_params.h" | 13 #include "content/public/common/file_chooser_params.h" |
| 13 #include "content/public/test/render_view_test.h" | 14 #include "content/public/test/render_view_test.h" |
| 14 #include "content/renderer/pepper/mock_renderer_ppapi_host.h" | 15 #include "content/renderer/pepper/mock_renderer_ppapi_host.h" |
| 15 #include "content/renderer/pepper/pepper_file_chooser_host.h" | 16 #include "content/renderer/pepper/pepper_file_chooser_host.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 int32_t result = chooser.OnResourceMessageReceived(show_msg, &context); | 89 int32_t result = chooser.OnResourceMessageReceived(show_msg, &context); |
| 89 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result); | 90 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 90 | 91 |
| 91 // The render view should have sent a chooser request to the browser | 92 // The render view should have sent a chooser request to the browser |
| 92 // (caught by the render thread's test message sink). | 93 // (caught by the render thread's test message sink). |
| 93 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( | 94 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching( |
| 94 ViewHostMsg_RunFileChooser::ID); | 95 ViewHostMsg_RunFileChooser::ID); |
| 95 ASSERT_TRUE(msg); | 96 ASSERT_TRUE(msg); |
| 96 ViewHostMsg_RunFileChooser::Schema::Param call_msg_param; | 97 ViewHostMsg_RunFileChooser::Schema::Param call_msg_param; |
| 97 ASSERT_TRUE(ViewHostMsg_RunFileChooser::Read(msg, &call_msg_param)); | 98 ASSERT_TRUE(ViewHostMsg_RunFileChooser::Read(msg, &call_msg_param)); |
| 98 const FileChooserParams& chooser_params = base::get<0>(call_msg_param); | 99 const FileChooserParams& chooser_params = std::get<0>(call_msg_param); |
| 99 | 100 |
| 100 // Basic validation of request. | 101 // Basic validation of request. |
| 101 EXPECT_EQ(FileChooserParams::Open, chooser_params.mode); | 102 EXPECT_EQ(FileChooserParams::Open, chooser_params.mode); |
| 102 ASSERT_EQ(1u, chooser_params.accept_types.size()); | 103 ASSERT_EQ(1u, chooser_params.accept_types.size()); |
| 103 EXPECT_EQ(accept[0], base::UTF16ToUTF8(chooser_params.accept_types[0])); | 104 EXPECT_EQ(accept[0], base::UTF16ToUTF8(chooser_params.accept_types[0])); |
| 104 | 105 |
| 105 // Send a chooser reply to the render view. Note our reply path has to have a | 106 // Send a chooser reply to the render view. Note our reply path has to have a |
| 106 // path separator so we include both a Unix and a Windows one. | 107 // path separator so we include both a Unix and a Windows one. |
| 107 content::FileChooserFileInfo selected_info; | 108 content::FileChooserFileInfo selected_info; |
| 108 selected_info.display_name = FILE_PATH_LITERAL("Hello, world"); | 109 selected_info.display_name = FILE_PATH_LITERAL("Hello, world"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 120 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching( | 121 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching( |
| 121 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); | 122 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); |
| 122 | 123 |
| 123 // Basic validation of reply. | 124 // Basic validation of reply. |
| 124 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); | 125 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); |
| 125 EXPECT_EQ(PP_OK, reply_params.result()); | 126 EXPECT_EQ(PP_OK, reply_params.result()); |
| 126 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; | 127 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; |
| 127 ASSERT_TRUE( | 128 ASSERT_TRUE( |
| 128 PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, &reply_msg_param)); | 129 PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, &reply_msg_param)); |
| 129 const std::vector<ppapi::FileRefCreateInfo>& chooser_results = | 130 const std::vector<ppapi::FileRefCreateInfo>& chooser_results = |
| 130 base::get<0>(reply_msg_param); | 131 std::get<0>(reply_msg_param); |
| 131 ASSERT_EQ(1u, chooser_results.size()); | 132 ASSERT_EQ(1u, chooser_results.size()); |
| 132 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), | 133 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), |
| 133 chooser_results[0].display_name); | 134 chooser_results[0].display_name); |
| 134 } | 135 } |
| 135 | 136 |
| 136 TEST_F(PepperFileChooserHostTest, NoUserGesture) { | 137 TEST_F(PepperFileChooserHostTest, NoUserGesture) { |
| 137 PP_Resource pp_resource = 123; | 138 PP_Resource pp_resource = 123; |
| 138 | 139 |
| 139 MockRendererPpapiHost host(view_, pp_instance()); | 140 MockRendererPpapiHost host(view_, pp_instance()); |
| 140 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource); | 141 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource); |
| 141 | 142 |
| 142 // Say there's no user gesture. | 143 // Say there's no user gesture. |
| 143 host.set_has_user_gesture(false); | 144 host.set_has_user_gesture(false); |
| 144 | 145 |
| 145 std::vector<std::string> accept; | 146 std::vector<std::string> accept; |
| 146 accept.push_back("text/plain"); | 147 accept.push_back("text/plain"); |
| 147 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); | 148 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); |
| 148 | 149 |
| 149 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); | 150 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); |
| 150 ppapi::host::HostMessageContext context(call_params); | 151 ppapi::host::HostMessageContext context(call_params); |
| 151 int32_t result = chooser.OnResourceMessageReceived(show_msg, &context); | 152 int32_t result = chooser.OnResourceMessageReceived(show_msg, &context); |
| 152 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); | 153 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); |
| 153 } | 154 } |
| 154 | 155 |
| 155 } // namespace content | 156 } // namespace content |
| OLD | NEW |