| 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 <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 // Define a fake PPB_Var for the host side so that we can send a string var. | |
| 45 void AddRef(PP_Var /*var*/) { | |
| 46 } | |
| 47 void Release(PP_Var /*var*/) { | |
| 48 } | |
| 49 PP_Var VarFromUtf8(const char* /*data*/, uint32_t len) { | |
| 50 return PP_MakeUndefined(); | |
| 51 } | |
| 52 // No matter what id we're given, always provide kTestString and its length. | |
| 53 const std::string kTestString = "Hello world!"; | |
| 54 const char* VarToUtf8(PP_Var /*var*/, uint32_t* len) { | |
| 55 *len = kTestString.size(); | |
| 56 return kTestString.c_str(); | |
| 57 } | |
| 58 | |
| 59 PPB_Var ppb_var_mock = { | |
| 60 &AddRef, | |
| 61 &Release, | |
| 62 &VarFromUtf8, | |
| 63 &VarToUtf8 | |
| 64 }; | |
| 65 | |
| 66 } // namespace | 44 } // namespace |
| 67 | 45 |
| 68 class PPP_Messaging_ProxyTest : public TwoWayTest { | 46 class PPP_Messaging_ProxyTest : public TwoWayTest { |
| 69 public: | 47 public: |
| 70 PPP_Messaging_ProxyTest() | 48 PPP_Messaging_ProxyTest() |
| 71 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { | 49 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { |
| 72 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, | 50 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, |
| 73 &ppp_messaging_mock); | 51 &ppp_messaging_mock); |
| 74 host().RegisterTestInterface(PPB_VAR_INTERFACE, &ppb_var_mock); | 52 } |
| 75 } | |
| 76 }; | 53 }; |
| 77 | 54 |
| 78 TEST_F(PPP_Messaging_ProxyTest, SendMessages) { | 55 TEST_F(PPP_Messaging_ProxyTest, SendMessages) { |
| 79 // Grab the host-side proxy of ppp_messaging. | 56 // Grab the host-side proxy of ppp_messaging. |
| 80 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( | 57 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( |
| 81 host().host_dispatcher()->GetProxiedInterface( | 58 host().host_dispatcher()->GetProxiedInterface( |
| 82 PPP_MESSAGING_INTERFACE)); | 59 PPP_MESSAGING_INTERFACE)); |
| 83 | 60 |
| 84 PP_Instance expected_instance = pp_instance(); | 61 PP_Instance expected_instance = pp_instance(); |
| 85 PP_Var expected_var = PP_MakeUndefined(); | 62 PP_Var expected_var = PP_MakeUndefined(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 113 EXPECT_EQ(expected_var.value.as_int, received_var.value.as_int); | 90 EXPECT_EQ(expected_var.value.as_int, received_var.value.as_int); |
| 114 | 91 |
| 115 expected_var = PP_MakeDouble(3.1415); | 92 expected_var = PP_MakeDouble(3.1415); |
| 116 ResetReceived(); | 93 ResetReceived(); |
| 117 ppp_messaging->HandleMessage(expected_instance, expected_var); | 94 ppp_messaging->HandleMessage(expected_instance, expected_var); |
| 118 handle_message_called.Wait(); | 95 handle_message_called.Wait(); |
| 119 EXPECT_EQ(expected_instance, received_instance); | 96 EXPECT_EQ(expected_instance, received_instance); |
| 120 EXPECT_EQ(expected_var.type, received_var.type); | 97 EXPECT_EQ(expected_var.type, received_var.type); |
| 121 EXPECT_EQ(expected_var.value.as_double, received_var.value.as_double); | 98 EXPECT_EQ(expected_var.value.as_double, received_var.value.as_double); |
| 122 | 99 |
| 123 expected_var.type = PP_VARTYPE_STRING; | 100 const std::string kTestString("Hello world!"); |
| 124 expected_var.value.as_id = 1979; | 101 expected_var = StringVar::StringToPPVar(kTestString); |
| 125 ResetReceived(); | 102 ResetReceived(); |
| 126 ppp_messaging->HandleMessage(expected_instance, expected_var); | 103 ppp_messaging->HandleMessage(expected_instance, expected_var); |
| 104 // Now release the var, and the string should go away (because the ref |
| 105 // count should be one). |
| 106 host().var_tracker().ReleaseVar(expected_var); |
| 107 EXPECT_FALSE(StringVar::FromPPVar(expected_var)); |
| 108 |
| 127 handle_message_called.Wait(); | 109 handle_message_called.Wait(); |
| 128 EXPECT_EQ(expected_instance, received_instance); | 110 EXPECT_EQ(expected_instance, received_instance); |
| 129 EXPECT_EQ(expected_var.type, received_var.type); | 111 EXPECT_EQ(expected_var.type, received_var.type); |
| 130 | 112 Var* received_string = plugin().var_tracker().GetVar(received_var); |
| 131 StringVar* received_string = StringVar::FromPPVar(received_var); | |
| 132 ASSERT_TRUE(received_string); | 113 ASSERT_TRUE(received_string); |
| 133 EXPECT_EQ(kTestString, received_string->value()); | 114 ASSERT_TRUE(received_string->AsStringVar()); |
| 115 EXPECT_EQ(kTestString, received_string->AsStringVar()->value()); |
| 134 // Now release the var, and the string should go away (because the ref | 116 // Now release the var, and the string should go away (because the ref |
| 135 // count should be one). | 117 // count should be one). |
| 136 plugin().var_tracker().ReleaseVar(received_var); | 118 plugin().var_tracker().ReleaseVar(received_var); |
| 137 EXPECT_FALSE(StringVar::FromPPVar(received_var)); | 119 EXPECT_FALSE(StringVar::FromPPVar(received_var)); |
| 138 } | 120 } |
| 139 | 121 |
| 140 } // namespace proxy | 122 } // namespace proxy |
| 141 } // namespace ppapi | 123 } // namespace ppapi |
| 142 | 124 |
| OLD | NEW |