OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <atlbase.h> | 5 #include <atlbase.h> |
6 #include <shlobj.h> | 6 #include <shlobj.h> |
7 | 7 |
| 8 #include "base/clipboard_util.h" |
8 #include "base/pickle.h" | 9 #include "base/pickle.h" |
9 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
10 #include "base/scoped_handle.h" | 11 #include "base/scoped_handle.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
12 #include "chrome/common/os_exchange_data.h" | 13 #include "chrome/common/os_exchange_data.h" |
13 #include "chrome/common/win_util.h" | 14 #include "chrome/common/win_util.h" |
14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 typedef testing::Test OSExchangeDataTest; | 18 typedef testing::Test OSExchangeDataTest; |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 scoped_refptr<OSExchangeData> copy(new OSExchangeData(data.get())); | 307 scoped_refptr<OSExchangeData> copy(new OSExchangeData(data.get())); |
307 std::wstring filename; | 308 std::wstring filename; |
308 std::string read_contents; | 309 std::string read_contents; |
309 EXPECT_TRUE(copy->GetFileContents(&filename, &read_contents)); | 310 EXPECT_TRUE(copy->GetFileContents(&filename, &read_contents)); |
310 EXPECT_EQ(L"filename.txt", filename); | 311 EXPECT_EQ(L"filename.txt", filename); |
311 EXPECT_EQ(file_contents, read_contents); | 312 EXPECT_EQ(file_contents, read_contents); |
312 } | 313 } |
313 | 314 |
314 TEST(OSExchangeDataTest, Html) { | 315 TEST(OSExchangeDataTest, Html) { |
315 scoped_refptr<OSExchangeData> data(new OSExchangeData); | 316 scoped_refptr<OSExchangeData> data(new OSExchangeData); |
316 std::wstring html(L"Version:0.9\nStartHTML:71\nEndHTML:160\n" | 317 GURL url("http://www.google.com/"); |
317 L"StartFragment:130\nEndFragment:150\n<HTML>\n<BODY>\n" | 318 std::wstring html( |
318 L"<!--StartFragment-->\n<b>bold.</b> <i><b>This is bold italic.</b></i>\n" | 319 L"<HTML>\n<BODY>\n" |
319 L"<!--EndFragment-->\n</BODY>\n</HTML>"); | 320 L"<b>bold.</b> <i><b>This is bold italic.</b></i>\n" |
320 data->SetCFHtml(html); | 321 L"</BODY>\n</HTML>"); |
| 322 data->SetHtml(html, url); |
321 | 323 |
322 scoped_refptr<OSExchangeData> copy(new OSExchangeData(data.get())); | 324 scoped_refptr<OSExchangeData> copy(new OSExchangeData(data.get())); |
323 std::wstring read_html; | 325 std::wstring read_html; |
324 EXPECT_TRUE(copy->GetCFHtml(&read_html)); | 326 EXPECT_TRUE(copy->GetHtml(&read_html, &url)); |
325 EXPECT_EQ(html, read_html); | 327 EXPECT_EQ(html, read_html); |
| 328 |
| 329 // Check the CF_HTML too. |
| 330 std::string expected_cf_html( |
| 331 "Version:0.9\r\nStartHTML:0000000138\r\nEndHTML:0000000291\r\n" |
| 332 "StartFragment:0000000176\r\nEndFragment:0000000253\r\n" |
| 333 "SourceURL:http://www.google.com/\r\n<html>\r\n<body>\r\n" |
| 334 "<!--StartFragment-->\r\n"); |
| 335 expected_cf_html += WideToUTF8(html); |
| 336 expected_cf_html.append("\r\n<!--EndFragment-->\r\n</body>\r\n</html>"); |
| 337 |
| 338 STGMEDIUM medium; |
| 339 EXPECT_EQ(S_OK, data->GetData(ClipboardUtil::GetHtmlFormat(), &medium)); |
| 340 ScopedHGlobal<char> glob(medium.hGlobal); |
| 341 std::string output(glob.get(), glob.Size()); |
| 342 EXPECT_EQ(expected_cf_html, output); |
| 343 ReleaseStgMedium(&medium); |
326 } | 344 } |
327 | 345 |
328 TEST(OSExchangeDataTest, SetURLWithMaxPath) { | 346 TEST(OSExchangeDataTest, SetURLWithMaxPath) { |
329 scoped_refptr<OSExchangeData> data(new OSExchangeData); | 347 scoped_refptr<OSExchangeData> data(new OSExchangeData); |
330 std::wstring long_title(L'a', MAX_PATH + 1); | 348 std::wstring long_title(L'a', MAX_PATH + 1); |
331 data->SetURL(GURL("http://google.com"), long_title); | 349 data->SetURL(GURL("http://google.com"), long_title); |
332 } | 350 } |
333 | 351 |
334 TEST(OSExchangeDataTest, ProvideURLForPlainTextURL) { | 352 TEST(OSExchangeDataTest, ProvideURLForPlainTextURL) { |
335 scoped_refptr<OSExchangeData> data(new OSExchangeData); | 353 scoped_refptr<OSExchangeData> data(new OSExchangeData); |
336 data->SetString(L"http://google.com"); | 354 data->SetString(L"http://google.com"); |
337 | 355 |
338 scoped_ptr<OSExchangeData> data2(new OSExchangeData(data.get())); | 356 scoped_ptr<OSExchangeData> data2(new OSExchangeData(data.get())); |
339 ASSERT_TRUE(data2->HasURL()); | 357 ASSERT_TRUE(data2->HasURL()); |
340 GURL read_url; | 358 GURL read_url; |
341 std::wstring title; | 359 std::wstring title; |
342 EXPECT_TRUE(data2->GetURLAndTitle(&read_url, &title)); | 360 EXPECT_TRUE(data2->GetURLAndTitle(&read_url, &title)); |
343 EXPECT_EQ(GURL("http://google.com"), read_url); | 361 EXPECT_EQ(GURL("http://google.com"), read_url); |
344 } | 362 } |
345 | 363 |
OLD | NEW |