Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Unified Diff: ui/base/clipboard/clipboard_test_template.h

Issue 2777723002: Add ScopedClipboardWriter::WriteData
Patch Set: Add ScopedClipboardWriter::WriteData Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/base/clipboard/clipboard_test_template.h
diff --git a/ui/base/clipboard/clipboard_test_template.h b/ui/base/clipboard/clipboard_test_template.h
index cf033779cefc506caa8427f2ad960c0ad40afbf8..9e4d68975faf8b50675be895844647c48e789f39 100644
--- a/ui/base/clipboard/clipboard_test_template.h
+++ b/ui/base/clipboard/clipboard_test_template.h
@@ -435,45 +435,36 @@ TYPED_TEST(ClipboardTest, DataTest) {
const ui::Clipboard::FormatType kFormat =
ui::Clipboard::GetFormatType("chromium/x-test-format");
std::string payload("test string");
- base::Pickle write_pickle;
- write_pickle.WriteString(payload);
{
ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE);
- clipboard_writer.WritePickledData(write_pickle, kFormat);
+ clipboard_writer.WriteData(payload.data(), static_cast<int>(payload.size()),
dcheng 2017/04/05 08:40:39 I think it'd be easier to read if we just renamed
+ kFormat);
}
ASSERT_TRUE(
this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE));
std::string output;
this->clipboard().ReadData(kFormat, &output);
- ASSERT_FALSE(output.empty());
-
- base::Pickle read_pickle(output.data(), static_cast<int>(output.size()));
- base::PickleIterator iter(read_pickle);
- std::string unpickled_string;
- ASSERT_TRUE(iter.ReadString(&unpickled_string));
- EXPECT_EQ(payload, unpickled_string);
+ EXPECT_EQ(payload, output);
}
TYPED_TEST(ClipboardTest, MultipleDataTest) {
const ui::Clipboard::FormatType kFormat1 =
ui::Clipboard::GetFormatType("chromium/x-test-format1");
std::string payload1("test string1");
- base::Pickle write_pickle1;
- write_pickle1.WriteString(payload1);
const ui::Clipboard::FormatType kFormat2 =
ui::Clipboard::GetFormatType("chromium/x-test-format2");
std::string payload2("test string2");
- base::Pickle write_pickle2;
- write_pickle2.WriteString(payload2);
{
ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE);
- clipboard_writer.WritePickledData(write_pickle1, kFormat1);
+ clipboard_writer.WriteData(payload1.data(),
+ static_cast<int>(payload1.size()) kFormat1);
// overwrite the previous pickle for fun
- clipboard_writer.WritePickledData(write_pickle2, kFormat2);
+ clipboard_writer.WriteData(payload2.data(),
+ static_cast<int>(payload2.size()), kFormat2);
}
ASSERT_TRUE(
@@ -482,19 +473,15 @@ TYPED_TEST(ClipboardTest, MultipleDataTest) {
// Check string 2.
std::string output2;
this->clipboard().ReadData(kFormat2, &output2);
- ASSERT_FALSE(output2.empty());
-
- base::Pickle read_pickle2(output2.data(), static_cast<int>(output2.size()));
- base::PickleIterator iter2(read_pickle2);
- std::string unpickled_string2;
- ASSERT_TRUE(iter2.ReadString(&unpickled_string2));
- EXPECT_EQ(payload2, unpickled_string2);
+ EXPECT_EQ(payload2, output2);
{
ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE);
- clipboard_writer.WritePickledData(write_pickle2, kFormat2);
+ clipboard_writer.WriteData(payload2.data(),
+ static_cast<int>(payload2.size()), kFormat2);
// overwrite the previous pickle for fun
- clipboard_writer.WritePickledData(write_pickle1, kFormat1);
+ clipboard_writer.WriteData(payload1.data(),
+ static_cast<int>(payload1.size()) kFormat1);
}
ASSERT_TRUE(
@@ -503,13 +490,31 @@ TYPED_TEST(ClipboardTest, MultipleDataTest) {
// Check string 1.
std::string output1;
this->clipboard().ReadData(kFormat1, &output1);
- ASSERT_FALSE(output1.empty());
+ EXPECT_EQ(payload1, output1);
+}
+
+TYPED_TEST(ClipboardTest, PickledDataTest) {
+ const ui::Clipboard::FormatType kFormat =
+ ui::Clipboard::GetFormatType("chromium/x-test-format");
+ std::string payload("test string");
+ base::Pickle write_pickle;
+ write_pickle.WriteString(payload);
+
+ {
+ ScopedClipboardWriter clipboard_writer(CLIPBOARD_TYPE_COPY_PASTE);
+ clipboard_writer.WritePickledData(write_pickle, kFormat);
+ }
+
+ ASSERT_TRUE(
+ this->clipboard().IsFormatAvailable(kFormat, CLIPBOARD_TYPE_COPY_PASTE));
+ std::string output;
+ this->clipboard().ReadData(kFormat, &output);
+ ASSERT_FALSE(output.empty());
- base::Pickle read_pickle1(output1.data(), static_cast<int>(output1.size()));
- base::PickleIterator iter1(read_pickle1);
- std::string unpickled_string1;
- ASSERT_TRUE(iter1.ReadString(&unpickled_string1));
- EXPECT_EQ(payload1, unpickled_string1);
+ base::Pickle read_pickle(output.data(), static_cast<int>(output.size()));
+ base::PickleIterator iter(read_pickle);
+ std::string unpickled_string;
+ ASSERT_TRUE(iter.ReadString(&unpickled_string));
}
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)

Powered by Google App Engine
This is Rietveld 408576698