OLD | NEW |
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 "content/test/mock_webclipboard_impl.h" | 5 #include "content/test/mock_webclipboard_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "content/renderer/clipboard_utils.h" | 13 #include "content/renderer/clipboard_utils.h" |
14 #include "third_party/WebKit/public/platform/WebCommon.h" | 14 #include "third_party/WebKit/public/platform/WebCommon.h" |
15 #include "third_party/WebKit/public/platform/WebDragData.h" | 15 #include "third_party/WebKit/public/platform/WebDragData.h" |
16 #include "third_party/WebKit/public/platform/WebImage.h" | 16 #include "third_party/WebKit/public/platform/WebImage.h" |
17 #include "third_party/WebKit/public/platform/WebURL.h" | 17 #include "third_party/WebKit/public/platform/WebURL.h" |
18 #include "ui/base/clipboard/clipboard.h" | 18 #include "ui/base/clipboard/clipboard.h" |
19 #include "ui/gfx/codec/png_codec.h" | 19 #include "ui/gfx/codec/png_codec.h" |
20 #include "ui/gfx/size.h" | 20 #include "ui/gfx/size.h" |
21 #include "webkit/glue/webkit_glue.h" | 21 #include "webkit/glue/webkit_glue.h" |
22 | 22 |
23 using WebKit::WebDragData; | 23 using WebKit::WebDragData; |
24 using WebKit::WebString; | 24 using WebKit::WebString; |
25 using WebKit::WebURL; | 25 using WebKit::WebURL; |
26 using WebKit::WebVector; | 26 using WebKit::WebVector; |
27 | 27 |
28 MockWebClipboardImpl::MockWebClipboardImpl() { | 28 namespace content { |
29 } | |
30 | 29 |
31 MockWebClipboardImpl::~MockWebClipboardImpl() { | 30 MockWebClipboardImpl::MockWebClipboardImpl() {} |
32 } | 31 |
| 32 MockWebClipboardImpl::~MockWebClipboardImpl() {} |
33 | 33 |
34 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { | 34 bool MockWebClipboardImpl::isFormatAvailable(Format format, Buffer buffer) { |
35 switch (format) { | 35 switch (format) { |
36 case FormatPlainText: | 36 case FormatPlainText: |
37 return !m_plainText.isNull(); | 37 return !m_plainText.isNull(); |
38 | 38 |
39 case FormatHTML: | 39 case FormatHTML: |
40 return !m_htmlText.isNull(); | 40 return !m_htmlText.isNull(); |
41 | 41 |
42 case FormatSmartPaste: | 42 case FormatSmartPaste: |
(...skipping 13 matching lines...) Expand all Loading... |
56 #endif | 56 #endif |
57 default: | 57 default: |
58 NOTREACHED(); | 58 NOTREACHED(); |
59 return false; | 59 return false; |
60 } | 60 } |
61 | 61 |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 WebVector<WebString> MockWebClipboardImpl::readAvailableTypes( | 65 WebVector<WebString> MockWebClipboardImpl::readAvailableTypes( |
66 Buffer buffer, bool* containsFilenames) { | 66 Buffer buffer, |
| 67 bool* containsFilenames) { |
67 *containsFilenames = false; | 68 *containsFilenames = false; |
68 std::vector<WebString> results; | 69 std::vector<WebString> results; |
69 if (!m_plainText.isEmpty()) { | 70 if (!m_plainText.isEmpty()) { |
70 results.push_back(WebString("text/plain")); | 71 results.push_back(WebString("text/plain")); |
71 } | 72 } |
72 if (!m_htmlText.isEmpty()) { | 73 if (!m_htmlText.isEmpty()) { |
73 results.push_back(WebString("text/html")); | 74 results.push_back(WebString("text/html")); |
74 } | 75 } |
75 if (!m_image.isNull()) { | 76 if (!m_image.isNull()) { |
76 results.push_back(WebString("image/png")); | 77 results.push_back(WebString("image/png")); |
77 } | 78 } |
78 for (std::map<base::string16, base::string16>::const_iterator it = | 79 for (std::map<base::string16, base::string16>::const_iterator it = |
79 m_customData.begin(); | 80 m_customData.begin(); |
80 it != m_customData.end(); ++it) { | 81 it != m_customData.end(); ++it) { |
81 CHECK(std::find(results.begin(), results.end(), it->first) == | 82 CHECK(std::find(results.begin(), results.end(), it->first) == |
82 results.end()); | 83 results.end()); |
83 results.push_back(it->first); | 84 results.push_back(it->first); |
84 } | 85 } |
85 return results; | 86 return results; |
86 } | 87 } |
87 | 88 |
88 WebKit::WebString MockWebClipboardImpl::readPlainText( | 89 WebKit::WebString MockWebClipboardImpl::readPlainText( |
89 WebKit::WebClipboard::Buffer buffer) { | 90 WebKit::WebClipboard::Buffer buffer) { |
90 return m_plainText; | 91 return m_plainText; |
91 } | 92 } |
92 | 93 |
93 // TODO(wtc): set output argument *url. | 94 // TODO(wtc): set output argument *url. |
94 WebKit::WebString MockWebClipboardImpl::readHTML( | 95 WebKit::WebString MockWebClipboardImpl::readHTML( |
95 WebKit::WebClipboard::Buffer buffer, WebKit::WebURL* url, | 96 WebKit::WebClipboard::Buffer buffer, |
96 unsigned* fragmentStart, unsigned* fragmentEnd) { | 97 WebKit::WebURL* url, |
| 98 unsigned* fragmentStart, |
| 99 unsigned* fragmentEnd) { |
97 *fragmentStart = 0; | 100 *fragmentStart = 0; |
98 *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); | 101 *fragmentEnd = static_cast<unsigned>(m_htmlText.length()); |
99 return m_htmlText; | 102 return m_htmlText; |
100 } | 103 } |
101 | 104 |
102 WebKit::WebData MockWebClipboardImpl::readImage( | 105 WebKit::WebData MockWebClipboardImpl::readImage( |
103 WebKit::WebClipboard::Buffer buffer) { | 106 WebKit::WebClipboard::Buffer buffer) { |
104 std::string data; | 107 std::string data; |
105 std::vector<unsigned char> encoded_image; | 108 std::vector<unsigned char> encoded_image; |
106 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that | 109 // TODO(dcheng): Verify that we can assume the image is ARGB8888. Note that |
(...skipping 19 matching lines...) Expand all Loading... |
126 WebKit::WebString MockWebClipboardImpl::readCustomData( | 129 WebKit::WebString MockWebClipboardImpl::readCustomData( |
127 WebKit::WebClipboard::Buffer buffer, | 130 WebKit::WebClipboard::Buffer buffer, |
128 const WebKit::WebString& type) { | 131 const WebKit::WebString& type) { |
129 std::map<base::string16, base::string16>::const_iterator it = | 132 std::map<base::string16, base::string16>::const_iterator it = |
130 m_customData.find(type); | 133 m_customData.find(type); |
131 if (it != m_customData.end()) | 134 if (it != m_customData.end()) |
132 return it->second; | 135 return it->second; |
133 return WebKit::WebString(); | 136 return WebKit::WebString(); |
134 } | 137 } |
135 | 138 |
136 void MockWebClipboardImpl::writeHTML( | 139 void MockWebClipboardImpl::writeHTML(const WebKit::WebString& htmlText, |
137 const WebKit::WebString& htmlText, const WebKit::WebURL& url, | 140 const WebKit::WebURL& url, |
138 const WebKit::WebString& plainText, bool writeSmartPaste) { | 141 const WebKit::WebString& plainText, |
| 142 bool writeSmartPaste) { |
139 clear(); | 143 clear(); |
140 | 144 |
141 m_htmlText = htmlText; | 145 m_htmlText = htmlText; |
142 m_plainText = plainText; | 146 m_plainText = plainText; |
143 m_writeSmartPaste = writeSmartPaste; | 147 m_writeSmartPaste = writeSmartPaste; |
144 } | 148 } |
145 | 149 |
146 void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { | 150 void MockWebClipboardImpl::writePlainText(const WebKit::WebString& plain_text) { |
147 clear(); | 151 clear(); |
148 | 152 |
149 m_plainText = plain_text; | 153 m_plainText = plain_text; |
150 } | 154 } |
151 | 155 |
152 void MockWebClipboardImpl::writeURL(const WebKit::WebURL& url, | 156 void MockWebClipboardImpl::writeURL(const WebKit::WebURL& url, |
153 const WebKit::WebString& title) { | 157 const WebKit::WebString& title) { |
154 clear(); | 158 clear(); |
155 | 159 |
156 m_htmlText = WebString::fromUTF8(content::URLToMarkup(url, title)); | 160 m_htmlText = WebString::fromUTF8(URLToMarkup(url, title)); |
157 m_plainText = url.spec().utf16(); | 161 m_plainText = url.spec().utf16(); |
158 } | 162 } |
159 | 163 |
160 void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, | 164 void MockWebClipboardImpl::writeImage(const WebKit::WebImage& image, |
161 const WebKit::WebURL& url, | 165 const WebKit::WebURL& url, |
162 const WebKit::WebString& title) { | 166 const WebKit::WebString& title) { |
163 if (!image.isNull()) { | 167 if (!image.isNull()) { |
164 clear(); | 168 clear(); |
165 | 169 |
166 m_plainText = m_htmlText; | 170 m_plainText = m_htmlText; |
167 m_htmlText = WebString::fromUTF8(content::URLToImageMarkup(url, title)); | 171 m_htmlText = WebString::fromUTF8(URLToImageMarkup(url, title)); |
168 m_image = image; | 172 m_image = image; |
169 } | 173 } |
170 } | 174 } |
171 | 175 |
172 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { | 176 void MockWebClipboardImpl::writeDataObject(const WebDragData& data) { |
173 clear(); | 177 clear(); |
174 | 178 |
175 const WebVector<WebDragData::Item>& itemList = data.items(); | 179 const WebVector<WebDragData::Item>& itemList = data.items(); |
176 for (size_t i = 0; i < itemList.size(); ++i) { | 180 for (size_t i = 0; i < itemList.size(); ++i) { |
177 const WebDragData::Item& item = itemList[i]; | 181 const WebDragData::Item& item = itemList[i]; |
(...skipping 17 matching lines...) Expand all Loading... |
195 } | 199 } |
196 } | 200 } |
197 | 201 |
198 void MockWebClipboardImpl::clear() { | 202 void MockWebClipboardImpl::clear() { |
199 m_plainText = WebString(); | 203 m_plainText = WebString(); |
200 m_htmlText = WebString(); | 204 m_htmlText = WebString(); |
201 m_image.reset(); | 205 m_image.reset(); |
202 m_customData.clear(); | 206 m_customData.clear(); |
203 m_writeSmartPaste = false; | 207 m_writeSmartPaste = false; |
204 } | 208 } |
| 209 |
| 210 } // namespace content |
OLD | NEW |