Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Test clipboard extension api chrome.clipboard.onClipboardDataChanged event. | |
| 6 | |
| 7 var testSuccessCount = 0; | |
| 8 | |
| 9 function testSetImageDataClipboard(imageUrl, imageType, expectSucceed) { | |
| 10 var oReq = new XMLHttpRequest(); | |
| 11 oReq.open("GET", imageUrl, true); | |
|
Devlin
2016/12/16 02:26:16
single quotes in js.
jennyz
2016/12/19 07:01:36
Done.
| |
| 12 oReq.responseType = "arraybuffer"; | |
| 13 | |
| 14 oReq.onload = function (oEvent) { | |
| 15 var arrayBuffer = oReq.response; | |
| 16 var binaryString = ''; | |
| 17 | |
| 18 if (arrayBuffer) { | |
| 19 chrome.clipboard.setImageData(arrayBuffer, imageType, function() { | |
| 20 chrome.test.assertEq(expectSucceed, !chrome.runtime.lastError); | |
| 21 chrome.test.succeed(); | |
| 22 }); | |
| 23 } else { | |
| 24 chrome.test.fail('Failed to load the png image file'); | |
| 25 } | |
| 26 }; | |
| 27 | |
| 28 oReq.send(null); | |
| 29 } | |
| 30 | |
| 31 function testSavePngImageToClipboard(baseUrl) { | |
| 32 testSetImageDataClipboard(baseUrl + '/icon1.png', 'png', true); | |
| 33 } | |
| 34 | |
| 35 function testSaveJpegImageToClipboard(baseUrl) { | |
| 36 testSetImageDataClipboard(baseUrl + '/test.jpg', 'jpeg', true); | |
| 37 } | |
| 38 | |
| 39 function testSaveBadImageData(baseUrl) { | |
| 40 testSetImageDataClipboard(baseUrl + '/redirect_target.gif', 'jpeg', false); | |
| 41 } | |
| 42 | |
| 43 function bindTest(test, param) { | |
| 44 var result = test.bind(null, param); | |
| 45 result.generatedName = test.name; | |
| 46 return result; | |
| 47 } | |
| 48 | |
| 49 chrome.test.getConfig(function(config) { | |
| 50 var baseUrl = 'http://localhost:' + config.testServer.port + '/extensions'; | |
| 51 chrome.test.runTests([ | |
| 52 bindTest(testSavePngImageToClipboard, baseUrl), | |
| 53 bindTest(testSaveJpegImageToClipboard, baseUrl), | |
| 54 bindTest(testSaveBadImageData, baseUrl) | |
| 55 ]); | |
| 56 }) | |
| OLD | NEW |