Chromium Code Reviews| 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 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most | 5 // Note: This header doesn't use REGISTER_TYPED_TEST_CASE_P like most |
| 6 // type-parameterized gtests. There are lot of test cases in here that are only | 6 // type-parameterized gtests. There are lot of test cases in here that are only |
| 7 // enabled on certain platforms. However, preprocessor directives in macro | 7 // enabled on certain platforms. However, preprocessor directives in macro |
| 8 // arguments result in undefined behavior (and don't work on MSVC). Instead, | 8 // arguments result in undefined behavior (and don't work on MSVC). Instead, |
| 9 // 'parameterized' tests should typedef TypesToTest (which is used to | 9 // 'parameterized' tests should typedef TypesToTest (which is used to |
| 10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this | 10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 clipboard_(ClipboardTraits::Create()) {} | 57 clipboard_(ClipboardTraits::Create()) {} |
| 58 #else | 58 #else |
| 59 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} | 59 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } | 62 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } |
| 63 | 63 |
| 64 protected: | 64 protected: |
| 65 Clipboard& clipboard() { return *clipboard_; } | 65 Clipboard& clipboard() { return *clipboard_; } |
| 66 | 66 |
| 67 bool AvailableTypesIsEmpty(ClipboardType type = CLIPBOARD_TYPE_COPY_PASTE) { | |
|
dcheng
2015/07/15 01:04:45
Default arguments are not permitted in Chromium.
Tobias Sargeant
2015/07/15 14:03:59
Done.
| |
| 68 bool contains_filenames; | |
| 69 std::vector<base::string16> types; | |
| 70 clipboard().ReadAvailableTypes( | |
| 71 type, | |
| 72 &types, | |
| 73 &contains_filenames); | |
| 74 return types.size() == 0; | |
|
dcheng
2015/07/15 01:04:45
types.empty()
Tobias Sargeant
2015/07/15 14:03:59
removed
| |
| 75 } | |
| 76 | |
| 77 bool AvailableTypesHas(ClipboardType type, | |
| 78 const std::set<base::string16> &expected) { | |
|
dcheng
2015/07/15 01:04:45
& by the type. For style issues like this, git cl
Tobias Sargeant
2015/07/15 14:04:00
Thanks for pointing this out. I did this soon afte
| |
| 79 bool contains_filenames; | |
| 80 std::vector<base::string16> types; | |
| 81 clipboard().ReadAvailableTypes( | |
| 82 type, | |
| 83 &types, | |
| 84 &contains_filenames); | |
| 85 | |
| 86 for (auto it = expected.begin(); it != expected.end(); ++it) { | |
|
dcheng
2015/07/15 01:04:45
This is copying each string16. Use const auto&
Tobias Sargeant
2015/07/15 14:03:59
removed (I admit it was lazy, but it didn't seem l
| |
| 87 if (std::find(types.begin(), types.end(), *it) == types.end()) { | |
| 88 return false; | |
| 89 } | |
| 90 } | |
| 91 | |
| 92 return true; | |
| 93 } | |
| 94 | |
| 95 bool AvailableTypesHas(const char* _1, | |
|
dcheng
2015/07/15 01:04:45
It seems to me that the code would be clearer if y
Tobias Sargeant
2015/07/15 14:03:59
I've switched everything to using this scheme. Tha
| |
| 96 ClipboardType type = CLIPBOARD_TYPE_COPY_PASTE) { | |
| 97 std::set<base::string16> expected; | |
| 98 expected.insert(base::UTF8ToUTF16(_1)); | |
| 99 return AvailableTypesHas(type, expected); | |
| 100 } | |
| 101 | |
| 102 bool AvailableTypesHas(const char* _1, | |
| 103 const char* _2, | |
| 104 ClipboardType type = CLIPBOARD_TYPE_COPY_PASTE) { | |
| 105 std::set<base::string16> expected; | |
| 106 expected.insert(base::UTF8ToUTF16(_1)); | |
| 107 expected.insert(base::UTF8ToUTF16(_2)); | |
| 108 return AvailableTypesHas(type, expected); | |
| 109 } | |
| 110 | |
| 67 private: | 111 private: |
| 68 base::MessageLoopForUI message_loop_; | 112 base::MessageLoopForUI message_loop_; |
| 69 #if defined(USE_AURA) | 113 #if defined(USE_AURA) |
| 70 scoped_ptr<PlatformEventSource> event_source_; | 114 scoped_ptr<PlatformEventSource> event_source_; |
| 71 #endif | 115 #endif |
| 72 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. | 116 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. |
| 73 Clipboard* const clipboard_; | 117 Clipboard* const clipboard_; |
| 74 }; | 118 }; |
| 75 | 119 |
| 76 // Hack for tests that need to call static methods of ClipboardTest. | 120 // Hack for tests that need to call static methods of ClipboardTest. |
| 77 struct NullClipboardTraits { | 121 struct NullClipboardTraits { |
| 78 static Clipboard* Create() { return nullptr; } | 122 static Clipboard* Create() { return nullptr; } |
| 79 static void Destroy(Clipboard*) {} | 123 static void Destroy(Clipboard*) {} |
| 80 }; | 124 }; |
| 81 | 125 |
| 82 TYPED_TEST_CASE(ClipboardTest, TypesToTest); | 126 TYPED_TEST_CASE(ClipboardTest, TypesToTest); |
| 83 | 127 |
| 84 TYPED_TEST(ClipboardTest, ClearTest) { | 128 TYPED_TEST(ClipboardTest, ClearTest) { |
| 85 { | 129 { |
| 86 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 130 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 87 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); | 131 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); |
| 88 } | 132 } |
| 89 | 133 |
| 90 this->clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); | 134 this->clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); |
| 91 | 135 |
| 136 EXPECT_TRUE(this->AvailableTypesIsEmpty()); | |
| 92 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 137 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 93 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 138 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 94 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 139 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 95 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 140 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 96 } | 141 } |
| 97 | 142 |
| 98 TYPED_TEST(ClipboardTest, TextTest) { | 143 TYPED_TEST(ClipboardTest, TextTest) { |
| 99 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; | 144 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; |
| 100 std::string ascii_text; | 145 std::string ascii_text; |
| 101 | 146 |
| 102 { | 147 { |
| 103 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 148 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 104 clipboard_writer.WriteText(text); | 149 clipboard_writer.WriteText(text); |
| 105 } | 150 } |
| 106 | 151 |
| 152 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeText)); | |
| 107 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 153 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 108 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 154 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 109 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 155 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 110 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 156 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 111 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 157 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 112 | 158 |
| 113 EXPECT_EQ(text, text_result); | 159 EXPECT_EQ(text, text_result); |
| 114 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 160 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
| 115 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 161 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
| 116 } | 162 } |
| 117 | 163 |
| 118 TYPED_TEST(ClipboardTest, HTMLTest) { | 164 TYPED_TEST(ClipboardTest, HTMLTest) { |
| 119 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; | 165 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; |
| 120 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; | 166 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; |
| 121 std::string url("http://www.example.com/"), url_result; | 167 std::string url("http://www.example.com/"), url_result; |
| 122 | 168 |
| 123 { | 169 { |
| 124 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 170 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 125 clipboard_writer.WriteText(plain); | 171 clipboard_writer.WriteText(plain); |
| 126 clipboard_writer.WriteHTML(markup, url); | 172 clipboard_writer.WriteHTML(markup, url); |
| 127 } | 173 } |
| 128 | 174 |
| 175 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeHTML)); | |
| 129 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 176 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 130 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 177 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 131 uint32 fragment_start; | 178 uint32 fragment_start; |
| 132 uint32 fragment_end; | 179 uint32 fragment_end; |
| 133 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 180 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 134 &url_result, &fragment_start, &fragment_end); | 181 &url_result, &fragment_start, &fragment_end); |
| 135 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 182 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 136 EXPECT_EQ(markup, | 183 EXPECT_EQ(markup, |
| 137 markup_result.substr(fragment_end - markup.size(), markup.size())); | 184 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 138 #if defined(OS_WIN) | 185 #if defined(OS_WIN) |
| 139 // TODO(playmobil): It's not clear that non windows clipboards need to support | 186 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 140 // this. | 187 // this. |
| 141 EXPECT_EQ(url, url_result); | 188 EXPECT_EQ(url, url_result); |
| 142 #endif // defined(OS_WIN) | 189 #endif // defined(OS_WIN) |
| 143 } | 190 } |
| 144 | 191 |
| 145 TYPED_TEST(ClipboardTest, RTFTest) { | 192 TYPED_TEST(ClipboardTest, RTFTest) { |
| 146 std::string rtf = | 193 std::string rtf = |
| 147 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" | 194 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" |
| 148 "This is some {\\b bold} text.\\par\n" | 195 "This is some {\\b bold} text.\\par\n" |
| 149 "}"; | 196 "}"; |
| 150 | 197 |
| 151 { | 198 { |
| 152 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 199 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 153 clipboard_writer.WriteRTF(rtf); | 200 clipboard_writer.WriteRTF(rtf); |
| 154 } | 201 } |
| 155 | 202 |
| 203 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeRTF)); | |
| 156 EXPECT_TRUE(this->clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), | 204 EXPECT_TRUE(this->clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), |
| 157 CLIPBOARD_TYPE_COPY_PASTE)); | 205 CLIPBOARD_TYPE_COPY_PASTE)); |
| 158 std::string result; | 206 std::string result; |
| 159 this->clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); | 207 this->clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); |
| 160 EXPECT_EQ(rtf, result); | 208 EXPECT_EQ(rtf, result); |
| 161 } | 209 } |
| 162 | 210 |
| 163 // TODO(dnicoara) Enable test once Ozone implements clipboard support: | 211 // TODO(dnicoara) Enable test once Ozone implements clipboard support: |
| 164 // crbug.com/361707 | 212 // crbug.com/361707 |
| 165 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) | 213 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) |
| 166 TYPED_TEST(ClipboardTest, MultipleBufferTest) { | 214 TYPED_TEST(ClipboardTest, MultipleBufferTest) { |
| 167 base::string16 text(ASCIIToUTF16("Standard")), text_result; | 215 base::string16 text(ASCIIToUTF16("Standard")), text_result; |
| 168 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); | 216 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); |
| 169 std::string url("http://www.example.com/"), url_result; | 217 std::string url("http://www.example.com/"), url_result; |
| 170 | 218 |
| 171 { | 219 { |
| 172 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 220 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 173 clipboard_writer.WriteText(text); | 221 clipboard_writer.WriteText(text); |
| 174 } | 222 } |
| 175 | 223 |
| 176 { | 224 { |
| 177 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_SELECTION); | 225 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_SELECTION); |
| 178 clipboard_writer.WriteHTML(markup, url); | 226 clipboard_writer.WriteHTML(markup, url); |
| 179 } | 227 } |
| 180 | 228 |
| 229 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeText, | |
| 230 CLIPBOARD_TYPE_COPY_PASTE)); | |
| 231 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeHTML, | |
| 232 CLIPBOARD_TYPE_SELECTION)); | |
| 233 | |
| 181 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 234 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 182 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 235 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 183 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 236 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 184 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_SELECTION)); | 237 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_SELECTION)); |
| 185 | 238 |
| 186 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 239 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 187 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 240 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 188 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 241 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 189 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_SELECTION)); | 242 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_SELECTION)); |
| 190 | 243 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 207 markup_result; | 260 markup_result; |
| 208 std::string url, url_result; | 261 std::string url, url_result; |
| 209 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; | 262 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; |
| 210 | 263 |
| 211 { | 264 { |
| 212 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 265 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 213 clipboard_writer.WriteText(plain); | 266 clipboard_writer.WriteText(plain); |
| 214 clipboard_writer.WriteHTML(markup, url); | 267 clipboard_writer.WriteHTML(markup, url); |
| 215 } | 268 } |
| 216 | 269 |
| 270 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeHTML)); | |
| 217 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 271 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 218 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 272 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 219 uint32 fragment_start; | 273 uint32 fragment_start; |
| 220 uint32 fragment_end; | 274 uint32 fragment_end; |
| 221 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 275 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 222 &url_result, &fragment_start, &fragment_end); | 276 &url_result, &fragment_start, &fragment_end); |
| 223 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 277 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 224 EXPECT_EQ(markup, | 278 EXPECT_EQ(markup, |
| 225 markup_result.substr(fragment_end - markup.size(), markup.size())); | 279 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 226 #if defined(OS_WIN) | 280 #if defined(OS_WIN) |
| 227 // TODO(playmobil): It's not clear that non windows clipboards need to support | 281 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 228 // this. | 282 // this. |
| 229 EXPECT_EQ(url, url_result); | 283 EXPECT_EQ(url, url_result); |
| 230 #endif // defined(OS_WIN) | 284 #endif // defined(OS_WIN) |
| 231 } | 285 } |
| 232 | 286 |
| 233 // Some platforms store HTML as UTF-8 internally. Make sure fragment indices are | 287 // Some platforms store HTML as UTF-8 internally. Make sure fragment indices are |
| 234 // adjusted appropriately when converting back to UTF-16. | 288 // adjusted appropriately when converting back to UTF-16. |
| 235 TYPED_TEST(ClipboardTest, UnicodeHTMLTest) { | 289 TYPED_TEST(ClipboardTest, UnicodeHTMLTest) { |
| 236 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), | 290 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), |
| 237 markup_result; | 291 markup_result; |
| 238 std::string url, url_result; | 292 std::string url, url_result; |
| 239 | 293 |
| 240 { | 294 { |
| 241 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 295 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 242 clipboard_writer.WriteHTML(markup, url); | 296 clipboard_writer.WriteHTML(markup, url); |
| 243 } | 297 } |
| 244 | 298 |
| 299 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeHTML)); | |
| 245 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 300 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 246 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 301 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 247 uint32 fragment_start; | 302 uint32 fragment_start; |
| 248 uint32 fragment_end; | 303 uint32 fragment_end; |
| 249 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 304 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 250 &url_result, &fragment_start, &fragment_end); | 305 &url_result, &fragment_start, &fragment_end); |
| 251 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 306 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 252 EXPECT_EQ(markup, | 307 EXPECT_EQ(markup, |
| 253 markup_result.substr(fragment_end - markup.size(), markup.size())); | 308 markup_result.substr( |
| 309 fragment_end - | |
| 310 std::min(fragment_end, static_cast<uint32>(markup.size())), | |
|
dcheng
2015/07/15 01:04:45
Can you explain to me why we need to use fragment_
Tobias Sargeant
2015/07/15 14:04:00
Again, It has been a while, and I can't remember t
dcheng
2015/07/16 06:10:00
As long as it passes the trybots.
| |
| 311 markup.size())); | |
| 254 #if defined(OS_WIN) | 312 #if defined(OS_WIN) |
| 255 EXPECT_EQ(url, url_result); | 313 EXPECT_EQ(url, url_result); |
| 256 #endif | 314 #endif |
| 257 } | 315 } |
| 258 | 316 |
| 259 // TODO(estade): Port the following test (decide what target we use for urls) | 317 // TODO(estade): Port the following test (decide what target we use for urls) |
| 260 #if !defined(OS_POSIX) || defined(OS_MACOSX) | 318 #if !defined(OS_POSIX) || defined(OS_MACOSX) |
| 261 TYPED_TEST(ClipboardTest, BookmarkTest) { | 319 TYPED_TEST(ClipboardTest, BookmarkTest) { |
| 262 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; | 320 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; |
| 263 std::string url("http://www.example.com/"), url_result; | 321 std::string url("http://www.example.com/"), url_result; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 280 base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; | 338 base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; |
| 281 std::string url("http://www.example.com/"), url_result; | 339 std::string url("http://www.example.com/"), url_result; |
| 282 std::string ascii_text; | 340 std::string ascii_text; |
| 283 | 341 |
| 284 { | 342 { |
| 285 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 343 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 286 clipboard_writer.WriteHTML(markup, url); | 344 clipboard_writer.WriteHTML(markup, url); |
| 287 clipboard_writer.WriteText(text); | 345 clipboard_writer.WriteText(text); |
| 288 } | 346 } |
| 289 | 347 |
| 348 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeHTML, | |
| 349 Clipboard::kMimeTypeText)); | |
| 290 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 350 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 291 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 351 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 292 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 352 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 293 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 353 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 294 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 354 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 295 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 355 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 296 uint32 fragment_start; | 356 uint32 fragment_start; |
| 297 uint32 fragment_end; | 357 uint32 fragment_end; |
| 298 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 358 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 299 &url_result, &fragment_start, &fragment_end); | 359 &url_result, &fragment_start, &fragment_end); |
| 300 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 360 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 301 EXPECT_EQ(markup, | 361 EXPECT_EQ(markup, |
| 302 markup_result.substr(fragment_end - markup.size(), markup.size())); | 362 markup_result.substr( |
| 363 fragment_end - | |
| 364 std::min(fragment_end, static_cast<uint32>(markup.size())), | |
| 365 markup.size())); | |
| 303 #if defined(OS_WIN) | 366 #if defined(OS_WIN) |
| 304 // TODO(playmobil): It's not clear that non windows clipboards need to support | 367 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 305 // this. | 368 // this. |
| 306 EXPECT_EQ(url, url_result); | 369 EXPECT_EQ(url, url_result); |
| 307 #endif // defined(OS_WIN) | 370 #endif // defined(OS_WIN) |
| 308 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 371 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 309 EXPECT_EQ(text, text_result); | 372 EXPECT_EQ(text, text_result); |
| 310 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 373 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
| 311 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 374 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
| 312 } | 375 } |
| 313 | 376 |
| 314 TYPED_TEST(ClipboardTest, URLTest) { | 377 TYPED_TEST(ClipboardTest, URLTest) { |
| 315 base::string16 url(ASCIIToUTF16("http://www.google.com/")); | 378 base::string16 url(ASCIIToUTF16("http://www.google.com/")); |
| 316 | 379 |
| 317 { | 380 { |
| 318 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 381 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 319 clipboard_writer.WriteURL(url); | 382 clipboard_writer.WriteURL(url); |
| 320 } | 383 } |
| 321 | 384 |
| 385 EXPECT_TRUE(this->AvailableTypesHas(Clipboard::kMimeTypeText)); | |
| 322 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 386 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 323 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 387 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 324 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 388 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 325 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 389 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 326 base::string16 text_result; | 390 base::string16 text_result; |
| 327 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 391 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 328 | 392 |
| 329 EXPECT_EQ(text_result, url); | 393 EXPECT_EQ(text_result, url); |
| 330 | 394 |
| 331 std::string ascii_text; | 395 std::string ascii_text; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 702 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 639 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); | 703 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); |
| 640 } | 704 } |
| 641 | 705 |
| 642 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { | 706 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { |
| 643 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 707 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 644 scw.WriteImage(SkBitmap()); | 708 scw.WriteImage(SkBitmap()); |
| 645 } | 709 } |
| 646 | 710 |
| 647 } // namespace ui | 711 } // namespace ui |
| OLD | NEW |