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/file_util.h" |
5 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
6 #include "base/pickle.h" | 7 #include "base/pickle.h" |
7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "net/base/filename_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "testing/platform_test.h" | 11 #include "testing/platform_test.h" |
10 #include "ui/base/dragdrop/os_exchange_data.h" | 12 #include "ui/base/dragdrop/os_exchange_data.h" |
11 #include "ui/events/platform/platform_event_source.h" | 13 #include "ui/events/platform/platform_event_source.h" |
12 #include "url/gurl.h" | 14 #include "url/gurl.h" |
13 | 15 |
14 namespace ui { | 16 namespace ui { |
15 | 17 |
16 class OSExchangeDataTest : public PlatformTest { | 18 class OSExchangeDataTest : public PlatformTest { |
17 public: | 19 public: |
(...skipping 13 matching lines...) Expand all Loading... |
31 EXPECT_TRUE(data.HasString()); | 33 EXPECT_TRUE(data.HasString()); |
32 | 34 |
33 OSExchangeData data2(data.provider().Clone()); | 35 OSExchangeData data2(data.provider().Clone()); |
34 base::string16 output; | 36 base::string16 output; |
35 EXPECT_TRUE(data2.HasString()); | 37 EXPECT_TRUE(data2.HasString()); |
36 EXPECT_TRUE(data2.GetString(&output)); | 38 EXPECT_TRUE(data2.GetString(&output)); |
37 EXPECT_EQ(input, output); | 39 EXPECT_EQ(input, output); |
38 std::string url_spec = "http://www.goats.com/"; | 40 std::string url_spec = "http://www.goats.com/"; |
39 GURL url(url_spec); | 41 GURL url(url_spec); |
40 base::string16 title; | 42 base::string16 title; |
41 EXPECT_FALSE( | 43 EXPECT_FALSE(data2.GetURLAndTitle( |
42 data2.GetURLAndTitle(OSExchangeData::CONVERT_FILENAMES, &url, &title)); | 44 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &title)); |
43 // No URLs in |data|, so url should be untouched. | 45 // No URLs in |data|, so url should be untouched. |
44 EXPECT_EQ(url_spec, url.spec()); | 46 EXPECT_EQ(url_spec, url.spec()); |
45 } | 47 } |
46 | 48 |
47 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { | 49 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { |
48 OSExchangeData data; | 50 OSExchangeData data; |
49 std::string url_spec = "http://www.google.com/"; | 51 std::string url_spec = "http://www.google.com/"; |
50 GURL url(url_spec); | 52 GURL url(url_spec); |
51 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); | 53 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); |
52 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 54 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
(...skipping 27 matching lines...) Expand all Loading... |
80 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); | 82 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); |
81 data.SetURL(url, url_title); | 83 data.SetURL(url, url_title); |
82 | 84 |
83 base::string16 output_string; | 85 base::string16 output_string; |
84 EXPECT_TRUE(data.GetString(&output_string)); | 86 EXPECT_TRUE(data.GetString(&output_string)); |
85 EXPECT_EQ(string, output_string); | 87 EXPECT_EQ(string, output_string); |
86 | 88 |
87 GURL output_url; | 89 GURL output_url; |
88 base::string16 output_title; | 90 base::string16 output_title; |
89 EXPECT_TRUE(data.GetURLAndTitle( | 91 EXPECT_TRUE(data.GetURLAndTitle( |
90 OSExchangeData::CONVERT_FILENAMES, &output_url, &output_title)); | 92 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &output_url, &output_title)); |
91 EXPECT_EQ(url_spec, output_url.spec()); | 93 EXPECT_EQ(url_spec, output_url.spec()); |
92 EXPECT_EQ(url_title, output_title); | 94 EXPECT_EQ(url_title, output_title); |
93 } | 95 } |
94 | 96 |
| 97 TEST_F(OSExchangeDataTest, TestFileToURLConversion) { |
| 98 OSExchangeData data; |
| 99 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 100 EXPECT_FALSE(data.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
| 101 EXPECT_FALSE(data.HasFile()); |
| 102 |
| 103 base::FilePath current_directory; |
| 104 ASSERT_TRUE(base::GetCurrentDirectory(¤t_directory)); |
| 105 |
| 106 data.SetFilename(current_directory); |
| 107 { |
| 108 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 109 GURL actual_url; |
| 110 base::string16 actual_title; |
| 111 EXPECT_FALSE(data.GetURLAndTitle( |
| 112 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title)); |
| 113 EXPECT_EQ(GURL(), actual_url); |
| 114 EXPECT_EQ(base::string16(), actual_title); |
| 115 } |
| 116 { |
| 117 // Filename to URL conversion is not implemented on ChromeOS. |
| 118 #if !defined(OS_CHROMEOS) |
| 119 const bool expected_success = true; |
| 120 const GURL expected_url(net::FilePathToFileURL(current_directory)); |
| 121 #else |
| 122 const bool expected_success = false; |
| 123 const GURL expected_url; |
| 124 #endif |
| 125 EXPECT_EQ(expected_success, data.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
| 126 GURL actual_url; |
| 127 base::string16 actual_title; |
| 128 EXPECT_EQ( |
| 129 expected_success, |
| 130 data.GetURLAndTitle( |
| 131 OSExchangeData::CONVERT_FILENAMES, &actual_url, &actual_title)); |
| 132 EXPECT_EQ(expected_url, actual_url); |
| 133 EXPECT_EQ(base::string16(), actual_title); |
| 134 } |
| 135 EXPECT_TRUE(data.HasFile()); |
| 136 base::FilePath actual_path; |
| 137 EXPECT_TRUE(data.GetFilename(&actual_path)); |
| 138 EXPECT_EQ(current_directory, actual_path); |
| 139 } |
| 140 |
95 TEST_F(OSExchangeDataTest, TestPickledData) { | 141 TEST_F(OSExchangeDataTest, TestPickledData) { |
96 const OSExchangeData::CustomFormat kTestFormat = | 142 const OSExchangeData::CustomFormat kTestFormat = |
97 ui::Clipboard::GetFormatType("application/vnd.chromium.test"); | 143 ui::Clipboard::GetFormatType("application/vnd.chromium.test"); |
98 | 144 |
99 Pickle saved_pickle; | 145 Pickle saved_pickle; |
100 saved_pickle.WriteInt(1); | 146 saved_pickle.WriteInt(1); |
101 saved_pickle.WriteInt(2); | 147 saved_pickle.WriteInt(2); |
102 OSExchangeData data; | 148 OSExchangeData data; |
103 data.SetPickledData(kTestFormat, saved_pickle); | 149 data.SetPickledData(kTestFormat, saved_pickle); |
104 | 150 |
(...skipping 21 matching lines...) Expand all Loading... |
126 data.SetHtml(html, url); | 172 data.SetHtml(html, url); |
127 | 173 |
128 OSExchangeData copy(data.provider().Clone()); | 174 OSExchangeData copy(data.provider().Clone()); |
129 base::string16 read_html; | 175 base::string16 read_html; |
130 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); | 176 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); |
131 EXPECT_EQ(html, read_html); | 177 EXPECT_EQ(html, read_html); |
132 } | 178 } |
133 #endif | 179 #endif |
134 | 180 |
135 } // namespace ui | 181 } // namespace ui |
OLD | NEW |