1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "app/gtk_dnd_util.h"
8 #include "base/pickle.h"
9 #include "base/scoped_ptr.h"
10 #include "base/utf_string_conversions.h"
11 #include "googleurl/src/gurl.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(GtkDndUtilTest
, ExtractNamedURLValid
) {
15 const std::string kTitle
= "title";
16 const std::string kUrl
= "http://www.foobar.com/";
18 pickle
.WriteString(kTitle
);
19 pickle
.WriteString(kUrl
);
21 GtkSelectionData data
;
22 scoped_array
<guchar
> test_data(new guchar
[pickle
.size()]);
23 memcpy(test_data
.get(), pickle
.data(), pickle
.size());
24 data
.data
= test_data
.get();
25 data
.length
= pickle
.size();
29 ASSERT_EQ(true, gtk_dnd_util::ExtractNamedURL(&data
, &url
, &title
));
30 EXPECT_EQ(UTF8ToUTF16(kTitle
), title
);
31 EXPECT_EQ(GURL(kUrl
), url
);
34 TEST(GtkDndUtilTest
, ExtractNamedURLInvalidURL
) {
35 const std::string kTitle
= "title";
36 const std::string kBadUrl
= "foobar";
38 pickle
.WriteString(kTitle
);
39 pickle
.WriteString(kBadUrl
);
41 GtkSelectionData data
;
42 scoped_array
<guchar
> test_data(new guchar
[pickle
.size()]);
43 memcpy(test_data
.get(), pickle
.data(), pickle
.size());
44 data
.data
= test_data
.get();
45 data
.length
= pickle
.size();
49 EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data
, &url
, &title
));
52 TEST(GtkDndUtilTest
, ExtractNamedURLInvalidInput
) {
55 GtkSelectionData data
;
59 EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data
, &url
, &title
));
61 guchar empty_data
[] = "";
62 data
.data
= empty_data
;
65 EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data
, &url
, &title
));
67 const std::string kTitle
= "title";
69 pickle
.WriteString(kTitle
);
71 scoped_array
<guchar
> test_data(new guchar
[pickle
.size()]);
72 memcpy(test_data
.get(), pickle
.data(), pickle
.size());
73 data
.data
= test_data
.get();
74 data
.length
= pickle
.size();
76 EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data
, &url
, &title
));