summaryrefslogtreecommitdiffstats
path: root/app/gtk_dnd_util_unittest.cc
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 19:55:55 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-07 19:55:55 +0000
commit9274ead1c74ef0025072923f14aeaedd2598c0d6 (patch)
treebaf28919c2f144b9009b6ba8d4470707ad2da7b8 /app/gtk_dnd_util_unittest.cc
parent5c311356f75f014502b63f1afa79c5452a0cfa59 (diff)
downloadchromium_src-9274ead1c74ef0025072923f14aeaedd2598c0d6.zip
chromium_src-9274ead1c74ef0025072923f14aeaedd2598c0d6.tar.gz
chromium_src-9274ead1c74ef0025072923f14aeaedd2598c0d6.tar.bz2
gtk: Fix gtk_dnd_util::ExtractNamedURL to not crash on invalid data.
BUG=43347 TEST=included Review URL: http://codereview.chromium.org/2003006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46731 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/gtk_dnd_util_unittest.cc')
-rw-r--r--app/gtk_dnd_util_unittest.cc77
1 files changed, 77 insertions, 0 deletions
diff --git a/app/gtk_dnd_util_unittest.cc b/app/gtk_dnd_util_unittest.cc
new file mode 100644
index 0000000..1de8991
--- /dev/null
+++ b/app/gtk_dnd_util_unittest.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2010 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 <string>
+
+#include "app/gtk_dnd_util.h"
+#include "base/pickle.h"
+#include "base/scoped_ptr.h"
+#include "base/utf_string_conversions.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(GtkDndUtilTest, ExtractNamedURLValid) {
+ const std::string kTitle = "title";
+ const std::string kUrl = "http://www.foobar.com/";
+ Pickle pickle;
+ pickle.WriteString(kTitle);
+ pickle.WriteString(kUrl);
+
+ GtkSelectionData data;
+ scoped_array<guchar> test_data(new guchar[pickle.size()]);
+ memcpy(test_data.get(), pickle.data(), pickle.size());
+ data.data = test_data.get();
+ data.length = pickle.size();
+
+ GURL url;
+ string16 title;
+ ASSERT_EQ(true, gtk_dnd_util::ExtractNamedURL(&data, &url, &title));
+ EXPECT_EQ(UTF8ToUTF16(kTitle), title);
+ EXPECT_EQ(GURL(kUrl), url);
+}
+
+TEST(GtkDndUtilTest, ExtractNamedURLInvalidURL) {
+ const std::string kTitle = "title";
+ const std::string kBadUrl = "foobar";
+ Pickle pickle;
+ pickle.WriteString(kTitle);
+ pickle.WriteString(kBadUrl);
+
+ GtkSelectionData data;
+ scoped_array<guchar> test_data(new guchar[pickle.size()]);
+ memcpy(test_data.get(), pickle.data(), pickle.size());
+ data.data = test_data.get();
+ data.length = pickle.size();
+
+ GURL url;
+ string16 title;
+ EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data, &url, &title));
+}
+
+TEST(GtkDndUtilTest, ExtractNamedURLInvalidInput) {
+ GURL url;
+ string16 title;
+ GtkSelectionData data;
+ data.data = NULL;
+ data.length = 0;
+
+ EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data, &url, &title));
+
+ guchar empty_data[] = "";
+ data.data = empty_data;
+ data.length = 0;
+
+ EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data, &url, &title));
+
+ const std::string kTitle = "title";
+ Pickle pickle;
+ pickle.WriteString(kTitle);
+
+ scoped_array<guchar> test_data(new guchar[pickle.size()]);
+ memcpy(test_data.get(), pickle.data(), pickle.size());
+ data.data = test_data.get();
+ data.length = pickle.size();
+
+ EXPECT_EQ(false, gtk_dnd_util::ExtractNamedURL(&data, &url, &title));
+}