1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h"
// Clean up X11 header polution
#undef None
#undef Bool
#include "base/message_loop/message_loop.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/dragdrop/file_info.h"
#include "ui/events/platform/x11/x11_event_source.h"
#include "url/gurl.h"
const char kFileURL[] = "file:///home/user/file.txt";
const char kFileName[] = "/home/user/file.txt";
const char kGoogleTitle[] = "Google";
const char kGoogleURL[] = "http://www.google.com/";
namespace ui {
class OSExchangeDataProviderAuraX11Test : public testing::Test {
public:
OSExchangeDataProviderAuraX11Test() : event_source(gfx::GetXDisplay()) {}
void AddURLList(const std::string& list_contents) {
std::string contents_copy = list_contents;
scoped_refptr<base::RefCountedMemory> mem(
base::RefCountedString::TakeString(&contents_copy));
provider.format_map_.Insert(
provider.atom_cache_.GetAtom(ui::Clipboard::kMimeTypeURIList),
mem);
}
protected:
base::MessageLoopForUI message_loop;
X11EventSource event_source;
ui::OSExchangeDataProviderAuraX11 provider;
};
TEST_F(OSExchangeDataProviderAuraX11Test, MozillaURL) {
// Check that we can get titled entries.
provider.SetURL(GURL(kGoogleURL), base::ASCIIToUTF16(kGoogleTitle));
{
GURL out_gurl;
base::string16 out_str;
EXPECT_TRUE(provider.GetURLAndTitle(
OSExchangeData::DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str));
EXPECT_EQ(base::ASCIIToUTF16(kGoogleTitle), out_str);
EXPECT_EQ(kGoogleURL, out_gurl.spec());
}
// Check that we can get non-titled entries.
provider.SetURL(GURL(kGoogleURL), base::string16());
{
GURL out_gurl;
base::string16 out_str;
EXPECT_TRUE(provider.GetURLAndTitle(
OSExchangeData::DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str));
EXPECT_EQ(base::string16(), out_str);
EXPECT_EQ(kGoogleURL, out_gurl.spec());
}
}
TEST_F(OSExchangeDataProviderAuraX11Test, FilesArentURLs) {
AddURLList(kFileURL);
EXPECT_TRUE(provider.HasFile());
EXPECT_TRUE(provider.HasURL(ui::OSExchangeData::CONVERT_FILENAMES));
EXPECT_FALSE(provider.HasURL(ui::OSExchangeData::DO_NOT_CONVERT_FILENAMES));
}
TEST_F(OSExchangeDataProviderAuraX11Test, HTTPURLsArentFiles) {
AddURLList(kGoogleURL);
EXPECT_FALSE(provider.HasFile());
EXPECT_TRUE(provider.HasURL(ui::OSExchangeData::CONVERT_FILENAMES));
EXPECT_TRUE(provider.HasURL(ui::OSExchangeData::DO_NOT_CONVERT_FILENAMES));
}
TEST_F(OSExchangeDataProviderAuraX11Test, URIListWithBoth) {
AddURLList("file:///home/user/file.txt\nhttp://www.google.com");
EXPECT_TRUE(provider.HasFile());
EXPECT_TRUE(provider.HasURL(ui::OSExchangeData::CONVERT_FILENAMES));
EXPECT_TRUE(provider.HasURL(ui::OSExchangeData::DO_NOT_CONVERT_FILENAMES));
// We should only receive the file from GetFilenames().
std::vector<FileInfo> filenames;
EXPECT_TRUE(provider.GetFilenames(&filenames));
ASSERT_EQ(1u, filenames.size());
EXPECT_EQ(kFileName, filenames[0].path.value());
// We should only receive the URL here.
GURL out_gurl;
base::string16 out_str;
EXPECT_TRUE(provider.GetURLAndTitle(
OSExchangeData::DO_NOT_CONVERT_FILENAMES, &out_gurl, &out_str));
EXPECT_EQ(base::string16(), out_str);
EXPECT_EQ(kGoogleURL, out_gurl.spec());
}
TEST_F(OSExchangeDataProviderAuraX11Test, OnlyStringURLIsUnfiltered) {
const base::string16 file_url = base::UTF8ToUTF16(kFileURL);
provider.SetString(file_url);
EXPECT_TRUE(provider.HasString());
EXPECT_FALSE(provider.HasURL(ui::OSExchangeData::DO_NOT_CONVERT_FILENAMES));
}
TEST_F(OSExchangeDataProviderAuraX11Test, StringAndURIListFilterString) {
const base::string16 file_url = base::UTF8ToUTF16(kFileURL);
provider.SetString(file_url);
AddURLList(kFileURL);
EXPECT_FALSE(provider.HasString());
base::string16 out_str;
EXPECT_FALSE(provider.GetString(&out_str));
EXPECT_TRUE(provider.HasFile());
}
} // namespace ui
|