| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
| 6 #include "ipc/ipc_message_utils.h" | 6 #include "ipc/ipc_message_utils.h" |
| 7 #include "ppapi/c/pp_var.h" | 7 #include "ppapi/c/pp_var.h" |
| 8 #include "ppapi/c/ppb_core.h" | 8 #include "ppapi/c/ppb_core.h" |
| 9 #include "ppapi/c/ppb_fullscreen.h" | 9 #include "ppapi/c/ppb_fullscreen.h" |
| 10 #include "ppapi/c/ppb_url_loader.h" | 10 #include "ppapi/c/ppb_url_loader.h" |
| 11 #include "ppapi/c/ppp_instance.h" | 11 #include "ppapi/c/ppp_instance.h" |
| 12 #include "ppapi/c/private/ppb_flash_fullscreen.h" | 12 #include "ppapi/c/private/ppb_flash_fullscreen.h" |
| 13 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
| 14 #include "ppapi/proxy/ppapi_proxy_test.h" | 14 #include "ppapi/proxy/ppapi_proxy_test.h" |
| 15 #include "ppapi/shared_impl/ppb_view_shared.h" |
| 16 #include "ppapi/shared_impl/scoped_pp_resource.h" |
| 15 | 17 |
| 16 namespace ppapi { | 18 namespace ppapi { |
| 17 namespace proxy { | 19 namespace proxy { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 // This is a poor man's mock of PPP_Instance using global variables. Eventually | 22 // This is a poor man's mock of PPP_Instance using global variables. Eventually |
| 21 // we should generalize making PPAPI interface mocks by using IDL or macro/ | 23 // we should generalize making PPAPI interface mocks by using IDL or macro/ |
| 22 // template magic. | 24 // template magic. |
| 23 PP_Instance received_instance; | 25 PP_Instance received_instance; |
| 24 uint32_t received_argc; | 26 uint32_t received_argc; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 109 } |
| 108 }; | 110 }; |
| 109 | 111 |
| 110 TEST_F(PPP_Instance_ProxyTest, PPPInstance1_0) { | 112 TEST_F(PPP_Instance_ProxyTest, PPPInstance1_0) { |
| 111 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_1_0, &ppp_instance_1_0); | 113 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_1_0, &ppp_instance_1_0); |
| 112 host().RegisterTestInterface(PPB_FLASHFULLSCREEN_INTERFACE, | 114 host().RegisterTestInterface(PPB_FLASHFULLSCREEN_INTERFACE, |
| 113 &ppb_flash_fullscreen); | 115 &ppb_flash_fullscreen); |
| 114 host().RegisterTestInterface(PPB_FULLSCREEN_INTERFACE, | 116 host().RegisterTestInterface(PPB_FULLSCREEN_INTERFACE, |
| 115 &ppb_fullscreen); | 117 &ppb_fullscreen); |
| 116 | 118 |
| 117 // Grab the host-side proxy for the 1.0 interface. | 119 // Grab the host-side proxy for the interface. The browser only speaks 1.1, |
| 118 const PPP_Instance_1_0* ppp_instance = static_cast<const PPP_Instance_1_0*>( | 120 // while the proxy ensures support for the 1.0 version on the plugin side. |
| 121 const PPP_Instance_1_1* ppp_instance = static_cast<const PPP_Instance_1_1*>( |
| 119 host().host_dispatcher()->GetProxiedInterface( | 122 host().host_dispatcher()->GetProxiedInterface( |
| 120 PPP_INSTANCE_INTERFACE_1_0)); | 123 PPP_INSTANCE_INTERFACE_1_1)); |
| 121 | 124 |
| 122 // Call each function in turn, make sure we get the expected values and | 125 // Call each function in turn, make sure we get the expected values and |
| 123 // returns. | 126 // returns. |
| 124 // | 127 // |
| 125 // We don't test DidDestroy, because it has the side-effect of removing the | 128 // We don't test DidDestroy, because it has the side-effect of removing the |
| 126 // PP_Instance from the PluginDispatcher, which will cause a failure later | 129 // PP_Instance from the PluginDispatcher, which will cause a failure later |
| 127 // when the test is torn down. | 130 // when the test is torn down. |
| 128 PP_Instance expected_instance = pp_instance(); | 131 PP_Instance expected_instance = pp_instance(); |
| 129 std::vector<std::string> expected_argn, expected_argv; | 132 std::vector<std::string> expected_argn, expected_argv; |
| 130 expected_argn.push_back("Hello"); | 133 expected_argn.push_back("Hello"); |
| 131 expected_argn.push_back("world."); | 134 expected_argn.push_back("world."); |
| 132 expected_argv.push_back("elloHay"); | 135 expected_argv.push_back("elloHay"); |
| 133 expected_argv.push_back("orldway."); | 136 expected_argv.push_back("orldway."); |
| 134 std::vector<const char*> argn_to_pass, argv_to_pass; | 137 std::vector<const char*> argn_to_pass, argv_to_pass; |
| 135 CHECK(expected_argn.size() == expected_argv.size()); | 138 CHECK(expected_argn.size() == expected_argv.size()); |
| 136 for (size_t i = 0; i < expected_argn.size(); ++i) { | 139 for (size_t i = 0; i < expected_argn.size(); ++i) { |
| 137 argn_to_pass.push_back(expected_argn[i].c_str()); | 140 argn_to_pass.push_back(expected_argn[i].c_str()); |
| 138 argv_to_pass.push_back(expected_argv[i].c_str()); | 141 argv_to_pass.push_back(expected_argv[i].c_str()); |
| 139 } | 142 } |
| 140 uint32_t expected_argc = expected_argn.size(); | 143 uint32_t expected_argc = expected_argn.size(); |
| 141 bool_to_return = PP_TRUE; | 144 bool_to_return = PP_TRUE; |
| 142 ResetReceived(); | 145 ResetReceived(); |
| 146 // Tell the host resource tracker about the instance. |
| 147 host().resource_tracker().DidCreateInstance(expected_instance); |
| 143 EXPECT_EQ(bool_to_return, ppp_instance->DidCreate(expected_instance, | 148 EXPECT_EQ(bool_to_return, ppp_instance->DidCreate(expected_instance, |
| 144 expected_argc, | 149 expected_argc, |
| 145 &argn_to_pass[0], | 150 &argn_to_pass[0], |
| 146 &argv_to_pass[0])); | 151 &argv_to_pass[0])); |
| 147 EXPECT_EQ(received_instance, expected_instance); | 152 EXPECT_EQ(received_instance, expected_instance); |
| 148 EXPECT_EQ(received_argc, expected_argc); | 153 EXPECT_EQ(received_argc, expected_argc); |
| 149 EXPECT_EQ(received_argn, expected_argn); | 154 EXPECT_EQ(received_argn, expected_argn); |
| 150 EXPECT_EQ(received_argv, expected_argv); | 155 EXPECT_EQ(received_argv, expected_argv); |
| 151 | 156 |
| 152 PP_Rect expected_position = { {1, 2}, {3, 4} }; | 157 PP_Rect expected_position = { {1, 2}, {3, 4} }; |
| 153 PP_Rect expected_clip = { {5, 6}, {7, 8} }; | 158 PP_Rect expected_clip = { {5, 6}, {7, 8} }; |
| 159 ViewData data; |
| 160 data.rect = expected_position; |
| 161 data.is_fullscreen = false; |
| 162 data.is_page_visible = true; |
| 163 data.clip_rect = expected_clip; |
| 154 ResetReceived(); | 164 ResetReceived(); |
| 155 ppp_instance->DidChangeView(expected_instance, &expected_position, | 165 ScopedPPResource view_resource( |
| 156 &expected_clip); | 166 ScopedPPResource::PassRef(), |
| 167 (new PPB_View_Shared(PPB_View_Shared::InitAsImpl(), |
| 168 expected_instance, data))->GetReference()); |
| 169 ppp_instance->DidChangeView(expected_instance, view_resource); |
| 157 did_change_view_called.Wait(); | 170 did_change_view_called.Wait(); |
| 158 EXPECT_EQ(received_instance, expected_instance); | 171 EXPECT_EQ(received_instance, expected_instance); |
| 159 EXPECT_EQ(received_position.point.x, expected_position.point.x); | 172 EXPECT_EQ(received_position.point.x, expected_position.point.x); |
| 160 EXPECT_EQ(received_position.point.y, expected_position.point.y); | 173 EXPECT_EQ(received_position.point.y, expected_position.point.y); |
| 161 EXPECT_EQ(received_position.size.width, expected_position.size.width); | 174 EXPECT_EQ(received_position.size.width, expected_position.size.width); |
| 162 EXPECT_EQ(received_position.size.height, expected_position.size.height); | 175 EXPECT_EQ(received_position.size.height, expected_position.size.height); |
| 163 EXPECT_EQ(received_clip.point.x, expected_clip.point.x); | 176 EXPECT_EQ(received_clip.point.x, expected_clip.point.x); |
| 164 EXPECT_EQ(received_clip.point.y, expected_clip.point.y); | 177 EXPECT_EQ(received_clip.point.y, expected_clip.point.y); |
| 165 EXPECT_EQ(received_clip.size.width, expected_clip.size.width); | 178 EXPECT_EQ(received_clip.size.width, expected_clip.size.width); |
| 166 EXPECT_EQ(received_clip.size.height, expected_clip.size.height); | 179 EXPECT_EQ(received_clip.size.height, expected_clip.size.height); |
| 167 | 180 |
| 168 PP_Bool expected_has_focus = PP_TRUE; | 181 PP_Bool expected_has_focus = PP_TRUE; |
| 169 ResetReceived(); | 182 ResetReceived(); |
| 170 ppp_instance->DidChangeFocus(expected_instance, expected_has_focus); | 183 ppp_instance->DidChangeFocus(expected_instance, expected_has_focus); |
| 171 did_change_focus_called.Wait(); | 184 did_change_focus_called.Wait(); |
| 172 EXPECT_EQ(received_instance, expected_instance); | 185 EXPECT_EQ(received_instance, expected_instance); |
| 173 EXPECT_EQ(received_has_focus, expected_has_focus); | 186 EXPECT_EQ(received_has_focus, expected_has_focus); |
| 174 | 187 |
| 175 // TODO(dmichael): Need to mock out a resource Tracker to be able to test | 188 // TODO(dmichael): Need to mock out a resource Tracker to be able to test |
| 176 // HandleResourceLoad. It also requires | 189 // HandleResourceLoad. It also requires |
| 177 // PPB_Core.AddRefResource and for PPB_URLLoader to be | 190 // PPB_Core.AddRefResource and for PPB_URLLoader to be |
| 178 // registered. | 191 // registered. |
| 192 |
| 193 host().resource_tracker().DidDeleteInstance(expected_instance); |
| 179 } | 194 } |
| 180 | 195 |
| 181 } // namespace proxy | 196 } // namespace proxy |
| 182 } // namespace ppapi | 197 } // namespace ppapi |
| OLD | NEW |