1 // Copyright 2013 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 "base/message_loop/message_loop.h"
6 #include "base/pickle.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h"
10 #include "ui/base/dragdrop/os_exchange_data.h"
15 class OSExchangeDataTest : public PlatformTest {
17 base::MessageLoopForUI message_loop_;
20 TEST_F(OSExchangeDataTest, StringDataGetAndSet) {
22 string16 input = ASCIIToUTF16("I can has cheezburger?");
23 data.SetString(input);
25 OSExchangeData data2(data.provider().Clone());
27 EXPECT_TRUE(data2.GetString(&output));
28 EXPECT_EQ(input, output);
29 std::string url_spec = "http://www.goats.com/";
32 EXPECT_FALSE(data2.GetURLAndTitle(&url, &title));
33 // No URLs in |data|, so url should be untouched.
34 EXPECT_EQ(url_spec, url.spec());
37 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) {
39 std::string url_spec = "http://www.google.com/";
41 string16 url_title = ASCIIToUTF16("www.google.com");
42 data.SetURL(url, url_title);
45 OSExchangeData data2(data.provider().Clone());
47 // URL spec and title should match
49 string16 output_title;
50 EXPECT_TRUE(data2.GetURLAndTitle(&output_url, &output_title));
51 EXPECT_EQ(url_spec, output_url.spec());
52 EXPECT_EQ(url_title, output_title);
53 string16 output_string;
55 // URL should be the raw text response
56 EXPECT_TRUE(data2.GetString(&output_string));
57 EXPECT_EQ(url_spec, UTF16ToUTF8(output_string));
60 TEST_F(OSExchangeDataTest, TestPickledData) {
61 const OSExchangeData::CustomFormat kTestFormat =
62 ui::Clipboard::GetFormatType("application/vnd.chromium.test");
65 saved_pickle.WriteInt(1);
66 saved_pickle.WriteInt(2);
68 data.SetPickledData(kTestFormat, saved_pickle);
70 OSExchangeData copy(data.provider().Clone());
71 EXPECT_TRUE(copy.HasCustomFormat(kTestFormat));
73 Pickle restored_pickle;
74 EXPECT_TRUE(copy.GetPickledData(kTestFormat, &restored_pickle));
75 PickleIterator iterator(restored_pickle);
77 EXPECT_TRUE(restored_pickle.ReadInt(&iterator, &value));
79 EXPECT_TRUE(restored_pickle.ReadInt(&iterator, &value));
83 TEST_F(OSExchangeDataTest, TestHTML) {
85 GURL url("http://www.google.com/");
86 string16 html = ASCIIToUTF16(
88 "<b>bold.</b> <i><b>This is bold italic.</b></i>\n"
90 data.SetHtml(html, url);
92 OSExchangeData copy(data.provider().Clone());
94 EXPECT_TRUE(copy.GetHtml(&read_html, &url));
95 EXPECT_EQ(html, read_html);