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

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: Address code review comments and add test cases. Created 4 years 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..a68fd17c9925360c3f67044b0ddb3a6a44b5cca1
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/clipboard/set_image_data/test.js
@@ -0,0 +1,67 @@
+// Copyright (c) 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() {
+ if (!chrome.runtime.lastError) {
Devlin 2016/12/09 15:23:51 Can't this big chunk just be chrome.test.assertEq(
jennyz 2016/12/14 01:15:36 Done.
+ if (expectSucceed)
+ chrome.test.succeed();
+ else
+ chrome.test.fail();
+ } else {
+ if (expectSucceed)
+ chrome.test.fail();
+ else
+ chrome.test.succeed();
+ }
+ testSuccessCount++;
+ chrome.test.sendMessage('test success ' + testSuccessCount);
Devlin 2016/12/09 15:23:51 why do we need these messages? The test system wi
jennyz 2016/12/14 01:15:36 Done.
+ });
+ } else {
+ chrome.test.fail('Failed to load the png image file');
+ }
+ };
+
+ oReq.send(null);
+}
+
+function testSavePngImageToClipboard(baseUrl) {
+ testSetImageDataClipboard(baseUrl + '/penguin.png', 'png', true);
Devlin 2016/12/09 15:23:52 Rietveld won't let me comment on the pictures, so
jennyz 2016/12/14 01:15:36 Good point. Changed to use the existing image file
Devlin 2016/12/16 02:26:15 I see we're still adding the other images, though?
jennyz 2016/12/19 07:01:36 The other images from copied from existing image f
Devlin 2016/12/19 23:08:22 Latest patch set: https://codereview.chromium.org/
jennyz 2016/12/20 22:16:54 I have removed the previously added image files.
+}
+
+function testSaveJpegImageToClipboard(baseUrl) {
+ testSetImageDataClipboard(baseUrl + '/panda.jpg', 'jpeg', true);
+}
+
+function testSaveBadImageData(baseUrl) {
+ testSetImageDataClipboard(baseUrl + '/star.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