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

Side by Side Diff: ui/base/dragdrop/os_exchange_data_provider_aurax11_unittest.cc

Issue 129113004: linux_aura: Implement file drag and drop in content area. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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
« no previous file with comments | « ui/base/dragdrop/os_exchange_data_provider_aurax11.cc ('k') | ui/base/x/selection_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" 5 #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h"
6 6
7 // Clean up X11 header polution 7 // Clean up X11 header polution
8 #undef None 8 #undef None
9 #undef Bool 9 #undef Bool
10 10
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "url/gurl.h" 15 #include "url/gurl.h"
16 16
17 const char kFileURL[] = "file:///home/user/file.txt";
18 const char kFileName[] = "/home/user/file.txt";
17 const char kGoogleTitle[] = "Google"; 19 const char kGoogleTitle[] = "Google";
18 const char kGoogleURL[] = "http://www.google.com/"; 20 const char kGoogleURL[] = "http://www.google.com/";
19 21
20 TEST(OSExchangeDataProviderAuraX11Test, MozillaURL) { 22 namespace ui {
23
24 class OSExchangeDataProviderAuraX11Test : public testing::Test {
25 public:
26 OSExchangeDataProviderAuraX11Test() {}
27
28 void AddURLList(const std::string& list_contents) {
29 std::string contents_copy = list_contents;
30 scoped_refptr<base::RefCountedMemory> mem(
31 base::RefCountedString::TakeString(&contents_copy));
32
33 provider.format_map_.Insert(
34 provider.atom_cache_.GetAtom(ui::Clipboard::kMimeTypeURIList),
35 mem);
36 }
37
38 protected:
21 base::MessageLoopForUI message_loop; 39 base::MessageLoopForUI message_loop;
22 ui::OSExchangeDataProviderAuraX11 provider; 40 ui::OSExchangeDataProviderAuraX11 provider;
41 };
23 42
43 TEST_F(OSExchangeDataProviderAuraX11Test, MozillaURL) {
24 // Check that we can get titled entries. 44 // Check that we can get titled entries.
25 provider.SetURL(GURL(kGoogleURL), base::ASCIIToUTF16(kGoogleTitle)); 45 provider.SetURL(GURL(kGoogleURL), base::ASCIIToUTF16(kGoogleTitle));
26 { 46 {
27 GURL out_gurl; 47 GURL out_gurl;
28 base::string16 out_str; 48 base::string16 out_str;
29 EXPECT_TRUE(provider.GetURLAndTitle(&out_gurl, &out_str)); 49 EXPECT_TRUE(provider.GetURLAndTitle(&out_gurl, &out_str));
30 EXPECT_EQ(base::ASCIIToUTF16(kGoogleTitle), out_str); 50 EXPECT_EQ(base::ASCIIToUTF16(kGoogleTitle), out_str);
31 EXPECT_EQ(kGoogleURL, out_gurl.spec()); 51 EXPECT_EQ(kGoogleURL, out_gurl.spec());
32 } 52 }
33 53
34 // Check that we can get non-titled entries. 54 // Check that we can get non-titled entries.
35 provider.SetURL(GURL(kGoogleURL), base::string16()); 55 provider.SetURL(GURL(kGoogleURL), base::string16());
36 { 56 {
37 GURL out_gurl; 57 GURL out_gurl;
38 base::string16 out_str; 58 base::string16 out_str;
39 EXPECT_TRUE(provider.GetURLAndTitle(&out_gurl, &out_str)); 59 EXPECT_TRUE(provider.GetURLAndTitle(&out_gurl, &out_str));
40 EXPECT_EQ(base::string16(), out_str); 60 EXPECT_EQ(base::string16(), out_str);
41 EXPECT_EQ(kGoogleURL, out_gurl.spec()); 61 EXPECT_EQ(kGoogleURL, out_gurl.spec());
42 } 62 }
43 } 63 }
64
65 TEST_F(OSExchangeDataProviderAuraX11Test, FilesArentURLs) {
66 AddURLList(kFileURL);
67
68 EXPECT_TRUE(provider.HasFile());
69 EXPECT_FALSE(provider.HasURL());
70 }
71
72 TEST_F(OSExchangeDataProviderAuraX11Test, HTTPURLsArentFiles) {
73 AddURLList(kGoogleURL);
74
75 EXPECT_FALSE(provider.HasFile());
76 EXPECT_TRUE(provider.HasURL());
77 }
78
79 TEST_F(OSExchangeDataProviderAuraX11Test, URIListWithBoth) {
80 AddURLList("file:///home/user/file.txt\nhttp://www.google.com");
81
82 EXPECT_TRUE(provider.HasFile());
83 EXPECT_TRUE(provider.HasURL());
84
85 // We should only receive the file from GetFilenames().
86 std::vector<OSExchangeData::FileInfo> filenames;
87 EXPECT_TRUE(provider.GetFilenames(&filenames));
88 ASSERT_EQ(1u, filenames.size());
89 EXPECT_EQ(kFileName, filenames[0].path.value());
90
91 // We should only receive the URL here.
92 GURL out_gurl;
93 base::string16 out_str;
94 EXPECT_TRUE(provider.GetURLAndTitle(&out_gurl, &out_str));
95 EXPECT_EQ(base::string16(), out_str);
96 EXPECT_EQ(kGoogleURL, out_gurl.spec());
97 }
98
99 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/dragdrop/os_exchange_data_provider_aurax11.cc ('k') | ui/base/x/selection_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698