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 "ppapi/tests/test_post_message.h" | 5 #include "ppapi/tests/test_post_message.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "ppapi/c/dev/ppb_testing_dev.h" | 10 #include "ppapi/c/dev/ppb_testing_dev.h" |
11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/cpp/dev/var_array_buffer_dev.h" | |
13 #include "ppapi/cpp/instance.h" | 12 #include "ppapi/cpp/instance.h" |
14 #include "ppapi/cpp/var.h" | 13 #include "ppapi/cpp/var.h" |
| 14 #include "ppapi/cpp/var_array_buffer.h" |
15 #include "ppapi/tests/pp_thread.h" | 15 #include "ppapi/tests/pp_thread.h" |
16 #include "ppapi/tests/test_utils.h" | 16 #include "ppapi/tests/test_utils.h" |
17 #include "ppapi/tests/testing_instance.h" | 17 #include "ppapi/tests/testing_instance.h" |
18 | 18 |
19 // Windows defines 'PostMessage', so we have to undef it. | 19 // Windows defines 'PostMessage', so we have to undef it. |
20 #ifdef PostMessage | 20 #ifdef PostMessage |
21 #undef PostMessage | 21 #undef PostMessage |
22 #endif | 22 #endif |
23 | 23 |
24 REGISTER_TEST_CASE(PostMessage); | 24 REGISTER_TEST_CASE(PostMessage); |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 253 |
254 // TODO(dmichael): Add testing of longer array buffers when crbug.com/106266 | 254 // TODO(dmichael): Add testing of longer array buffers when crbug.com/106266 |
255 // is fixed. | 255 // is fixed. |
256 uint32_t sizes[] = { 0, 100, 1000 }; | 256 uint32_t sizes[] = { 0, 100, 1000 }; |
257 for (size_t i = 0; i < sizeof(sizes)/sizeof(sizes[i]); ++i) { | 257 for (size_t i = 0; i < sizeof(sizes)/sizeof(sizes[i]); ++i) { |
258 std::ostringstream size_stream; | 258 std::ostringstream size_stream; |
259 size_stream << sizes[i]; | 259 size_stream << sizes[i]; |
260 const std::string kSizeAsString(size_stream.str()); | 260 const std::string kSizeAsString(size_stream.str()); |
261 | 261 |
262 // Create an appropriately sized array buffer with test_data[i] == i. | 262 // Create an appropriately sized array buffer with test_data[i] == i. |
263 pp::VarArrayBuffer_Dev test_data(sizes[i]); | 263 pp::VarArrayBuffer test_data(sizes[i]); |
264 if (sizes[i] > 0) | 264 if (sizes[i] > 0) |
265 ASSERT_NE(NULL, test_data.Map()); | 265 ASSERT_NE(NULL, test_data.Map()); |
266 ASSERT_EQ(sizes[i], test_data.ByteLength()); | 266 ASSERT_EQ(sizes[i], test_data.ByteLength()); |
267 unsigned char* buff = static_cast<unsigned char*>(test_data.Map()); | 267 unsigned char* buff = static_cast<unsigned char*>(test_data.Map()); |
268 const uint32_t kByteLength = test_data.ByteLength(); | 268 const uint32_t kByteLength = test_data.ByteLength(); |
269 for (size_t j = 0; j < kByteLength; ++j) | 269 for (size_t j = 0; j < kByteLength; ++j) |
270 buff[j] = static_cast<uint8_t>(j % 256u); | 270 buff[j] = static_cast<uint8_t>(j % 256u); |
271 | 271 |
272 // Have the listener test some properties of the ArrayBuffer. | 272 // Have the listener test some properties of the ArrayBuffer. |
273 std::vector<std::string> properties_to_check; | 273 std::vector<std::string> properties_to_check; |
(...skipping 27 matching lines...) Expand all Loading... |
301 | 301 |
302 // Set up the JavaScript message event listener to echo the data part of the | 302 // Set up the JavaScript message event listener to echo the data part of the |
303 // message event back to us. | 303 // message event back to us. |
304 ASSERT_TRUE(AddEchoingListener("message_event.data")); | 304 ASSERT_TRUE(AddEchoingListener("message_event.data")); |
305 message_data_.clear(); | 305 message_data_.clear(); |
306 instance_->PostMessage(test_data); | 306 instance_->PostMessage(test_data); |
307 // PostMessage is asynchronous, so we should not receive a response yet. | 307 // PostMessage is asynchronous, so we should not receive a response yet. |
308 ASSERT_EQ(message_data_.size(), 0); | 308 ASSERT_EQ(message_data_.size(), 0); |
309 ASSERT_EQ(WaitForMessages(), 1); | 309 ASSERT_EQ(WaitForMessages(), 1); |
310 ASSERT_TRUE(message_data_.back().is_array_buffer()); | 310 ASSERT_TRUE(message_data_.back().is_array_buffer()); |
311 pp::VarArrayBuffer_Dev received(message_data_.back()); | 311 pp::VarArrayBuffer received(message_data_.back()); |
312 message_data_.clear(); | 312 message_data_.clear(); |
313 ASSERT_EQ(test_data.ByteLength(), received.ByteLength()); | 313 ASSERT_EQ(test_data.ByteLength(), received.ByteLength()); |
314 unsigned char* received_buff = static_cast<unsigned char*>(received.Map()); | 314 unsigned char* received_buff = static_cast<unsigned char*>(received.Map()); |
315 // The buffer should be copied, so this should be a distinct buffer. When | 315 // The buffer should be copied, so this should be a distinct buffer. When |
316 // 'transferrables' are implemented for PPAPI, we'll also want to test that | 316 // 'transferrables' are implemented for PPAPI, we'll also want to test that |
317 // we get the _same_ buffer back when it's transferred. | 317 // we get the _same_ buffer back when it's transferred. |
318 if (sizes[i] > 0) | 318 if (sizes[i] > 0) |
319 ASSERT_NE(buff, received_buff); | 319 ASSERT_NE(buff, received_buff); |
320 for (size_t i = 0; i < test_data.ByteLength(); ++i) | 320 for (size_t i = 0; i < test_data.ByteLength(); ++i) |
321 ASSERT_EQ(buff[i], received_buff[i]); | 321 ASSERT_EQ(buff[i], received_buff[i]); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 ++received_counts[received_value]; | 478 ++received_counts[received_value]; |
479 } | 479 } |
480 ASSERT_EQ(received_counts, expected_counts); | 480 ASSERT_EQ(received_counts, expected_counts); |
481 | 481 |
482 message_data_.clear(); | 482 message_data_.clear(); |
483 ASSERT_TRUE(ClearListeners()); | 483 ASSERT_TRUE(ClearListeners()); |
484 | 484 |
485 PASS(); | 485 PASS(); |
486 } | 486 } |
487 | 487 |
OLD | NEW |