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

Unified Diff: ppapi/tests/test_flash_clipboard.cc

Issue 9212066: Modified the flash cipboard interface to add html clipboard support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/tests/test_flash_clipboard.cc
diff --git a/ppapi/tests/test_flash_clipboard.cc b/ppapi/tests/test_flash_clipboard.cc
index 3022705cc98a6873c677a4d17fd4b7cdc84d1acd..794d40100bfe3896a5f27611efb60c69bf81397a 100644
--- a/ppapi/tests/test_flash_clipboard.cc
+++ b/ppapi/tests/test_flash_clipboard.cc
@@ -11,6 +11,12 @@
REGISTER_TEST_CASE(FlashClipboard);
+// WriteData() causes an async request sent to the browser process.
+// As a result, the string written may not be reflected by IsFormatAvailable()
+// or ReadPlainText() immediately. We need to wait and retry.
+const int TestFlashClipboard::kIntervalMs = 250;
+const int TestFlashClipboard::kMaxIntervals = kActionTimeoutMs / kIntervalMs;
+
TestFlashClipboard::TestFlashClipboard(TestingInstance* instance)
: TestCase(instance),
clipboard_interface_(NULL) {
@@ -18,53 +24,113 @@ TestFlashClipboard::TestFlashClipboard(TestingInstance* instance)
bool TestFlashClipboard::Init() {
clipboard_interface_ = static_cast<const PPB_Flash_Clipboard*>(
- pp::Module::Get()->GetBrowserInterface(PPB_FLASH_CLIPBOARD_INTERFACE));
+ pp::Module::Get()->GetBrowserInterface(
+ PPB_FLASH_CLIPBOARD_INTERFACE));
return !!clipboard_interface_;
}
void TestFlashClipboard::RunTests(const std::string& filter) {
- RUN_TEST(ReadWrite, filter);
+ RUN_TEST(ReadWritePlainText, filter);
+ RUN_TEST(ReadWriteHTML, filter);
+ RUN_TEST(ReadWriteMultipleFormats, filter);
}
-std::string TestFlashClipboard::TestReadWrite() {
- std::string input_str("Hello, world");
- pp::Var input_var(input_str);
- clipboard_interface_->WritePlainText(instance_->pp_instance(),
- PP_FLASH_CLIPBOARD_TYPE_STANDARD,
- input_var.pp_var());
-
- // WritePlainText() causes an async request sent to the browser process.
- // As a result, the string written may not be reflected by IsFormatAvailable()
- // or ReadPlainText() immediately. We need to wait and retry.
- const int kIntervalMs = 250;
- const int kMaxIntervals = kActionTimeoutMs / kIntervalMs;
-
+PP_Bool TestFlashClipboard::IsFormatAvailable(
+ PP_Flash_Clipboard_Format format) {
PP_Bool is_available = PP_FALSE;
for (int i = 0; i < kMaxIntervals; ++i) {
is_available = clipboard_interface_->IsFormatAvailable(
instance_->pp_instance(),
PP_FLASH_CLIPBOARD_TYPE_STANDARD,
- PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT);
+ format);
if (is_available)
break;
PlatformSleep(kIntervalMs);
}
- ASSERT_TRUE(is_available);
+ return is_available;
+}
+std::string TestFlashClipboard::ReadStringVar(
+ PP_Flash_Clipboard_Format format) {
std::string result_str;
for (int i = 0; i < kMaxIntervals; ++i) {
pp::Var result_var(pp::Var::PassRef(),
- clipboard_interface_->ReadPlainText(instance_->pp_instance(),
- PP_FLASH_CLIPBOARD_TYPE_STANDARD));
- ASSERT_TRUE(result_var.is_string());
- result_str = result_var.AsString();
- if (result_str == input_str)
+ clipboard_interface_->ReadData(instance_->pp_instance(),
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ format));
+
+ if (result_var.is_string()) {
+ result_str = result_var.AsString();
break;
+ }
PlatformSleep(kIntervalMs);
}
+ return result_str;
+}
+
+int32_t TestFlashClipboard::WriteStringVar(PP_Flash_Clipboard_Format format,
+ const std::string& input) {
+ pp::Var input_var(input);
+ PP_Flash_Clipboard_Data_Item item = {format, input_var.pp_var()};
+ int32_t success = clipboard_interface_->WriteData(
+ instance_->pp_instance(),
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ 1,
+ &item);
+ return success;
+}
+
+std::string TestFlashClipboard::TestReadWritePlainText() {
+ std::string input = "Hello world plain text!";
+ ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
+ input) == PP_OK);
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT));
+ ASSERT_TRUE(ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) == input);
+
+ PASS();
+}
+
+std::string TestFlashClipboard::TestReadWriteHTML() {
+ std::string input = "Hello world html!";
+ ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML,
+ input) == PP_OK);
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_HTML));
+ std::string result = ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML);
+ // Metadata is inserted at the start of pasted html clipboard data. So check
+ // that it ends with what was copied in.
+ int match = result.compare(result.length() - input.length(),
+ input.length(), input);
+ ASSERT_TRUE(match == 0);
+
+ PASS();
+}
+
+std::string TestFlashClipboard::TestReadWriteMultipleFormats() {
+ std::string plain_text("plain text");
+ std::string html("html");
+ pp::Var plain_text_var(plain_text);
+ pp::Var html_var(html);
+ PP_Flash_Clipboard_Data_Item items[] = {
+ {PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, plain_text_var.pp_var()},
+ {PP_FLASH_CLIPBOARD_FORMAT_HTML, html_var.pp_var()}
+ };
+ int32_t success = clipboard_interface_->WriteData(
+ instance_->pp_instance(),
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ 2,
+ items);
+ ASSERT_TRUE(success == PP_OK);
+
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT));
+ ASSERT_TRUE(IsFormatAvailable(PP_FLASH_CLIPBOARD_FORMAT_HTML));
+
+ ASSERT_TRUE(ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT) == plain_text);
+ std::string result_html = ReadStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML);
+ int match = result_html.compare(result_html.length() - html.length(),
+ html.length(), html);
+ ASSERT_TRUE(match == 0);
- ASSERT_TRUE(result_str == input_str);
PASS();
}

Powered by Google App Engine
This is Rietveld 408576698