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

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, 5 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
55 // For testing to convert our hardcoded file paths to 8-bit.
56 std::string FilePathToUTF8(const FilePath::StringType& path) {
57 #if defined(OS_WIN)
58 return UTF16ToUTF8(path);
59 #else
60 return path.value();
61 #endif
62 }
63
64 } // namespace
65
66 TEST_F(PepperFileChooserHostTest, Show) {
67 PP_Resource pp_resource = 123;
68
69 ppapi::proxy::ResourceMessageTestSink sink;
70 ppapi::host::PpapiHost host(&sink, NULL);
71 RenderViewImpl* view_impl = static_cast<RenderViewImpl*>(view_);
72 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource, view_impl);
73
74 std::vector<std::string> accept;
75 accept.push_back("text/plain");
76 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept);
77
78 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0);
79 ppapi::host::HostMessageContext context(call_params);
80 int32 result = chooser.OnResourceMessageReceived(show_msg, &context);
81 EXPECT_EQ(PP_OK_COMPLETIONPENDING, result);
82
83 // The render view should have sent a chooser request to the browser
84 // caught by the render thread's test message sink).
bbudge 2012/07/02 20:06:06 opening paren missing?
85 const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
86 ViewHostMsg_RunFileChooser::ID);
87 ASSERT_TRUE(msg);
88 ViewHostMsg_RunFileChooser::Schema::Param call_msg_param;
89 ASSERT_TRUE(ViewHostMsg_RunFileChooser::Read(msg, &call_msg_param));
90 const FileChooserParams& chooser_params = call_msg_param.a;
91
92 // Basic validateion of request.
bbudge 2012/07/02 20:06:06 sp. validation
93 EXPECT_EQ(FileChooserParams::Open, chooser_params.mode);
94 ASSERT_EQ(1u, chooser_params.accept_types.size());
95 EXPECT_EQ(accept[0], UTF16ToUTF8(chooser_params.accept_types[0]));
96
97 // Send a chooser reply to the render view. Note our reply path has to have a
98 // path separator so we include both a Unix and a Windows one.
99 SelectedFileInfo selected_info;
100 selected_info.display_name = FILE_PATH_LITERAL("Hello, world");
101 selected_info.path = FilePath(FILE_PATH_LITERAL("myp\\ath/foo"));
102 std::vector<SelectedFileInfo> selected_info_vector;
103 selected_info_vector.push_back(selected_info);
104 ViewMsg_RunFileChooserResponse response(view_impl->routing_id(),
105 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),
126 chooser_results[0].name);
127 }
128
129 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698