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

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

Issue 2379573008: Add SetImageData api to chrome.clipboard. (Closed)
Patch Set: Fix nits. Created 3 years, 11 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
new file mode 100644
index 0000000000000000000000000000000000000000..fc587c58b0cd0ed718ab8e130eaf8e063221626f
--- /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);
+ 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)
+ ]);
+})

Powered by Google App Engine
This is Rietveld 408576698