OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/tools/test_shell/mock_webclipboard_impl.h" | 5 #include "webkit/tools/test_shell/mock_webclipboard_impl.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 11 #include "base/string_util.h" |
10 #include "net/base/escape.h" | 12 #include "net/base/escape.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCommon.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCommon.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
15 #include "webkit/glue/webclipboard_impl.h" | 17 #include "webkit/glue/webclipboard_impl.h" |
16 #include "webkit/glue/webkit_glue.h" | 18 #include "webkit/glue/webkit_glue.h" |
17 #include "webkit/support/webkit_support_gfx.h" | 19 #include "webkit/support/webkit_support_gfx.h" |
18 | 20 |
19 #if WEBKIT_USING_CG | 21 #if WEBKIT_USING_CG |
20 #include <ApplicationServices/ApplicationServices.h> | 22 #include <ApplicationServices/ApplicationServices.h> |
21 #include <CoreFoundation/CoreFoundation.h> | 23 #include <CoreFoundation/CoreFoundation.h> |
22 #endif | 24 #endif |
23 | 25 |
| 26 using WebKit::WebDragData; |
24 using WebKit::WebString; | 27 using WebKit::WebString; |
25 using WebKit::WebURL; | 28 using WebKit::WebURL; |
26 using WebKit::WebVector; | 29 using WebKit::WebVector; |
27 | 30 |
28 MockWebClipboardImpl::MockWebClipboardImpl() { | 31 MockWebClipboardImpl::MockWebClipboardImpl() { |
29 } | 32 } |
30 | 33 |
31 MockWebClipboardImpl::~MockWebClipboardImpl() { | 34 MockWebClipboardImpl::~MockWebClipboardImpl() { |
32 } | 35 } |
33 | 36 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 std::vector<WebString> results; | 71 std::vector<WebString> results; |
69 if (!m_plainText.isEmpty()) { | 72 if (!m_plainText.isEmpty()) { |
70 results.push_back(WebString("text/plain")); | 73 results.push_back(WebString("text/plain")); |
71 } | 74 } |
72 if (!m_htmlText.isEmpty()) { | 75 if (!m_htmlText.isEmpty()) { |
73 results.push_back(WebString("text/html")); | 76 results.push_back(WebString("text/html")); |
74 } | 77 } |
75 if (!m_image.isNull()) { | 78 if (!m_image.isNull()) { |
76 results.push_back(WebString("image/png")); | 79 results.push_back(WebString("image/png")); |
77 } | 80 } |
| 81 for (size_t i = 0; i < m_customData.size(); ++i) { |
| 82 CHECK(std::find(results.begin(), results.end(), m_customData[i].m_type) == |
| 83 results.end()); |
| 84 results.push_back(m_customData[i].m_type); |
| 85 } |
78 return results; | 86 return results; |
79 } | 87 } |
80 | 88 |
81 WebKit::WebString MockWebClipboardImpl::readPlainText( | 89 WebKit::WebString MockWebClipboardImpl::readPlainText( |
82 WebKit::WebClipboard::Buffer buffer) { | 90 WebKit::WebClipboard::Buffer buffer) { |
83 return m_plainText; | 91 return m_plainText; |
84 } | 92 } |
85 | 93 |
86 // TODO(wtc): set output argument *url. | 94 // TODO(wtc): set output argument *url. |
87 WebKit::WebString MockWebClipboardImpl::readHTML( | 95 WebKit::WebString MockWebClipboardImpl::readHTML( |
(...skipping 29 matching lines...) Expand all Loading... |
117 CGImageGetBytesPerRow(image), | 125 CGImageGetBytesPerRow(image), |
118 false, | 126 false, |
119 &encoded_image); | 127 &encoded_image); |
120 CFRelease(image_data_ref); | 128 CFRelease(image_data_ref); |
121 #endif | 129 #endif |
122 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), | 130 data.assign(reinterpret_cast<char*>(vector_as_array(&encoded_image)), |
123 encoded_image.size()); | 131 encoded_image.size()); |
124 return data; | 132 return data; |
125 } | 133 } |
126 | 134 |
| 135 WebKit::WebString MockWebClipboardImpl::readCustomData( |
| 136 WebKit::WebClipboard::Buffer buffer, |
| 137 const WebKit::WebString& type) { |
| 138 for (size_t i = 0; i < m_customData.size(); ++i) { |
| 139 if (m_customData[i].m_type == type) { |
| 140 return m_customData[i].m_data; |
| 141 } |
| 142 } |
| 143 return WebKit::WebString(); |
| 144 } |
| 145 |
127 void MockWebClipboardImpl::writeHTML( | 146 void MockWebClipboardImpl::writeHTML( |
128 const WebKit::WebString& htmlText, const WebKit::WebURL& url, | 147 const WebKit::WebString& htmlText, const WebKit::WebURL& url, |
129 const WebKit::WebString& plainText, bool writeSmartPaste) { | 148 const WebKit::WebString& plainText, bool writeSmartPaste) { |
130 m_htmlText = htmlText; | 149 m_htmlText = htmlText; |
131 m_plainText = plainText; | 150 m_plainText = plainText; |
132 m_image.reset(); | 151 m_image.reset(); |
| 152 m_customData = WebVector<WebDragData::CustomData>(); |
133 m_writeSmartPaste = writeSmartPaste; | 153 m_writeSmartPaste = writeSmartPaste; |
134 } | 154 } |
135 | 155 |
136 void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { | 156 void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { |
137 m_htmlText = WebKit::WebString(); | 157 m_htmlText = WebKit::WebString(); |
138 m_plainText = plain_text; | 158 m_plainText = plain_text; |
139 m_image.reset(); | 159 m_image.reset(); |
| 160 m_customData = WebVector<WebDragData::CustomData>(); |
140 m_writeSmartPaste = false; | 161 m_writeSmartPaste = false; |
141 } | 162 } |
142 | 163 |
143 void MockWebClipboardImpl::writeURL( | 164 void MockWebClipboardImpl::writeURL( |
144 const WebKit::WebURL& url, const WebKit::WebString& title) { | 165 const WebKit::WebURL& url, const WebKit::WebString& title) { |
145 m_htmlText = WebString::fromUTF8( | 166 m_htmlText = WebString::fromUTF8( |
146 webkit_glue::WebClipboardImpl::URLToMarkup(url, title)); | 167 webkit_glue::WebClipboardImpl::URLToMarkup(url, title)); |
147 m_plainText = url.spec().utf16(); | 168 m_plainText = url.spec().utf16(); |
148 m_image.reset(); | 169 m_image.reset(); |
| 170 m_customData = WebVector<WebDragData::CustomData>(); |
149 m_writeSmartPaste = false; | 171 m_writeSmartPaste = false; |
150 } | 172 } |
151 | 173 |
152 void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, | 174 void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, |
153 const WebKit::WebURL& url, const WebKit::WebString& title) { | 175 const WebKit::WebURL& url, const WebKit::WebString& title) { |
154 if (!image.isNull()) { | 176 if (!image.isNull()) { |
155 m_htmlText = WebString::fromUTF8( | 177 m_htmlText = WebString::fromUTF8( |
156 webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title)); | 178 webkit_glue::WebClipboardImpl::URLToImageMarkup(url, title)); |
157 m_plainText = m_htmlText; | 179 m_plainText = m_htmlText; |
158 m_image = image; | 180 m_image = image; |
| 181 m_customData = WebVector<WebDragData::CustomData>(); |
159 m_writeSmartPaste = false; | 182 m_writeSmartPaste = false; |
160 } | 183 } |
161 } | 184 } |
162 | 185 |
163 void MockWebClipboardImpl::writeDataObject(const WebKit::WebDragData& data) { | 186 void MockWebClipboardImpl::writeDataObject(const WebKit::WebDragData& data) { |
164 m_htmlText = data.htmlText(); | 187 m_htmlText = data.htmlText(); |
165 m_plainText = data.plainText(); | 188 m_plainText = data.plainText(); |
166 m_image.reset(); | 189 m_image.reset(); |
| 190 m_customData = data.customData(); |
167 m_writeSmartPaste = false; | 191 m_writeSmartPaste = false; |
168 } | 192 } |
OLD | NEW |