Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: ppapi/proxy/ppp_messaging_proxy_unittest.cc

Issue 9139054: Revert 117399 - Make it possible to have 1 PpapiGlobals per thread. Update unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppp_instance_proxy_unittest.cc ('k') | ppapi/proxy/serialized_var_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <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"
11 #include "ppapi/proxy/ppapi_proxy_test.h" 11 #include "ppapi/proxy/ppapi_proxy_test.h"
(...skipping 22 matching lines...) Expand all
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
44 } // namespace 66 } // namespace
45 67
46 class PPP_Messaging_ProxyTest : public TwoWayTest { 68 class PPP_Messaging_ProxyTest : public TwoWayTest {
47 public: 69 public:
48 PPP_Messaging_ProxyTest() 70 PPP_Messaging_ProxyTest()
49 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) { 71 : TwoWayTest(TwoWayTest::TEST_PPP_INTERFACE) {
50 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE, 72 plugin().RegisterTestInterface(PPP_MESSAGING_INTERFACE,
51 &ppp_messaging_mock); 73 &ppp_messaging_mock);
52 } 74 host().RegisterTestInterface(PPB_VAR_INTERFACE, &ppb_var_mock);
75 }
53 }; 76 };
54 77
55 TEST_F(PPP_Messaging_ProxyTest, SendMessages) { 78 TEST_F(PPP_Messaging_ProxyTest, SendMessages) {
56 // Grab the host-side proxy of ppp_messaging. 79 // Grab the host-side proxy of ppp_messaging.
57 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>( 80 const PPP_Messaging* ppp_messaging = static_cast<const PPP_Messaging*>(
58 host().host_dispatcher()->GetProxiedInterface( 81 host().host_dispatcher()->GetProxiedInterface(
59 PPP_MESSAGING_INTERFACE)); 82 PPP_MESSAGING_INTERFACE));
60 83
61 PP_Instance expected_instance = pp_instance(); 84 PP_Instance expected_instance = pp_instance();
62 PP_Var expected_var = PP_MakeUndefined(); 85 PP_Var expected_var = PP_MakeUndefined();
(...skipping 27 matching lines...) Expand all
90 EXPECT_EQ(expected_var.value.as_int, received_var.value.as_int); 113 EXPECT_EQ(expected_var.value.as_int, received_var.value.as_int);
91 114
92 expected_var = PP_MakeDouble(3.1415); 115 expected_var = PP_MakeDouble(3.1415);
93 ResetReceived(); 116 ResetReceived();
94 ppp_messaging->HandleMessage(expected_instance, expected_var); 117 ppp_messaging->HandleMessage(expected_instance, expected_var);
95 handle_message_called.Wait(); 118 handle_message_called.Wait();
96 EXPECT_EQ(expected_instance, received_instance); 119 EXPECT_EQ(expected_instance, received_instance);
97 EXPECT_EQ(expected_var.type, received_var.type); 120 EXPECT_EQ(expected_var.type, received_var.type);
98 EXPECT_EQ(expected_var.value.as_double, received_var.value.as_double); 121 EXPECT_EQ(expected_var.value.as_double, received_var.value.as_double);
99 122
100 const std::string kTestString("Hello world!"); 123 expected_var.type = PP_VARTYPE_STRING;
101 expected_var = StringVar::StringToPPVar(kTestString); 124 expected_var.value.as_id = 1979;
102 ResetReceived(); 125 ResetReceived();
103 ppp_messaging->HandleMessage(expected_instance, expected_var); 126 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
109 handle_message_called.Wait(); 127 handle_message_called.Wait();
110 EXPECT_EQ(expected_instance, received_instance); 128 EXPECT_EQ(expected_instance, received_instance);
111 EXPECT_EQ(expected_var.type, received_var.type); 129 EXPECT_EQ(expected_var.type, received_var.type);
112 Var* received_string = plugin().var_tracker().GetVar(received_var); 130
131 StringVar* received_string = StringVar::FromPPVar(received_var);
113 ASSERT_TRUE(received_string); 132 ASSERT_TRUE(received_string);
114 ASSERT_TRUE(received_string->AsStringVar()); 133 EXPECT_EQ(kTestString, received_string->value());
115 EXPECT_EQ(kTestString, received_string->AsStringVar()->value());
116 // Now release the var, and the string should go away (because the ref 134 // Now release the var, and the string should go away (because the ref
117 // count should be one). 135 // count should be one).
118 plugin().var_tracker().ReleaseVar(received_var); 136 plugin().var_tracker().ReleaseVar(received_var);
119 EXPECT_FALSE(StringVar::FromPPVar(received_var)); 137 EXPECT_FALSE(StringVar::FromPPVar(received_var));
120 } 138 }
121 139
122 } // namespace proxy 140 } // namespace proxy
123 } // namespace ppapi 141 } // namespace ppapi
124 142
OLDNEW
« no previous file with comments | « ppapi/proxy/ppp_instance_proxy_unittest.cc ('k') | ppapi/proxy/serialized_var_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698