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_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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ppapi/shared_impl/test_globals.h" | 24 #include "ppapi/shared_impl/test_globals.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 #include "ui/shell_dialogs/selected_file_info.h" | 26 #include "ui/shell_dialogs/selected_file_info.h" |
27 | 27 |
28 namespace content { | 28 namespace content { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 class PepperFileChooserHostTest : public RenderViewTest { | 32 class PepperFileChooserHostTest : public RenderViewTest { |
33 public: | 33 public: |
34 PepperFileChooserHostTest() | 34 PepperFileChooserHostTest() : pp_instance_(123456) {} |
35 : pp_instance_(123456) {} | |
36 | 35 |
37 virtual void SetUp() { | 36 virtual void SetUp() { |
38 SetContentClient(&client_); | 37 SetContentClient(&client_); |
39 RenderViewTest::SetUp(); | 38 RenderViewTest::SetUp(); |
40 ppapi::ProxyLock::DisableLockingOnThreadForTest(); | 39 ppapi::ProxyLock::DisableLockingOnThreadForTest(); |
41 | 40 |
42 globals_.GetResourceTracker()->DidCreateInstance(pp_instance_); | 41 globals_.GetResourceTracker()->DidCreateInstance(pp_instance_); |
43 } | 42 } |
44 virtual void TearDown() { | 43 virtual void TearDown() { |
45 globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_); | 44 globals_.GetResourceTracker()->DidDeleteInstance(pp_instance_); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // This should have sent the Pepper reply to our test sink. | 113 // This should have sent the Pepper reply to our test sink. |
115 ppapi::proxy::ResourceMessageReplyParams reply_params; | 114 ppapi::proxy::ResourceMessageReplyParams reply_params; |
116 IPC::Message reply_msg; | 115 IPC::Message reply_msg; |
117 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching( | 116 ASSERT_TRUE(host.sink().GetFirstResourceReplyMatching( |
118 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); | 117 PpapiPluginMsg_FileChooser_ShowReply::ID, &reply_params, &reply_msg)); |
119 | 118 |
120 // Basic validation of reply. | 119 // Basic validation of reply. |
121 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); | 120 EXPECT_EQ(call_params.sequence(), reply_params.sequence()); |
122 EXPECT_EQ(PP_OK, reply_params.result()); | 121 EXPECT_EQ(PP_OK, reply_params.result()); |
123 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; | 122 PpapiPluginMsg_FileChooser_ShowReply::Schema::Param reply_msg_param; |
124 ASSERT_TRUE(PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, | 123 ASSERT_TRUE( |
125 &reply_msg_param)); | 124 PpapiPluginMsg_FileChooser_ShowReply::Read(&reply_msg, &reply_msg_param)); |
126 const std::vector<ppapi::FileRefCreateInfo>& chooser_results = | 125 const std::vector<ppapi::FileRefCreateInfo>& chooser_results = |
127 reply_msg_param.a; | 126 reply_msg_param.a; |
128 ASSERT_EQ(1u, chooser_results.size()); | 127 ASSERT_EQ(1u, chooser_results.size()); |
129 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), | 128 EXPECT_EQ(FilePathToUTF8(selected_info.display_name), |
130 chooser_results[0].display_name); | 129 chooser_results[0].display_name); |
131 } | 130 } |
132 | 131 |
133 TEST_F(PepperFileChooserHostTest, NoUserGesture) { | 132 TEST_F(PepperFileChooserHostTest, NoUserGesture) { |
134 PP_Resource pp_resource = 123; | 133 PP_Resource pp_resource = 123; |
135 | 134 |
136 MockRendererPpapiHost host(view_, pp_instance()); | 135 MockRendererPpapiHost host(view_, pp_instance()); |
137 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource); | 136 PepperFileChooserHost chooser(&host, pp_instance(), pp_resource); |
138 | 137 |
139 // Say there's no user gesture. | 138 // Say there's no user gesture. |
140 host.set_has_user_gesture(false); | 139 host.set_has_user_gesture(false); |
141 | 140 |
142 std::vector<std::string> accept; | 141 std::vector<std::string> accept; |
143 accept.push_back("text/plain"); | 142 accept.push_back("text/plain"); |
144 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); | 143 PpapiHostMsg_FileChooser_Show show_msg(false, false, std::string(), accept); |
145 | 144 |
146 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); | 145 ppapi::proxy::ResourceMessageCallParams call_params(pp_resource, 0); |
147 ppapi::host::HostMessageContext context(call_params); | 146 ppapi::host::HostMessageContext context(call_params); |
148 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); | 147 int32 result = chooser.OnResourceMessageReceived(show_msg, &context); |
149 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); | 148 EXPECT_EQ(PP_ERROR_NO_USER_GESTURE, result); |
150 } | 149 } |
151 | 150 |
152 } // namespace content | 151 } // namespace content |
OLD | NEW |