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

Side by Side Diff: base/clipboard_unittest.cc

Issue 8038: Simultaneously store multiple formats on the linux clipboard. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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 | « base/clipboard_linux.cc ('k') | no next file » | 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) 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/platform_test.h" 9 #include "base/platform_test.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 24 matching lines...) Expand all
35 EXPECT_EQ(true, clipboard.IsFormatAvailable( 35 EXPECT_EQ(true, clipboard.IsFormatAvailable(
36 Clipboard::GetPlainTextWFormatType())); 36 Clipboard::GetPlainTextWFormatType()));
37 EXPECT_EQ(true, clipboard.IsFormatAvailable( 37 EXPECT_EQ(true, clipboard.IsFormatAvailable(
38 Clipboard::GetPlainTextFormatType())); 38 Clipboard::GetPlainTextFormatType()));
39 clipboard.ReadText(&text_result); 39 clipboard.ReadText(&text_result);
40 EXPECT_EQ(text, text_result); 40 EXPECT_EQ(text, text_result);
41 clipboard.ReadAsciiText(&ascii_text); 41 clipboard.ReadAsciiText(&ascii_text);
42 EXPECT_EQ(WideToUTF8(text), ascii_text); 42 EXPECT_EQ(WideToUTF8(text), ascii_text);
43 } 43 }
44 44
45 TEST_F(ClipboardTest, OverwriteTest) {
46 Clipboard clipboard;
47
48 std::wstring text1(L"first string"), text2(L"second string"), text_result;
49
50 clipboard.Clear();
51 clipboard.WriteText(text1);
52 clipboard.WriteText(text2);
53
54 EXPECT_TRUE(clipboard.IsFormatAvailable(
55 Clipboard::GetPlainTextWFormatType()));
56 clipboard.ReadText(&text_result);
57 EXPECT_EQ(text2, text_result);
58 }
59
45 TEST_F(ClipboardTest, HTMLTest) { 60 TEST_F(ClipboardTest, HTMLTest) {
46 Clipboard clipboard; 61 Clipboard clipboard;
47 62
48 std::wstring markup(L"<strong>Hi!</string>"), markup_result; 63 std::wstring markup(L"<strong>Hi!</string>"), markup_result;
49 std::string url("http://www.example.com/"), url_result; 64 std::string url("http://www.example.com/"), url_result;
50 65
51 clipboard.Clear(); 66 clipboard.Clear();
52 clipboard.WriteHTML(markup, url); 67 clipboard.WriteHTML(markup, url);
53 EXPECT_EQ(true, clipboard.IsFormatAvailable( 68 EXPECT_EQ(true, clipboard.IsFormatAvailable(
54 Clipboard::GetHtmlFormatType())); 69 Clipboard::GetHtmlFormatType()));
55 clipboard.ReadHTML(&markup_result, &url_result); 70 clipboard.ReadHTML(&markup_result, &url_result);
56 EXPECT_EQ(markup, markup_result); 71 EXPECT_EQ(markup, markup_result);
57 #if defined(OS_WIN) 72 #if defined(OS_WIN)
58 // TODO(playmobil): It's not clear that non windows clipboards need to support 73 // TODO(playmobil): It's not clear that non windows clipboards need to support
59 // this. 74 // this.
60 EXPECT_EQ(url, url_result); 75 EXPECT_EQ(url, url_result);
61 #endif 76 #endif
62 } 77 }
63 78
64 // TODO(estade): Port the following tests.
65 #if !defined(OS_LINUX)
66 TEST_F(ClipboardTest, TrickyHTMLTest) { 79 TEST_F(ClipboardTest, TrickyHTMLTest) {
67 Clipboard clipboard; 80 Clipboard clipboard;
68 81
69 std::wstring markup(L"<em>Bye!<!--EndFragment --></em>"), markup_result; 82 std::wstring markup(L"<em>Bye!<!--EndFragment --></em>"), markup_result;
70 std::string url, url_result; 83 std::string url, url_result;
71 84
72 clipboard.Clear(); 85 clipboard.Clear();
73 clipboard.WriteHTML(markup, url); 86 clipboard.WriteHTML(markup, url);
74 EXPECT_EQ(true, clipboard.IsFormatAvailable( 87 EXPECT_EQ(true, clipboard.IsFormatAvailable(
75 Clipboard::GetHtmlFormatType())); 88 Clipboard::GetHtmlFormatType()));
76 clipboard.ReadHTML(&markup_result, &url_result); 89 clipboard.ReadHTML(&markup_result, &url_result);
77 EXPECT_EQ(markup, markup_result); 90 EXPECT_EQ(markup, markup_result);
78 91 #if defined(OS_WIN)
79 #if defined(OS_MACOSX) 92 // TODO(playmobil): It's not clear that non windows clipboards need to support
80 // TODO(playmobil): It's not clear that the OS X clipboard needs to support
81 // this. 93 // this.
82 #else
83 EXPECT_EQ(url, url_result); 94 EXPECT_EQ(url, url_result);
84 #endif 95 #endif
85 } 96 }
86 97
98 // TODO(estade): Port the following test (decide what target we use for urls)
99 #if !defined(OS_LINUX)
87 TEST_F(ClipboardTest, BookmarkTest) { 100 TEST_F(ClipboardTest, BookmarkTest) {
88 Clipboard clipboard; 101 Clipboard clipboard;
89 102
90 std::wstring title(L"The Example Company"), title_result; 103 std::wstring title(L"The Example Company"), title_result;
91 std::string url("http://www.example.com/"), url_result; 104 std::string url("http://www.example.com/"), url_result;
92 105
93 clipboard.Clear(); 106 clipboard.Clear();
94 clipboard.WriteBookmark(title, url); 107 clipboard.WriteBookmark(title, url);
95 EXPECT_EQ(true, 108 EXPECT_EQ(true,
96 clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType())); 109 clipboard.IsFormatAvailable(Clipboard::GetUrlWFormatType()));
97 clipboard.ReadBookmark(&title_result, &url_result); 110 clipboard.ReadBookmark(&title_result, &url_result);
98 EXPECT_EQ(title, title_result); 111 EXPECT_EQ(title, title_result);
99 EXPECT_EQ(url, url_result); 112 EXPECT_EQ(url, url_result);
100 } 113 }
114 #endif
101 115
102 TEST_F(ClipboardTest, MultiFormatTest) { 116 TEST_F(ClipboardTest, MultiFormatTest) {
103 Clipboard clipboard; 117 Clipboard clipboard;
104 118
105 std::wstring text(L"Hi!"), text_result; 119 std::wstring text(L"Hi!"), text_result;
106 std::wstring markup(L"<strong>Hi!</string>"), markup_result; 120 std::wstring markup(L"<strong>Hi!</string>"), markup_result;
107 std::string url("http://www.example.com/"), url_result; 121 std::string url("http://www.example.com/"), url_result;
108 std::string ascii_text; 122 std::string ascii_text;
109 123
110 clipboard.Clear(); 124 clipboard.Clear();
111 clipboard.WriteHTML(markup, url); 125 clipboard.WriteHTML(markup, url);
112 clipboard.WriteText(text); 126 clipboard.WriteText(text);
113 EXPECT_EQ(true, 127 EXPECT_EQ(true,
114 clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType())); 128 clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType()));
115 EXPECT_EQ(true, clipboard.IsFormatAvailable( 129 EXPECT_EQ(true, clipboard.IsFormatAvailable(
116 Clipboard::GetPlainTextWFormatType())); 130 Clipboard::GetPlainTextWFormatType()));
117 EXPECT_EQ(true, clipboard.IsFormatAvailable( 131 EXPECT_EQ(true, clipboard.IsFormatAvailable(
118 Clipboard::GetPlainTextFormatType())); 132 Clipboard::GetPlainTextFormatType()));
119 clipboard.ReadHTML(&markup_result, &url_result); 133 clipboard.ReadHTML(&markup_result, &url_result);
120 EXPECT_EQ(markup, markup_result); 134 EXPECT_EQ(markup, markup_result);
121 #if defined(OS_MACOSX) 135 #if defined(OS_WIN)
122 // TODO(playmobil): It's not clear that the OS X clipboard needs to support 136 // TODO(playmobil): It's not clear that non windows clipboards need to support
123 // this. 137 // this.
124 #else
125 EXPECT_EQ(url, url_result); 138 EXPECT_EQ(url, url_result);
126 #endif 139 #endif
127 clipboard.ReadText(&text_result); 140 clipboard.ReadText(&text_result);
128 EXPECT_EQ(text, text_result); 141 EXPECT_EQ(text, text_result);
129 clipboard.ReadAsciiText(&ascii_text); 142 clipboard.ReadAsciiText(&ascii_text);
130 EXPECT_EQ(WideToUTF8(text), ascii_text); 143 EXPECT_EQ(WideToUTF8(text), ascii_text);
131 } 144 }
132 145
146 // TODO(estade): Port the following tests (decide what targets we use for files)
147 #if !defined(OS_LINUX)
133 // Files for this test don't actually need to exist on the file system, just 148 // Files for this test don't actually need to exist on the file system, just
134 // don't try to use a non-existent file you've retrieved from the clipboard. 149 // don't try to use a non-existent file you've retrieved from the clipboard.
135 TEST_F(ClipboardTest, FileTest) { 150 TEST_F(ClipboardTest, FileTest) {
136 Clipboard clipboard; 151 Clipboard clipboard;
137 clipboard.Clear(); 152 clipboard.Clear();
138 #if defined(OS_WIN) 153 #if defined(OS_WIN)
139 std::wstring file = L"C:\\Downloads\\My Downloads\\A Special File.txt"; 154 std::wstring file = L"C:\\Downloads\\My Downloads\\A Special File.txt";
140 #else 155 #else
141 // OS X will print a warning message if we stick a non-existant file on the 156 // OS X will print a warning message if we stick a non-existant file on the
142 // clipboard. 157 // clipboard.
(...skipping 26 matching lines...) Expand all
169 files.push_back(file3); 184 files.push_back(file3);
170 clipboard.WriteFiles(files); 185 clipboard.WriteFiles(files);
171 186
172 std::vector<std::wstring> out_files; 187 std::vector<std::wstring> out_files;
173 clipboard.ReadFiles(&out_files); 188 clipboard.ReadFiles(&out_files);
174 189
175 EXPECT_EQ(files.size(), out_files.size()); 190 EXPECT_EQ(files.size(), out_files.size());
176 for (size_t i = 0; i < out_files.size(); ++i) 191 for (size_t i = 0; i < out_files.size(); ++i)
177 EXPECT_EQ(files[i], out_files[i]); 192 EXPECT_EQ(files[i], out_files[i]);
178 } 193 }
194 #endif // !defined(OS_LINUX)
179 195
180 #if defined(OS_WIN) // Windows only tests. 196 #if defined(OS_WIN) // Windows only tests.
181 TEST_F(ClipboardTest, HyperlinkTest) { 197 TEST_F(ClipboardTest, HyperlinkTest) {
182 Clipboard clipboard; 198 Clipboard clipboard;
183 199
184 std::wstring title(L"The Example Company"), title_result; 200 std::wstring title(L"The Example Company"), title_result;
185 std::string url("http://www.example.com/"), url_result; 201 std::string url("http://www.example.com/"), url_result;
186 std::wstring html(L"<a href=\"http://www.example.com/\">" 202 std::wstring html(L"<a href=\"http://www.example.com/\">"
187 L"The Example Company</a>"), html_result; 203 L"The Example Company</a>"), html_result;
188 204
(...skipping 28 matching lines...) Expand all
217 }; 233 };
218 234
219 Clipboard clipboard; 235 Clipboard clipboard;
220 236
221 clipboard.Clear(); 237 clipboard.Clear();
222 clipboard.WriteBitmap(fake_bitmap, gfx::Size(3, 4)); 238 clipboard.WriteBitmap(fake_bitmap, gfx::Size(3, 4));
223 EXPECT_EQ(true, clipboard.IsFormatAvailable( 239 EXPECT_EQ(true, clipboard.IsFormatAvailable(
224 Clipboard::GetBitmapFormatType())); 240 Clipboard::GetBitmapFormatType()));
225 } 241 }
226 #endif 242 #endif
227 #endif // !defined(OS_LINUX)
OLDNEW
« no previous file with comments | « base/clipboard_linux.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698