| 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 // Unlike most type-parameterized test templates, instantiating the tests in |
| 6 // type-parameterized gtests. There are lot of test cases in here that are only | 6 // this header requires two things: |
| 7 // enabled on certain platforms. However, preprocessor directives in macro | 7 // 1. #define CLIPBOARD_TEST_FIXTURE_NAME to something unique. |
| 8 // arguments result in undefined behavior (and don't work on MSVC). Instead, | 8 // 2. #define CLIPBOARD_TYPE_TO_TEST to the name of the clipboard traits. |
| 9 // 'parameterized' tests should typedef TypesToTest (which is used to | 9 // |
| 10 // instantiate the tests using the TYPED_TEST_CASE macro) and then #include this | 10 // This complexity results from several factors: |
| 11 // header. | 11 // - not all clipboard tests work on all platforms, so this header cannot use |
| 12 // the standard REGISTER_TYPED_TEST_CASE_P macro. |
| 13 // - as a result of using the TYPED_TEST_CASE/TYPED_TEST macros, multiple |
| 14 // instantiations of this test template in the same binary result in |
| 15 // multiply-defined symbols, hence the CLIPBOARD_TEST_FIXTURE_NAME |
| 16 // requirement. |
| 17 // - the test fixture name also needs to encoder whether or not the tests need |
| 18 // to run serially. |
| 19 // |
| 12 // TODO(dcheng): This is really horrible. In general, all tests should run on | 20 // TODO(dcheng): This is really horrible. In general, all tests should run on |
| 13 // all platforms, to avoid this mess. | 21 // all platforms, to avoid this mess. |
| 14 | 22 |
| 15 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 16 | 24 |
| 17 #include <string> | 25 #include <string> |
| 18 | 26 |
| 19 #include "base/basictypes.h" | 27 #include "base/basictypes.h" |
| 28 #include "base/gtest_prod_util.h" |
| 20 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | 30 #include "base/message_loop/message_loop.h" |
| 22 #include "base/pickle.h" | 31 #include "base/pickle.h" |
| 23 #include "base/run_loop.h" | 32 #include "base/run_loop.h" |
| 24 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 34 #include "base/strings/utf_string_conversions.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "testing/platform_test.h" | 36 #include "testing/platform_test.h" |
| 28 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
| 29 #include "third_party/skia/include/core/SkColor.h" | 38 #include "third_party/skia/include/core/SkColor.h" |
| 30 #include "third_party/skia/include/core/SkScalar.h" | 39 #include "third_party/skia/include/core/SkScalar.h" |
| 31 #include "third_party/skia/include/core/SkUnPreMultiply.h" | 40 #include "third_party/skia/include/core/SkUnPreMultiply.h" |
| 32 #include "ui/base/clipboard/clipboard.h" | 41 #include "ui/base/clipboard/clipboard.h" |
| 33 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 42 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 34 #include "ui/base/test/test_clipboard.h" | 43 #include "ui/base/test/test_clipboard.h" |
| 35 #include "ui/gfx/geometry/size.h" | 44 #include "ui/gfx/geometry/size.h" |
| 36 | 45 |
| 37 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| 38 #include "ui/base/clipboard/clipboard_util_win.h" | 47 #include "ui/base/clipboard/clipboard_util_win.h" |
| 39 #endif | 48 #endif |
| 40 | 49 |
| 41 #if defined(USE_AURA) | 50 #if defined(USE_AURA) |
| 42 #include "ui/events/platform/platform_event_source.h" | 51 #include "ui/events/platform/platform_event_source.h" |
| 43 #endif | 52 #endif |
| 44 | 53 |
| 54 #if !defined(CLIPBOARD_TEST_FIXTURE_NAME) |
| 55 #error CLIPBOARD_TEST_FIXTURE_NAME must be #defined! |
| 56 #endif |
| 57 |
| 58 #if !defined(CLIPBOARD_TYPE_TO_TEST) |
| 59 #error CLIPBOARD_TYPE_TO_TEST must be #defined! |
| 60 #endif |
| 61 |
| 62 #define CLIPBOARD_TYPED_TEST_CASE_HELPER(x, y) TYPED_TEST_CASE(x, y) |
| 63 #if defined(CLIPBOARD_TESTS_RUN_SERIALLY) |
| 64 #define CLIPBOARD_TYPED_TEST_HELPER(x, y) TYPED_TEST_SERIALIZE(x, y) |
| 65 #else |
| 66 #define CLIPBOARD_TYPED_TEST_HELPER(x, y) TYPED_TEST(x, y) |
| 67 #endif |
| 68 |
| 69 #define CLIPBOARD_TYPED_TEST_CASE(x) \ |
| 70 CLIPBOARD_TYPED_TEST_CASE_HELPER(CLIPBOARD_TEST_FIXTURE_NAME, x) |
| 71 #define CLIPBOARD_TYPED_TEST(x) \ |
| 72 CLIPBOARD_TYPED_TEST_HELPER(CLIPBOARD_TEST_FIXTURE_NAME, x) |
| 73 |
| 45 using base::ASCIIToUTF16; | 74 using base::ASCIIToUTF16; |
| 46 using base::UTF8ToUTF16; | 75 using base::UTF8ToUTF16; |
| 47 using base::UTF16ToUTF8; | 76 using base::UTF16ToUTF8; |
| 48 | 77 |
| 49 namespace ui { | 78 namespace ui { |
| 50 | 79 |
| 51 template <typename ClipboardTraits> | 80 template <typename ClipboardTraits> |
| 52 class ClipboardTest : public PlatformTest { | 81 class CLIPBOARD_TEST_FIXTURE_NAME : public PlatformTest { |
| 53 public: | 82 public: |
| 54 #if defined(USE_AURA) | 83 #if defined(USE_AURA) |
| 55 ClipboardTest() | 84 CLIPBOARD_TEST_FIXTURE_NAME() |
| 56 : event_source_(PlatformEventSource::CreateDefault()), | 85 : event_source_(PlatformEventSource::CreateDefault()), |
| 57 clipboard_(ClipboardTraits::Create()) {} | 86 clipboard_(ClipboardTraits::Create()) {} |
| 58 #else | 87 #else |
| 59 ClipboardTest() : clipboard_(ClipboardTraits::Create()) {} | 88 CLIPBOARD_TEST_FIXTURE_NAME() : clipboard_(ClipboardTraits::Create()) {} |
| 60 #endif | 89 #endif |
| 61 | 90 |
| 62 ~ClipboardTest() override { ClipboardTraits::Destroy(clipboard_); } | 91 ~CLIPBOARD_TEST_FIXTURE_NAME() override { |
| 92 ClipboardTraits::Destroy(clipboard_); |
| 93 } |
| 63 | 94 |
| 64 protected: | 95 protected: |
| 65 Clipboard& clipboard() { return *clipboard_; } | 96 Clipboard& clipboard() { return *clipboard_; } |
| 66 | 97 |
| 67 private: | 98 private: |
| 68 base::MessageLoopForUI message_loop_; | 99 base::MessageLoopForUI message_loop_; |
| 69 #if defined(USE_AURA) | 100 #if defined(USE_AURA) |
| 70 scoped_ptr<PlatformEventSource> event_source_; | 101 scoped_ptr<PlatformEventSource> event_source_; |
| 71 #endif | 102 #endif |
| 72 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. | 103 // ui::Clipboard has a protected destructor, so scoped_ptr doesn't work here. |
| 73 Clipboard* const clipboard_; | 104 Clipboard* const clipboard_; |
| 74 }; | 105 }; |
| 75 | 106 |
| 76 // Hack for tests that need to call static methods of ClipboardTest. | 107 CLIPBOARD_TYPED_TEST_CASE(CLIPBOARD_TYPE_TO_TEST); |
| 77 struct NullClipboardTraits { | |
| 78 static Clipboard* Create() { return nullptr; } | |
| 79 static void Destroy(Clipboard*) {} | |
| 80 }; | |
| 81 | 108 |
| 82 TYPED_TEST_CASE(ClipboardTest, TypesToTest); | 109 CLIPBOARD_TYPED_TEST(ClearTest) { |
| 83 | |
| 84 TYPED_TEST(ClipboardTest, ClearTest) { | |
| 85 { | 110 { |
| 86 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 111 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 87 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); | 112 clipboard_writer.WriteText(ASCIIToUTF16("clear me")); |
| 88 } | 113 } |
| 89 | 114 |
| 90 this->clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); | 115 this->clipboard().Clear(CLIPBOARD_TYPE_COPY_PASTE); |
| 91 | 116 |
| 92 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 117 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 93 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 118 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 94 EXPECT_FALSE(this->clipboard().IsFormatAvailable( | 119 EXPECT_FALSE(this->clipboard().IsFormatAvailable( |
| 95 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 120 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 96 } | 121 } |
| 97 | 122 |
| 98 TYPED_TEST(ClipboardTest, TextTest) { | 123 CLIPBOARD_TYPED_TEST(TextTest) { |
| 99 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; | 124 base::string16 text(ASCIIToUTF16("This is a base::string16!#$")), text_result; |
| 100 std::string ascii_text; | 125 std::string ascii_text; |
| 101 | 126 |
| 102 { | 127 { |
| 103 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 128 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 104 clipboard_writer.WriteText(text); | 129 clipboard_writer.WriteText(text); |
| 105 } | 130 } |
| 106 | 131 |
| 107 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 132 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 108 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 133 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 109 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 134 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 110 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 135 Clipboard::GetPlainTextFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 111 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 136 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 112 | 137 |
| 113 EXPECT_EQ(text, text_result); | 138 EXPECT_EQ(text, text_result); |
| 114 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 139 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
| 115 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 140 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
| 116 } | 141 } |
| 117 | 142 |
| 118 TYPED_TEST(ClipboardTest, HTMLTest) { | 143 CLIPBOARD_TYPED_TEST(HTMLTest) { |
| 119 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; | 144 base::string16 markup(ASCIIToUTF16("<string>Hi!</string>")), markup_result; |
| 120 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; | 145 base::string16 plain(ASCIIToUTF16("Hi!")), plain_result; |
| 121 std::string url("http://www.example.com/"), url_result; | 146 std::string url("http://www.example.com/"), url_result; |
| 122 | 147 |
| 123 { | 148 { |
| 124 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 149 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 125 clipboard_writer.WriteText(plain); | 150 clipboard_writer.WriteText(plain); |
| 126 clipboard_writer.WriteHTML(markup, url); | 151 clipboard_writer.WriteHTML(markup, url); |
| 127 } | 152 } |
| 128 | 153 |
| 129 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 154 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 130 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 155 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 131 uint32 fragment_start; | 156 uint32 fragment_start; |
| 132 uint32 fragment_end; | 157 uint32 fragment_end; |
| 133 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 158 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 134 &url_result, &fragment_start, &fragment_end); | 159 &url_result, &fragment_start, &fragment_end); |
| 135 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 160 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 136 EXPECT_EQ(markup, | 161 EXPECT_EQ(markup, |
| 137 markup_result.substr(fragment_end - markup.size(), markup.size())); | 162 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 138 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
| 139 // TODO(playmobil): It's not clear that non windows clipboards need to support | 164 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 140 // this. | 165 // this. |
| 141 EXPECT_EQ(url, url_result); | 166 EXPECT_EQ(url, url_result); |
| 142 #endif // defined(OS_WIN) | 167 #endif // defined(OS_WIN) |
| 143 } | 168 } |
| 144 | 169 |
| 145 TYPED_TEST(ClipboardTest, RTFTest) { | 170 CLIPBOARD_TYPED_TEST(RTFTest) { |
| 146 std::string rtf = | 171 std::string rtf = |
| 147 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" | 172 "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\n" |
| 148 "This is some {\\b bold} text.\\par\n" | 173 "This is some {\\b bold} text.\\par\n" |
| 149 "}"; | 174 "}"; |
| 150 | 175 |
| 151 { | 176 { |
| 152 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 177 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 153 clipboard_writer.WriteRTF(rtf); | 178 clipboard_writer.WriteRTF(rtf); |
| 154 } | 179 } |
| 155 | 180 |
| 156 EXPECT_TRUE(this->clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), | 181 EXPECT_TRUE(this->clipboard().IsFormatAvailable(Clipboard::GetRtfFormatType(), |
| 157 CLIPBOARD_TYPE_COPY_PASTE)); | 182 CLIPBOARD_TYPE_COPY_PASTE)); |
| 158 std::string result; | 183 std::string result; |
| 159 this->clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); | 184 this->clipboard().ReadRTF(CLIPBOARD_TYPE_COPY_PASTE, &result); |
| 160 EXPECT_EQ(rtf, result); | 185 EXPECT_EQ(rtf, result); |
| 161 } | 186 } |
| 162 | 187 |
| 163 // TODO(dnicoara) Enable test once Ozone implements clipboard support: | 188 // TODO(dnicoara) Enable test once Ozone implements clipboard support: |
| 164 // crbug.com/361707 | 189 // crbug.com/361707 |
| 165 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) | 190 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(USE_OZONE) |
| 166 TYPED_TEST(ClipboardTest, MultipleBufferTest) { | 191 CLIPBOARD_TYPED_TEST(MultipleBufferTest) { |
| 167 base::string16 text(ASCIIToUTF16("Standard")), text_result; | 192 base::string16 text(ASCIIToUTF16("Standard")), text_result; |
| 168 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); | 193 base::string16 markup(ASCIIToUTF16("<string>Selection</string>")); |
| 169 std::string url("http://www.example.com/"), url_result; | 194 std::string url("http://www.example.com/"), url_result; |
| 170 | 195 |
| 171 { | 196 { |
| 172 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 197 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 173 clipboard_writer.WriteText(text); | 198 clipboard_writer.WriteText(text); |
| 174 } | 199 } |
| 175 | 200 |
| 176 { | 201 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 195 uint32 fragment_start; | 220 uint32 fragment_start; |
| 196 uint32 fragment_end; | 221 uint32 fragment_end; |
| 197 this->clipboard().ReadHTML(CLIPBOARD_TYPE_SELECTION, &markup_result, | 222 this->clipboard().ReadHTML(CLIPBOARD_TYPE_SELECTION, &markup_result, |
| 198 &url_result, &fragment_start, &fragment_end); | 223 &url_result, &fragment_start, &fragment_end); |
| 199 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 224 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 200 EXPECT_EQ(markup, | 225 EXPECT_EQ(markup, |
| 201 markup_result.substr(fragment_end - markup.size(), markup.size())); | 226 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 202 } | 227 } |
| 203 #endif | 228 #endif |
| 204 | 229 |
| 205 TYPED_TEST(ClipboardTest, TrickyHTMLTest) { | 230 CLIPBOARD_TYPED_TEST(TrickyHTMLTest) { |
| 206 base::string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")), | 231 base::string16 markup(ASCIIToUTF16("<em>Bye!<!--EndFragment --></em>")), |
| 207 markup_result; | 232 markup_result; |
| 208 std::string url, url_result; | 233 std::string url, url_result; |
| 209 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; | 234 base::string16 plain(ASCIIToUTF16("Bye!")), plain_result; |
| 210 | 235 |
| 211 { | 236 { |
| 212 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 237 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 213 clipboard_writer.WriteText(plain); | 238 clipboard_writer.WriteText(plain); |
| 214 clipboard_writer.WriteHTML(markup, url); | 239 clipboard_writer.WriteHTML(markup, url); |
| 215 } | 240 } |
| 216 | 241 |
| 217 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 242 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 218 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 243 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 219 uint32 fragment_start; | 244 uint32 fragment_start; |
| 220 uint32 fragment_end; | 245 uint32 fragment_end; |
| 221 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 246 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 222 &url_result, &fragment_start, &fragment_end); | 247 &url_result, &fragment_start, &fragment_end); |
| 223 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 248 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 224 EXPECT_EQ(markup, | 249 EXPECT_EQ(markup, |
| 225 markup_result.substr(fragment_end - markup.size(), markup.size())); | 250 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 226 #if defined(OS_WIN) | 251 #if defined(OS_WIN) |
| 227 // TODO(playmobil): It's not clear that non windows clipboards need to support | 252 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 228 // this. | 253 // this. |
| 229 EXPECT_EQ(url, url_result); | 254 EXPECT_EQ(url, url_result); |
| 230 #endif // defined(OS_WIN) | 255 #endif // defined(OS_WIN) |
| 231 } | 256 } |
| 232 | 257 |
| 233 // Some platforms store HTML as UTF-8 internally. Make sure fragment indices are | 258 // Some platforms store HTML as UTF-8 internally. Make sure fragment indices are |
| 234 // adjusted appropriately when converting back to UTF-16. | 259 // adjusted appropriately when converting back to UTF-16. |
| 235 TYPED_TEST(ClipboardTest, UnicodeHTMLTest) { | 260 CLIPBOARD_TYPED_TEST(UnicodeHTMLTest) { |
| 236 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), | 261 base::string16 markup(UTF8ToUTF16("<div>A \xc3\xb8 \xe6\xb0\xb4</div>")), |
| 237 markup_result; | 262 markup_result; |
| 238 std::string url, url_result; | 263 std::string url, url_result; |
| 239 | 264 |
| 240 { | 265 { |
| 241 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 266 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 242 clipboard_writer.WriteHTML(markup, url); | 267 clipboard_writer.WriteHTML(markup, url); |
| 243 } | 268 } |
| 244 | 269 |
| 245 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 270 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 246 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 271 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 247 uint32 fragment_start; | 272 uint32 fragment_start; |
| 248 uint32 fragment_end; | 273 uint32 fragment_end; |
| 249 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, | 274 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &markup_result, |
| 250 &url_result, &fragment_start, &fragment_end); | 275 &url_result, &fragment_start, &fragment_end); |
| 251 EXPECT_LE(markup.size(), fragment_end - fragment_start); | 276 EXPECT_LE(markup.size(), fragment_end - fragment_start); |
| 252 EXPECT_EQ(markup, | 277 EXPECT_EQ(markup, |
| 253 markup_result.substr(fragment_end - markup.size(), markup.size())); | 278 markup_result.substr(fragment_end - markup.size(), markup.size())); |
| 254 #if defined(OS_WIN) | 279 #if defined(OS_WIN) |
| 255 EXPECT_EQ(url, url_result); | 280 EXPECT_EQ(url, url_result); |
| 256 #endif | 281 #endif |
| 257 } | 282 } |
| 258 | 283 |
| 259 // TODO(estade): Port the following test (decide what target we use for urls) | 284 // TODO(estade): Port the following test (decide what target we use for urls) |
| 260 #if !defined(OS_POSIX) || defined(OS_MACOSX) | 285 #if !defined(OS_POSIX) || defined(OS_MACOSX) |
| 261 TYPED_TEST(ClipboardTest, BookmarkTest) { | 286 CLIPBOARD_TYPED_TEST(BookmarkTest) { |
| 262 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; | 287 base::string16 title(ASCIIToUTF16("The Example Company")), title_result; |
| 263 std::string url("http://www.example.com/"), url_result; | 288 std::string url("http://www.example.com/"), url_result; |
| 264 | 289 |
| 265 { | 290 { |
| 266 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 291 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 267 clipboard_writer.WriteBookmark(title, url); | 292 clipboard_writer.WriteBookmark(title, url); |
| 268 } | 293 } |
| 269 | 294 |
| 270 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 295 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 271 Clipboard::GetUrlWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 296 Clipboard::GetUrlWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 272 this->clipboard().ReadBookmark(&title_result, &url_result); | 297 this->clipboard().ReadBookmark(&title_result, &url_result); |
| 273 EXPECT_EQ(title, title_result); | 298 EXPECT_EQ(title, title_result); |
| 274 EXPECT_EQ(url, url_result); | 299 EXPECT_EQ(url, url_result); |
| 275 } | 300 } |
| 276 #endif // !defined(OS_POSIX) || defined(OS_MACOSX) | 301 #endif // !defined(OS_POSIX) || defined(OS_MACOSX) |
| 277 | 302 |
| 278 TYPED_TEST(ClipboardTest, MultiFormatTest) { | 303 CLIPBOARD_TYPED_TEST(MultiFormatTest) { |
| 279 base::string16 text(ASCIIToUTF16("Hi!")), text_result; | 304 base::string16 text(ASCIIToUTF16("Hi!")), text_result; |
| 280 base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; | 305 base::string16 markup(ASCIIToUTF16("<strong>Hi!</string>")), markup_result; |
| 281 std::string url("http://www.example.com/"), url_result; | 306 std::string url("http://www.example.com/"), url_result; |
| 282 std::string ascii_text; | 307 std::string ascii_text; |
| 283 | 308 |
| 284 { | 309 { |
| 285 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 310 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 286 clipboard_writer.WriteHTML(markup, url); | 311 clipboard_writer.WriteHTML(markup, url); |
| 287 clipboard_writer.WriteText(text); | 312 clipboard_writer.WriteText(text); |
| 288 } | 313 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 304 // TODO(playmobil): It's not clear that non windows clipboards need to support | 329 // TODO(playmobil): It's not clear that non windows clipboards need to support |
| 305 // this. | 330 // this. |
| 306 EXPECT_EQ(url, url_result); | 331 EXPECT_EQ(url, url_result); |
| 307 #endif // defined(OS_WIN) | 332 #endif // defined(OS_WIN) |
| 308 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); | 333 this->clipboard().ReadText(CLIPBOARD_TYPE_COPY_PASTE, &text_result); |
| 309 EXPECT_EQ(text, text_result); | 334 EXPECT_EQ(text, text_result); |
| 310 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); | 335 this->clipboard().ReadAsciiText(CLIPBOARD_TYPE_COPY_PASTE, &ascii_text); |
| 311 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); | 336 EXPECT_EQ(UTF16ToUTF8(text), ascii_text); |
| 312 } | 337 } |
| 313 | 338 |
| 314 TYPED_TEST(ClipboardTest, URLTest) { | 339 CLIPBOARD_TYPED_TEST(URLTest) { |
| 315 base::string16 url(ASCIIToUTF16("http://www.google.com/")); | 340 base::string16 url(ASCIIToUTF16("http://www.google.com/")); |
| 316 | 341 |
| 317 { | 342 { |
| 318 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 343 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 319 clipboard_writer.WriteURL(url); | 344 clipboard_writer.WriteURL(url); |
| 320 } | 345 } |
| 321 | 346 |
| 322 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 347 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 323 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 348 Clipboard::GetPlainTextWFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 324 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 349 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 for (int j = 0; j < image.height(); ++j) { | 386 for (int j = 0; j < image.height(); ++j) { |
| 362 const uint32* row_address = image.getAddr32(0, j); | 387 const uint32* row_address = image.getAddr32(0, j); |
| 363 for (int i = 0; i < image.width(); ++i) { | 388 for (int i = 0; i < image.width(); ++i) { |
| 364 int offset = i + j * image.width(); | 389 int offset = i + j * image.width(); |
| 365 EXPECT_EQ(bitmap_data[offset], row_address[i]) << "i = " << i | 390 EXPECT_EQ(bitmap_data[offset], row_address[i]) << "i = " << i |
| 366 << ", j = " << j; | 391 << ", j = " << j; |
| 367 } | 392 } |
| 368 } | 393 } |
| 369 } | 394 } |
| 370 | 395 |
| 371 TYPED_TEST(ClipboardTest, SharedBitmapTest) { | 396 CLIPBOARD_TYPED_TEST(SharedBitmapTest) { |
| 372 const uint32 fake_bitmap_1[] = { | 397 const uint32 fake_bitmap_1[] = { |
| 373 0x46061626, 0xf69f5988, 0x793f2937, 0xfa55b986, | 398 0x46061626, 0xf69f5988, 0x793f2937, 0xfa55b986, |
| 374 0x78772152, 0x87692a30, 0x36322a25, 0x4320401b, | 399 0x78772152, 0x87692a30, 0x36322a25, 0x4320401b, |
| 375 0x91848c21, 0xc3177b3c, 0x6946155c, 0x64171952, | 400 0x91848c21, 0xc3177b3c, 0x6946155c, 0x64171952, |
| 376 }; | 401 }; |
| 377 { | 402 { |
| 378 SCOPED_TRACE("first bitmap"); | 403 SCOPED_TRACE("first bitmap"); |
| 379 TestBitmapWrite(&this->clipboard(), gfx::Size(4, 3), fake_bitmap_1); | 404 TestBitmapWrite(&this->clipboard(), gfx::Size(4, 3), fake_bitmap_1); |
| 380 } | 405 } |
| 381 | 406 |
| 382 const uint32 fake_bitmap_2[] = { | 407 const uint32 fake_bitmap_2[] = { |
| 383 0x46061626, 0xf69f5988, | 408 0x46061626, 0xf69f5988, |
| 384 0x793f2937, 0xfa55b986, | 409 0x793f2937, 0xfa55b986, |
| 385 0x78772152, 0x87692a30, | 410 0x78772152, 0x87692a30, |
| 386 0x36322a25, 0x4320401b, | 411 0x36322a25, 0x4320401b, |
| 387 0x91848c21, 0xc3177b3c, | 412 0x91848c21, 0xc3177b3c, |
| 388 0x6946155c, 0x64171952, | 413 0x6946155c, 0x64171952, |
| 389 0xa6910313, 0x8302323e, | 414 0xa6910313, 0x8302323e, |
| 390 }; | 415 }; |
| 391 { | 416 { |
| 392 SCOPED_TRACE("second bitmap"); | 417 SCOPED_TRACE("second bitmap"); |
| 393 TestBitmapWrite(&this->clipboard(), gfx::Size(2, 7), fake_bitmap_2); | 418 TestBitmapWrite(&this->clipboard(), gfx::Size(2, 7), fake_bitmap_2); |
| 394 } | 419 } |
| 395 } | 420 } |
| 396 | 421 |
| 397 TYPED_TEST(ClipboardTest, DataTest) { | 422 CLIPBOARD_TYPED_TEST(DataTest) { |
| 398 const ui::Clipboard::FormatType kFormat = | 423 const ui::Clipboard::FormatType kFormat = |
| 399 ui::Clipboard::GetFormatType("chromium/x-test-format"); | 424 ui::Clipboard::GetFormatType("chromium/x-test-format"); |
| 400 std::string payload("test string"); | 425 std::string payload("test string"); |
| 401 Pickle write_pickle; | 426 Pickle write_pickle; |
| 402 write_pickle.WriteString(payload); | 427 write_pickle.WriteString(payload); |
| 403 | 428 |
| 404 { | 429 { |
| 405 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 430 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 406 clipboard_writer.WritePickledData(write_pickle, kFormat); | 431 clipboard_writer.WritePickledData(write_pickle, kFormat); |
| 407 } | 432 } |
| 408 | 433 |
| 409 ASSERT_TRUE( | 434 ASSERT_TRUE( |
| 410 this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE)); | 435 this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE)); |
| 411 std::string output; | 436 std::string output; |
| 412 this->clipboard().ReadData(kFormat, &output); | 437 this->clipboard().ReadData(kFormat, &output); |
| 413 ASSERT_FALSE(output.empty()); | 438 ASSERT_FALSE(output.empty()); |
| 414 | 439 |
| 415 Pickle read_pickle(output.data(), output.size()); | 440 Pickle read_pickle(output.data(), output.size()); |
| 416 PickleIterator iter(read_pickle); | 441 PickleIterator iter(read_pickle); |
| 417 std::string unpickled_string; | 442 std::string unpickled_string; |
| 418 ASSERT_TRUE(iter.ReadString(&unpickled_string)); | 443 ASSERT_TRUE(iter.ReadString(&unpickled_string)); |
| 419 EXPECT_EQ(payload, unpickled_string); | 444 EXPECT_EQ(payload, unpickled_string); |
| 420 } | 445 } |
| 421 | 446 |
| 422 TYPED_TEST(ClipboardTest, MultipleDataTest) { | 447 CLIPBOARD_TYPED_TEST(MultipleDataTest) { |
| 423 const ui::Clipboard::FormatType kFormat1 = | 448 const ui::Clipboard::FormatType kFormat1 = |
| 424 ui::Clipboard::GetFormatType("chromium/x-test-format1"); | 449 ui::Clipboard::GetFormatType("chromium/x-test-format1"); |
| 425 std::string payload1("test string1"); | 450 std::string payload1("test string1"); |
| 426 Pickle write_pickle1; | 451 Pickle write_pickle1; |
| 427 write_pickle1.WriteString(payload1); | 452 write_pickle1.WriteString(payload1); |
| 428 | 453 |
| 429 const ui::Clipboard::FormatType kFormat2 = | 454 const ui::Clipboard::FormatType kFormat2 = |
| 430 ui::Clipboard::GetFormatType("chromium/x-test-format2"); | 455 ui::Clipboard::GetFormatType("chromium/x-test-format2"); |
| 431 std::string payload2("test string2"); | 456 std::string payload2("test string2"); |
| 432 Pickle write_pickle2; | 457 Pickle write_pickle2; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 ASSERT_FALSE(output1.empty()); | 494 ASSERT_FALSE(output1.empty()); |
| 470 | 495 |
| 471 Pickle read_pickle1(output1.data(), output1.size()); | 496 Pickle read_pickle1(output1.data(), output1.size()); |
| 472 PickleIterator iter1(read_pickle1); | 497 PickleIterator iter1(read_pickle1); |
| 473 std::string unpickled_string1; | 498 std::string unpickled_string1; |
| 474 ASSERT_TRUE(iter1.ReadString(&unpickled_string1)); | 499 ASSERT_TRUE(iter1.ReadString(&unpickled_string1)); |
| 475 EXPECT_EQ(payload1, unpickled_string1); | 500 EXPECT_EQ(payload1, unpickled_string1); |
| 476 } | 501 } |
| 477 | 502 |
| 478 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 503 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 479 TYPED_TEST(ClipboardTest, HyperlinkTest) { | 504 CLIPBOARD_TYPED_TEST(HyperlinkTest) { |
| 480 const std::string kTitle("The <Example> Company's \"home page\""); | 505 const std::string kTitle("The <Example> Company's \"home page\""); |
| 481 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); | 506 const std::string kUrl("http://www.example.com?x=3<=3#\"'<>"); |
| 482 const base::string16 kExpectedHtml(UTF8ToUTF16( | 507 const base::string16 kExpectedHtml(UTF8ToUTF16( |
| 483 "<a href=\"http://www.example.com?x=3&lt=3#"'<>\">" | 508 "<a href=\"http://www.example.com?x=3&lt=3#"'<>\">" |
| 484 "The <Example> Company's "home page"</a>")); | 509 "The <Example> Company's "home page"</a>")); |
| 485 | 510 |
| 486 std::string url_result; | 511 std::string url_result; |
| 487 base::string16 html_result; | 512 base::string16 html_result; |
| 488 { | 513 { |
| 489 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 514 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 490 clipboard_writer.WriteHyperlink(ASCIIToUTF16(kTitle), kUrl); | 515 clipboard_writer.WriteHyperlink(ASCIIToUTF16(kTitle), kUrl); |
| 491 } | 516 } |
| 492 | 517 |
| 493 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 518 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 494 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 519 Clipboard::GetHtmlFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 495 uint32 fragment_start; | 520 uint32 fragment_start; |
| 496 uint32 fragment_end; | 521 uint32 fragment_end; |
| 497 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &html_result, | 522 this->clipboard().ReadHTML(CLIPBOARD_TYPE_COPY_PASTE, &html_result, |
| 498 &url_result, &fragment_start, &fragment_end); | 523 &url_result, &fragment_start, &fragment_end); |
| 499 EXPECT_EQ(kExpectedHtml, | 524 EXPECT_EQ(kExpectedHtml, |
| 500 html_result.substr(fragment_end - kExpectedHtml.size(), | 525 html_result.substr(fragment_end - kExpectedHtml.size(), |
| 501 kExpectedHtml.size())); | 526 kExpectedHtml.size())); |
| 502 } | 527 } |
| 503 #endif | 528 #endif |
| 504 | 529 |
| 505 TYPED_TEST(ClipboardTest, WebSmartPasteTest) { | 530 CLIPBOARD_TYPED_TEST(WebSmartPasteTest) { |
| 506 { | 531 { |
| 507 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); | 532 ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 508 clipboard_writer.WriteWebSmartPaste(); | 533 clipboard_writer.WriteWebSmartPaste(); |
| 509 } | 534 } |
| 510 | 535 |
| 511 EXPECT_TRUE(this->clipboard().IsFormatAvailable( | 536 EXPECT_TRUE(this->clipboard().IsFormatAvailable( |
| 512 Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); | 537 Clipboard::GetWebKitSmartPasteFormatType(), CLIPBOARD_TYPE_COPY_PASTE)); |
| 513 } | 538 } |
| 514 | 539 |
| 515 #if defined(OS_WIN) // Windows only tests. | 540 #if defined(OS_WIN) // Windows only tests. |
| 516 void HtmlTestHelper(const std::string& cf_html, | 541 static void HtmlTestHelper(const std::string& cf_html, |
| 517 const std::string& expected_html) { | 542 const std::string& expected_html) { |
| 518 std::string html; | 543 std::string html; |
| 519 ClipboardUtil::CFHtmlToHtml(cf_html, &html, NULL); | 544 ClipboardUtil::CFHtmlToHtml(cf_html, &html, NULL); |
| 520 EXPECT_EQ(html, expected_html); | 545 EXPECT_EQ(html, expected_html); |
| 521 } | 546 } |
| 522 | 547 |
| 523 TYPED_TEST(ClipboardTest, HtmlTest) { | 548 CLIPBOARD_TYPED_TEST(HtmlTest) { |
| 524 // Test converting from CF_HTML format data with <!--StartFragment--> and | 549 // Test converting from CF_HTML format data with <!--StartFragment--> and |
| 525 // <!--EndFragment--> comments, like from MS Word. | 550 // <!--EndFragment--> comments, like from MS Word. |
| 526 HtmlTestHelper( | 551 HtmlTestHelper( |
| 527 "Version:1.0\r\n" | 552 "Version:1.0\r\n" |
| 528 "StartHTML:0000000105\r\n" | 553 "StartHTML:0000000105\r\n" |
| 529 "EndHTML:0000000199\r\n" | 554 "EndHTML:0000000199\r\n" |
| 530 "StartFragment:0000000123\r\n" | 555 "StartFragment:0000000123\r\n" |
| 531 "EndFragment:0000000161\r\n" | 556 "EndFragment:0000000161\r\n" |
| 532 "\r\n" | 557 "\r\n" |
| 533 "<html>\r\n" | 558 "<html>\r\n" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 552 "<html>\r\n" | 577 "<html>\r\n" |
| 553 "<body>\r\n" | 578 "<body>\r\n" |
| 554 "<p>Foo</p>\r\n" | 579 "<p>Foo</p>\r\n" |
| 555 "</body>\r\n" | 580 "</body>\r\n" |
| 556 "</html>\r\n\r\n", | 581 "</html>\r\n\r\n", |
| 557 "<p>Foo</p>"); | 582 "<p>Foo</p>"); |
| 558 } | 583 } |
| 559 #endif // defined(OS_WIN) | 584 #endif // defined(OS_WIN) |
| 560 | 585 |
| 561 // Test writing all formats we have simultaneously. | 586 // Test writing all formats we have simultaneously. |
| 562 TYPED_TEST(ClipboardTest, WriteEverything) { | 587 CLIPBOARD_TYPED_TEST(WriteEverything) { |
| 563 { | 588 { |
| 564 ScopedClipboardWriter writer(CLIPBOARD_TYPE_COPY_PASTE); | 589 ScopedClipboardWriter writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 565 writer.WriteText(UTF8ToUTF16("foo")); | 590 writer.WriteText(UTF8ToUTF16("foo")); |
| 566 writer.WriteURL(UTF8ToUTF16("foo")); | 591 writer.WriteURL(UTF8ToUTF16("foo")); |
| 567 writer.WriteHTML(UTF8ToUTF16("foo"), "bar"); | 592 writer.WriteHTML(UTF8ToUTF16("foo"), "bar"); |
| 568 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); | 593 writer.WriteBookmark(UTF8ToUTF16("foo"), "bar"); |
| 569 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); | 594 writer.WriteHyperlink(ASCIIToUTF16("foo"), "bar"); |
| 570 writer.WriteWebSmartPaste(); | 595 writer.WriteWebSmartPaste(); |
| 571 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. | 596 // Left out: WriteFile, WriteFiles, WriteBitmapFromPixels, WritePickledData. |
| 572 } | 597 } |
| 573 | 598 |
| 574 // Passes if we don't crash. | 599 // Passes if we don't crash. |
| 575 } | 600 } |
| 576 | 601 |
| 577 // TODO(dcheng): Fix this test for Android. It's rather involved, since the | 602 // TODO(dcheng): Fix this test for Android. It's rather involved, since the |
| 578 // clipboard change listener is posted to the Java message loop, and spinning | 603 // clipboard change listener is posted to the Java message loop, and spinning |
| 579 // that loop from C++ to trigger the callback in the test requires a non-trivial | 604 // that loop from C++ to trigger the callback in the test requires a non-trivial |
| 580 // amount of additional work. | 605 // amount of additional work. |
| 581 #if !defined(OS_ANDROID) | 606 #if !defined(OS_ANDROID) |
| 582 // Simple test that the sequence number appears to change when the clipboard is | 607 // Simple test that the sequence number appears to change when the clipboard is |
| 583 // written to. | 608 // written to. |
| 584 // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION. | 609 // TODO(dcheng): Add a version to test CLIPBOARD_TYPE_SELECTION. |
| 585 TYPED_TEST(ClipboardTest, GetSequenceNumber) { | 610 CLIPBOARD_TYPED_TEST(GetSequenceNumber) { |
| 586 const uint64 first_sequence_number = | 611 const uint64 first_sequence_number = |
| 587 this->clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); | 612 this->clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); |
| 588 | 613 |
| 589 { | 614 { |
| 590 ScopedClipboardWriter writer(CLIPBOARD_TYPE_COPY_PASTE); | 615 ScopedClipboardWriter writer(CLIPBOARD_TYPE_COPY_PASTE); |
| 591 writer.WriteText(UTF8ToUTF16("World")); | 616 writer.WriteText(UTF8ToUTF16("World")); |
| 592 } | 617 } |
| 593 | 618 |
| 594 // On some platforms, the sequence number is updated by a UI callback so pump | 619 // On some platforms, the sequence number is updated by a UI callback so pump |
| 595 // the message loop to make sure we get the notification. | 620 // the message loop to make sure we get the notification. |
| 596 base::RunLoop().RunUntilIdle(); | 621 base::RunLoop().RunUntilIdle(); |
| 597 | 622 |
| 598 const uint64 second_sequence_number = | 623 const uint64 second_sequence_number = |
| 599 this->clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); | 624 this->clipboard().GetSequenceNumber(CLIPBOARD_TYPE_COPY_PASTE); |
| 600 | 625 |
| 601 EXPECT_NE(first_sequence_number, second_sequence_number); | 626 EXPECT_NE(first_sequence_number, second_sequence_number); |
| 602 } | 627 } |
| 603 #endif | 628 #endif |
| 604 | 629 |
| 605 // Test that writing empty parameters doesn't try to dereference an empty data | 630 // Test that writing empty parameters doesn't try to dereference an empty data |
| 606 // vector. Not crashing = passing. | 631 // vector. Not crashing = passing. |
| 607 TYPED_TEST(ClipboardTest, WriteTextEmptyParams) { | 632 CLIPBOARD_TYPED_TEST(WriteTextEmptyParams) { |
| 608 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 633 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 609 scw.WriteText(base::string16()); | 634 scw.WriteText(base::string16()); |
| 610 } | 635 } |
| 611 | 636 |
| 612 TYPED_TEST(ClipboardTest, WriteURLEmptyParams) { | 637 CLIPBOARD_TYPED_TEST(WriteURLEmptyParams) { |
| 613 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 638 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 614 scw.WriteURL(base::string16()); | 639 scw.WriteURL(base::string16()); |
| 615 } | 640 } |
| 616 | 641 |
| 617 TYPED_TEST(ClipboardTest, WriteHTMLEmptyParams) { | 642 CLIPBOARD_TYPED_TEST(WriteHTMLEmptyParams) { |
| 618 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 643 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 619 scw.WriteHTML(base::string16(), std::string()); | 644 scw.WriteHTML(base::string16(), std::string()); |
| 620 } | 645 } |
| 621 | 646 |
| 622 TYPED_TEST(ClipboardTest, WriteRTFEmptyParams) { | 647 CLIPBOARD_TYPED_TEST(WriteRTFEmptyParams) { |
| 623 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 648 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 624 scw.WriteRTF(std::string()); | 649 scw.WriteRTF(std::string()); |
| 625 } | 650 } |
| 626 | 651 |
| 627 TYPED_TEST(ClipboardTest, WriteBookmarkEmptyParams) { | 652 CLIPBOARD_TYPED_TEST(WriteBookmarkEmptyParams) { |
| 628 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 653 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 629 scw.WriteBookmark(base::string16(), std::string()); | 654 scw.WriteBookmark(base::string16(), std::string()); |
| 630 } | 655 } |
| 631 | 656 |
| 632 TYPED_TEST(ClipboardTest, WriteHyperlinkEmptyParams) { | 657 CLIPBOARD_TYPED_TEST(WriteHyperlinkEmptyParams) { |
| 633 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 658 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 634 scw.WriteHyperlink(base::string16(), std::string()); | 659 scw.WriteHyperlink(base::string16(), std::string()); |
| 635 } | 660 } |
| 636 | 661 |
| 637 TYPED_TEST(ClipboardTest, WritePickledData) { | 662 CLIPBOARD_TYPED_TEST(WritePickledData) { |
| 638 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 663 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 639 scw.WritePickledData(Pickle(), Clipboard::GetPlainTextFormatType()); | 664 scw.WritePickledData(Pickle(), Clipboard::GetPlainTextFormatType()); |
| 640 } | 665 } |
| 641 | 666 |
| 642 TYPED_TEST(ClipboardTest, WriteImageEmptyParams) { | 667 CLIPBOARD_TYPED_TEST(WriteImageEmptyParams) { |
| 643 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); | 668 ScopedClipboardWriter scw(CLIPBOARD_TYPE_COPY_PASTE); |
| 644 scw.WriteImage(SkBitmap()); | 669 scw.WriteImage(SkBitmap()); |
| 645 } | 670 } |
| 646 | 671 |
| 647 } // namespace ui | 672 } // namespace ui |
| OLD | NEW |