Chromium Code Reviews| 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "net/base/filename_util.h" | 9 #include "net/base/filename_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 TEST_F(OSExchangeDataTest, TestFileToURLConversion) { | 97 TEST_F(OSExchangeDataTest, TestFileToURLConversion) { |
| 98 OSExchangeData data; | 98 OSExchangeData data; |
| 99 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 99 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 100 EXPECT_FALSE(data.HasURL(OSExchangeData::CONVERT_FILENAMES)); | 100 EXPECT_FALSE(data.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
| 101 EXPECT_FALSE(data.HasFile()); | 101 EXPECT_FALSE(data.HasFile()); |
| 102 | 102 |
| 103 base::FilePath current_directory; | 103 base::FilePath current_directory; |
| 104 ASSERT_TRUE(base::GetCurrentDirectory(¤t_directory)); | 104 ASSERT_TRUE(base::GetCurrentDirectory(¤t_directory)); |
| 105 | 105 |
| 106 data.SetFilename(current_directory); | 106 data.SetFilename(current_directory); |
| 107 | |
| 108 // NSPasteboard does not support not converting, writing NSFilenamesPboardType | |
|
dcheng
2014/09/10 00:22:54
We need to manually clear it in the code that read
Andre
2014/09/13 01:10:50
I couldn't find a way to clear the URL from the pa
| |
| 109 // will automatically populates URL types as well. | |
| 110 #if !defined(OS_MACOSX) | |
| 107 { | 111 { |
| 108 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 112 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 109 GURL actual_url; | 113 GURL actual_url; |
| 110 base::string16 actual_title; | 114 base::string16 actual_title; |
| 111 EXPECT_FALSE(data.GetURLAndTitle( | 115 EXPECT_FALSE(data.GetURLAndTitle( |
| 112 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title)); | 116 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title)); |
| 113 EXPECT_EQ(GURL(), actual_url); | 117 EXPECT_EQ(GURL(), actual_url); |
| 114 EXPECT_EQ(base::string16(), actual_title); | 118 EXPECT_EQ(base::string16(), actual_title); |
| 115 } | 119 } |
| 120 #endif | |
| 121 | |
| 116 { | 122 { |
| 117 // Filename to URL conversion is not implemented on ChromeOS or on non-X11 Linux | 123 // Filename to URL conversion is not implemented on ChromeOS or on non-X11 Linux |
| 118 // builds. | 124 // builds. |
| 119 #if defined(OS_CHROMEOS) || (defined(OS_LINUX) && !defined(USE_X11)) | 125 #if defined(OS_CHROMEOS) || (defined(OS_LINUX) && !defined(USE_X11)) |
| 120 const bool expected_success = false; | 126 const bool expected_success = false; |
| 121 const GURL expected_url; | 127 const GURL expected_url; |
| 122 #else | 128 #else |
| 123 const bool expected_success = true; | 129 const bool expected_success = true; |
| 124 const GURL expected_url(net::FilePathToFileURL(current_directory)); | 130 const GURL expected_url(net::FilePathToFileURL(current_directory)); |
| 125 #endif | 131 #endif |
| 126 EXPECT_EQ(expected_success, data.HasURL(OSExchangeData::CONVERT_FILENAMES)); | 132 EXPECT_EQ(expected_success, data.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
| 127 GURL actual_url; | 133 GURL actual_url; |
| 128 base::string16 actual_title; | 134 base::string16 actual_title; |
| 129 EXPECT_EQ( | 135 EXPECT_EQ( |
| 130 expected_success, | 136 expected_success, |
| 131 data.GetURLAndTitle( | 137 data.GetURLAndTitle( |
| 132 OSExchangeData::CONVERT_FILENAMES, &actual_url, &actual_title)); | 138 OSExchangeData::CONVERT_FILENAMES, &actual_url, &actual_title)); |
| 133 EXPECT_EQ(expected_url, actual_url); | 139 // Some Mac OS versions return the URL in file://localhost form instead |
| 140 // of file:///, so we compare the url's path not its absolute string. | |
| 141 EXPECT_EQ(expected_url.path(), actual_url.path()); | |
| 134 EXPECT_EQ(base::string16(), actual_title); | 142 EXPECT_EQ(base::string16(), actual_title); |
| 135 } | 143 } |
| 136 EXPECT_TRUE(data.HasFile()); | 144 EXPECT_TRUE(data.HasFile()); |
| 137 base::FilePath actual_path; | 145 base::FilePath actual_path; |
| 138 EXPECT_TRUE(data.GetFilename(&actual_path)); | 146 EXPECT_TRUE(data.GetFilename(&actual_path)); |
| 139 EXPECT_EQ(current_directory, actual_path); | 147 EXPECT_EQ(current_directory, actual_path); |
| 140 } | 148 } |
| 141 | 149 |
| 142 TEST_F(OSExchangeDataTest, TestPickledData) { | 150 TEST_F(OSExchangeDataTest, TestPickledData) { |
| 143 const OSExchangeData::CustomFormat kTestFormat = | 151 const OSExchangeData::CustomFormat kTestFormat = |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 173 data.SetHtml(html, url); | 181 data.SetHtml(html, url); |
| 174 | 182 |
| 175 OSExchangeData copy(data.provider().Clone()); | 183 OSExchangeData copy(data.provider().Clone()); |
| 176 base::string16 read_html; | 184 base::string16 read_html; |
| 177 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); | 185 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); |
| 178 EXPECT_EQ(html, read_html); | 186 EXPECT_EQ(html, read_html); |
| 179 } | 187 } |
| 180 #endif | 188 #endif |
| 181 | 189 |
| 182 } // namespace ui | 190 } // namespace ui |
| OLD | NEW |