Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_flash_clipboard.h" | 5 #include "ppapi/tests/test_flash_clipboard.h" |
| 6 | 6 |
| 7 #include "ppapi/cpp/instance.h" | 7 #include "ppapi/cpp/instance.h" |
| 8 #include "ppapi/cpp/module.h" | 8 #include "ppapi/cpp/module.h" |
| 9 #include "ppapi/cpp/point.h" | 9 #include "ppapi/cpp/point.h" |
| 10 #include "ppapi/tests/testing_instance.h" | 10 #include "ppapi/tests/testing_instance.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 RUN_TEST(ReadWrite); | 26 RUN_TEST(ReadWrite); |
| 27 } | 27 } |
| 28 | 28 |
| 29 std::string TestFlashClipboard::TestReadWrite() { | 29 std::string TestFlashClipboard::TestReadWrite() { |
| 30 std::string input_str("Hello, world"); | 30 std::string input_str("Hello, world"); |
| 31 pp::Var input_var(input_str); | 31 pp::Var input_var(input_str); |
| 32 clipboard_interface_->WritePlainText(instance_->pp_instance(), | 32 clipboard_interface_->WritePlainText(instance_->pp_instance(), |
| 33 PP_FLASH_CLIPBOARD_TYPE_STANDARD, | 33 PP_FLASH_CLIPBOARD_TYPE_STANDARD, |
| 34 input_var.pp_var()); | 34 input_var.pp_var()); |
| 35 | 35 |
| 36 ASSERT_TRUE(clipboard_interface_->IsFormatAvailable( | 36 // WritePlainText() causes an async request sent to the browser process. |
| 37 instance_->pp_instance(), | 37 // As a result, the string written may not be reflected by IsFormatAvailable() |
| 38 PP_FLASH_CLIPBOARD_TYPE_STANDARD, | 38 // or ReadPlainText() immediately. We need to wait and retry. |
|
Paweł Hajdan Jr.
2011/11/14 12:32:48
I'm not sure how well this will work. If you reall
dmichael (off chromium)
2011/11/14 15:48:15
Oops, he is right. I wasn't looking carefully enou
| |
| 39 PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT)); | 39 const int kIntervalMs = 250; |
| 40 const int kMaxIntervals = kActionTimeoutMs / kIntervalMs; | |
| 40 | 41 |
| 41 pp::Var result_var(pp::Var::PassRef(), | 42 PP_Bool is_available = PP_FALSE; |
| 42 clipboard_interface_->ReadPlainText(instance_->pp_instance(), | 43 for (int i = 0; i < kMaxIntervals; ++i) { |
| 43 PP_FLASH_CLIPBOARD_TYPE_STANDARD)); | 44 is_available = clipboard_interface_->IsFormatAvailable( |
| 44 ASSERT_TRUE(result_var.is_string()); | 45 instance_->pp_instance(), |
| 46 PP_FLASH_CLIPBOARD_TYPE_STANDARD, | |
| 47 PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT); | |
| 48 if (is_available) | |
| 49 break; | |
| 45 | 50 |
| 46 std::string result_str = result_var.AsString(); | 51 PlatformSleep(kIntervalMs); |
| 52 } | |
| 53 ASSERT_TRUE(is_available); | |
| 54 | |
| 55 std::string result_str; | |
| 56 for (int i = 0; i < kMaxIntervals; ++i) { | |
| 57 pp::Var result_var(pp::Var::PassRef(), | |
| 58 clipboard_interface_->ReadPlainText(instance_->pp_instance(), | |
| 59 PP_FLASH_CLIPBOARD_TYPE_STANDARD)); | |
| 60 ASSERT_TRUE(result_var.is_string()); | |
| 61 result_str = result_var.AsString(); | |
| 62 if (result_str == input_str) | |
| 63 break; | |
| 64 | |
| 65 PlatformSleep(kIntervalMs); | |
| 66 } | |
| 67 | |
| 47 ASSERT_TRUE(result_str == input_str); | 68 ASSERT_TRUE(result_str == input_str); |
| 48 PASS(); | 69 PASS(); |
| 49 } | 70 } |
| OLD | NEW |