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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 // Test clipboard extension api chrome.clipboard.onClipboardDataChanged event. 5 // Test clipboard extension api chrome.clipboard.onClipboardDataChanged event.
6 6
7 var testSuccessCount = 0; 7 var testSuccessCount = 0;
8 8
9 function testSetImageDataClipboard(imageUrl, imageType, expectSucceed) { 9 function testSetImageDataClipboard(imageUrl, imageType, additional_items,
10 expectSucceed) {
Devlin 2017/04/26 18:20:15 We should expand this to take some kind of expecte
jennyz 2017/05/16 18:22:03 Done.
10 var oReq = new XMLHttpRequest(); 11 var oReq = new XMLHttpRequest();
11 oReq.open('GET', imageUrl, true); 12 oReq.open('GET', imageUrl, true);
12 oReq.responseType = 'arraybuffer'; 13 oReq.responseType = 'arraybuffer';
13 14
14 oReq.onload = function (oEvent) { 15 oReq.onload = function (oEvent) {
15 var arrayBuffer = oReq.response; 16 var arrayBuffer = oReq.response;
16 var binaryString = ''; 17 var binaryString = '';
17 18
18 if (arrayBuffer) { 19 if (arrayBuffer) {
19 chrome.clipboard.setImageData(arrayBuffer, imageType, function() { 20 chrome.clipboard.setImageData(arrayBuffer, imageType,
21 additional_items, function() {
20 chrome.test.assertEq(expectSucceed, !chrome.runtime.lastError); 22 chrome.test.assertEq(expectSucceed, !chrome.runtime.lastError);
21 chrome.test.succeed(); 23 chrome.test.succeed();
22 }); 24 });
23 } else { 25 } else {
24 chrome.test.fail('Failed to load the png image file'); 26 chrome.test.fail('Failed to load the png image file');
25 } 27 }
26 }; 28 };
27 29
28 oReq.send(null); 30 oReq.send(null);
29 } 31 }
30 32
31 function testSavePngImageToClipboard(baseUrl) { 33 function testSavePngImageToClipboard(baseUrl) {
32 testSetImageDataClipboard(baseUrl + '/icon1.png', 'png', true); 34 var additional_items = [];
35 testSetImageDataClipboard(
36 baseUrl + '/icon1.png', 'png', additional_items, true);
33 } 37 }
34 38
35 function testSaveJpegImageToClipboard(baseUrl) { 39 function testSaveJpegImageToClipboard(baseUrl) {
36 testSetImageDataClipboard(baseUrl + '/test.jpg', 'jpeg', true); 40 var additional_items = [];
41 testSetImageDataClipboard(
42 baseUrl + '/test.jpg', 'jpeg', additional_items, true);
37 } 43 }
38 44
39 function testSaveBadImageData(baseUrl) { 45 function testSaveBadImageData(baseUrl) {
40 testSetImageDataClipboard(baseUrl + '/redirect_target.gif', 'jpeg', false); 46 var additional_items = [];
47 testSetImageDataClipboard(
48 baseUrl + '/redirect_target.gif', 'jpeg', additional_items, false);
49 }
50
51 function testSavePngImageWithAdditionalDataToClipboard(baseUrl) {
52 var additional_items = [];
53 var text_item = {
54 type: 'text/plain',
55 data: 'Hello, world'
56 }
57 var html_item = {
58 type: 'text/html',
59 data: '<b>This is an html markup</b>'
60 }
61 additional_items.push(text_item);
62 additional_items.push(html_item);
63 testSetImageDataClipboard(
64 baseUrl + '/icon1.png', 'png', additional_items, true);
65 }
66
67 function testSavePngImageWithAdditionalDataToClipboardInvalidType(baseUrl) {
68 var additional_items = [];
69 var text_item = {
70 type: 'text/css',
71 data: 'Hello, world'
72 }
73 additional_items.push(text_item);
74 testSetImageDataClipboard(
75 baseUrl + '/icon1.png', 'png', additional_items, false);
76 }
77
78 function testSavePngImageWithAdditionalDataToClipboardDuplicateTypeItems(baseUrl ) {
79 var additional_items = [];
80 var text_item1 = {
81 type: 'text/plain',
82 data: 'Hello, world'
83 }
84 var text_item2 = {
85 type: 'text/plain',
86 data: 'Another text item'
87 }
88 additional_items.push(text_item1);
89 additional_items.push(text_item2);
90 testSetImageDataClipboard(
91 baseUrl + '/icon1.png', 'png', additional_items, false);
41 } 92 }
42 93
43 function bindTest(test, param) { 94 function bindTest(test, param) {
44 var result = test.bind(null, param); 95 var result = test.bind(null, param);
45 result.generatedName = test.name; 96 result.generatedName = test.name;
46 return result; 97 return result;
47 } 98 }
48 99
49 chrome.test.getConfig(function(config) { 100 chrome.test.getConfig(function(config) {
50 var baseUrl = 'http://localhost:' + config.testServer.port + '/extensions'; 101 var baseUrl = 'http://localhost:' + config.testServer.port + '/extensions';
51 chrome.test.runTests([ 102 chrome.test.runTests([
52 bindTest(testSavePngImageToClipboard, baseUrl), 103 bindTest(testSavePngImageToClipboard, baseUrl),
53 bindTest(testSaveJpegImageToClipboard, baseUrl), 104 bindTest(testSaveJpegImageToClipboard, baseUrl),
54 bindTest(testSaveBadImageData, baseUrl) 105 bindTest(testSaveBadImageData, baseUrl),
106 bindTest(testSavePngImageWithAdditionalDataToClipboard, baseUrl),
107 bindTest(testSavePngImageWithAdditionalDataToClipboardInvalidType, baseUrl),
108 bindTest(testSavePngImageWithAdditionalDataToClipboardDuplicateTypeItems,
109 baseUrl)
55 ]); 110 ]);
56 }) 111 })
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698