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

Unified Diff: chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js

Issue 2837983002: Modify SetImageData to add additional items along with image data to save on clipboard. (Closed)
Patch Set: Make additional data items parameter optional and address other comments. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js
diff --git a/chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js b/chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js
index fc587c58b0cd0ed718ab8e130eaf8e063221626f..3ddfd2df18098948fdefdea7a945d10cffdc139e 100644
--- a/chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js
+++ b/chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js
@@ -6,7 +6,18 @@
var testSuccessCount = 0;
-function testSetImageDataClipboard(imageUrl, imageType, expectSucceed) {
+function testSetImageDataClipboard(imageUrl, imageType, expectedError) {
+ testSetImageDataClipboardWithAdditionalData(
+ imageUrl, imageType, null, expectedError);
+}
+
+function verifySetImageDataResult(expectedError) {
+ chrome.test.assertEq(expectedError, chrome.runtime.lastError);
Devlin 2017/05/17 16:08:43 instead of this, which requires callers to pass in
jennyz 2017/05/18 23:33:49 Done.
+ chrome.test.succeed();
+}
+
+function testSetImageDataClipboardWithAdditionalData(
Devlin 2017/05/17 16:08:43 Seems like we can combine this with testSetImageDa
jennyz 2017/05/18 23:33:48 Done.
+ imageUrl, imageType, additional_items, expectedError) {
Devlin 2017/05/17 16:08:44 additional_items: useJsStyle :)
jennyz 2017/05/18 23:33:49 Done.
var oReq = new XMLHttpRequest();
oReq.open('GET', imageUrl, true);
oReq.responseType = 'arraybuffer';
@@ -16,12 +27,19 @@ function testSetImageDataClipboard(imageUrl, imageType, expectSucceed) {
var binaryString = '';
if (arrayBuffer) {
- chrome.clipboard.setImageData(arrayBuffer, imageType, function() {
- chrome.test.assertEq(expectSucceed, !chrome.runtime.lastError);
- chrome.test.succeed();
- });
+ if (additional_items == null) {
Devlin 2017/05/17 16:08:43 why not just if (additionalItems)?
jennyz 2017/05/18 23:33:49 Done.
+ chrome.clipboard.setImageData(arrayBuffer, imageType,
+ function() {
+ verifySetImageDataResult(expectedError);
+ });
+ } else {
+ chrome.clipboard.setImageData(arrayBuffer, imageType, additional_items,
+ function() {
+ verifySetImageDataResult(expectedError);
+ });
+ }
} else {
- chrome.test.fail('Failed to load the png image file');
+ chrome.test.fail('Failed to load the image file');
}
};
@@ -29,15 +47,56 @@ function testSetImageDataClipboard(imageUrl, imageType, expectSucceed) {
}
function testSavePngImageToClipboard(baseUrl) {
- testSetImageDataClipboard(baseUrl + '/icon1.png', 'png', true);
+ testSetImageDataClipboard(
+ baseUrl + '/icon1.png', 'png', undefined);
Devlin 2017/05/17 16:08:43 no need to pass undefined
jennyz 2017/05/18 23:33:48 Done.
}
function testSaveJpegImageToClipboard(baseUrl) {
- testSetImageDataClipboard(baseUrl + '/test.jpg', 'jpeg', true);
+ testSetImageDataClipboard(
+ baseUrl + '/test.jpg', 'jpeg', undefined);
}
function testSaveBadImageData(baseUrl) {
- testSetImageDataClipboard(baseUrl + '/redirect_target.gif', 'jpeg', false);
+ var expectedError = {
+ 'message': 'Image data decoding failed.'
Devlin 2017/05/17 16:08:44 no need for quotes around keys, but moot with othe
jennyz 2017/05/18 23:33:49 Done.
+ };
+ testSetImageDataClipboard(
+ baseUrl + '/redirect_target.gif', 'jpeg', expectedError);
+}
+
+function testSavePngImageWithAdditionalDataToClipboard(baseUrl) {
+ var additional_items = [];
+ var text_item = {
+ type: 'text_plain',
+ data: 'Hello, world'
+ }
+ var html_item = {
+ type: 'text_html',
+ data: '<b>This is an html markup</b>'
+ }
+ additional_items.push(text_item);
+ additional_items.push(html_item);
+ testSetImageDataClipboardWithAdditionalData(
+ baseUrl + '/icon1.png', 'png', additional_items, undefined);
+}
+
+function testSavePngImageWithAdditionalDataToClipboardDuplicateTypeItems(baseUrl) {
Devlin 2017/05/17 16:08:44 lines <= 80 char
jennyz 2017/05/18 23:33:49 Done.
+ var additional_items = [];
+ var text_item1 = {
+ type: 'text_plain',
+ data: 'Hello, world'
+ }
+ var text_item2 = {
+ type: 'text_plain',
+ data: 'Another text item'
+ }
+ additional_items.push(text_item1);
+ additional_items.push(text_item2);
+ var expectedError = {
+ 'message': 'Unsupported additional_items parameter data.'
+ };
+ testSetImageDataClipboardWithAdditionalData(
+ baseUrl + '/icon1.png', 'png', additional_items, expectedError);
}
function bindTest(test, param) {
@@ -51,6 +110,9 @@ chrome.test.getConfig(function(config) {
chrome.test.runTests([
bindTest(testSavePngImageToClipboard, baseUrl),
bindTest(testSaveJpegImageToClipboard, baseUrl),
- bindTest(testSaveBadImageData, baseUrl)
+ bindTest(testSaveBadImageData, baseUrl),
+ bindTest(testSavePngImageWithAdditionalDataToClipboard, baseUrl),
+ bindTest(testSavePngImageWithAdditionalDataToClipboardDuplicateTypeItems,
+ baseUrl)
]);
})

Powered by Google App Engine
This is Rietveld 408576698