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

Side by Side Diff: ui/base/dragdrop/os_exchange_data_unittest.cc

Issue 2179813003: Allow OSExchangeData::Provider to be overridden at run time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac + win Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « ui/base/dragdrop/os_exchange_data_provider_win.cc ('k') | ui/base/ui_base.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory>
6
5 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
6 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
7 #include "base/pickle.h" 9 #include "base/pickle.h"
8 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 11 #include "build/build_config.h"
10 #include "net/base/filename_util.h" 12 #include "net/base/filename_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
13 #include "ui/base/dragdrop/os_exchange_data.h" 15 #include "ui/base/dragdrop/os_exchange_data.h"
14 #include "ui/events/platform/platform_event_source.h" 16 #include "ui/events/platform/platform_event_source.h"
(...skipping 11 matching lines...) Expand all
26 std::unique_ptr<PlatformEventSource> event_source_; 28 std::unique_ptr<PlatformEventSource> event_source_;
27 }; 29 };
28 30
29 TEST_F(OSExchangeDataTest, StringDataGetAndSet) { 31 TEST_F(OSExchangeDataTest, StringDataGetAndSet) {
30 OSExchangeData data; 32 OSExchangeData data;
31 base::string16 input = base::ASCIIToUTF16("I can has cheezburger?"); 33 base::string16 input = base::ASCIIToUTF16("I can has cheezburger?");
32 EXPECT_FALSE(data.HasString()); 34 EXPECT_FALSE(data.HasString());
33 data.SetString(input); 35 data.SetString(input);
34 EXPECT_TRUE(data.HasString()); 36 EXPECT_TRUE(data.HasString());
35 37
36 OSExchangeData data2(data.provider().Clone()); 38 OSExchangeData data2(
39 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone()));
37 base::string16 output; 40 base::string16 output;
38 EXPECT_TRUE(data2.HasString()); 41 EXPECT_TRUE(data2.HasString());
39 EXPECT_TRUE(data2.GetString(&output)); 42 EXPECT_TRUE(data2.GetString(&output));
40 EXPECT_EQ(input, output); 43 EXPECT_EQ(input, output);
41 std::string url_spec = "http://www.goats.com/"; 44 std::string url_spec = "http://www.goats.com/";
42 GURL url(url_spec); 45 GURL url(url_spec);
43 base::string16 title; 46 base::string16 title;
44 EXPECT_FALSE(data2.GetURLAndTitle( 47 EXPECT_FALSE(data2.GetURLAndTitle(
45 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &title)); 48 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &url, &title));
46 // No URLs in |data|, so url should be untouched. 49 // No URLs in |data|, so url should be untouched.
47 EXPECT_EQ(url_spec, url.spec()); 50 EXPECT_EQ(url_spec, url.spec());
48 } 51 }
49 52
50 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) { 53 TEST_F(OSExchangeDataTest, TestURLExchangeFormats) {
51 OSExchangeData data; 54 OSExchangeData data;
52 std::string url_spec = "http://www.google.com/"; 55 std::string url_spec = "http://www.google.com/";
53 GURL url(url_spec); 56 GURL url(url_spec);
54 base::string16 url_title = base::ASCIIToUTF16("www.google.com"); 57 base::string16 url_title = base::ASCIIToUTF16("www.google.com");
55 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); 58 EXPECT_FALSE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES));
56 data.SetURL(url, url_title); 59 data.SetURL(url, url_title);
57 EXPECT_TRUE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); 60 EXPECT_TRUE(data.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES));
58 61
59 OSExchangeData data2(data.provider().Clone()); 62 OSExchangeData data2(
63 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone()));
60 64
61 // URL spec and title should match 65 // URL spec and title should match
62 GURL output_url; 66 GURL output_url;
63 base::string16 output_title; 67 base::string16 output_title;
64 EXPECT_TRUE(data2.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES)); 68 EXPECT_TRUE(data2.HasURL(OSExchangeData::DO_NOT_CONVERT_FILENAMES));
65 EXPECT_TRUE(data2.GetURLAndTitle( 69 EXPECT_TRUE(data2.GetURLAndTitle(
66 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &output_url, &output_title)); 70 OSExchangeData::DO_NOT_CONVERT_FILENAMES, &output_url, &output_title));
67 EXPECT_EQ(url_spec, output_url.spec()); 71 EXPECT_EQ(url_spec, output_url.spec());
68 EXPECT_EQ(url_title, output_title); 72 EXPECT_EQ(url_title, output_title);
69 base::string16 output_string; 73 base::string16 output_string;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 TEST_F(OSExchangeDataTest, TestPickledData) { 141 TEST_F(OSExchangeDataTest, TestPickledData) {
138 const Clipboard::FormatType kTestFormat = 142 const Clipboard::FormatType kTestFormat =
139 Clipboard::GetFormatType("application/vnd.chromium.test"); 143 Clipboard::GetFormatType("application/vnd.chromium.test");
140 144
141 base::Pickle saved_pickle; 145 base::Pickle saved_pickle;
142 saved_pickle.WriteInt(1); 146 saved_pickle.WriteInt(1);
143 saved_pickle.WriteInt(2); 147 saved_pickle.WriteInt(2);
144 OSExchangeData data; 148 OSExchangeData data;
145 data.SetPickledData(kTestFormat, saved_pickle); 149 data.SetPickledData(kTestFormat, saved_pickle);
146 150
147 OSExchangeData copy(data.provider().Clone()); 151 OSExchangeData copy(
152 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone()));
148 EXPECT_TRUE(copy.HasCustomFormat(kTestFormat)); 153 EXPECT_TRUE(copy.HasCustomFormat(kTestFormat));
149 154
150 base::Pickle restored_pickle; 155 base::Pickle restored_pickle;
151 EXPECT_TRUE(copy.GetPickledData(kTestFormat, &restored_pickle)); 156 EXPECT_TRUE(copy.GetPickledData(kTestFormat, &restored_pickle));
152 base::PickleIterator iterator(restored_pickle); 157 base::PickleIterator iterator(restored_pickle);
153 int value; 158 int value;
154 EXPECT_TRUE(iterator.ReadInt(&value)); 159 EXPECT_TRUE(iterator.ReadInt(&value));
155 EXPECT_EQ(1, value); 160 EXPECT_EQ(1, value);
156 EXPECT_TRUE(iterator.ReadInt(&value)); 161 EXPECT_TRUE(iterator.ReadInt(&value));
157 EXPECT_EQ(2, value); 162 EXPECT_EQ(2, value);
158 } 163 }
159 164
160 #if defined(USE_AURA) 165 #if defined(USE_AURA)
161 TEST_F(OSExchangeDataTest, TestHTML) { 166 TEST_F(OSExchangeDataTest, TestHTML) {
162 OSExchangeData data; 167 OSExchangeData data;
163 GURL url("http://www.google.com/"); 168 GURL url("http://www.google.com/");
164 base::string16 html = base::ASCIIToUTF16( 169 base::string16 html = base::ASCIIToUTF16(
165 "<HTML>\n<BODY>\n" 170 "<HTML>\n<BODY>\n"
166 "<b>bold.</b> <i><b>This is bold italic.</b></i>\n" 171 "<b>bold.</b> <i><b>This is bold italic.</b></i>\n"
167 "</BODY>\n</HTML>"); 172 "</BODY>\n</HTML>");
168 data.SetHtml(html, url); 173 data.SetHtml(html, url);
169 174
170 OSExchangeData copy(data.provider().Clone()); 175 OSExchangeData copy(
176 std::unique_ptr<OSExchangeData::Provider>(data.provider().Clone()));
171 base::string16 read_html; 177 base::string16 read_html;
172 EXPECT_TRUE(copy.GetHtml(&read_html, &url)); 178 EXPECT_TRUE(copy.GetHtml(&read_html, &url));
173 EXPECT_EQ(html, read_html); 179 EXPECT_EQ(html, read_html);
174 } 180 }
175 #endif 181 #endif
176 182
177 } // namespace ui 183 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/dragdrop/os_exchange_data_provider_win.cc ('k') | ui/base/ui_base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698