Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6d75051a6babaeda4ab1508666d1eaab68f70acd |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js |
| @@ -0,0 +1,56 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Test clipboard extension api chrome.clipboard.onClipboardDataChanged event. |
| + |
| +var testSuccessCount = 0; |
| + |
| +function testSetImageDataClipboard(imageUrl, imageType, expectSucceed) { |
| + var oReq = new XMLHttpRequest(); |
| + oReq.open("GET", imageUrl, true); |
|
Devlin
2016/12/16 02:26:16
single quotes in js.
jennyz
2016/12/19 07:01:36
Done.
|
| + oReq.responseType = "arraybuffer"; |
| + |
| + oReq.onload = function (oEvent) { |
| + var arrayBuffer = oReq.response; |
| + var binaryString = ''; |
| + |
| + if (arrayBuffer) { |
| + chrome.clipboard.setImageData(arrayBuffer, imageType, function() { |
| + chrome.test.assertEq(expectSucceed, !chrome.runtime.lastError); |
| + chrome.test.succeed(); |
| + }); |
| + } else { |
| + chrome.test.fail('Failed to load the png image file'); |
| + } |
| + }; |
| + |
| + oReq.send(null); |
| +} |
| + |
| +function testSavePngImageToClipboard(baseUrl) { |
| + testSetImageDataClipboard(baseUrl + '/icon1.png', 'png', true); |
| +} |
| + |
| +function testSaveJpegImageToClipboard(baseUrl) { |
| + testSetImageDataClipboard(baseUrl + '/test.jpg', 'jpeg', true); |
| +} |
| + |
| +function testSaveBadImageData(baseUrl) { |
| + testSetImageDataClipboard(baseUrl + '/redirect_target.gif', 'jpeg', false); |
| +} |
| + |
| +function bindTest(test, param) { |
| + var result = test.bind(null, param); |
| + result.generatedName = test.name; |
| + return result; |
| +} |
| + |
| +chrome.test.getConfig(function(config) { |
| + var baseUrl = 'http://localhost:' + config.testServer.port + '/extensions'; |
| + chrome.test.runTests([ |
| + bindTest(testSavePngImageToClipboard, baseUrl), |
| + bindTest(testSaveJpegImageToClipboard, baseUrl), |
| + bindTest(testSaveBadImageData, baseUrl) |
| + ]); |
| +}) |