| 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/dev/ppb_fullscreen_dev.h" | 7 #include "ppapi/c/dev/ppb_fullscreen_dev.h" |
| 8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
| 9 #include "ppapi/c/ppb_core.h" | 9 #include "ppapi/c/ppb_core.h" |
| 10 #include "ppapi/c/ppb_url_loader.h" | 10 #include "ppapi/c/ppb_url_loader.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 PP_Bool received_has_focus; | 55 PP_Bool received_has_focus; |
| 56 base::WaitableEvent did_change_focus_called(false, false); | 56 base::WaitableEvent did_change_focus_called(false, false); |
| 57 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { | 57 void DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { |
| 58 received_instance = instance; | 58 received_instance = instance; |
| 59 received_has_focus = has_focus; | 59 received_has_focus = has_focus; |
| 60 did_change_focus_called.Signal(); | 60 did_change_focus_called.Signal(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 PP_InputEvent received_event; | |
| 64 PP_Bool HandleInputEvent(PP_Instance instance, const PP_InputEvent* event) { | |
| 65 received_instance = instance; | |
| 66 memcpy(&received_event, event, sizeof(*event));; | |
| 67 return bool_to_return; | |
| 68 } | |
| 69 | |
| 70 PP_Bool HandleDocumentLoad(PP_Instance instance, PP_Resource url_loader) { | 63 PP_Bool HandleDocumentLoad(PP_Instance instance, PP_Resource url_loader) { |
| 71 // This one requires use of the PPB_URLLoader proxy and PPB_Core, plus a | 64 // This one requires use of the PPB_URLLoader proxy and PPB_Core, plus a |
| 72 // resource tracker for the url_loader resource. | 65 // resource tracker for the url_loader resource. |
| 73 // TODO(dmichael): Mock those out and test this function. | 66 // TODO(dmichael): Mock those out and test this function. |
| 74 NOTREACHED(); | 67 NOTREACHED(); |
| 75 return PP_FALSE; | 68 return PP_FALSE; |
| 76 } | 69 } |
| 77 | 70 |
| 78 PP_Var var_to_return; | 71 PP_Var var_to_return; |
| 79 PP_Var GetInstanceObject(PP_Instance instance) { | 72 PP_Var GetInstanceObject(PP_Instance instance) { |
| 80 received_instance = instance; | 73 received_instance = instance; |
| 81 return var_to_return; | 74 return var_to_return; |
| 82 } | 75 } |
| 83 | 76 |
| 84 // Clear all the 'received' values for our mock. Call this before you expect | 77 // Clear all the 'received' values for our mock. Call this before you expect |
| 85 // one of the functions to be invoked. TODO(dmichael): It would be better to | 78 // one of the functions to be invoked. TODO(dmichael): It would be better to |
| 86 // have a flag also for each function, so we know the right one got called. | 79 // have a flag also for each function, so we know the right one got called. |
| 87 void ResetReceived() { | 80 void ResetReceived() { |
| 88 received_instance = 0; | 81 received_instance = 0; |
| 89 received_argc = 0; | 82 received_argc = 0; |
| 90 received_argn.clear(); | 83 received_argn.clear(); |
| 91 received_argv.clear(); | 84 received_argv.clear(); |
| 92 memset(&received_position, 0, sizeof(received_position)); | 85 memset(&received_position, 0, sizeof(received_position)); |
| 93 memset(&received_clip, 0, sizeof(received_clip)); | 86 memset(&received_clip, 0, sizeof(received_clip)); |
| 94 received_has_focus = PP_FALSE; | 87 received_has_focus = PP_FALSE; |
| 95 memset(&received_event, 0, sizeof(received_event)); | |
| 96 } | 88 } |
| 97 | 89 |
| 98 PPP_Instance_0_5 ppp_instance_0_5 = { | 90 PPP_Instance_1_0 ppp_instance_1_0 = { |
| 99 &DidCreate, | 91 &DidCreate, |
| 100 &DidDestroy, | 92 &DidDestroy, |
| 101 &DidChangeView, | 93 &DidChangeView, |
| 102 &DidChangeFocus, | 94 &DidChangeFocus, |
| 103 &HandleInputEvent, | |
| 104 &HandleDocumentLoad | 95 &HandleDocumentLoad |
| 105 }; | 96 }; |
| 106 | 97 |
| 107 // PPP_Instance_Proxy::DidChangeView relies on PPB_FullscreenDev being | 98 // PPP_Instance_Proxy::DidChangeView relies on PPB_FullscreenDev being |
| 108 // available with a valid implementation of IsFullScreen, so we mock it. | 99 // available with a valid implementation of IsFullScreen, so we mock it. |
| 109 PP_Bool IsFullscreen(PP_Instance instance) { | 100 PP_Bool IsFullscreen(PP_Instance instance) { |
| 110 return PP_FALSE; | 101 return PP_FALSE; |
| 111 } | 102 } |
| 112 PPB_Fullscreen_Dev ppb_fullscreen_dev = { &IsFullscreen }; | 103 PPB_Fullscreen_Dev ppb_fullscreen_dev = { &IsFullscreen }; |
| 113 | 104 |
| 114 } // namespace | 105 } // namespace |
| 115 | 106 |
| 116 class PPP_Instance_ProxyTest : public TwoWayTest { | 107 class PPP_Instance_ProxyTest : public TwoWayTest { |
| 117 public: | 108 public: |
| 118 PPP_Instance_ProxyTest() | 109 PPP_Instance_ProxyTest() |
| 119 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { | 110 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { |
| 120 } | 111 } |
| 121 }; | 112 }; |
| 122 | 113 |
| 123 TEST_F(PPP_Instance_ProxyTest, PPPInstance0_5) { | 114 TEST_F(PPP_Instance_ProxyTest, PPPInstance1_0) { |
| 124 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_0_5, &ppp_instance_0_5); | 115 plugin().RegisterTestInterface(PPP_INSTANCE_INTERFACE_1_0, &ppp_instance_1_0); |
| 125 host().RegisterTestInterface(PPB_FULLSCREEN_DEV_INTERFACE, | 116 host().RegisterTestInterface(PPB_FULLSCREEN_DEV_INTERFACE, |
| 126 &ppb_fullscreen_dev); | 117 &ppb_fullscreen_dev); |
| 127 | 118 |
| 128 // Grab the host-side proxy for the 0.5 interface. | 119 // Grab the host-side proxy for the 1.0 interface. |
| 129 const PPP_Instance_0_5* ppp_instance = static_cast<const PPP_Instance_0_5*>( | 120 const PPP_Instance_1_0* ppp_instance = static_cast<const PPP_Instance_1_0*>( |
| 130 host().host_dispatcher()->GetProxiedInterface( | 121 host().host_dispatcher()->GetProxiedInterface( |
| 131 PPP_INSTANCE_INTERFACE_0_5)); | 122 PPP_INSTANCE_INTERFACE_1_0)); |
| 132 | 123 |
| 133 // Call each function in turn, make sure we get the expected values and | 124 // Call each function in turn, make sure we get the expected values and |
| 134 // returns. | 125 // returns. |
| 135 // | 126 // |
| 136 // We don't test DidDestroy, because it has the side-effect of removing the | 127 // We don't test DidDestroy, because it has the side-effect of removing the |
| 137 // PP_Instance from the PluginDispatcher, which will cause a failure later | 128 // PP_Instance from the PluginDispatcher, which will cause a failure later |
| 138 // when the test is torn down. | 129 // when the test is torn down. |
| 139 PP_Instance expected_instance = pp_instance(); | 130 PP_Instance expected_instance = pp_instance(); |
| 140 std::vector<std::string> expected_argn, expected_argv; | 131 std::vector<std::string> expected_argn, expected_argv; |
| 141 expected_argn.push_back("Hello"); | 132 expected_argn.push_back("Hello"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 EXPECT_EQ(received_clip.size.width, expected_clip.size.width); | 167 EXPECT_EQ(received_clip.size.width, expected_clip.size.width); |
| 177 EXPECT_EQ(received_clip.size.height, expected_clip.size.height); | 168 EXPECT_EQ(received_clip.size.height, expected_clip.size.height); |
| 178 | 169 |
| 179 PP_Bool expected_has_focus = PP_TRUE; | 170 PP_Bool expected_has_focus = PP_TRUE; |
| 180 ResetReceived(); | 171 ResetReceived(); |
| 181 ppp_instance->DidChangeFocus(expected_instance, expected_has_focus); | 172 ppp_instance->DidChangeFocus(expected_instance, expected_has_focus); |
| 182 did_change_focus_called.Wait(); | 173 did_change_focus_called.Wait(); |
| 183 EXPECT_EQ(received_instance, expected_instance); | 174 EXPECT_EQ(received_instance, expected_instance); |
| 184 EXPECT_EQ(received_has_focus, expected_has_focus); | 175 EXPECT_EQ(received_has_focus, expected_has_focus); |
| 185 | 176 |
| 186 PP_InputEvent expected_event = { PP_INPUTEVENT_TYPE_KEYDOWN, // type | |
| 187 0, // padding | |
| 188 1.0, // time_stamp | |
| 189 { { 2, 3 } } }; // u (as PP_InputEvent_Key) | |
| 190 ResetReceived(); | |
| 191 EXPECT_EQ(bool_to_return, | |
| 192 ppp_instance->HandleInputEvent(expected_instance, &expected_event)); | |
| 193 EXPECT_EQ(received_instance, expected_instance); | |
| 194 ASSERT_EQ(received_event.type, expected_event.type); | |
| 195 // Ignore padding; it's okay if it's not serialized. | |
| 196 EXPECT_EQ(received_event.time_stamp, expected_event.time_stamp); | |
| 197 EXPECT_EQ(received_event.u.key.modifier, expected_event.u.key.modifier); | |
| 198 EXPECT_EQ(received_event.u.key.key_code, expected_event.u.key.key_code); | |
| 199 | |
| 200 // TODO(dmichael): Need to mock out a resource Tracker to be able to test | 177 // TODO(dmichael): Need to mock out a resource Tracker to be able to test |
| 201 // HandleResourceLoad. It also requires | 178 // HandleResourceLoad. It also requires |
| 202 // PPB_Core.AddRefResource and for PPB_URLLoader to be | 179 // PPB_Core.AddRefResource and for PPB_URLLoader to be |
| 203 // registered. | 180 // registered. |
| 204 } | 181 } |
| 205 | 182 |
| 206 } // namespace proxy | 183 } // namespace proxy |
| 207 } // namespace pp | 184 } // namespace pp |
| 208 | 185 |
| OLD | NEW |