| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 void InvokePostMessageThreadFunc(void* user_data) { | 53 void InvokePostMessageThreadFunc(void* user_data) { |
| 54 InvokePostMessageThreadArg* arg = | 54 InvokePostMessageThreadArg* arg = |
| 55 static_cast<InvokePostMessageThreadArg*>(user_data); | 55 static_cast<InvokePostMessageThreadArg*>(user_data); |
| 56 for (int32_t i = 0; i < kMessagesToSendPerThread; ++i) | 56 for (int32_t i = 0; i < kMessagesToSendPerThread; ++i) |
| 57 arg->instance->PostMessage(arg->value_to_send); | 57 arg->instance->PostMessage(arg->value_to_send); |
| 58 delete arg; | 58 delete arg; |
| 59 } | 59 } |
| 60 | 60 |
| 61 class ScopedArrayBufferSizeSetter { |
| 62 public: |
| 63 ScopedArrayBufferSizeSetter(const PPB_Testing_Dev* interface, |
| 64 PP_Instance instance, |
| 65 uint32_t threshold) |
| 66 : interface_(interface), |
| 67 instance_(instance) { |
| 68 interface_->SetMinimumArrayBufferSizeForShmem(instance_, threshold); |
| 69 } |
| 70 ~ScopedArrayBufferSizeSetter() { |
| 71 interface_->SetMinimumArrayBufferSizeForShmem(instance_, 0); |
| 72 } |
| 73 private: |
| 74 const PPB_Testing_Dev* interface_; |
| 75 PP_Instance instance_; |
| 76 }; |
| 77 |
| 61 #define FINISHED_WAITING_MESSAGE "TEST_POST_MESSAGE_FINISHED_WAITING" | 78 #define FINISHED_WAITING_MESSAGE "TEST_POST_MESSAGE_FINISHED_WAITING" |
| 62 | 79 |
| 63 } // namespace | 80 } // namespace |
| 64 | 81 |
| 65 TestPostMessage::TestPostMessage(TestingInstance* instance) | 82 TestPostMessage::TestPostMessage(TestingInstance* instance) |
| 66 : TestCase(instance) { | 83 : TestCase(instance) { |
| 67 } | 84 } |
| 68 | 85 |
| 69 TestPostMessage::~TestPostMessage() { | 86 TestPostMessage::~TestPostMessage() { |
| 70 // Remove the special listener that only responds to a FINISHED_WAITING | 87 // Remove the special listener that only responds to a FINISHED_WAITING |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 271 |
| 255 std::string TestPostMessage::TestSendingArrayBuffer() { | 272 std::string TestPostMessage::TestSendingArrayBuffer() { |
| 256 // Clean up after previous tests. This also swallows the message sent by Init | 273 // Clean up after previous tests. This also swallows the message sent by Init |
| 257 // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit' | 274 // if we didn't run the 'SendInInit' test. All tests other than 'SendInInit' |
| 258 // should start with these. | 275 // should start with these. |
| 259 WaitForMessages(); | 276 WaitForMessages(); |
| 260 ASSERT_TRUE(ClearListeners()); | 277 ASSERT_TRUE(ClearListeners()); |
| 261 | 278 |
| 262 // TODO(sehr,dmichael): Add testing of longer array buffers when | 279 // TODO(sehr,dmichael): Add testing of longer array buffers when |
| 263 // crbug.com/110086 is fixed. | 280 // crbug.com/110086 is fixed. |
| 264 #if defined(OS_LINUX) | 281 ScopedArrayBufferSizeSetter setter(testing_interface_, |
| 265 uint32_t sizes[] = { 0, 100, 1000, 10000, 100000, 1000000 }; | 282 instance_->pp_instance(), |
| 266 #else | 283 200); |
| 267 uint32_t sizes[] = { 0, 100, 1000, 10000, 100000 }; | 284 uint32_t sizes[] = { 0, 100, 1000, 10000 }; |
| 268 #endif | |
| 269 for (size_t i = 0; i < sizeof(sizes)/sizeof(sizes[i]); ++i) { | 285 for (size_t i = 0; i < sizeof(sizes)/sizeof(sizes[i]); ++i) { |
| 270 std::ostringstream size_stream; | 286 std::ostringstream size_stream; |
| 271 size_stream << sizes[i]; | 287 size_stream << sizes[i]; |
| 272 const std::string kSizeAsString(size_stream.str()); | 288 const std::string kSizeAsString(size_stream.str()); |
| 273 | 289 |
| 274 // Create an appropriately sized array buffer with test_data[i] == i. | 290 // Create an appropriately sized array buffer with test_data[i] == i. |
| 275 pp::VarArrayBuffer test_data(sizes[i]); | 291 pp::VarArrayBuffer test_data(sizes[i]); |
| 276 if (sizes[i] > 0) | 292 if (sizes[i] > 0) |
| 277 ASSERT_NE(NULL, test_data.Map()); | 293 ASSERT_NE(NULL, test_data.Map()); |
| 278 // Make sure we can Unmap/Map successfully (there's not really any way to | 294 // Make sure we can Unmap/Map successfully (there's not really any way to |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 ASSERT_TRUE(received_value <= kThreadsToRun); | 510 ASSERT_TRUE(received_value <= kThreadsToRun); |
| 495 ++received_counts[received_value]; | 511 ++received_counts[received_value]; |
| 496 } | 512 } |
| 497 ASSERT_EQ(received_counts, expected_counts); | 513 ASSERT_EQ(received_counts, expected_counts); |
| 498 | 514 |
| 499 message_data_.clear(); | 515 message_data_.clear(); |
| 500 ASSERT_TRUE(ClearListeners()); | 516 ASSERT_TRUE(ClearListeners()); |
| 501 | 517 |
| 502 PASS(); | 518 PASS(); |
| 503 } | 519 } |
| OLD | NEW |