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