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

Side by Side Diff: ppapi/tests/test_post_message.cc

Issue 8982006: Add GetLiveVars to PPB_Testing_Dev. Fix leaks it uncovered. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged Created 9 years 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/tests/test_memory.cc ('k') | ppapi/tests/test_scrollbar.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) 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 "ppapi/tests/test_post_message.h" 5 #include "ppapi/tests/test_post_message.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ppapi/c/dev/ppb_testing_dev.h" 9 #include "ppapi/c/dev/ppb_testing_dev.h"
10 #include "ppapi/c/pp_var.h" 10 #include "ppapi/c/pp_var.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // string. See Init for where it gets added. 62 // string. See Init for where it gets added.
63 std::string js_code; 63 std::string js_code;
64 js_code += "var plugin = document.getElementById('plugin');" 64 js_code += "var plugin = document.getElementById('plugin');"
65 "plugin.removeEventListener('message'," 65 "plugin.removeEventListener('message',"
66 " plugin.wait_for_messages_handler);" 66 " plugin.wait_for_messages_handler);"
67 "delete plugin.wait_for_messages_handler;"; 67 "delete plugin.wait_for_messages_handler;";
68 instance_->EvalScript(js_code); 68 instance_->EvalScript(js_code);
69 } 69 }
70 70
71 bool TestPostMessage::Init() { 71 bool TestPostMessage::Init() {
72 bool success = InitTestingInterface(); 72 bool success = CheckTestingInterface();
73 73
74 // Set up a special listener that only responds to a FINISHED_WAITING string. 74 // Set up a special listener that only responds to a FINISHED_WAITING string.
75 // This is for use by WaitForMessages. 75 // This is for use by WaitForMessages.
76 std::string js_code; 76 std::string js_code;
77 // Note the following code is dependent on some features of test_case.html. 77 // Note the following code is dependent on some features of test_case.html.
78 // E.g., it is assumed that the DOM element where the plugin is embedded has 78 // E.g., it is assumed that the DOM element where the plugin is embedded has
79 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows 79 // an id of 'plugin', and there is a function 'IsTestingMessage' that allows
80 // us to ignore the messages that are intended for use by the testing 80 // us to ignore the messages that are intended for use by the testing
81 // framework itself. 81 // framework itself.
82 js_code += "var plugin = document.getElementById('plugin');" 82 js_code += "var plugin = document.getElementById('plugin');"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // received (which may be zero). 172 // received (which may be zero).
173 return message_data_.size() - message_size_before; 173 return message_data_.size() - message_size_before;
174 } 174 }
175 175
176 std::string TestPostMessage::TestSendInInit() { 176 std::string TestPostMessage::TestSendInInit() {
177 ASSERT_EQ(WaitForMessages(), 1); 177 ASSERT_EQ(WaitForMessages(), 1);
178 // This test assumes Init already sent a message. 178 // This test assumes Init already sent a message.
179 ASSERT_EQ(message_data_.size(), 1); 179 ASSERT_EQ(message_data_.size(), 1);
180 ASSERT_TRUE(message_data_.back().is_string()); 180 ASSERT_TRUE(message_data_.back().is_string());
181 ASSERT_EQ(message_data_.back().AsString(), kTestString); 181 ASSERT_EQ(message_data_.back().AsString(), kTestString);
182 message_data_.clear();
182 PASS(); 183 PASS();
183 } 184 }
184 185
185 std::string TestPostMessage::TestSendingData() { 186 std::string TestPostMessage::TestSendingData() {
186 // Clean up after previous tests. This also swallows the message sent by Init 187 // Clean up after previous tests. This also swallows the message sent by Init
187 // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit' 188 // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit'
188 // should start with these. 189 // should start with these.
189 WaitForMessages(); 190 WaitForMessages();
190 ASSERT_TRUE(ClearListeners()); 191 ASSERT_TRUE(ClearListeners());
191 // Set up the JavaScript message event listener to echo the data part of the 192 // Set up the JavaScript message event listener to echo the data part of the
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 ASSERT_EQ(message_data_.size(), 0); 230 ASSERT_EQ(message_data_.size(), 0);
230 ASSERT_EQ(WaitForMessages(), 1); 231 ASSERT_EQ(WaitForMessages(), 1);
231 ASSERT_TRUE(message_data_.back().is_undefined()); 232 ASSERT_TRUE(message_data_.back().is_undefined());
232 233
233 message_data_.clear(); 234 message_data_.clear();
234 instance_->PostMessage(pp::Var(pp::Var::Null())); 235 instance_->PostMessage(pp::Var(pp::Var::Null()));
235 ASSERT_EQ(message_data_.size(), 0); 236 ASSERT_EQ(message_data_.size(), 0);
236 ASSERT_EQ(WaitForMessages(), 1); 237 ASSERT_EQ(WaitForMessages(), 1);
237 ASSERT_TRUE(message_data_.back().is_null()); 238 ASSERT_TRUE(message_data_.back().is_null());
238 239
240 message_data_.clear();
239 ASSERT_TRUE(ClearListeners()); 241 ASSERT_TRUE(ClearListeners());
240 242
241 PASS(); 243 PASS();
242 } 244 }
243 245
244 std::string TestPostMessage::TestSendingArrayBuffer() { 246 std::string TestPostMessage::TestSendingArrayBuffer() {
245 // Clean up after previous tests. This also swallows the message sent by Init 247 // Clean up after previous tests. This also swallows the message sent by Init
246 // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit' 248 // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit'
247 // should start with these. 249 // should start with these.
248 WaitForMessages(); 250 WaitForMessages();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 message_data_.clear(); 291 message_data_.clear();
290 ASSERT_EQ(test_data.ByteLength(), received.ByteLength()); 292 ASSERT_EQ(test_data.ByteLength(), received.ByteLength());
291 unsigned char* received_buff = static_cast<unsigned char*>(received.Map()); 293 unsigned char* received_buff = static_cast<unsigned char*>(received.Map());
292 // The buffer should be copied, so this should be a distinct buffer. When 294 // The buffer should be copied, so this should be a distinct buffer. When
293 // 'transferrables' are implemented for PPAPI, we'll also want to test that 295 // 'transferrables' are implemented for PPAPI, we'll also want to test that
294 // we get the _same_ buffer back when it's transferred. 296 // we get the _same_ buffer back when it's transferred.
295 ASSERT_NE(buff, received_buff); 297 ASSERT_NE(buff, received_buff);
296 for (size_t i = 0; i < test_data.ByteLength(); ++i) 298 for (size_t i = 0; i < test_data.ByteLength(); ++i)
297 ASSERT_EQ(buff[i], received_buff[i]); 299 ASSERT_EQ(buff[i], received_buff[i]);
298 300
301 message_data_.clear();
299 ASSERT_TRUE(ClearListeners()); 302 ASSERT_TRUE(ClearListeners());
300 303
301 PASS(); 304 PASS();
302 } 305 }
303 306
304 std::string TestPostMessage::TestMessageEvent() { 307 std::string TestPostMessage::TestMessageEvent() {
305 // Set up the JavaScript message event listener to pass us some values from 308 // Set up the JavaScript message event listener to pass us some values from
306 // the MessageEvent and make sure they match our expectations. 309 // the MessageEvent and make sure they match our expectations.
307 310
308 WaitForMessages(); 311 WaitForMessages();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 std::vector<double> double_vec; 357 std::vector<double> double_vec;
355 for (; iter != the_end; ++iter) { 358 for (; iter != the_end; ++iter) {
356 ASSERT_TRUE(iter->is_number()); 359 ASSERT_TRUE(iter->is_number());
357 double_vec.push_back(iter->AsDouble()); 360 double_vec.push_back(iter->AsDouble());
358 } 361 }
359 std::sort(double_vec.begin(), double_vec.end()); 362 std::sort(double_vec.begin(), double_vec.end());
360 ASSERT_DOUBLE_EQ(double_vec[0], 1.0); 363 ASSERT_DOUBLE_EQ(double_vec[0], 1.0);
361 ASSERT_DOUBLE_EQ(double_vec[1], 2.0); 364 ASSERT_DOUBLE_EQ(double_vec[1], 2.0);
362 ASSERT_DOUBLE_EQ(double_vec[2], 3.0); 365 ASSERT_DOUBLE_EQ(double_vec[2], 3.0);
363 366
367 message_data_.clear();
368 ASSERT_TRUE(ClearListeners());
369
364 PASS(); 370 PASS();
365 } 371 }
366 372
367 std::string TestPostMessage::TestNoHandler() { 373 std::string TestPostMessage::TestNoHandler() {
368 // Delete any lingering messages and event listeners. 374 // Delete any lingering messages and event listeners.
369 WaitForMessages(); 375 WaitForMessages();
370 ASSERT_TRUE(ClearListeners()); 376 ASSERT_TRUE(ClearListeners());
371 377
372 // Now send a message. We shouldn't get a response. 378 // Now send a message. We shouldn't get a response.
373 message_data_.clear(); 379 message_data_.clear();
(...skipping 11 matching lines...) Expand all
385 // Add a listener that will respond with 1 and an empty array (where the 391 // Add a listener that will respond with 1 and an empty array (where the
386 // message port array would appear if it was Worker postMessage). 392 // message port array would appear if it was Worker postMessage).
387 ASSERT_TRUE(AddEchoingListener("1, []")); 393 ASSERT_TRUE(AddEchoingListener("1, []"));
388 394
389 // Now send a message. We shouldn't get a response. 395 // Now send a message. We shouldn't get a response.
390 message_data_.clear(); 396 message_data_.clear();
391 instance_->PostMessage(pp::Var()); 397 instance_->PostMessage(pp::Var());
392 ASSERT_EQ(WaitForMessages(), 0); 398 ASSERT_EQ(WaitForMessages(), 0);
393 ASSERT_TRUE(message_data_.empty()); 399 ASSERT_TRUE(message_data_.empty());
394 400
401 ASSERT_TRUE(ClearListeners());
402
395 PASS(); 403 PASS();
396 } 404 }
397 405
398 std::string TestPostMessage::TestNonMainThread() { 406 std::string TestPostMessage::TestNonMainThread() {
399 WaitForMessages(); 407 WaitForMessages();
400 ASSERT_TRUE(ClearListeners()); 408 ASSERT_TRUE(ClearListeners());
401 ASSERT_TRUE(AddEchoingListener("message_event.data")); 409 ASSERT_TRUE(AddEchoingListener("message_event.data"));
402 message_data_.clear(); 410 message_data_.clear();
403 411
404 // Set up a thread for each integer from 0 to (kThreadsToRun - 1). Make each 412 // Set up a thread for each integer from 0 to (kThreadsToRun - 1). Make each
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 received_value = latest_var.AsInt(); 449 received_value = latest_var.AsInt();
442 } else if (latest_var.is_double()) { 450 } else if (latest_var.is_double()) {
443 received_value = static_cast<int32_t>(latest_var.AsDouble() + 0.5); 451 received_value = static_cast<int32_t>(latest_var.AsDouble() + 0.5);
444 } 452 }
445 ASSERT_TRUE(received_value >= 0); 453 ASSERT_TRUE(received_value >= 0);
446 ASSERT_TRUE(received_value <= kThreadsToRun); 454 ASSERT_TRUE(received_value <= kThreadsToRun);
447 ++received_counts[received_value]; 455 ++received_counts[received_value];
448 } 456 }
449 ASSERT_EQ(received_counts, expected_counts); 457 ASSERT_EQ(received_counts, expected_counts);
450 458
459 message_data_.clear();
460 ASSERT_TRUE(ClearListeners());
461
451 PASS(); 462 PASS();
452 } 463 }
453 464
OLDNEW
« no previous file with comments | « ppapi/tests/test_memory.cc ('k') | ppapi/tests/test_scrollbar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698