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

Side by Side Diff: content/renderer/pepper/pepper_file_chooser_host_browsertest.cc

Issue 10544089: Implement the file chooser as a new resource "host" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/file_path.h"
6 #include "base/utf_string_conversions.h"
7 #include "content/public/test/render_view_test.h"
8 #include "content/common/view_messages.h"
9 #include "content/public/common/file_chooser_params.h"
10 #include "content/public/common/selected_file_info.h"
11 #include "content/renderer/pepper/pepper_file_chooser_host.h"
12 #include "content/renderer/render_view_impl.h"
13 #include "content/test/test_content_client.h"
14 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/host/host_message_context.h"
16 #include "ppapi/host/ppapi_host.h"
17 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/proxy/resource_message_params.h"
19 #include "ppapi/proxy/resource_message_test_sink.h"
20 #include "ppapi/shared_impl/ppb_file_ref_shared.h"
21 #include "ppapi/shared_impl/resource_tracker.h"
22 #include "ppapi/shared_impl/test_globals.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24
25 namespace content {
26
27 namespace {
28
29 class PepperFileChooserHostTest : public RenderViewTest {
30 public:
31 PepperFileChooserHostTest() : pp_instance_(123456) {}
32
33 virtual void SetUp() {
34 SetContentClient(&client_);
35 RenderViewTest::SetUp();
36
37 globals_.GetResourceTracker()->DidCreateInstance(pp_instance_);
38 }
39 virtual void TearDown() {
40 globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_);
41
42 RenderViewTest::TearDown();
43 SetContentClient(NULL);
44 }
45
46 PP_Instance pp_instance() const { return pp_instance_; }
47
48 private:
49 PP_Instance pp_instance_;
50
51 ppapi::TestGlobals globals_;
52 TestContentClient client_;
53 };
54 //typedef RenderViewTest PepperFileChooserHostTest;
55
56 // For testing to convert our hardcoded file paths to 8-bit.
57 std::string FilePathToUTF8(const FilePath::StringType& path) {
58 #if defined(OS_WIN)
59 return UTF16ToUTF8(path);
60 #else
61 return path.value();
62 #endif
63 }
64
65 } // namespace
66
67 TEST_F(PepperFileChooserHostTest, Show) {
68 PP_Resource pp_resource = 123;
69
70 ppapi::proxy::ResourceMessageTestSink sink;
71 ppapi::host::PpapiHost host(&sink, NULL);
72 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
73 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource, view_impl);
74
75 std::vector<std::string> accept;
76 accept.push_back("text/plain");
77 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
78
79 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
80 ppapi::host::HostMessageContext context(call_params);
81 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
82 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result);
83
84 // The render view should have sent a chooser request to the browser
85 // caught by the render thread's test message sink).
86 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
87 ViewHostMsg_RunFileChooser::ID);
88 ASSERT_TRUE(msg);
89 ViewHostMsg_RunFileChooser::Schema::Param call_msg_param;
90 ASSERT_TRUE(ViewHostMsg_RunFileChooser::Read(msg, &call_msg_param));
91 const FileChooserParams& chooser_params = call_msg_param.a;
92
93 // Basic validateion of request.
94 EXPECT_EQ(FileChooserParams::Open, chooser_params.mode);
95 ASSERT_EQ(1u, chooser_params.accept_types.size());
96 EXPECT_EQ(accept[0], UTF16ToUTF8(chooser_params.accept_types[0]));
97
98 // Send a chooser reply to the render view. Note our reply path has to have a
99 // path separator so we include both a Unix and a Windows one.
100 SelectedFileInfo selected_info;
101 selected_info.display_name = FILE_PATH_LITERAL("Hello, world");
102 selected_info.path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo"));
103 std::vector<SelectedFileInfo> selected_info_vector;
104 selected_info_vector.push_back(selected_info);
105 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(), selected_info _vector);
106 EXPECT_TRUE(view_impl->OnMessageReceived(response));
107
108 // This should have sent the Pepper reply to our test sink.
109 ppapi::proxy::ResourceMessageReplyParams reply_params;
110 IPC::Message reply_msg;
111 ASSERT_TRUE(sink.GetFirstResourceReplyMatching(
112 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg));
113
114 // Basic validation of reply.
115 EXPECT_EQ(call_params.sequence(), reply_params.sequence());
116 EXPECT_EQ(PP_OK, reply_params.result());
117 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param;
118 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg,
119 &reply_msg_param));
120 const std::vector<ppapi::PPB_FileRef_CreateInfo>& chooser_results =
121 reply_msg_param.a;
122 ASSERT_EQ(1u, chooser_results.size());
123 // Note path is empty because this is an external filesystem.
124 EXPECT_EQ(std::string(), chooser_results[0].path);
125 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), chooser_results[0].name) ;
126 }
127
128 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_file_chooser_host.cc ('k') | content/renderer/pepper/pepper_in_process_resource_creation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698