1 // Copyright (c) 2011 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.
5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/dragdrop/gtk_dnd_util.h"
15 TEST(BookmarkUtilsGtkTest
, GetNodesFromSelectionInvalid
) {
16 std::vector
<const BookmarkNode
*> nodes
;
17 nodes
= GetNodesFromSelection(NULL
, NULL
, 0, NULL
, NULL
, NULL
);
18 EXPECT_EQ(0u, nodes
.size());
20 GtkSelectionData data
;
23 nodes
= GetNodesFromSelection(NULL
, &data
, 0, NULL
, NULL
, NULL
);
24 EXPECT_EQ(0u, nodes
.size());
26 nodes
= GetNodesFromSelection(
27 NULL
, NULL
, ui::CHROME_BOOKMARK_ITEM
, NULL
, NULL
, NULL
);
28 EXPECT_EQ(0u, nodes
.size());
32 nodes
= GetNodesFromSelection(
33 NULL
, &data
, ui::CHROME_BOOKMARK_ITEM
, NULL
, NULL
, NULL
);
34 EXPECT_EQ(0u, nodes
.size());
36 guchar test_data
[] = "";
37 data
.data
= test_data
;
39 nodes
= GetNodesFromSelection(
40 NULL
, &data
, ui::CHROME_BOOKMARK_ITEM
, NULL
, NULL
, NULL
);
41 EXPECT_EQ(0u, nodes
.size());
44 TEST(BookmarkUtilsGtkTest
, WriteBookmarkToSelectionHTML
) {
45 BookmarkNode
x(GURL("http://www.google.com"));
46 x
.SetTitle(base::string16(base::ASCIIToUTF16("Google")));
47 GtkSelectionData data
;
50 WriteBookmarkToSelection(&x
, &data
, ui::TEXT_HTML
, NULL
);
51 std::string
selection(reinterpret_cast<char*>(data
.data
), data
.length
);
52 EXPECT_EQ("<a href=\"http://www.google.com/\">Google</a>", selection
);
54 // Free the copied data in GtkSelectionData
55 gtk_selection_data_set(&data
, data
.type
, data
.format
, NULL
, -1);