| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/aura/mus/os_exchange_data_provider_mus.h" |
| 6 |
| 5 #include <memory> | 7 #include <memory> |
| 6 | 8 |
| 7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 8 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 10 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 13 #include "net/base/filename_util.h" | 15 #include "net/base/filename_util.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
| 16 #include "ui/base/dragdrop/os_exchange_data.h" | 18 #include "ui/base/dragdrop/os_exchange_data.h" |
| 17 #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" | 19 #include "ui/base/dragdrop/os_exchange_data_provider_factory.h" |
| 18 #include "ui/events/platform/platform_event_source.h" | 20 #include "ui/events/platform/platform_event_source.h" |
| 19 #include "ui/views/mus/os_exchange_data_provider_mus.h" | |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 using ui::Clipboard; | 23 using ui::Clipboard; |
| 23 using ui::OSExchangeData; | 24 using ui::OSExchangeData; |
| 24 | 25 |
| 25 namespace views { | 26 namespace aura { |
| 26 | 27 |
| 27 // This file is a copy/paste of the unit tests in os_exchange_data_unittest.cc, | 28 // This file is a copy/paste of the unit tests in os_exchange_data_unittest.cc, |
| 28 // with additional SetUp() to force the mus override. I thought about changeing | 29 // with additional SetUp() to force the mus override. I thought about changeing |
| 29 // the OSExchangeData test suite to a parameterized test suite, but I've | 30 // the OSExchangeData test suite to a parameterized test suite, but I've |
| 30 // previously had problems with that feature of gtest. | 31 // previously had problems with that feature of gtest. |
| 31 | 32 |
| 32 class OSExchangeDataProviderMusTest | 33 class OSExchangeDataProviderMusTest |
| 33 : public PlatformTest, | 34 : public PlatformTest, |
| 34 public ui::OSExchangeDataProviderFactory::Factory { | 35 public ui::OSExchangeDataProviderFactory::Factory { |
| 35 public: | 36 public: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 64 | 65 |
| 65 OSExchangeData data2( | 66 OSExchangeData data2( |
| 66 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); | 67 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); |
| 67 base::string16 output; | 68 base::string16 output; |
| 68 EXPECT_TRUE(data2.HasString()); | 69 EXPECT_TRUE(data2.HasString()); |
| 69 EXPECT_TRUE(data2.GetString(&output)); | 70 EXPECT_TRUE(data2.GetString(&output)); |
| 70 EXPECT_EQ(input, output); | 71 EXPECT_EQ(input, output); |
| 71 std::string url_spec = "http://www.goats.com/"; | 72 std::string url_spec = "http://www.goats.com/"; |
| 72 GURL url(url_spec); | 73 GURL url(url_spec); |
| 73 base::string16 title; | 74 base::string16 title; |
| 74 EXPECT_FALSE(data2.GetURLAndTitle( | 75 EXPECT_FALSE(data2.GetURLAndTitle(OSExchangeData::DO_NOT_CONVERT_FILENAMES, |
| 75 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &title)); | 76 &url, &title)); |
| 76 // No URLs in |data|, so url should be untouched. | 77 // No URLs in |data|, so url should be untouched. |
| 77 EXPECT_EQ(url_spec, url.spec()); | 78 EXPECT_EQ(url_spec, url.spec()); |
| 78 } | 79 } |
| 79 | 80 |
| 80 TEST_F(OSExchangeDataProviderMusTest, TestURLExchangeFormats) { | 81 TEST_F(OSExchangeDataProviderMusTest, TestURLExchangeFormats) { |
| 81 OSExchangeData data; | 82 OSExchangeData data; |
| 82 std::string url_spec = "http://www.google.com/"; | 83 std::string url_spec = "http://www.google.com/"; |
| 83 GURL url(url_spec); | 84 GURL url(url_spec); |
| 84 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); | 85 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); |
| 85 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 86 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 86 data.SetURL(url, url_title); | 87 data.SetURL(url, url_title); |
| 87 EXPECT_TRUE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 88 EXPECT_TRUE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 88 | 89 |
| 89 OSExchangeData data2( | 90 OSExchangeData data2( |
| 90 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); | 91 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); |
| 91 | 92 |
| 92 // URL spec and title should match | 93 // URL spec and title should match |
| 93 GURL output_url; | 94 GURL output_url; |
| 94 base::string16 output_title; | 95 base::string16 output_title; |
| 95 EXPECT_TRUE(data2.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 96 EXPECT_TRUE(data2.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 96 EXPECT_TRUE(data2.GetURLAndTitle( | 97 EXPECT_TRUE(data2.GetURLAndTitle(OSExchangeData::DO_NOT_CONVERT_FILENAMES, |
| 97 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &output_url, &output_title)); | 98 &output_url, &output_title)); |
| 98 EXPECT_EQ(url_spec, output_url.spec()); | 99 EXPECT_EQ(url_spec, output_url.spec()); |
| 99 EXPECT_EQ(url_title, output_title); | 100 EXPECT_EQ(url_title, output_title); |
| 100 base::string16 output_string; | 101 base::string16 output_string; |
| 101 | 102 |
| 102 // URL should be the raw text response | 103 // URL should be the raw text response |
| 103 EXPECT_TRUE(data2.GetString(&output_string)); | 104 EXPECT_TRUE(data2.GetString(&output_string)); |
| 104 EXPECT_EQ(url_spec, base::UTF16ToUTF8(output_string)); | 105 EXPECT_EQ(url_spec, base::UTF16ToUTF8(output_string)); |
| 105 } | 106 } |
| 106 | 107 |
| 107 // Test that setting the URL does not overwrite a previously set custom string. | 108 // Test that setting the URL does not overwrite a previously set custom string. |
| 108 TEST_F(OSExchangeDataProviderMusTest, URLAndString) { | 109 TEST_F(OSExchangeDataProviderMusTest, URLAndString) { |
| 109 OSExchangeData data; | 110 OSExchangeData data; |
| 110 base::string16 string = base::ASCIIToUTF16("I can has cheezburger?"); | 111 base::string16 string = base::ASCIIToUTF16("I can has cheezburger?"); |
| 111 data.SetString(string); | 112 data.SetString(string); |
| 112 std::string url_spec = "http://www.google.com/"; | 113 std::string url_spec = "http://www.google.com/"; |
| 113 GURL url(url_spec); | 114 GURL url(url_spec); |
| 114 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); | 115 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); |
| 115 data.SetURL(url, url_title); | 116 data.SetURL(url, url_title); |
| 116 | 117 |
| 117 base::string16 output_string; | 118 base::string16 output_string; |
| 118 EXPECT_TRUE(data.GetString(&output_string)); | 119 EXPECT_TRUE(data.GetString(&output_string)); |
| 119 EXPECT_EQ(string, output_string); | 120 EXPECT_EQ(string, output_string); |
| 120 | 121 |
| 121 GURL output_url; | 122 GURL output_url; |
| 122 base::string16 output_title; | 123 base::string16 output_title; |
| 123 EXPECT_TRUE(data.GetURLAndTitle( | 124 EXPECT_TRUE(data.GetURLAndTitle(OSExchangeData::DO_NOT_CONVERT_FILENAMES, |
| 124 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &output_url, &output_title)); | 125 &output_url, &output_title)); |
| 125 EXPECT_EQ(url_spec, output_url.spec()); | 126 EXPECT_EQ(url_spec, output_url.spec()); |
| 126 EXPECT_EQ(url_title, output_title); | 127 EXPECT_EQ(url_title, output_title); |
| 127 } | 128 } |
| 128 | 129 |
| 129 TEST_F(OSExchangeDataProviderMusTest, TestFileToURLConversion) { | 130 TEST_F(OSExchangeDataProviderMusTest, TestFileToURLConversion) { |
| 130 OSExchangeData data; | 131 OSExchangeData data; |
| 131 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 132 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 132 EXPECT_FALSE(data.HasURL(OSExchangeData::CONVERT_FILENAMES)); | 133 EXPECT_FALSE(data.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
| 133 EXPECT_FALSE(data.HasFile()); | 134 EXPECT_FALSE(data.HasFile()); |
| 134 | 135 |
| 135 base::FilePath current_directory; | 136 base::FilePath current_directory; |
| 136 ASSERT_TRUE(base::GetCurrentDirectory(¤t_directory)); | 137 ASSERT_TRUE(base::GetCurrentDirectory(¤t_directory)); |
| 137 | 138 |
| 138 data.SetFilename(current_directory); | 139 data.SetFilename(current_directory); |
| 139 | 140 |
| 140 { | 141 { |
| 141 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 142 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 142 GURL actual_url; | 143 GURL actual_url; |
| 143 base::string16 actual_title; | 144 base::string16 actual_title; |
| 144 EXPECT_FALSE(data.GetURLAndTitle( | 145 EXPECT_FALSE(data.GetURLAndTitle(OSExchangeData::DO_NOT_CONVERT_FILENAMES, |
| 145 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title)); | 146 &actual_url, &actual_title)); |
| 146 EXPECT_EQ(GURL(), actual_url); | 147 EXPECT_EQ(GURL(), actual_url); |
| 147 EXPECT_EQ(base::string16(), actual_title); | 148 EXPECT_EQ(base::string16(), actual_title); |
| 148 } | 149 } |
| 149 | 150 |
| 150 { | 151 { |
| 151 EXPECT_TRUE(data.HasURL(OSExchangeData::CONVERT_FILENAMES)); | 152 EXPECT_TRUE(data.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
| 152 GURL actual_url; | 153 GURL actual_url; |
| 153 base::string16 actual_title; | 154 base::string16 actual_title; |
| 154 EXPECT_TRUE(data.GetURLAndTitle(OSExchangeData::CONVERT_FILENAMES, | 155 EXPECT_TRUE(data.GetURLAndTitle(OSExchangeData::CONVERT_FILENAMES, |
| 155 &actual_url, &actual_title)); | 156 &actual_url, &actual_title)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 data.SetHtml(html, url); | 201 data.SetHtml(html, url); |
| 201 | 202 |
| 202 OSExchangeData copy( | 203 OSExchangeData copy( |
| 203 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); | 204 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone())); |
| 204 base::string16 read_html; | 205 base::string16 read_html; |
| 205 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); | 206 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); |
| 206 EXPECT_EQ(html, read_html); | 207 EXPECT_EQ(html, read_html); |
| 207 } | 208 } |
| 208 #endif | 209 #endif |
| 209 | 210 |
| 210 } // namespace views | 211 } // namespace aura |
| 211 | |
| OLD | NEW |