| 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_flash_clipboard.h" |    5 #include "ppapi/tests/test_flash_clipboard.h" | 
|    6  |    6  | 
|    7 #include <algorithm> |    7 #include <algorithm> | 
|    8 #include <vector> |    8 #include <vector> | 
|    9  |    9  | 
|   10 #include "ppapi/cpp/instance.h" |   10 #include "ppapi/cpp/instance.h" | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|   32  |   32  | 
|   33 void TestFlashClipboard::RunTests(const std::string& filter) { |   33 void TestFlashClipboard::RunTests(const std::string& filter) { | 
|   34   RUN_TEST(ReadWritePlainText, filter); |   34   RUN_TEST(ReadWritePlainText, filter); | 
|   35   RUN_TEST(ReadWriteHTML, filter); |   35   RUN_TEST(ReadWriteHTML, filter); | 
|   36   RUN_TEST(ReadWriteRTF, filter); |   36   RUN_TEST(ReadWriteRTF, filter); | 
|   37   RUN_TEST(ReadWriteCustomData, filter); |   37   RUN_TEST(ReadWriteCustomData, filter); | 
|   38   RUN_TEST(ReadWriteMultipleFormats, filter); |   38   RUN_TEST(ReadWriteMultipleFormats, filter); | 
|   39   RUN_TEST(Clear, filter); |   39   RUN_TEST(Clear, filter); | 
|   40   RUN_TEST(InvalidFormat, filter); |   40   RUN_TEST(InvalidFormat, filter); | 
|   41   RUN_TEST(RegisterCustomFormat, filter); |   41   RUN_TEST(RegisterCustomFormat, filter); | 
 |   42   RUN_TEST(GetSequenceNumber, filter); | 
|   42 } |   43 } | 
|   43  |   44  | 
|   44 bool TestFlashClipboard::ReadStringVar(uint32_t format, std::string* result) { |   45 bool TestFlashClipboard::ReadStringVar(uint32_t format, std::string* result) { | 
|   45   pp::Var text; |   46   pp::Var text; | 
|   46   bool success = pp::flash::Clipboard::ReadData( |   47   bool success = pp::flash::Clipboard::ReadData( | 
|   47       instance_, |   48       instance_, | 
|   48       PP_FLASH_CLIPBOARD_TYPE_STANDARD, |   49       PP_FLASH_CLIPBOARD_TYPE_STANDARD, | 
|   49       format, |   50       format, | 
|   50       &text); |   51       &text); | 
|   51   if (success && text.is_string()) { |   52   if (success && text.is_string()) { | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  106         result.find("<!--StartFragment-->") == std::string::npos && |  107         result.find("<!--StartFragment-->") == std::string::npos && | 
|  107         result.find("<!--EndFragment-->") == std::string::npos) { |  108         result.find("<!--EndFragment-->") == std::string::npos) { | 
|  108       return true; |  109       return true; | 
|  109     } |  110     } | 
|  110  |  111  | 
|  111     PlatformSleep(kIntervalMs); |  112     PlatformSleep(kIntervalMs); | 
|  112   } |  113   } | 
|  113   return false; |  114   return false; | 
|  114 } |  115 } | 
|  115  |  116  | 
 |  117 uint64_t TestFlashClipboard::GetSequenceNumber(uint64_t last_sequence_number) { | 
 |  118   uint64_t next_sequence_number = last_sequence_number; | 
 |  119   for (int i = 0; i < kMaxIntervals; ++i) { | 
 |  120     pp::flash::Clipboard::GetSequenceNumber( | 
 |  121         instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, &next_sequence_number); | 
 |  122     if (next_sequence_number != last_sequence_number) | 
 |  123       return next_sequence_number; | 
 |  124  | 
 |  125     PlatformSleep(kIntervalMs); | 
 |  126   } | 
 |  127   return next_sequence_number; | 
 |  128 } | 
 |  129  | 
|  116 std::string TestFlashClipboard::TestReadWritePlainText() { |  130 std::string TestFlashClipboard::TestReadWritePlainText() { | 
|  117   std::string input = "Hello world plain text!"; |  131   std::string input = "Hello world plain text!"; | 
|  118   ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, input)); |  132   ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, input)); | 
|  119   ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, |  133   ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, | 
|  120                                        true)); |  134                                        true)); | 
|  121   ASSERT_TRUE(ReadPlainTextMatches(input)); |  135   ASSERT_TRUE(ReadPlainTextMatches(input)); | 
|  122  |  136  | 
|  123   PASS(); |  137   PASS(); | 
|  124 } |  138 } | 
|  125  |  139  | 
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  269       pp::flash::Clipboard::RegisterCustomFormat(instance_, "a-b"); |  283       pp::flash::Clipboard::RegisterCustomFormat(instance_, "a-b"); | 
|  270   ASSERT_EQ(format_id, format_id2); |  284   ASSERT_EQ(format_id, format_id2); | 
|  271  |  285  | 
|  272   // Check that the second format registered has a different id. |  286   // Check that the second format registered has a different id. | 
|  273   uint32_t format_id3 = |  287   uint32_t format_id3 = | 
|  274       pp::flash::Clipboard::RegisterCustomFormat(instance_, "a-b-c"); |  288       pp::flash::Clipboard::RegisterCustomFormat(instance_, "a-b-c"); | 
|  275   ASSERT_NE(format_id, format_id3); |  289   ASSERT_NE(format_id, format_id3); | 
|  276  |  290  | 
|  277   PASS(); |  291   PASS(); | 
|  278 } |  292 } | 
 |  293  | 
 |  294 std::string TestFlashClipboard::TestGetSequenceNumber() { | 
 |  295   uint64_t sequence_number_before = 0; | 
 |  296   uint64_t sequence_number_after = 0; | 
 |  297   ASSERT_TRUE(pp::flash::Clipboard::GetSequenceNumber( | 
 |  298       instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, &sequence_number_before)); | 
 |  299  | 
 |  300   // Test the sequence number changes after writing html. | 
 |  301   ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML, "<html>")); | 
 |  302   sequence_number_after = GetSequenceNumber(sequence_number_before); | 
 |  303   ASSERT_NE(sequence_number_before, sequence_number_after); | 
 |  304   sequence_number_before = sequence_number_after; | 
 |  305  | 
 |  306   // Test the sequence number changes after writing some custom data. | 
 |  307   std::string custom_data = "custom_data"; | 
 |  308   pp::VarArrayBuffer array_buffer(custom_data.size()); | 
 |  309   char* bytes = static_cast<char*>(array_buffer.Map()); | 
 |  310   std::copy(custom_data.begin(), custom_data.end(), bytes); | 
 |  311   uint32_t format_id = | 
 |  312       pp::flash::Clipboard::RegisterCustomFormat(instance_, "my-format"); | 
 |  313   std::vector<uint32_t> formats_vector(1, format_id); | 
 |  314   std::vector<pp::Var> data_vector(1, array_buffer); | 
 |  315   ASSERT_TRUE(pp::flash::Clipboard::WriteData(instance_, | 
 |  316                                               PP_FLASH_CLIPBOARD_TYPE_STANDARD, | 
 |  317                                               formats_vector, | 
 |  318                                               data_vector)); | 
 |  319   sequence_number_after = GetSequenceNumber(sequence_number_before); | 
 |  320   ASSERT_NE(sequence_number_before, sequence_number_after); | 
 |  321   sequence_number_before = sequence_number_after; | 
 |  322  | 
 |  323   // Read the data and make sure the sequence number doesn't change. | 
 |  324   pp::Var custom_data_result; | 
 |  325   ASSERT_TRUE(pp::flash::Clipboard::ReadData( | 
 |  326       instance_, | 
 |  327       PP_FLASH_CLIPBOARD_TYPE_STANDARD, | 
 |  328       format_id, | 
 |  329       &custom_data_result)); | 
 |  330   ASSERT_TRUE(pp::flash::Clipboard::GetSequenceNumber( | 
 |  331       instance_, PP_FLASH_CLIPBOARD_TYPE_STANDARD, &sequence_number_after)); | 
 |  332   ASSERT_EQ(sequence_number_before, sequence_number_after); | 
 |  333   sequence_number_before = sequence_number_after; | 
 |  334  | 
 |  335   // Clear the clipboard and check the sequence number changes. | 
 |  336   pp::flash::Clipboard::WriteData(instance_, | 
 |  337                                   PP_FLASH_CLIPBOARD_TYPE_STANDARD, | 
 |  338                                   std::vector<uint32_t>(), | 
 |  339                                   std::vector<pp::Var>()); | 
 |  340   sequence_number_after = GetSequenceNumber(sequence_number_before); | 
 |  341   ASSERT_NE(sequence_number_before, sequence_number_after); | 
 |  342  | 
 |  343   PASS(); | 
 |  344 } | 
| OLD | NEW |