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