summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-08 19:20:54 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-08 19:20:54 +0000
commite771a5c216106b31c84b4adf2a711ce5d6d5cc0f (patch)
tree7fb1ed2cc12644e933127f5ca1fc1bacf124f749 /app
parentbac0e4cbbfa119381a1bb0a74c123001baf30581 (diff)
downloadchromium_src-e771a5c216106b31c84b4adf2a711ce5d6d5cc0f.zip
chromium_src-e771a5c216106b31c84b4adf2a711ce5d6d5cc0f.tar.gz
chromium_src-e771a5c216106b31c84b4adf2a711ce5d6d5cc0f.tar.bz2
Linux: improve format of text/html copy paste data.
BUG=28888 TEST=works to paste html into firefox/thunderbird Review URL: http://codereview.chromium.org/465081 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34070 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/clipboard/clipboard_linux.cc14
-rw-r--r--app/clipboard/clipboard_unittest.cc19
2 files changed, 26 insertions, 7 deletions
diff --git a/app/clipboard/clipboard_linux.cc b/app/clipboard/clipboard_linux.cc
index dba93f0..eb05331 100644
--- a/app/clipboard/clipboard_linux.cc
+++ b/app/clipboard/clipboard_linux.cc
@@ -166,11 +166,17 @@ void Clipboard::WriteHTML(const char* markup_data,
size_t markup_len,
const char* url_data,
size_t url_len) {
- // TODO(estade): might not want to ignore |url_data|
- char* data = new char[markup_len];
- memcpy(data, markup_data, markup_len);
+ // TODO(estade): We need to expand relative links with |url_data|.
+ static const char* html_prefix = "<meta http-equiv=\"content-type\" "
+ "content=\"text/html; charset=utf-8\">";
+ int html_prefix_len = strlen(html_prefix);
+ int total_len = html_prefix_len + markup_len;
- InsertMapping(kMimeHtml, data, markup_len);
+ char* data = new char[total_len];
+ snprintf(data, total_len, "%s", html_prefix);
+ memcpy(data + html_prefix_len, markup_data, markup_len);
+
+ InsertMapping(kMimeHtml, data, total_len);
}
// Write an extra flavor that signifies WebKit was the last to modify the
diff --git a/app/clipboard/clipboard_unittest.cc b/app/clipboard/clipboard_unittest.cc
index 84cc69c..6f19d97 100644
--- a/app/clipboard/clipboard_unittest.cc
+++ b/app/clipboard/clipboard_unittest.cc
@@ -30,6 +30,19 @@ class ClipboardTest : public PlatformTest {
typedef PlatformTest ClipboardTest;
#endif // defined(OS_WIN)
+namespace {
+
+bool ClipboardContentsIsExpected(const string16& copied_markup,
+ const string16& pasted_markup) {
+#if defined(OS_LINUX)
+ return pasted_markup.find(copied_markup) != string16::npos;
+#else
+ return copied_markup == pasted_markup;
+#endif
+}
+
+} // namespace
+
TEST_F(ClipboardTest, ClearTest) {
Clipboard clipboard;
@@ -85,7 +98,7 @@ TEST_F(ClipboardTest, HTMLTest) {
EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
Clipboard::BUFFER_STANDARD));
clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result);
- EXPECT_EQ(markup, markup_result);
+ EXPECT_TRUE(ClipboardContentsIsExpected(markup, markup_result));
#if defined(OS_WIN)
// TODO(playmobil): It's not clear that non windows clipboards need to support
// this.
@@ -108,7 +121,7 @@ TEST_F(ClipboardTest, TrickyHTMLTest) {
EXPECT_TRUE(clipboard.IsFormatAvailable(Clipboard::GetHtmlFormatType(),
Clipboard::BUFFER_STANDARD));
clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result);
- EXPECT_EQ(markup, markup_result);
+ EXPECT_TRUE(ClipboardContentsIsExpected(markup, markup_result));
#if defined(OS_WIN)
// TODO(playmobil): It's not clear that non windows clipboards need to support
// this.
@@ -158,7 +171,7 @@ TEST_F(ClipboardTest, MultiFormatTest) {
EXPECT_TRUE(clipboard.IsFormatAvailable(
Clipboard::GetPlainTextFormatType(), Clipboard::BUFFER_STANDARD));
clipboard.ReadHTML(Clipboard::BUFFER_STANDARD, &markup_result, &url_result);
- EXPECT_EQ(markup, markup_result);
+ EXPECT_TRUE(ClipboardContentsIsExpected(markup, markup_result));
#if defined(OS_WIN)
// TODO(playmobil): It's not clear that non windows clipboards need to support
// this.