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

Side by Side 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: Fix Windows 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10 matching lines...) Expand all
28 base::string16 input = base::ASCIIToUTF16("I can has cheezburger?"); 30 base::string16 input = base::ASCIIToUTF16("I can has cheezburger?");
29 data.SetString(input); 31 data.SetString(input);
30 32
31 OSExchangeData data2(data.provider().Clone()); 33 OSExchangeData data2(data.provider().Clone());
32 base::string16 output; 34 base::string16 output;
33 EXPECT_TRUE(data2.GetString(&output)); 35 EXPECT_TRUE(data2.GetString(&output));
34 EXPECT_EQ(input, output); 36 EXPECT_EQ(input, output);
35 std::string url_spec = "http://www.goats.com/"; 37 std::string url_spec = "http://www.goats.com/";
36 GURL url(url_spec); 38 GURL url(url_spec);
37 base::string16 title; 39 base::string16 title;
38 EXPECT_FALSE( 40 EXPECT_FALSE(data2.GetURLAndTitle(
39 data2.GetURLAndTitle(OSExchangeData::CONVERT_FILENAMES, &url, &title)); 41 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &title));
40 // No URLs in |data|, so url should be untouched. 42 // No URLs in |data|, so url should be untouched.
41 EXPECT_EQ(url_spec, url.spec()); 43 EXPECT_EQ(url_spec, url.spec());
42 } 44 }
43 45
44 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { 46 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) {
45 OSExchangeData data; 47 OSExchangeData data;
46 std::string url_spec = "http://www.google.com/"; 48 std::string url_spec = "http://www.google.com/";
47 GURL url(url_spec); 49 GURL url(url_spec);
48 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); 50 base::string16 url_title = base::ASCIIToUTF16("www.google.com");
49 data.SetURL(url, url_title); 51 data.SetURL(url, url_title);
50 base::string16 output; 52 base::string16 output;
51 53
52 OSExchangeData data2(data.provider().Clone()); 54 OSExchangeData data2(data.provider().Clone());
53 55
54 // URL spec and title should match 56 // URL spec and title should match
55 GURL output_url; 57 GURL output_url;
56 base::string16 output_title; 58 base::string16 output_title;
57 EXPECT_TRUE(data2.GetURLAndTitle( 59 EXPECT_TRUE(data2.GetURLAndTitle(
58 OSExchangeData::CONVERT_FILENAMES, &output_url, &output_title)); 60 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &output_url, &output_title));
59 EXPECT_EQ(url_spec, output_url.spec()); 61 EXPECT_EQ(url_spec, output_url.spec());
60 EXPECT_EQ(url_title, output_title); 62 EXPECT_EQ(url_title, output_title);
61 base::string16 output_string; 63 base::string16 output_string;
62 64
63 // URL should be the raw text response 65 // URL should be the raw text response
64 EXPECT_TRUE(data2.GetString(&output_string)); 66 EXPECT_TRUE(data2.GetString(&output_string));
65 EXPECT_EQ(url_spec, base::UTF16ToUTF8(output_string)); 67 EXPECT_EQ(url_spec, base::UTF16ToUTF8(output_string));
66 } 68 }
67 69
70 TEST_F(OSExchangeDataTest, TestFileToURLConversion) {
71 OSExchangeData data;
72 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES));
73 EXPECT_FALSE(data.HasURL(OSExchangeData::CONVERT_FILENAMES));
74 EXPECT_FALSE(data.HasFile());
75
76 base::FilePath current_directory;
77 ASSERT_TRUE(base::GetCurrentDirectory(&current_directory));
78
79 data.SetFilename(current_directory);
80 {
81 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES));
82 GURL actual_url;
83 base::string16 actual_title;
84 EXPECT_FALSE(data.GetURLAndTitle(
85 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &actual_url, &actual_title));
86 EXPECT_EQ(GURL(), actual_url);
87 EXPECT_EQ(base::string16(), actual_title);
88 }
89 {
90 // Filename to URL conversion is not implemented on ChromeOS.
91 #if !defined(OS_CHROMEOS)
92 const bool expected_success = true;
93 const GURL expected_url(net::FilePathToFileURL(current_directory));
94 #else
95 const bool expected_success = false;
96 const GURL expected_url;
97 #endif
98 EXPECT_EQ(expected_success, data.HasURL(OSExchangeData::CONVERT_FILENAMES));
99 GURL actual_url;
100 base::string16 actual_title;
101 EXPECT_EQ(
102 expected_success,
103 data.GetURLAndTitle(
104 OSExchangeData::CONVERT_FILENAMES, &actual_url, &actual_title));
105 EXPECT_EQ(expected_url, actual_url);
106 EXPECT_EQ(base::string16(), actual_title);
107 }
108 EXPECT_TRUE(data.HasFile());
109 base::FilePath actual_path;
110 EXPECT_TRUE(data.GetFilename(&actual_path));
111 EXPECT_EQ(current_directory, actual_path);
112 }
113
68 TEST_F(OSExchangeDataTest, TestPickledData) { 114 TEST_F(OSExchangeDataTest, TestPickledData) {
69 const OSExchangeData::CustomFormat kTestFormat = 115 const OSExchangeData::CustomFormat kTestFormat =
70 ui::Clipboard::GetFormatType("application/vnd.chromium.test"); 116 ui::Clipboard::GetFormatType("application/vnd.chromium.test");
71 117
72 Pickle saved_pickle; 118 Pickle saved_pickle;
73 saved_pickle.WriteInt(1); 119 saved_pickle.WriteInt(1);
74 saved_pickle.WriteInt(2); 120 saved_pickle.WriteInt(2);
75 OSExchangeData data; 121 OSExchangeData data;
76 data.SetPickledData(kTestFormat, saved_pickle); 122 data.SetPickledData(kTestFormat, saved_pickle);
77 123
(...skipping 21 matching lines...) Expand all
99 data.SetHtml(html, url); 145 data.SetHtml(html, url);
100 146
101 OSExchangeData copy(data.provider().Clone()); 147 OSExchangeData copy(data.provider().Clone());
102 base::string16 read_html; 148 base::string16 read_html;
103 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); 149 EXPECT_TRUE(copy.GetHtml(&read_html, &url));
104 EXPECT_EQ(html, read_html); 150 EXPECT_EQ(html, read_html);
105 } 151 }
106 #endif 152 #endif
107 153
108 } // namespace ui 154 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698