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

Side by Side Diff: trunk/src/content/renderer/pepper/pepper_file_chooser_host_unittest.cc

Issue 22903002: Revert 216744 "Pepper: Move FileRef to the "new" resource proxy." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 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/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_params.h" 8 #include "content/public/common/file_chooser_params.h"
9 #include "content/public/test/render_view_test.h" 9 #include "content/public/test/render_view_test.h"
10 #include "content/renderer/pepper/mock_renderer_ppapi_host.h" 10 #include "content/renderer/pepper/mock_renderer_ppapi_host.h"
11 #include "content/renderer/pepper/pepper_file_chooser_host.h" 11 #include "content/renderer/pepper/pepper_file_chooser_host.h"
12 #include "content/renderer/render_view_impl.h" 12 #include "content/renderer/render_view_impl.h"
13 #include "content/test/test_content_client.h" 13 #include "content/test/test_content_client.h"
14 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/host/host_message_context.h" 15 #include "ppapi/host/host_message_context.h"
16 #include "ppapi/host/ppapi_host.h" 16 #include "ppapi/host/ppapi_host.h"
17 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/proxy/resource_message_params.h" 18 #include "ppapi/proxy/resource_message_params.h"
19 #include "ppapi/proxy/resource_message_test_sink.h" 19 #include "ppapi/proxy/resource_message_test_sink.h"
20 #include "ppapi/shared_impl/ppapi_permissions.h" 20 #include "ppapi/shared_impl/ppapi_permissions.h"
21 #include "ppapi/shared_impl/ppb_file_ref_shared.h"
21 #include "ppapi/shared_impl/resource_tracker.h" 22 #include "ppapi/shared_impl/resource_tracker.h"
22 #include "ppapi/shared_impl/test_globals.h" 23 #include "ppapi/shared_impl/test_globals.h"
23 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/shell_dialogs/selected_file_info.h" 25 #include "ui/shell_dialogs/selected_file_info.h"
25 26
26 namespace content { 27 namespace content {
27 28
28 namespace { 29 namespace {
29 30
30 class PepperFileChooserHostTest : public RenderViewTest { 31 class PepperFileChooserHostTest : public RenderViewTest {
(...skipping 26 matching lines...) Expand all
57 std::string FilePathToUTF8(const base::FilePath::StringType& path) { 58 std::string FilePathToUTF8(const base::FilePath::StringType& path) {
58 #if defined(OS_WIN) 59 #if defined(OS_WIN)
59 return UTF16ToUTF8(path); 60 return UTF16ToUTF8(path);
60 #else 61 #else
61 return path; 62 return path;
62 #endif 63 #endif
63 } 64 }
64 65
65 } // namespace 66 } // namespace
66 67
67 // TODO(teravest): Write a good test for the "Show" interface of FileChooser. 68 TEST_F(PepperFileChooserHostTest, Show) {
68 // We can't do this very easily today because we need direct access to the 69 PP_Resource pp_resource = 123;
69 // RenderViewImpl, but also need renderer and browser instances fully set up. 70
70 // This is was caused by the "new" FileRef refactor, which moved FileRef 71 MockRendererPpapiHost host(view_, pp_instance());
71 // hosting to the browser. http://crbug.com/270322 72 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource);
73
74 // Say there's a user gesture.
75 host.set_has_user_gesture(true);
76
77 std::vector<std::string> accept;
78 accept.push_back("text/plain");
79 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
80
81 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
82 ppapi::host::HostMessageContext context(call_params);
83 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
84 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result);
85
86 // The render view should have sent a chooser request to the browser
87 // (caught by the render thread's test message sink).
88 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
89 ViewHostMsg_RunFileChooser::ID);
90 ASSERT_TRUE(msg);
91 ViewHostMsg_RunFileChooser::Schema::Param call_msg_param;
92 ASSERT_TRUE(ViewHostMsg_RunFileChooser::Read(msg, &call_msg_param));
93 const FileChooserParams& chooser_params = call_msg_param.a;
94
95 // Basic validation of request.
96 EXPECT_EQ(FileChooserParams::Open, chooser_params.mode);
97 ASSERT_EQ(1u, chooser_params.accept_types.size());
98 EXPECT_EQ(accept[0], UTF16ToUTF8(chooser_params.accept_types[0]));
99
100 // Send a chooser reply to the render view. Note our reply path has to have a
101 // path separator so we include both a Unix and a Windows one.
102 ui::SelectedFileInfo selected_info;
103 selected_info.display_name = FILE_PATH_LITERAL("Hello, world");
104 selected_info.local_path = base::FilePath(FILE_PATH_LITERAL("myp\\ath/foo"));
105 std::vector<ui::SelectedFileInfo> selected_info_vector;
106 selected_info_vector.push_back(selected_info);
107 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
108 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(),
109 selected_info_vector);
110 EXPECT_TRUE(view_impl->OnMessageReceived(response));
111
112 // This should have sent the Pepper reply to our test sink.
113 ppapi::proxy::ResourceMessageReplyParams reply_params;
114 IPC::Message reply_msg;
115 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching(
116 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg));
117
118 // Basic validation of reply.
119 EXPECT_EQ(call_params.sequence(), reply_params.sequence());
120 EXPECT_EQ(PP_OK, reply_params.result());
121 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param;
122 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg,
123 &reply_msg_param));
124 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results =
125 reply_msg_param.a;
126 ASSERT_EQ(1u, chooser_results.size());
127 // Note path is empty because this is an external filesystem.
128 EXPECT_EQ(std::string(), chooser_results[0].path);
129 EXPECT_EQ(FilePathToUTF8(selected_info.display_name),
130 chooser_results[0].name);
131 }
72 132
73 TEST_F(PepperFileChooserHostTest, NoUserGesture) { 133 TEST_F(PepperFileChooserHostTest, NoUserGesture) {
74 PP_Resource pp_resource = 123; 134 PP_Resource pp_resource = 123;
75 135
76 MockRendererPpapiHost host(view_, pp_instance()); 136 MockRendererPpapiHost host(view_, pp_instance());
77 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource); 137 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource);
78 138
79 // Say there's no user gesture. 139 // Say there's no user gesture.
80 host.set_has_user_gesture(false); 140 host.set_has_user_gesture(false);
81 141
82 std::vector<std::string> accept; 142 std::vector<std::string> accept;
83 accept.push_back("text/plain"); 143 accept.push_back("text/plain");
84 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); 144 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
85 145
86 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); 146 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
87 ppapi::host::HostMessageContext context(call_params); 147 ppapi::host::HostMessageContext context(call_params);
88 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); 148 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
89 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); 149 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result);
90 } 150 }
91 151
92 } // namespace content 152 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/renderer/pepper/pepper_file_chooser_host.cc ('k') | trunk/src/content/renderer/pepper/pepper_file_io_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698