| 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 <cstring> | 5 #include <cstring> |
| 6 | 6 |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
| 9 #include "ppapi/c/ppb_var.h" | 9 #include "ppapi/c/ppb_var.h" |
| 10 #include "ppapi/c/ppp_messaging.h" | 10 #include "ppapi/c/ppp_messaging.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 void ResetReceived() { | 34 void ResetReceived() { |
| 35 received_instance = 0; | 35 received_instance = 0; |
| 36 received_var.type = PP_VARTYPE_UNDEFINED; | 36 received_var.type = PP_VARTYPE_UNDEFINED; |
| 37 received_var.value.as_id = 0; | 37 received_var.value.as_id = 0; |
| 38 } | 38 } |
| 39 | 39 |
| 40 PPP_Messaging ppp_messaging_mock = { | 40 PPP_Messaging ppp_messaging_mock = { |
| 41 &HandleMessage | 41 &HandleMessage |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace | |
| 45 | |
| 46 class PPP_Messaging_ProxyTest : public TwoWayTest { | 44 class PPP_Messaging_ProxyTest : public TwoWayTest { |
| 47 public: | 45 public: |
| 48 PPP_Messaging_ProxyTest() | 46 PPP_Messaging_ProxyTest() |
| 49 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { | 47 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { |
| 50 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, | 48 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, |
| 51 &ppp_messaging_mock); | 49 &ppp_messaging_mock); |
| 52 } | 50 } |
| 53 }; | 51 }; |
| 54 | 52 |
| 53 void CompareAndReleaseStringVar(PluginProxyTestHarness* plugin_harness, |
| 54 PP_Var received_var, |
| 55 const std::string& test_string) { |
| 56 Var* received_string = plugin_harness->var_tracker().GetVar(received_var); |
| 57 ASSERT_TRUE(received_string); |
| 58 ASSERT_TRUE(received_string->AsStringVar()); |
| 59 EXPECT_EQ(test_string, received_string->AsStringVar()->value()); |
| 60 // Now release the var, and the string should go away (because the ref |
| 61 // count should be one). |
| 62 plugin_harness->var_tracker().ReleaseVar(received_var); |
| 63 EXPECT_FALSE(StringVar::FromPPVar(received_var)); |
| 64 } |
| 65 |
| 66 } // namespace |
| 67 |
| 55 TEST_F(PPP_Messaging_ProxyTest, SendMessages) { | 68 TEST_F(PPP_Messaging_ProxyTest, SendMessages) { |
| 56 // Grab the host-side proxy of ppp_messaging. | 69 // Grab the host-side proxy of ppp_messaging. |
| 57 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( | 70 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( |
| 58 host().host_dispatcher()->GetProxiedInterface( | 71 host().host_dispatcher()->GetProxiedInterface( |
| 59 PPP_MESSAGING_INTERFACE)); | 72 PPP_MESSAGING_INTERFACE)); |
| 60 | 73 |
| 61 PP_Instance expected_instance = pp_instance(); | 74 PP_Instance expected_instance = pp_instance(); |
| 62 PP_Var expected_var = PP_MakeUndefined(); | 75 PP_Var expected_var = PP_MakeUndefined(); |
| 63 ResetReceived(); | 76 ResetReceived(); |
| 64 ppp_messaging->HandleMessage(expected_instance, expected_var); | 77 ppp_messaging->HandleMessage(expected_instance, expected_var); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 ResetReceived(); | 115 ResetReceived(); |
| 103 ppp_messaging->HandleMessage(expected_instance, expected_var); | 116 ppp_messaging->HandleMessage(expected_instance, expected_var); |
| 104 // Now release the var, and the string should go away (because the ref | 117 // Now release the var, and the string should go away (because the ref |
| 105 // count should be one). | 118 // count should be one). |
| 106 host().var_tracker().ReleaseVar(expected_var); | 119 host().var_tracker().ReleaseVar(expected_var); |
| 107 EXPECT_FALSE(StringVar::FromPPVar(expected_var)); | 120 EXPECT_FALSE(StringVar::FromPPVar(expected_var)); |
| 108 | 121 |
| 109 handle_message_called.Wait(); | 122 handle_message_called.Wait(); |
| 110 EXPECT_EQ(expected_instance, received_instance); | 123 EXPECT_EQ(expected_instance, received_instance); |
| 111 EXPECT_EQ(expected_var.type, received_var.type); | 124 EXPECT_EQ(expected_var.type, received_var.type); |
| 112 Var* received_string = plugin().var_tracker().GetVar(received_var); | 125 PostTaskOnRemoteHarness( |
| 113 ASSERT_TRUE(received_string); | 126 base::Bind(CompareAndReleaseStringVar, |
| 114 ASSERT_TRUE(received_string->AsStringVar()); | 127 &plugin(), |
| 115 EXPECT_EQ(kTestString, received_string->AsStringVar()->value()); | 128 received_var, |
| 116 // Now release the var, and the string should go away (because the ref | 129 kTestString)); |
| 117 // count should be one). | |
| 118 plugin().var_tracker().ReleaseVar(received_var); | |
| 119 EXPECT_FALSE(StringVar::FromPPVar(received_var)); | |
| 120 } | 130 } |
| 121 | 131 |
| 122 } // namespace proxy | 132 } // namespace proxy |
| 123 } // namespace ppapi | 133 } // namespace ppapi |
| 124 | 134 |
| OLD | NEW |