| 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 |
| 107 { | 108 { |
| 108 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); | 109 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); |
| 109 GURL actual_url; | 110 GURL actual_url; |
| 110 base::string16 actual_title; | 111 base::string16 actual_title; |
| 111 EXPECT_FALSE(data.GetURLAndTitle( | 112 EXPECT_FALSE(data.GetURLAndTitle( |
| 112 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title)); | 113 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title)); |
| 113 EXPECT_EQ(GURL(), actual_url); | 114 EXPECT_EQ(GURL(), actual_url); |
| 114 EXPECT_EQ(base::string16(), actual_title); | 115 EXPECT_EQ(base::string16(), actual_title); |
| 115 } | 116 } |
| 117 |
| 116 { | 118 { |
| 117 // Filename to URL conversion is not implemented on ChromeOS or on non-X11 Linux | 119 // Filename to URL conversion is not implemented on ChromeOS or on non-X11 Linux |
| 118 // builds. | 120 // builds. |
| 119 #if defined(OS_CHROMEOS) || (defined(OS_LINUX) && !defined(USE_X11)) | 121 #if defined(OS_CHROMEOS) || (defined(OS_LINUX) && !defined(USE_X11)) |
| 120 const bool expected_success = false; | 122 const bool expected_success = false; |
| 121 const GURL expected_url; | 123 const GURL expected_url; |
| 122 #else | 124 #else |
| 123 const bool expected_success = true; | 125 const bool expected_success = true; |
| 124 const GURL expected_url(net::FilePathToFileURL(current_directory)); | 126 const GURL expected_url(net::FilePathToFileURL(current_directory)); |
| 125 #endif | 127 #endif |
| 126 EXPECT_EQ(expected_success, data.HasURL(OSExchangeData::CONVERT_FILENAMES)); | 128 EXPECT_EQ(expected_success, data.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
| 127 GURL actual_url; | 129 GURL actual_url; |
| 128 base::string16 actual_title; | 130 base::string16 actual_title; |
| 129 EXPECT_EQ( | 131 EXPECT_EQ( |
| 130 expected_success, | 132 expected_success, |
| 131 data.GetURLAndTitle( | 133 data.GetURLAndTitle( |
| 132 OSExchangeData::CONVERT_FILENAMES, &actual_url, &actual_title)); | 134 OSExchangeData::CONVERT_FILENAMES, &actual_url, &actual_title)); |
| 133 EXPECT_EQ(expected_url, actual_url); | 135 // Some Mac OS versions return the URL in file://localhost form instead |
| 136 // of file:///, so we compare the url's path not its absolute string. |
| 137 EXPECT_EQ(expected_url.path(), actual_url.path()); |
| 134 EXPECT_EQ(base::string16(), actual_title); | 138 EXPECT_EQ(base::string16(), actual_title); |
| 135 } | 139 } |
| 136 EXPECT_TRUE(data.HasFile()); | 140 EXPECT_TRUE(data.HasFile()); |
| 137 base::FilePath actual_path; | 141 base::FilePath actual_path; |
| 138 EXPECT_TRUE(data.GetFilename(&actual_path)); | 142 EXPECT_TRUE(data.GetFilename(&actual_path)); |
| 139 EXPECT_EQ(current_directory, actual_path); | 143 EXPECT_EQ(current_directory, actual_path); |
| 140 } | 144 } |
| 141 | 145 |
| 142 TEST_F(OSExchangeDataTest, TestPickledData) { | 146 TEST_F(OSExchangeDataTest, TestPickledData) { |
| 143 const OSExchangeData::CustomFormat kTestFormat = | 147 const OSExchangeData::CustomFormat kTestFormat = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 173 data.SetHtml(html, url); | 177 data.SetHtml(html, url); |
| 174 | 178 |
| 175 OSExchangeData copy(data.provider().Clone()); | 179 OSExchangeData copy(data.provider().Clone()); |
| 176 base::string16 read_html; | 180 base::string16 read_html; |
| 177 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); | 181 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); |
| 178 EXPECT_EQ(html, read_html); | 182 EXPECT_EQ(html, read_html); |
| 179 } | 183 } |
| 180 #endif | 184 #endif |
| 181 | 185 |
| 182 } // namespace ui | 186 } // namespace ui |
| OLD | NEW |