summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_flash_clipboard.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ppapi/tests/test_flash_clipboard.cc')
-rw-r--r--ppapi/tests/test_flash_clipboard.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/ppapi/tests/test_flash_clipboard.cc b/ppapi/tests/test_flash_clipboard.cc
index c328269..505399d 100644
--- a/ppapi/tests/test_flash_clipboard.cc
+++ b/ppapi/tests/test_flash_clipboard.cc
@@ -39,6 +39,7 @@ void TestFlashClipboard::RunTests(const std::string& filter) {
RUN_TEST(Clear, filter);
RUN_TEST(InvalidFormat, filter);
RUN_TEST(RegisterCustomFormat, filter);
+ RUN_TEST(GetSequenceNumber, filter);
}
bool TestFlashClipboard::ReadStringVar(uint32_t format, std::string* result) {
@@ -113,6 +114,19 @@ bool TestFlashClipboard::ReadHTMLMatches(const std::string& expected) {
return false;
}
+uint64_t TestFlashClipboard::GetSequenceNumber(uint64_t last_sequence_number) {
+ uint64_t next_sequence_number = last_sequence_number;
+ for (int i = 0; i < kMaxIntervals; ++i) {
+ pp::flash::Clipboard::GetSequenceNumber(
+ instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, &next_sequence_number);
+ if (next_sequence_number != last_sequence_number)
+ return next_sequence_number;
+
+ PlatformSleep(kIntervalMs);
+ }
+ return next_sequence_number;
+}
+
std::string TestFlashClipboard::TestReadWritePlainText() {
std::string input = "Hello world plain text!";
ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, input));
@@ -282,3 +296,55 @@ std::string TestFlashClipboard::TestRegisterCustomFormat() {
PASS();
}
+
+std::string TestFlashClipboard::TestGetSequenceNumber() {
+ uint64_t sequence_number_before = 0;
+ uint64_t sequence_number_after = 0;
+ ASSERT_TRUE(pp::flash::Clipboard::GetSequenceNumber(
+ instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, &sequence_number_before));
+
+ // Test the sequence number changes after writing html.
+ ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML, "<html>"));
+ sequence_number_after = GetSequenceNumber(sequence_number_before);
+ ASSERT_NE(sequence_number_before, sequence_number_after);
+ sequence_number_before = sequence_number_after;
+
+ // Test the sequence number changes after writing some custom data.
+ std::string custom_data = "custom_data";
+ pp::VarArrayBuffer array_buffer(custom_data.size());
+ char* bytes = static_cast<char*>(array_buffer.Map());
+ std::copy(custom_data.begin(), custom_data.end(), bytes);
+ uint32_t format_id =
+ pp::flash::Clipboard::RegisterCustomFormat(instance_, "my-format");
+ std::vector<uint32_t> formats_vector(1, format_id);
+ std::vector<pp::Var> data_vector(1, array_buffer);
+ ASSERT_TRUE(pp::flash::Clipboard::WriteData(instance_,
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ formats_vector,
+ data_vector));
+ sequence_number_after = GetSequenceNumber(sequence_number_before);
+ ASSERT_NE(sequence_number_before, sequence_number_after);
+ sequence_number_before = sequence_number_after;
+
+ // Read the data and make sure the sequence number doesn't change.
+ pp::Var custom_data_result;
+ ASSERT_TRUE(pp::flash::Clipboard::ReadData(
+ instance_,
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ format_id,
+ &custom_data_result));
+ ASSERT_TRUE(pp::flash::Clipboard::GetSequenceNumber(
+ instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, &sequence_number_after));
+ ASSERT_EQ(sequence_number_before, sequence_number_after);
+ sequence_number_before = sequence_number_after;
+
+ // Clear the clipboard and check the sequence number changes.
+ pp::flash::Clipboard::WriteData(instance_,
+ PP_FLASH_CLIPBOARD_TYPE_STANDARD,
+ std::vector<uint32_t>(),
+ std::vector<pp::Var>());
+ sequence_number_after = GetSequenceNumber(sequence_number_before);
+ ASSERT_NE(sequence_number_before, sequence_number_after);
+
+ PASS();
+}