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 |
| 11 // header. | 11 // header. |
| 12 // TODO(dcheng): This is really horrible. In general, all tests should run on | 12 // TODO(dcheng): This is really horrible. In general, all tests should run on |
| 13 // all platforms, to avoid this mess. | 13 // all platforms, to avoid this mess. |
| 14 | 14 |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 | 16 |
| 17 #include <string> | 17 #include <string> |
| 18 | 18 |
| 19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
| 20 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 21 #include "base/message_loop/message_loop.h" |
| 22 #include "base/pickle.h" | 22 #include "base/pickle.h" |
| 23 #include "base/run_loop.h" | 23 #include "base/run_loop.h" |
| 24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "testing/gmock/include/gmock/gmock-matchers.h" | |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "testing/platform_test.h" | 28 #include "testing/platform_test.h" |
| 28 #include "third_party/skia/include/core/SkBitmap.h" | 29 #include "third_party/skia/include/core/SkBitmap.h" |
| 29 #include "third_party/skia/include/core/SkColor.h" | 30 #include "third_party/skia/include/core/SkColor.h" |
| 30 #include "third_party/skia/include/core/SkScalar.h" | 31 #include "third_party/skia/include/core/SkScalar.h" |
| 31 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 32 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
| 32 #include "ui/base/clipboard/clipboard.h" | 33 #include "ui/base/clipboard/clipboard.h" |
| 33 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 34 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 34 #include "ui/base/test/test_clipboard.h" | 35 #include "ui/base/test/test_clipboard.h" |
| 35 #include "ui/gfx/geometry/size.h" | 36 #include "ui/gfx/geometry/size.h" |
| 36 | 37 |
| 37 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 38 #include "ui/base/clipboard/clipboard_util_win.h" | 39 #include "ui/base/clipboard/clipboard_util_win.h" |
| 39 #endif | 40 #endif |
| 40 | 41 |
| 41 #if defined(USE_AURA) | 42 #if defined(USE_AURA) |
| 42 #include "ui/events/platform/platform_event_source.h" | 43 #include "ui/events/platform/platform_event_source.h" |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 using base::ASCIIToUTF16; | 46 using base::ASCIIToUTF16; |
| 46 using base::UTF8ToUTF16; | 47 using base::UTF8ToUTF16; |
| 47 using base::UTF16ToUTF8; | 48 using base::UTF16ToUTF8; |
| 48 | 49 |
| 50 using testing::Contains; | |
| 51 | |
| 49 namespace ui { | 52 namespace ui { |
| 50 | 53 |
| 51 template <typename ClipboardTraits> | 54 template <typename ClipboardTraits> |
| 52 class ClipboardTest : public PlatformTest { | 55 class ClipboardTest : public PlatformTest { |
| 53 public: | 56 public: |
| 54 #if defined(USE_AURA) | 57 #if defined(USE_AURA) |
| 55 ClipboardTest() | 58 ClipboardTest() |
| 56 : event_source_(PlatformEventSource::CreateDefault()), | 59 : event_source_(PlatformEventSource::CreateDefault()), |
| 57 clipboard_(ClipboardTraits::Create()) {} | 60 clipboard_(ClipboardTraits::Create()) {} |
| 58 #else | 61 #else |
| 59 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} | 62 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} |
| 60 #endif | 63 #endif |
| 61 | 64 |
| 62 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } | 65 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } |
| 63 | 66 |
| 64 protected: | 67 protected: |
| 65 Clipboard& clipboard() { return *clipboard_; } | 68 Clipboard& clipboard() { return *clipboard_; } |
| 66 | 69 |
| 70 std::vector<base::string16> GetAvailableTypes(ClipboardType type) { | |
| 71 bool contains_filenames; | |
| 72 std::vector<base::string16> types; | |
| 73 clipboard().ReadAvailableTypes(type, &types, &contains_filenames); | |
| 74 return types; | |
| 75 } | |
| 76 | |
| 67 private: | 77 private: |
| 68 base::MessageLoopForUI message_loop_; | 78 base::MessageLoopForUI message_loop_; |
| 69 #if defined(USE_AURA) | 79 #if defined(USE_AURA) |
| 70 scoped_ptr<PlatformEventSource> event_source_; | 80 scoped_ptr<PlatformEventSource> event_source_; |
| 71 #endif | 81 #endif |
| 72 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. | 82 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. |
| 73 Clipboard* const clipboard_; | 83 Clipboard* const clipboard_; |
| 74 }; | 84 }; |
| 75 | 85 |
| 76 // Hack for tests that need to call static methods of ClipboardTest. | 86 // Hack for tests that need to call static methods of ClipboardTest. |
| 77 struct NullClipboardTraits { | 87 struct NullClipboardTraits { |
| 78 static Clipboard* Create() { return nullptr; } | 88 static Clipboard* Create() { return nullptr; } |
| 79 static void Destroy(Clipboard*) {} | 89 static void Destroy(Clipboard*) {} |
| 80 }; | 90 }; |
| 81 | 91 |
| 82 TYPED_TEST_CASE(ClipboardTest, TypesToTest); | 92 TYPED_TEST_CASE(ClipboardTest, TypesToTest); |
| 83 | 93 |
| 84 TYPED_TEST(ClipboardTest, ClearTest) { | 94 TYPED_TEST(ClipboardTest, ClearTest) { |
| 85 { | 95 { |
| 86 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 96 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 87 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); | 97 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); |
| 88 } | 98 } |
| 89 | 99 |
| 90 this->clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); | 100 this->clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); |
| 91 | 101 |
| 102 EXPECT_TRUE(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE).empty()); | |
| 92 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 103 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 93 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 104 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 94 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 105 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 95 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 106 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 96 } | 107 } |
| 97 | 108 |
| 98 TYPED_TEST(ClipboardTest, TextTest) { | 109 TYPED_TEST(ClipboardTest, TextTest) { |
| 99 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; | 110 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; |
| 100 std::string ascii_text; | 111 std::string ascii_text; |
| 101 | 112 |
| 102 { | 113 { |
| 103 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 114 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 104 clipboard_writer.WriteText(text); | 115 clipboard_writer.WriteText(text); |
| 105 } | 116 } |
| 106 | 117 |
| 118 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 119 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeText)))); | |
|
dcheng
2015/07/16 06:10:00
Here and elsewhere, the explicit invocation of bas
| |
| 107 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 120 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 108 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 121 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 109 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 122 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 110 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 123 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 111 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 124 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 112 | 125 |
| 113 EXPECT_EQ(text, text_result); | 126 EXPECT_EQ(text, text_result); |
| 114 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 127 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
| 115 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 128 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
| 116 } | 129 } |
| 117 | 130 |
| 118 TYPED_TEST(ClipboardTest, HTMLTest) { | 131 TYPED_TEST(ClipboardTest, HTMLTest) { |
| 119 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; | 132 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; |
| 120 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; | 133 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; |
| 121 std::string url("http://www.example.com/"), url_result; | 134 std::string url("http://www.example.com/"), url_result; |
| 122 | 135 |
| 123 { | 136 { |
| 124 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 137 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 125 clipboard_writer.WriteText(plain); | 138 clipboard_writer.WriteText(plain); |
| 126 clipboard_writer.WriteHTML(markup, url); | 139 clipboard_writer.WriteHTML(markup, url); |
| 127 } | 140 } |
| 128 | 141 |
| 142 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 143 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeHTML)))); | |
| 129 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 144 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 130 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 145 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 131 uint32 fragment_start; | 146 uint32 fragment_start; |
| 132 uint32 fragment_end; | 147 uint32 fragment_end; |
| 133 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 148 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 134 &url_result, &fragment_start, &fragment_end); | 149 &url_result, &fragment_start, &fragment_end); |
| 135 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 150 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 136 EXPECT_EQ(markup, | 151 EXPECT_EQ(markup, |
| 137 markup_result.substr(fragment_end - markup.size(), markup.size())); | 152 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 138 #if defined(OS_WIN) | 153 #if defined(OS_WIN) |
| 139 // TODO(playmobil): It's not clear that non windows clipboards need to support | 154 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 140 // this. | 155 // this. |
| 141 EXPECT_EQ(url, url_result); | 156 EXPECT_EQ(url, url_result); |
| 142 #endif // defined(OS_WIN) | 157 #endif // defined(OS_WIN) |
| 143 } | 158 } |
| 144 | 159 |
| 145 TYPED_TEST(ClipboardTest, RTFTest) { | 160 TYPED_TEST(ClipboardTest, RTFTest) { |
| 146 std::string rtf = | 161 std::string rtf = |
| 147 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" | 162 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" |
| 148 "This is some {\\b bold} text.\\par\n" | 163 "This is some {\\b bold} text.\\par\n" |
| 149 "}"; | 164 "}"; |
| 150 | 165 |
| 151 { | 166 { |
| 152 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 167 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 153 clipboard_writer.WriteRTF(rtf); | 168 clipboard_writer.WriteRTF(rtf); |
| 154 } | 169 } |
| 155 | 170 |
| 171 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 172 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeRTF)))); | |
| 156 EXPECT_TRUE(this->clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), | 173 EXPECT_TRUE(this->clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), |
| 157 CLIPBOARD_TYPE_COPY_PASTE)); | 174 CLIPBOARD_TYPE_COPY_PASTE)); |
| 158 std::string result; | 175 std::string result; |
| 159 this->clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); | 176 this->clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); |
| 160 EXPECT_EQ(rtf, result); | 177 EXPECT_EQ(rtf, result); |
| 161 } | 178 } |
| 162 | 179 |
| 163 // TODO(dnicoara) Enable test once Ozone implements clipboard support: | 180 // TODO(dnicoara) Enable test once Ozone implements clipboard support: |
| 164 // crbug.com/361707 | 181 // crbug.com/361707 |
| 165 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) | 182 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) |
| 166 TYPED_TEST(ClipboardTest, MultipleBufferTest) { | 183 TYPED_TEST(ClipboardTest, MultipleBufferTest) { |
| 167 base::string16 text(ASCIIToUTF16("Standard")), text_result; | 184 base::string16 text(ASCIIToUTF16("Standard")), text_result; |
| 168 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); | 185 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); |
| 169 std::string url("http://www.example.com/"), url_result; | 186 std::string url("http://www.example.com/"), url_result; |
| 170 | 187 |
| 171 { | 188 { |
| 172 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 189 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 173 clipboard_writer.WriteText(text); | 190 clipboard_writer.WriteText(text); |
| 174 } | 191 } |
| 175 | 192 |
| 176 { | 193 { |
| 177 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_SELECTION); | 194 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_SELECTION); |
| 178 clipboard_writer.WriteHTML(markup, url); | 195 clipboard_writer.WriteHTML(markup, url); |
| 179 } | 196 } |
| 180 | 197 |
| 198 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 199 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeText)))); | |
| 200 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_SELECTION), | |
| 201 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeHTML)))); | |
| 202 | |
| 181 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 203 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 182 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 204 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 183 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 205 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 184 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_SELECTION)); | 206 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_SELECTION)); |
| 185 | 207 |
| 186 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 208 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 187 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 209 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 188 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 210 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 189 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_SELECTION)); | 211 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_SELECTION)); |
| 190 | 212 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 207 markup_result; | 229 markup_result; |
| 208 std::string url, url_result; | 230 std::string url, url_result; |
| 209 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; | 231 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; |
| 210 | 232 |
| 211 { | 233 { |
| 212 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 234 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 213 clipboard_writer.WriteText(plain); | 235 clipboard_writer.WriteText(plain); |
| 214 clipboard_writer.WriteHTML(markup, url); | 236 clipboard_writer.WriteHTML(markup, url); |
| 215 } | 237 } |
| 216 | 238 |
| 239 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 240 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeHTML)))); | |
| 217 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 241 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 218 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 242 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 219 uint32 fragment_start; | 243 uint32 fragment_start; |
| 220 uint32 fragment_end; | 244 uint32 fragment_end; |
| 221 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 245 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 222 &url_result, &fragment_start, &fragment_end); | 246 &url_result, &fragment_start, &fragment_end); |
| 223 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 247 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 224 EXPECT_EQ(markup, | 248 EXPECT_EQ(markup, |
| 225 markup_result.substr(fragment_end - markup.size(), markup.size())); | 249 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 226 #if defined(OS_WIN) | 250 #if defined(OS_WIN) |
| 227 // TODO(playmobil): It's not clear that non windows clipboards need to support | 251 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 228 // this. | 252 // this. |
| 229 EXPECT_EQ(url, url_result); | 253 EXPECT_EQ(url, url_result); |
| 230 #endif // defined(OS_WIN) | 254 #endif // defined(OS_WIN) |
| 231 } | 255 } |
| 232 | 256 |
| 233 // Some platforms store HTML as UTF-8 internally. Make sure fragment indices are | 257 // Some platforms store HTML as UTF-8 internally. Make sure fragment indices are |
| 234 // adjusted appropriately when converting back to UTF-16. | 258 // adjusted appropriately when converting back to UTF-16. |
| 235 TYPED_TEST(ClipboardTest, UnicodeHTMLTest) { | 259 TYPED_TEST(ClipboardTest, UnicodeHTMLTest) { |
| 236 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), | 260 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), |
| 237 markup_result; | 261 markup_result; |
| 238 std::string url, url_result; | 262 std::string url, url_result; |
| 239 | 263 |
| 240 { | 264 { |
| 241 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 265 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 242 clipboard_writer.WriteHTML(markup, url); | 266 clipboard_writer.WriteHTML(markup, url); |
| 243 } | 267 } |
| 244 | 268 |
| 269 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 270 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeHTML)))); | |
| 245 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 271 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 246 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 272 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 247 uint32 fragment_start; | 273 uint32 fragment_start; |
| 248 uint32 fragment_end; | 274 uint32 fragment_end; |
| 249 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 275 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 250 &url_result, &fragment_start, &fragment_end); | 276 &url_result, &fragment_start, &fragment_end); |
| 251 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 277 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 252 EXPECT_EQ(markup, | 278 EXPECT_EQ(markup, markup_result.substr(fragment_start, |
| 253 markup_result.substr(fragment_end - markup.size(), markup.size())); | 279 fragment_end - fragment_start)); |
| 254 #if defined(OS_WIN) | 280 #if defined(OS_WIN) |
| 255 EXPECT_EQ(url, url_result); | 281 EXPECT_EQ(url, url_result); |
| 256 #endif | 282 #endif |
| 257 } | 283 } |
| 258 | 284 |
| 259 // TODO(estade): Port the following test (decide what target we use for urls) | 285 // TODO(estade): Port the following test (decide what target we use for urls) |
| 260 #if !defined(OS_POSIX) || defined(OS_MACOSX) | 286 #if !defined(OS_POSIX) || defined(OS_MACOSX) |
| 261 TYPED_TEST(ClipboardTest, BookmarkTest) { | 287 TYPED_TEST(ClipboardTest, BookmarkTest) { |
| 262 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; | 288 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; |
| 263 std::string url("http://www.example.com/"), url_result; | 289 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; | 306 base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; |
| 281 std::string url("http://www.example.com/"), url_result; | 307 std::string url("http://www.example.com/"), url_result; |
| 282 std::string ascii_text; | 308 std::string ascii_text; |
| 283 | 309 |
| 284 { | 310 { |
| 285 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 311 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 286 clipboard_writer.WriteHTML(markup, url); | 312 clipboard_writer.WriteHTML(markup, url); |
| 287 clipboard_writer.WriteText(text); | 313 clipboard_writer.WriteText(text); |
| 288 } | 314 } |
| 289 | 315 |
| 316 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 317 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeHTML)))); | |
| 318 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 319 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeText)))); | |
| 290 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 320 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 291 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 321 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 292 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 322 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 293 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 323 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 294 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 324 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 295 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 325 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 296 uint32 fragment_start; | 326 uint32 fragment_start; |
| 297 uint32 fragment_end; | 327 uint32 fragment_end; |
| 298 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 328 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 299 &url_result, &fragment_start, &fragment_end); | 329 &url_result, &fragment_start, &fragment_end); |
| 300 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 330 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 301 EXPECT_EQ(markup, | 331 EXPECT_EQ(markup, markup_result.substr(fragment_start, |
| 302 markup_result.substr(fragment_end - markup.size(), markup.size())); | 332 fragment_end - fragment_start)); |
| 303 #if defined(OS_WIN) | 333 #if defined(OS_WIN) |
| 304 // TODO(playmobil): It's not clear that non windows clipboards need to support | 334 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 305 // this. | 335 // this. |
| 306 EXPECT_EQ(url, url_result); | 336 EXPECT_EQ(url, url_result); |
| 307 #endif // defined(OS_WIN) | 337 #endif // defined(OS_WIN) |
| 308 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 338 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 309 EXPECT_EQ(text, text_result); | 339 EXPECT_EQ(text, text_result); |
| 310 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 340 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
| 311 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 341 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
| 312 } | 342 } |
| 313 | 343 |
| 314 TYPED_TEST(ClipboardTest, URLTest) { | 344 TYPED_TEST(ClipboardTest, URLTest) { |
| 315 base::string16 url(ASCIIToUTF16("http://www.google.com/")); | 345 base::string16 url(ASCIIToUTF16("http://www.google.com/")); |
| 316 | 346 |
| 317 { | 347 { |
| 318 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 348 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 319 clipboard_writer.WriteURL(url); | 349 clipboard_writer.WriteURL(url); |
| 320 } | 350 } |
| 321 | 351 |
| 352 EXPECT_THAT(this->GetAvailableTypes(CLIPBOARD_TYPE_COPY_PASTE), | |
| 353 Contains(base::string16(ASCIIToUTF16(Clipboard::kMimeTypeText)))); | |
| 322 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 354 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 323 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 355 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 324 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 356 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 325 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 357 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 326 base::string16 text_result; | 358 base::string16 text_result; |
| 327 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 359 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 328 | 360 |
| 329 EXPECT_EQ(text_result, url); | 361 EXPECT_EQ(text_result, url); |
| 330 | 362 |
| 331 std::string ascii_text; | 363 std::string ascii_text; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 670 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 639 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); | 671 scw.WritePickledData(base::Pickle(), Clipboard::GetPlainTextFormatType()); |
| 640 } | 672 } |
| 641 | 673 |
| 642 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { | 674 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { |
| 643 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 675 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 644 scw.WriteImage(SkBitmap()); | 676 scw.WriteImage(SkBitmap()); |
| 645 } | 677 } |
| 646 | 678 |
| 647 } // namespace ui | 679 } // namespace ui |
| OLD | NEW |