OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/clipboard.h" | 8 #include "base/clipboard.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/scoped_clipboard_writer.h" | 10 #include "base/scoped_clipboard_writer.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
14 | 14 |
15 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
16 class ClipboardTest : public PlatformTest { | 16 class ClipboardTest : public PlatformTest { |
17 protected: | 17 protected: |
18 virtual void SetUp() { | 18 virtual void SetUp() { |
19 message_loop_.reset(new MessageLoopForUI()); | 19 message_loop_.reset(new MessageLoopForUI()); |
20 } | 20 } |
21 virtual void TearDown() { | 21 virtual void TearDown() { |
22 } | 22 } |
23 | 23 |
24 private: | 24 private: |
25 scoped_ptr<MessageLoop> message_loop_; | 25 scoped_ptr<MessageLoop> message_loop_; |
26 }; | 26 }; |
27 #elif defined(OS_POSIX) | 27 #elif defined(OS_POSIX) |
28 typedef PlatformTest ClipboardTest; | 28 typedef PlatformTest ClipboardTest; |
29 #endif // defined(OS_WIN) | 29 #endif // defined(OS_WIN) |
30 | 30 |
31 TEST_F(ClipboardTest, ClearTest) { | 31 TEST_F(ClipboardTest, ClearTest) { |
32 Clipboard clipboard; | 32 Clipboard clipboard; |
33 | 33 |
34 { | 34 { |
35 ScopedClipboardWriter clipboard_writer(&clipboard); | 35 ScopedClipboardWriter clipboard_writer(&clipboard); |
36 clipboard_writer.WriteText(std::wstring(L"clear me")); | 36 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); |
37 } | 37 } |
38 | 38 |
39 { | 39 { |
40 ScopedClipboardWriter clipboard_writer(&clipboard); | 40 ScopedClipboardWriter clipboard_writer(&clipboard); |
41 clipboard_writer.WriteHTML(std::wstring(L"<b>broom</b>"), ""); | 41 clipboard_writer.WriteHTML(ASCIIToUTF16("<b>broom</b>"), ""); |
42 } | 42 } |
43 | 43 |
44 EXPECT_FALSE(clipboard.IsFormatAvailable( | 44 EXPECT_FALSE(clipboard.IsFormatAvailable( |
45 Clipboard::GetPlainTextWFormatType())); | 45 Clipboard::GetPlainTextWFormatType())); |
46 EXPECT_FALSE(clipboard.IsFormatAvailable( | 46 EXPECT_FALSE(clipboard.IsFormatAvailable( |
47 Clipboard::GetPlainTextFormatType())); | 47 Clipboard::GetPlainTextFormatType())); |
48 } | 48 } |
49 | 49 |
50 TEST_F(ClipboardTest, TextTest) { | 50 TEST_F(ClipboardTest, TextTest) { |
51 Clipboard clipboard; | 51 Clipboard clipboard; |
52 | 52 |
53 std::wstring text(L"This is a wstring!#$"), text_result; | 53 string16 text(ASCIIToUTF16("This is a string16!#$")), text_result; |
54 std::string ascii_text; | 54 std::string ascii_text; |
55 | 55 |
56 { | 56 { |
57 ScopedClipboardWriter clipboard_writer(&clipboard); | 57 ScopedClipboardWriter clipboard_writer(&clipboard); |
58 clipboard_writer.WriteText(text); | 58 clipboard_writer.WriteText(text); |
59 } | 59 } |
60 | 60 |
61 EXPECT_TRUE(clipboard.IsFormatAvailable( | 61 EXPECT_TRUE(clipboard.IsFormatAvailable( |
62 Clipboard::GetPlainTextWFormatType())); | 62 Clipboard::GetPlainTextWFormatType())); |
63 EXPECT_TRUE(clipboard.IsFormatAvailable( | 63 EXPECT_TRUE(clipboard.IsFormatAvailable( |
64 Clipboard::GetPlainTextFormatType())); | 64 Clipboard::GetPlainTextFormatType())); |
65 clipboard.ReadText(&text_result); | 65 clipboard.ReadText(&text_result); |
| 66 |
66 EXPECT_EQ(text, text_result); | 67 EXPECT_EQ(text, text_result); |
67 clipboard.ReadAsciiText(&ascii_text); | 68 clipboard.ReadAsciiText(&ascii_text); |
68 EXPECT_EQ(WideToUTF8(text), ascii_text); | 69 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
69 } | 70 } |
70 | 71 |
71 TEST_F(ClipboardTest, HTMLTest) { | 72 TEST_F(ClipboardTest, HTMLTest) { |
72 Clipboard clipboard; | 73 Clipboard clipboard; |
73 | 74 |
74 std::wstring markup(L"<string>Hi!</string>"), markup_result; | 75 string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; |
75 std::string url("http://www.example.com/"), url_result; | 76 std::string url("http://www.example.com/"), url_result; |
76 | 77 |
77 { | 78 { |
78 ScopedClipboardWriter clipboard_writer(&clipboard); | 79 ScopedClipboardWriter clipboard_writer(&clipboard); |
79 clipboard_writer.WriteHTML(markup, url); | 80 clipboard_writer.WriteHTML(markup, url); |
80 } | 81 } |
81 | 82 |
82 EXPECT_EQ(true, clipboard.IsFormatAvailable( | 83 EXPECT_EQ(true, clipboard.IsFormatAvailable( |
83 Clipboard::GetHtmlFormatType())); | 84 Clipboard::GetHtmlFormatType())); |
84 clipboard.ReadHTML(&markup_result, &url_result); | 85 clipboard.ReadHTML(&markup_result, &url_result); |
85 EXPECT_EQ(markup, markup_result); | 86 EXPECT_EQ(markup, markup_result); |
86 #if defined(OS_WIN) | 87 #if defined(OS_WIN) |
87 // TODO(playmobil): It's not clear that non windows clipboards need to support | 88 // TODO(playmobil): It's not clear that non windows clipboards need to support |
88 // this. | 89 // this. |
89 EXPECT_EQ(url, url_result); | 90 EXPECT_EQ(url, url_result); |
90 #endif // defined(OS_WIN) | 91 #endif // defined(OS_WIN) |
91 } | 92 } |
92 | 93 |
93 TEST_F(ClipboardTest, TrickyHTMLTest) { | 94 TEST_F(ClipboardTest, TrickyHTMLTest) { |
94 Clipboard clipboard; | 95 Clipboard clipboard; |
95 | 96 |
96 std::wstring markup(L"<em>Bye!<!--EndFragment --></em>"), markup_result; | 97 string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")), |
| 98 markup_result; |
97 std::string url, url_result; | 99 std::string url, url_result; |
98 | 100 |
99 { | 101 { |
100 ScopedClipboardWriter clipboard_writer(&clipboard); | 102 ScopedClipboardWriter clipboard_writer(&clipboard); |
101 clipboard_writer.WriteHTML(markup, url); | 103 clipboard_writer.WriteHTML(markup, url); |
102 } | 104 } |
103 | 105 |
104 EXPECT_EQ(true, clipboard.IsFormatAvailable( | 106 EXPECT_EQ(true, clipboard.IsFormatAvailable( |
105 Clipboard::GetHtmlFormatType())); | 107 Clipboard::GetHtmlFormatType())); |
106 clipboard.ReadHTML(&markup_result, &url_result); | 108 clipboard.ReadHTML(&markup_result, &url_result); |
107 EXPECT_EQ(markup, markup_result); | 109 EXPECT_EQ(markup, markup_result); |
108 #if defined(OS_WIN) | 110 #if defined(OS_WIN) |
109 // TODO(playmobil): It's not clear that non windows clipboards need to support | 111 // TODO(playmobil): It's not clear that non windows clipboards need to support |
110 // this. | 112 // this. |
111 EXPECT_EQ(url, url_result); | 113 EXPECT_EQ(url, url_result); |
112 #endif // defined(OS_WIN) | 114 #endif // defined(OS_WIN) |
113 } | 115 } |
114 | 116 |
115 // TODO(estade): Port the following test (decide what target we use for urls) | 117 // TODO(estade): Port the following test (decide what target we use for urls) |
116 #if !defined(OS_LINUX) | 118 #if !defined(OS_LINUX) |
117 TEST_F(ClipboardTest, BookmarkTest) { | 119 TEST_F(ClipboardTest, BookmarkTest) { |
118 Clipboard clipboard; | 120 Clipboard clipboard; |
119 | 121 |
120 std::wstring title(L"The Example Company"), title_result; | 122 string16 title(ASCIIToUTF16("The Example Company")), title_result; |
121 std::string url("http://www.example.com/"), url_result; | 123 std::string url("http://www.example.com/"), url_result; |
122 | 124 |
123 { | 125 { |
124 ScopedClipboardWriter clipboard_writer(&clipboard); | 126 ScopedClipboardWriter clipboard_writer(&clipboard); |
125 clipboard_writer.WriteBookmark(title, url); | 127 clipboard_writer.WriteBookmark(title, url); |
126 } | 128 } |
127 | 129 |
128 EXPECT_EQ(true, | 130 EXPECT_EQ(true, |
129 clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); | 131 clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); |
130 clipboard.ReadBookmark(&title_result, &url_result); | 132 clipboard.ReadBookmark(&title_result, &url_result); |
131 EXPECT_EQ(title, title_result); | 133 EXPECT_EQ(title, title_result); |
132 EXPECT_EQ(url, url_result); | 134 EXPECT_EQ(url, url_result); |
133 } | 135 } |
134 #endif // defined(OS_WIN) | 136 #endif // defined(OS_WIN) |
135 | 137 |
136 TEST_F(ClipboardTest, MultiFormatTest) { | 138 TEST_F(ClipboardTest, MultiFormatTest) { |
137 Clipboard clipboard; | 139 Clipboard clipboard; |
138 | 140 |
139 std::wstring text(L"Hi!"), text_result; | 141 string16 text(ASCIIToUTF16("Hi!")), text_result; |
140 std::wstring markup(L"<strong>Hi!</string>"), markup_result; | 142 string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; |
141 std::string url("http://www.example.com/"), url_result; | 143 std::string url("http://www.example.com/"), url_result; |
142 std::string ascii_text; | 144 std::string ascii_text; |
143 | 145 |
144 { | 146 { |
145 ScopedClipboardWriter clipboard_writer(&clipboard); | 147 ScopedClipboardWriter clipboard_writer(&clipboard); |
146 clipboard_writer.WriteHTML(markup, url); | 148 clipboard_writer.WriteHTML(markup, url); |
147 clipboard_writer.WriteText(text); | 149 clipboard_writer.WriteText(text); |
148 } | 150 } |
149 | 151 |
150 EXPECT_EQ(true, | 152 EXPECT_EQ(true, |
151 clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); | 153 clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); |
152 EXPECT_EQ(true, clipboard.IsFormatAvailable( | 154 EXPECT_EQ(true, clipboard.IsFormatAvailable( |
153 Clipboard::GetPlainTextWFormatType())); | 155 Clipboard::GetPlainTextWFormatType())); |
154 EXPECT_EQ(true, clipboard.IsFormatAvailable( | 156 EXPECT_EQ(true, clipboard.IsFormatAvailable( |
155 Clipboard::GetPlainTextFormatType())); | 157 Clipboard::GetPlainTextFormatType())); |
156 clipboard.ReadHTML(&markup_result, &url_result); | 158 clipboard.ReadHTML(&markup_result, &url_result); |
157 EXPECT_EQ(markup, markup_result); | 159 EXPECT_EQ(markup, markup_result); |
158 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
159 // TODO(playmobil): It's not clear that non windows clipboards need to support | 161 // TODO(playmobil): It's not clear that non windows clipboards need to support |
160 // this. | 162 // this. |
161 EXPECT_EQ(url, url_result); | 163 EXPECT_EQ(url, url_result); |
162 #endif // defined(OS_WIN) | 164 #endif // defined(OS_WIN) |
163 clipboard.ReadText(&text_result); | 165 clipboard.ReadText(&text_result); |
164 EXPECT_EQ(text, text_result); | 166 EXPECT_EQ(text, text_result); |
165 clipboard.ReadAsciiText(&ascii_text); | 167 clipboard.ReadAsciiText(&ascii_text); |
166 EXPECT_EQ(WideToUTF8(text), ascii_text); | 168 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
167 } | 169 } |
168 | 170 |
169 // TODO(estade): Port the following tests (decide what targets we use for files) | 171 // TODO(estade): Port the following tests (decide what targets we use for files) |
170 #if !defined(OS_LINUX) | 172 #if !defined(OS_LINUX) |
171 // Files for this test don't actually need to exist on the file system, just | 173 // Files for this test don't actually need to exist on the file system, just |
172 // don't try to use a non-existent file you've retrieved from the clipboard. | 174 // don't try to use a non-existent file you've retrieved from the clipboard. |
173 TEST_F(ClipboardTest, FileTest) { | 175 TEST_F(ClipboardTest, FileTest) { |
174 Clipboard clipboard; | 176 Clipboard clipboard; |
175 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
176 std::wstring file = L"C:\\Downloads\\My Downloads\\A Special File.txt"; | 178 FilePath file(L"C:\\Downloads\\My Downloads\\A Special File.txt"); |
177 #elif defined(OS_MACOSX) | 179 #elif defined(OS_MACOSX) |
178 // OS X will print a warning message if we stick a non-existant file on the | 180 // OS X will print a warning message if we stick a non-existant file on the |
179 // clipboard. | 181 // clipboard. |
180 std::wstring file = L"/usr/bin/make"; | 182 FilePath file("/usr/bin/make"); |
181 #endif // defined(OS_MACOSX) | 183 #endif // defined(OS_MACOSX) |
182 | 184 |
183 { | 185 { |
184 ScopedClipboardWriter clipboard_writer(&clipboard); | 186 ScopedClipboardWriter clipboard_writer(&clipboard); |
185 clipboard_writer.WriteFile(file); | 187 clipboard_writer.WriteFile(file); |
186 } | 188 } |
187 | 189 |
188 std::wstring out_file; | 190 string16 out_file; |
189 clipboard.ReadFile(&out_file); | 191 clipboard.ReadFile(&out_file); |
190 EXPECT_EQ(file, out_file); | 192 EXPECT_EQ(file, out_file); |
191 } | 193 } |
192 | 194 |
193 TEST_F(ClipboardTest, MultipleFilesTest) { | 195 TEST_F(ClipboardTest, MultipleFilesTest) { |
194 Clipboard clipboard; | 196 Clipboard clipboard; |
195 | 197 |
196 #if defined(OS_WIN) | 198 #if defined(OS_WIN) |
197 std::wstring file1 = L"C:\\Downloads\\My Downloads\\File 1.exe"; | 199 FilePath file1(L"C:\\Downloads\\My Downloads\\File 1.exe"); |
198 std::wstring file2 = L"C:\\Downloads\\My Downloads\\File 2.pdf"; | 200 FilePath file2(L"C:\\Downloads\\My Downloads\\File 2.pdf"); |
199 std::wstring file3 = L"C:\\Downloads\\My Downloads\\File 3.doc"; | 201 FilePath file3(L"C:\\Downloads\\My Downloads\\File 3.doc"); |
200 #elif defined(OS_MACOSX) | 202 #elif defined(OS_MACOSX) |
201 // OS X will print a warning message if we stick a non-existant file on the | 203 // OS X will print a warning message if we stick a non-existant file on the |
202 // clipboard. | 204 // clipboard. |
203 std::wstring file1 = L"/usr/bin/make"; | 205 FilePath file1("/usr/bin/make"); |
204 std::wstring file2 = L"/usr/bin/man"; | 206 FilePath file2("/usr/bin/man"); |
205 std::wstring file3 = L"/usr/bin/perl"; | 207 FilePath file3("/usr/bin/perl"); |
206 #endif // defined(OS_MACOSX) | 208 #endif // defined(OS_MACOSX) |
207 std::vector<std::wstring> files; | 209 std::vector<FilePath> files; |
208 files.push_back(file1); | 210 files.push_back(file1); |
209 files.push_back(file2); | 211 files.push_back(file2); |
210 files.push_back(file3); | 212 files.push_back(file3); |
211 | 213 |
212 { | 214 { |
213 ScopedClipboardWriter clipboard_writer(&clipboard); | 215 ScopedClipboardWriter clipboard_writer(&clipboard); |
214 clipboard_writer.WriteFiles(files); | 216 clipboard_writer.WriteFiles(files); |
215 } | 217 } |
216 | 218 |
217 std::vector<std::wstring> out_files; | 219 std::vector<string16> out_files; |
218 clipboard.ReadFiles(&out_files); | 220 clipboard.ReadFiles(&out_files); |
219 | 221 |
220 EXPECT_EQ(files.size(), out_files.size()); | 222 EXPECT_EQ(files.size(), out_files.size()); |
221 for (size_t i = 0; i < out_files.size(); ++i) | 223 for (size_t i = 0; i < out_files.size(); ++i) |
222 EXPECT_EQ(files[i], out_files[i]); | 224 EXPECT_EQ(files[i], out_files[i]); |
223 } | 225 } |
224 #endif // !defined(OS_LINUX) | 226 #endif // !defined(OS_LINUX) |
225 | 227 |
226 #if defined(OS_WIN) // Windows only tests. | 228 #if defined(OS_WIN) // Windows only tests. |
227 TEST_F(ClipboardTest, HyperlinkTest) { | 229 TEST_F(ClipboardTest, HyperlinkTest) { |
228 Clipboard clipboard; | 230 Clipboard clipboard; |
229 | 231 |
230 std::wstring title(L"The Example Company"), title_result; | 232 string16 title(ASCIIToUTF16("The Example Company")), title_result; |
231 std::string url("http://www.example.com/"), url_result; | 233 std::string url("http://www.example.com/"), url_result; |
232 std::wstring html(L"<a href=\"http://www.example.com/\">" | 234 string16 html(ASCIIToUTF16("<a href=\"http://www.example.com/\">" |
233 L"The Example Company</a>"), html_result; | 235 "The Example Company</a>")), html_result; |
234 | 236 |
235 { | 237 { |
236 ScopedClipboardWriter clipboard_writer(&clipboard); | 238 ScopedClipboardWriter clipboard_writer(&clipboard); |
237 clipboard_writer.WriteHyperlink(title, url); | 239 clipboard_writer.WriteHyperlink(title, url); |
238 } | 240 } |
239 | 241 |
240 EXPECT_EQ(true, | 242 EXPECT_EQ(true, |
241 clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); | 243 clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); |
242 EXPECT_EQ(true, | 244 EXPECT_EQ(true, |
243 clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); | 245 clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); |
(...skipping 28 matching lines...) Expand all Loading... |
272 { | 274 { |
273 ScopedClipboardWriter clipboard_writer(&clipboard); | 275 ScopedClipboardWriter clipboard_writer(&clipboard); |
274 clipboard_writer.WriteBitmapFromPixels(fake_bitmap, gfx::Size(3, 4)); | 276 clipboard_writer.WriteBitmapFromPixels(fake_bitmap, gfx::Size(3, 4)); |
275 } | 277 } |
276 | 278 |
277 EXPECT_EQ(true, clipboard.IsFormatAvailable( | 279 EXPECT_EQ(true, clipboard.IsFormatAvailable( |
278 Clipboard::GetBitmapFormatType())); | 280 Clipboard::GetBitmapFormatType())); |
279 } | 281 } |
280 #endif // defined(OS_WIN) | 282 #endif // defined(OS_WIN) |
281 | 283 |
OLD | NEW |