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