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

Side by Side Diff: ppapi/tests/test_flash_clipboard.cc

Issue 9921018: Added RTF support to pepper API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_flash_clipboard.h ('k') | webkit/glue/clipboard_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 8 #include <vector>
8 9
9 #include "ppapi/cpp/instance.h" 10 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/module.h" 11 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/point.h" 12 #include "ppapi/cpp/point.h"
12 #include "ppapi/cpp/private/flash_clipboard.h" 13 #include "ppapi/cpp/private/flash_clipboard.h"
14 #include "ppapi/cpp/var.h"
15 #include "ppapi/cpp/var_array_buffer.h"
13 #include "ppapi/tests/testing_instance.h" 16 #include "ppapi/tests/testing_instance.h"
14 17
15 REGISTER_TEST_CASE(FlashClipboard); 18 REGISTER_TEST_CASE(FlashClipboard);
16 19
17 // WriteData() sends an async request to the browser process. As a result, the 20 // WriteData() sends an async request to the browser process. As a result, the
18 // string written may not be reflected by IsFormatAvailable() or ReadPlainText() 21 // string written may not be reflected by IsFormatAvailable() or ReadPlainText()
19 // immediately. We need to wait and retry. 22 // immediately. We need to wait and retry.
20 const int kIntervalMs = 250; 23 const int kIntervalMs = 250;
21 const int kMaxIntervals = kActionTimeoutMs / kIntervalMs; 24 const int kMaxIntervals = kActionTimeoutMs / kIntervalMs;
22 25
23 TestFlashClipboard::TestFlashClipboard(TestingInstance* instance) 26 TestFlashClipboard::TestFlashClipboard(TestingInstance* instance)
24 : TestCase(instance) { 27 : TestCase(instance) {
25 } 28 }
26 29
27 void TestFlashClipboard::RunTests(const std::string& filter) { 30 void TestFlashClipboard::RunTests(const std::string& filter) {
28 RUN_TEST(ReadWritePlainText, filter); 31 RUN_TEST(ReadWritePlainText, filter);
29 RUN_TEST(ReadWriteHTML, filter); 32 RUN_TEST(ReadWriteHTML, filter);
33 RUN_TEST(ReadWriteRTF, filter);
30 RUN_TEST(ReadWriteMultipleFormats, filter); 34 RUN_TEST(ReadWriteMultipleFormats, filter);
31 RUN_TEST(Clear, filter); 35 RUN_TEST(Clear, filter);
32 } 36 }
33 37
34 std::string TestFlashClipboard::ReadStringVar( 38 std::string TestFlashClipboard::ReadStringVar(
35 PP_Flash_Clipboard_Format format) { 39 PP_Flash_Clipboard_Format format) {
36 pp::Var text; 40 pp::Var text;
37 bool success = pp::flash::Clipboard::ReadData( 41 bool success = pp::flash::Clipboard::ReadData(
38 instance_, 42 instance_,
39 PP_FLASH_CLIPBOARD_TYPE_STANDARD, 43 PP_FLASH_CLIPBOARD_TYPE_STANDARD,
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 111 }
108 112
109 std::string TestFlashClipboard::TestReadWriteHTML() { 113 std::string TestFlashClipboard::TestReadWriteHTML() {
110 std::string input = "Hello world html!"; 114 std::string input = "Hello world html!";
111 ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML, input)); 115 ASSERT_TRUE(WriteStringVar(PP_FLASH_CLIPBOARD_FORMAT_HTML, input));
112 ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_HTML, true)); 116 ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_HTML, true));
113 ASSERT_TRUE(ReadHTMLMatches(input)); 117 ASSERT_TRUE(ReadHTMLMatches(input));
114 118
115 PASS(); 119 PASS();
116 } 120 }
117 121
viettrungluu 2012/03/29 21:25:10 While you're at it, could you add tests to verify
122 std::string TestFlashClipboard::TestReadWriteRTF() {
123 std::string rtf_string =
124 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n"
125 "This is some {\\b bold} text.\\par\n"
126 "}";
127 pp::VarArrayBuffer array_buffer(rtf_string.size());
128 char *bytes = static_cast<char*>(array_buffer.Map());
129 std::copy(rtf_string.data(), rtf_string.data() + rtf_string.size(), bytes);
130 std::vector<PP_Flash_Clipboard_Format> formats_vector(1,
131 PP_FLASH_CLIPBOARD_FORMAT_RTF);
132 std::vector<pp::Var> data_vector(1, array_buffer);
133 ASSERT_TRUE(pp::flash::Clipboard::WriteData(
134 instance_,
135 PP_FLASH_CLIPBOARD_TYPE_STANDARD,
136 formats_vector,
137 data_vector));
138
139 ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_RTF, true));
140
141 pp::Var rtf_result;
142 ASSERT_TRUE(pp::flash::Clipboard::ReadData(
143 instance_,
144 PP_FLASH_CLIPBOARD_TYPE_STANDARD,
145 PP_FLASH_CLIPBOARD_FORMAT_RTF,
146 &rtf_result));
147 ASSERT_TRUE(rtf_result.is_array_buffer());
148 pp::VarArrayBuffer array_buffer_result(rtf_result);
149 ASSERT_TRUE(array_buffer_result.ByteLength() == array_buffer.ByteLength());
150 char *bytes_result = static_cast<char*>(array_buffer_result.Map());
151 ASSERT_TRUE(std::equal(bytes, bytes + array_buffer.ByteLength(),
152 bytes_result));
153
154 PASS();
155 }
156
118 std::string TestFlashClipboard::TestReadWriteMultipleFormats() { 157 std::string TestFlashClipboard::TestReadWriteMultipleFormats() {
119 std::vector<PP_Flash_Clipboard_Format> formats; 158 std::vector<PP_Flash_Clipboard_Format> formats;
120 std::vector<pp::Var> data; 159 std::vector<pp::Var> data;
121 formats.push_back(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT); 160 formats.push_back(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT);
122 data.push_back(pp::Var("plain text")); 161 data.push_back(pp::Var("plain text"));
123 formats.push_back(PP_FLASH_CLIPBOARD_FORMAT_HTML); 162 formats.push_back(PP_FLASH_CLIPBOARD_FORMAT_HTML);
124 data.push_back(pp::Var("html")); 163 data.push_back(pp::Var("html"));
125 bool success = pp::flash::Clipboard::WriteData( 164 bool success = pp::flash::Clipboard::WriteData(
126 instance_, 165 instance_,
127 PP_FLASH_CLIPBOARD_TYPE_STANDARD, 166 PP_FLASH_CLIPBOARD_TYPE_STANDARD,
(...skipping 18 matching lines...) Expand all
146 instance_, 185 instance_,
147 PP_FLASH_CLIPBOARD_TYPE_STANDARD, 186 PP_FLASH_CLIPBOARD_TYPE_STANDARD,
148 std::vector<PP_Flash_Clipboard_Format>(), 187 std::vector<PP_Flash_Clipboard_Format>(),
149 std::vector<pp::Var>()); 188 std::vector<pp::Var>());
150 ASSERT_TRUE(success); 189 ASSERT_TRUE(success);
151 ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT, 190 ASSERT_TRUE(IsFormatAvailableMatches(PP_FLASH_CLIPBOARD_FORMAT_PLAINTEXT,
152 false)); 191 false));
153 192
154 PASS(); 193 PASS();
155 } 194 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_flash_clipboard.h ('k') | webkit/glue/clipboard_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698