OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/win/scoped_hglobal.h" | 8 #include "base/win/scoped_hglobal.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/clipboard/clipboard.h" | 10 #include "ui/base/clipboard/clipboard.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 base::win::ScopedComPtr<IDataObject> com_data( | 42 base::win::ScopedComPtr<IDataObject> com_data( |
43 OSExchangeDataProviderWin::GetIDataObject(data)); | 43 OSExchangeDataProviderWin::GetIDataObject(data)); |
44 | 44 |
45 // Store data in the object using the COM SetData API. | 45 // Store data in the object using the COM SetData API. |
46 CLIPFORMAT cfstr_ineturl = RegisterClipboardFormat(CFSTR_INETURL); | 46 CLIPFORMAT cfstr_ineturl = RegisterClipboardFormat(CFSTR_INETURL); |
47 FORMATETC format_etc = | 47 FORMATETC format_etc = |
48 { cfstr_ineturl, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; | 48 { cfstr_ineturl, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; |
49 STGMEDIUM medium; | 49 STGMEDIUM medium; |
50 medium.tymed = TYMED_HGLOBAL; | 50 medium.tymed = TYMED_HGLOBAL; |
51 HGLOBAL glob = GlobalAlloc(GPTR, sizeof(wchar_t) * (input.size() + 1)); | 51 HGLOBAL glob = GlobalAlloc(GPTR, sizeof(wchar_t) * (input.size() + 1)); |
52 size_t stringsz = input.size(); | |
53 SIZE_T sz = GlobalSize(glob); | |
54 base::win::ScopedHGlobal<wchar_t*> global_lock(glob); | 52 base::win::ScopedHGlobal<wchar_t*> global_lock(glob); |
55 wchar_t* buffer_handle = global_lock.get(); | 53 wchar_t* buffer_handle = global_lock.get(); |
56 wcscpy_s(buffer_handle, input.size() + 1, input.c_str()); | 54 wcscpy_s(buffer_handle, input.size() + 1, input.c_str()); |
57 medium.hGlobal = glob; | 55 medium.hGlobal = glob; |
58 medium.pUnkForRelease = NULL; | 56 medium.pUnkForRelease = NULL; |
59 EXPECT_EQ(S_OK, com_data->SetData(&format_etc, &medium, TRUE)); | 57 EXPECT_EQ(S_OK, com_data->SetData(&format_etc, &medium, TRUE)); |
60 | 58 |
61 // Construct a new object with the old object so that we can use our access | 59 // Construct a new object with the old object so that we can use our access |
62 // APIs. | 60 // APIs. |
63 OSExchangeData data2(data.provider().Clone()); | 61 OSExchangeData data2(data.provider().Clone()); |
(...skipping 16 matching lines...) Expand all Loading... |
80 OSExchangeDataProviderWin::GetIDataObject(data)); | 78 OSExchangeDataProviderWin::GetIDataObject(data)); |
81 | 79 |
82 // Store data in the object using the COM SetData API. | 80 // Store data in the object using the COM SetData API. |
83 CLIPFORMAT cfstr_ineturl = RegisterClipboardFormat(CFSTR_INETURL); | 81 CLIPFORMAT cfstr_ineturl = RegisterClipboardFormat(CFSTR_INETURL); |
84 FORMATETC format_etc = | 82 FORMATETC format_etc = |
85 { cfstr_ineturl, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; | 83 { cfstr_ineturl, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; |
86 STGMEDIUM medium; | 84 STGMEDIUM medium; |
87 medium.tymed = TYMED_HGLOBAL; | 85 medium.tymed = TYMED_HGLOBAL; |
88 { | 86 { |
89 HGLOBAL glob = GlobalAlloc(GPTR, sizeof(wchar_t) * (input.size() + 1)); | 87 HGLOBAL glob = GlobalAlloc(GPTR, sizeof(wchar_t) * (input.size() + 1)); |
90 size_t stringsz = input.size(); | |
91 SIZE_T sz = GlobalSize(glob); | |
92 base::win::ScopedHGlobal<wchar_t*> global_lock(glob); | 88 base::win::ScopedHGlobal<wchar_t*> global_lock(glob); |
93 wchar_t* buffer_handle = global_lock.get(); | 89 wchar_t* buffer_handle = global_lock.get(); |
94 wcscpy_s(buffer_handle, input.size() + 1, input.c_str()); | 90 wcscpy_s(buffer_handle, input.size() + 1, input.c_str()); |
95 medium.hGlobal = glob; | 91 medium.hGlobal = glob; |
96 medium.pUnkForRelease = NULL; | 92 medium.pUnkForRelease = NULL; |
97 EXPECT_EQ(S_OK, com_data->SetData(&format_etc, &medium, TRUE)); | 93 EXPECT_EQ(S_OK, com_data->SetData(&format_etc, &medium, TRUE)); |
98 } | 94 } |
99 // This should clobber the existing data. | 95 // This should clobber the existing data. |
100 { | 96 { |
101 HGLOBAL glob = GlobalAlloc(GPTR, sizeof(wchar_t) * (input2.size() + 1)); | 97 HGLOBAL glob = GlobalAlloc(GPTR, sizeof(wchar_t) * (input2.size() + 1)); |
102 size_t stringsz = input2.size(); | |
103 SIZE_T sz = GlobalSize(glob); | |
104 base::win::ScopedHGlobal<wchar_t*> global_lock(glob); | 98 base::win::ScopedHGlobal<wchar_t*> global_lock(glob); |
105 wchar_t* buffer_handle = global_lock.get(); | 99 wchar_t* buffer_handle = global_lock.get(); |
106 wcscpy_s(buffer_handle, input2.size() + 1, input2.c_str()); | 100 wcscpy_s(buffer_handle, input2.size() + 1, input2.c_str()); |
107 medium.hGlobal = glob; | 101 medium.hGlobal = glob; |
108 medium.pUnkForRelease = NULL; | 102 medium.pUnkForRelease = NULL; |
109 EXPECT_EQ(S_OK, com_data->SetData(&format_etc, &medium, TRUE)); | 103 EXPECT_EQ(S_OK, com_data->SetData(&format_etc, &medium, TRUE)); |
110 } | 104 } |
111 EXPECT_EQ(1u, static_cast<DataObjectImpl*>(com_data.get())->size()); | 105 EXPECT_EQ(1u, static_cast<DataObjectImpl*>(com_data.get())->size()); |
112 | 106 |
113 // Construct a new object with the old object so that we can use our access | 107 // Construct a new object with the old object so that we can use our access |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 OSExchangeData data2(data.provider().Clone()); | 342 OSExchangeData data2(data.provider().Clone()); |
349 ASSERT_TRUE(data2.HasURL(OSExchangeData::CONVERT_FILENAMES)); | 343 ASSERT_TRUE(data2.HasURL(OSExchangeData::CONVERT_FILENAMES)); |
350 GURL read_url; | 344 GURL read_url; |
351 std::wstring title; | 345 std::wstring title; |
352 EXPECT_TRUE(data2.GetURLAndTitle( | 346 EXPECT_TRUE(data2.GetURLAndTitle( |
353 OSExchangeData::CONVERT_FILENAMES, &read_url, &title)); | 347 OSExchangeData::CONVERT_FILENAMES, &read_url, &title)); |
354 EXPECT_EQ(GURL("http://google.com"), read_url); | 348 EXPECT_EQ(GURL("http://google.com"), read_url); |
355 } | 349 } |
356 | 350 |
357 } // namespace ui | 351 } // namespace ui |
OLD | NEW |