Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: ui/base/dragdrop/os_exchange_data_unittest.cc

Issue 380553002: Add a unit test that filenames aren't unintentionally converted to URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/dragdrop/os_exchange_data_unittest.cc
diff --git a/ui/base/dragdrop/os_exchange_data_unittest.cc b/ui/base/dragdrop/os_exchange_data_unittest.cc
index 1440c85f489551f8459fc86a83f42fb01c04393c..39364bf4a73d4b330729e5f2f61356d9bc47ddfa 100644
--- a/ui/base/dragdrop/os_exchange_data_unittest.cc
+++ b/ui/base/dragdrop/os_exchange_data_unittest.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/pickle.h"
#include "base/strings/utf_string_conversions.h"
+#include "net/base/filename_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "ui/base/dragdrop/os_exchange_data.h"
@@ -38,8 +40,8 @@ TEST_F(OSExchangeDataTest, StringDataGetAndSet) {
std::string url_spec = "http://www.goats.com/";
GURL url(url_spec);
base::string16 title;
- EXPECT_FALSE(
- data2.GetURLAndTitle(OSExchangeData::CONVERT_FILENAMES, &url, &title));
+ EXPECT_FALSE(data2.GetURLAndTitle(
+ OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &title));
// No URLs in |data|, so url should be untouched.
EXPECT_EQ(url_spec, url.spec());
}
@@ -87,11 +89,55 @@ TEST_F(OSExchangeDataTest, URLAndString) {
GURL output_url;
base::string16 output_title;
EXPECT_TRUE(data.GetURLAndTitle(
- OSExchangeData::CONVERT_FILENAMES, &output_url, &output_title));
+ OSExchangeData::DO_NOT_CONVERT_FILENAMES, &output_url, &output_title));
EXPECT_EQ(url_spec, output_url.spec());
EXPECT_EQ(url_title, output_title);
}
+TEST_F(OSExchangeDataTest, TestFileToURLConversion) {
+ OSExchangeData data;
+ EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES));
+ EXPECT_FALSE(data.HasURL(OSExchangeData::CONVERT_FILENAMES));
+ EXPECT_FALSE(data.HasFile());
+
+ base::FilePath current_directory;
+ ASSERT_TRUE(base::GetCurrentDirectory(&current_directory));
+
+ data.SetFilename(current_directory);
+ {
+ EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES));
+ GURL actual_url;
+ base::string16 actual_title;
+ EXPECT_FALSE(data.GetURLAndTitle(
+ OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title));
+ EXPECT_EQ(GURL(), actual_url);
+ EXPECT_EQ(base::string16(), actual_title);
+ }
+ {
+// Filename to URL conversion is not implemented on ChromeOS.
+#if !defined(OS_CHROMEOS)
+ const bool expected_success = true;
+ const GURL expected_url(net::FilePathToFileURL(current_directory));
+#else
+ const bool expected_success = false;
+ const GURL expected_url;
+#endif
+ EXPECT_EQ(expected_success, data.HasURL(OSExchangeData::CONVERT_FILENAMES));
+ GURL actual_url;
+ base::string16 actual_title;
+ EXPECT_EQ(
+ expected_success,
+ data.GetURLAndTitle(
+ OSExchangeData::CONVERT_FILENAMES, &actual_url, &actual_title));
+ EXPECT_EQ(expected_url, actual_url);
+ EXPECT_EQ(base::string16(), actual_title);
+ }
+ EXPECT_TRUE(data.HasFile());
+ base::FilePath actual_path;
+ EXPECT_TRUE(data.GetFilename(&actual_path));
+ EXPECT_EQ(current_directory, actual_path);
+}
+
TEST_F(OSExchangeDataTest, TestPickledData) {
const OSExchangeData::CustomFormat kTestFormat =
ui::Clipboard::GetFormatType("application/vnd.chromium.test");
« no previous file with comments | « ui/base/dragdrop/os_exchange_data_provider_win.cc ('k') | ui/base/dragdrop/os_exchange_data_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698