| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/pickle.h" | 6 #include "base/pickle.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
| 10 #include "ui/base/dragdrop/os_exchange_data.h" | 10 #include "ui/base/dragdrop/os_exchange_data.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace ui { | 13 namespace ui { |
| 14 | 14 |
| 15 class OSExchangeDataTest : public PlatformTest { | 15 class OSExchangeDataTest : public PlatformTest { |
| 16 private: | 16 private: |
| 17 base::MessageLoopForUI message_loop_; | 17 base::MessageLoopForUI message_loop_; |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 TEST_F(OSExchangeDataTest, StringDataGetAndSet) { | 20 TEST_F(OSExchangeDataTest, StringDataGetAndSet) { |
| 21 OSExchangeData data; | 21 OSExchangeData data; |
| 22 string16 input = ASCIIToUTF16("I can has cheezburger?"); | 22 base::string16 input = ASCIIToUTF16("I can has cheezburger?"); |
| 23 data.SetString(input); | 23 data.SetString(input); |
| 24 | 24 |
| 25 OSExchangeData data2(data.provider().Clone()); | 25 OSExchangeData data2(data.provider().Clone()); |
| 26 string16 output; | 26 base::string16 output; |
| 27 EXPECT_TRUE(data2.GetString(&output)); | 27 EXPECT_TRUE(data2.GetString(&output)); |
| 28 EXPECT_EQ(input, output); | 28 EXPECT_EQ(input, output); |
| 29 std::string url_spec = "http://www.goats.com/"; | 29 std::string url_spec = "http://www.goats.com/"; |
| 30 GURL url(url_spec); | 30 GURL url(url_spec); |
| 31 string16 title; | 31 base::string16 title; |
| 32 EXPECT_FALSE(data2.GetURLAndTitle(&url, &title)); | 32 EXPECT_FALSE(data2.GetURLAndTitle(&url, &title)); |
| 33 // No URLs in |data|, so url should be untouched. | 33 // No URLs in |data|, so url should be untouched. |
| 34 EXPECT_EQ(url_spec, url.spec()); | 34 EXPECT_EQ(url_spec, url.spec()); |
| 35 } | 35 } |
| 36 | 36 |
| 37 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { | 37 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { |
| 38 OSExchangeData data; | 38 OSExchangeData data; |
| 39 std::string url_spec = "http://www.google.com/"; | 39 std::string url_spec = "http://www.google.com/"; |
| 40 GURL url(url_spec); | 40 GURL url(url_spec); |
| 41 string16 url_title = ASCIIToUTF16("www.google.com"); | 41 base::string16 url_title = ASCIIToUTF16("www.google.com"); |
| 42 data.SetURL(url, url_title); | 42 data.SetURL(url, url_title); |
| 43 string16 output; | 43 base::string16 output; |
| 44 | 44 |
| 45 OSExchangeData data2(data.provider().Clone()); | 45 OSExchangeData data2(data.provider().Clone()); |
| 46 | 46 |
| 47 // URL spec and title should match | 47 // URL spec and title should match |
| 48 GURL output_url; | 48 GURL output_url; |
| 49 string16 output_title; | 49 base::string16 output_title; |
| 50 EXPECT_TRUE(data2.GetURLAndTitle(&output_url, &output_title)); | 50 EXPECT_TRUE(data2.GetURLAndTitle(&output_url, &output_title)); |
| 51 EXPECT_EQ(url_spec, output_url.spec()); | 51 EXPECT_EQ(url_spec, output_url.spec()); |
| 52 EXPECT_EQ(url_title, output_title); | 52 EXPECT_EQ(url_title, output_title); |
| 53 string16 output_string; | 53 base::string16 output_string; |
| 54 | 54 |
| 55 // URL should be the raw text response | 55 // URL should be the raw text response |
| 56 EXPECT_TRUE(data2.GetString(&output_string)); | 56 EXPECT_TRUE(data2.GetString(&output_string)); |
| 57 EXPECT_EQ(url_spec, UTF16ToUTF8(output_string)); | 57 EXPECT_EQ(url_spec, UTF16ToUTF8(output_string)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST_F(OSExchangeDataTest, TestPickledData) { | 60 TEST_F(OSExchangeDataTest, TestPickledData) { |
| 61 const OSExchangeData::CustomFormat kTestFormat = | 61 const OSExchangeData::CustomFormat kTestFormat = |
| 62 ui::Clipboard::GetFormatType("application/vnd.chromium.test"); | 62 ui::Clipboard::GetFormatType("application/vnd.chromium.test"); |
| 63 | 63 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 76 int value; | 76 int value; |
| 77 EXPECT_TRUE(restored_pickle.ReadInt(&iterator, &value)); | 77 EXPECT_TRUE(restored_pickle.ReadInt(&iterator, &value)); |
| 78 EXPECT_EQ(1, value); | 78 EXPECT_EQ(1, value); |
| 79 EXPECT_TRUE(restored_pickle.ReadInt(&iterator, &value)); | 79 EXPECT_TRUE(restored_pickle.ReadInt(&iterator, &value)); |
| 80 EXPECT_EQ(2, value); | 80 EXPECT_EQ(2, value); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(OSExchangeDataTest, TestHTML) { | 83 TEST_F(OSExchangeDataTest, TestHTML) { |
| 84 OSExchangeData data; | 84 OSExchangeData data; |
| 85 GURL url("http://www.google.com/"); | 85 GURL url("http://www.google.com/"); |
| 86 string16 html = ASCIIToUTF16( | 86 base::string16 html = ASCIIToUTF16( |
| 87 "<HTML>\n<BODY>\n" | 87 "<HTML>\n<BODY>\n" |
| 88 "<b>bold.</b> <i><b>This is bold italic.</b></i>\n" | 88 "<b>bold.</b> <i><b>This is bold italic.</b></i>\n" |
| 89 "</BODY>\n</HTML>"); | 89 "</BODY>\n</HTML>"); |
| 90 data.SetHtml(html, url); | 90 data.SetHtml(html, url); |
| 91 | 91 |
| 92 OSExchangeData copy(data.provider().Clone()); | 92 OSExchangeData copy(data.provider().Clone()); |
| 93 string16 read_html; | 93 base::string16 read_html; |
| 94 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); | 94 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); |
| 95 EXPECT_EQ(html, read_html); | 95 EXPECT_EQ(html, read_html); |
| 96 } | 96 } |
| 97 | 97 |
| 98 } // namespace ui | 98 } // namespace ui |
| OLD | NEW |