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