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

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

Issue 9107046: PPAPI: Move PPB_ArrayBuffer out of Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor fixes Created 8 years, 10 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/tests/all_cpp_includes.h ('k') | ppapi/tests/test_websocket.h » ('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) 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
253 253
254 // TODO(sehr,dmichael): Add testing of longer array buffers when 254 // TODO(sehr,dmichael): Add testing of longer array buffers when
255 // crbug.com/110086 is fixed. 255 // crbug.com/110086 is fixed.
256 uint32_t sizes[] = { 0, 100, 1000, 10000, 100000 }; 256 uint32_t sizes[] = { 0, 100, 1000, 10000, 100000 };
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 // Make sure we can Unmap/Map successfully (there's not really any way to 266 // Make sure we can Unmap/Map successfully (there's not really any way to
267 // detect if it's unmapped, so we just re-map before getting the pointer to 267 // detect if it's unmapped, so we just re-map before getting the pointer to
268 // the buffer). 268 // the buffer).
269 test_data.Unmap(); 269 test_data.Unmap();
270 test_data.Map(); 270 test_data.Map();
271 ASSERT_EQ(sizes[i], test_data.ByteLength()); 271 ASSERT_EQ(sizes[i], test_data.ByteLength());
272 unsigned char* buff = static_cast<unsigned char*>(test_data.Map()); 272 unsigned char* buff = static_cast<unsigned char*>(test_data.Map());
273 const uint32_t kByteLength = test_data.ByteLength(); 273 const uint32_t kByteLength = test_data.ByteLength();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 306
307 // Set up the JavaScript message event listener to echo the data part of the 307 // Set up the JavaScript message event listener to echo the data part of the
308 // message event back to us. 308 // message event back to us.
309 ASSERT_TRUE(AddEchoingListener("message_event.data")); 309 ASSERT_TRUE(AddEchoingListener("message_event.data"));
310 message_data_.clear(); 310 message_data_.clear();
311 instance_->PostMessage(test_data); 311 instance_->PostMessage(test_data);
312 // PostMessage is asynchronous, so we should not receive a response yet. 312 // PostMessage is asynchronous, so we should not receive a response yet.
313 ASSERT_EQ(message_data_.size(), 0); 313 ASSERT_EQ(message_data_.size(), 0);
314 ASSERT_EQ(WaitForMessages(), 1); 314 ASSERT_EQ(WaitForMessages(), 1);
315 ASSERT_TRUE(message_data_.back().is_array_buffer()); 315 ASSERT_TRUE(message_data_.back().is_array_buffer());
316 pp::VarArrayBuffer_Dev received(message_data_.back()); 316 pp::VarArrayBuffer received(message_data_.back());
317 message_data_.clear(); 317 message_data_.clear();
318 ASSERT_EQ(test_data.ByteLength(), received.ByteLength()); 318 ASSERT_EQ(test_data.ByteLength(), received.ByteLength());
319 unsigned char* received_buff = static_cast<unsigned char*>(received.Map()); 319 unsigned char* received_buff = static_cast<unsigned char*>(received.Map());
320 // The buffer should be copied, so this should be a distinct buffer. When 320 // The buffer should be copied, so this should be a distinct buffer. When
321 // 'transferrables' are implemented for PPAPI, we'll also want to test that 321 // 'transferrables' are implemented for PPAPI, we'll also want to test that
322 // we get the _same_ buffer back when it's transferred. 322 // we get the _same_ buffer back when it's transferred.
323 if (sizes[i] > 0) 323 if (sizes[i] > 0)
324 ASSERT_NE(buff, received_buff); 324 ASSERT_NE(buff, received_buff);
325 for (size_t i = 0; i < test_data.ByteLength(); ++i) 325 for (size_t i = 0; i < test_data.ByteLength(); ++i)
326 ASSERT_EQ(buff[i], received_buff[i]); 326 ASSERT_EQ(buff[i], received_buff[i]);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 ASSERT_TRUE(received_value <= kThreadsToRun); 482 ASSERT_TRUE(received_value <= kThreadsToRun);
483 ++received_counts[received_value]; 483 ++received_counts[received_value];
484 } 484 }
485 ASSERT_EQ(received_counts, expected_counts); 485 ASSERT_EQ(received_counts, expected_counts);
486 486
487 message_data_.clear(); 487 message_data_.clear();
488 ASSERT_TRUE(ClearListeners()); 488 ASSERT_TRUE(ClearListeners());
489 489
490 PASS(); 490 PASS();
491 } 491 }
OLDNEW
« no previous file with comments | « ppapi/tests/all_cpp_includes.h ('k') | ppapi/tests/test_websocket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698