diff --git a/js/common.js b/js/common.js
index 5ad72afd..346e1423 100644
--- a/js/common.js
+++ b/js/common.js
@@ -152,3 +152,22 @@ exports.urlToString = function (url) {
encodeURI(url.query.join('').replace(/^&+|&+$/gm,'')) : '') +
(url.fragment ? '#' + encodeURI(url.fragment) : '');
};
+
+exports.enableClipboard = function () {
+ navigator.clipboard = (function () {
+ let savedText = "";
+
+ async function writeText(text) {
+ savedText = text;
+ };
+
+ async function readText() {
+ return savedText;
+ };
+
+ return {
+ writeText,
+ readText,
+ };
+ })();
+};
diff --git a/js/privatebin.js b/js/privatebin.js
index a06d80b0..b67de8ad 100644
--- a/js/privatebin.js
+++ b/js/privatebin.js
@@ -5459,9 +5459,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
copyIcon,
successIcon,
shortcutHint,
- url,
- testMode,
- testClipboard;
+ url;
/**
* Handle copy to clipboard button click
@@ -5542,11 +5540,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
* @function
*/
function saveToClipboard(text) {
- if (testMode) {
- testClipboard = text;
- } else {
- navigator.clipboard.writeText(text);
- }
+ navigator.clipboard.writeText(text);
};
/**
@@ -5612,35 +5606,6 @@ jQuery.PrivateBin = (function($, RawDeflate) {
url = newUrl;
};
- /**
- * Enable test mode, using for unit tests
- *
- * @name CopyToClipboard.testMode
- * @function
- */
- me.enableTestMode = function () {
- testMode = true;
- };
-
- /**
- * Read text from user's clipboard
- *
- * @name CopyToClipboard.readFromClipboard
- * @function
- * @returns {string}
- */
- me.readFromClipboard = function () {
- let clipboardData = "";
-
- if (testMode) {
- clipboardData = testClipboard;
- } else {
- clipboardData = navigator.clipboard.readText();
- }
-
- return clipboardData;
- };
-
/**
* Initialize
*
diff --git a/js/test/CopyToClipboard.js b/js/test/CopyToClipboard.js
index 00ec7438..9d2df2f1 100644
--- a/js/test/CopyToClipboard.js
+++ b/js/test/CopyToClipboard.js
@@ -1,12 +1,13 @@
'use strict';
-var common = require('../common');
+const common = require('../common');
describe('CopyToClipboard', function() {
this.timeout(30000);
describe ('Copy paste co clipboard', function () {
- jsc.property('Copy with button click', common.jscFormats(), 'nestring', function (format, text) {
+ jsc.property('Copy with button click', common.jscFormats(), 'nestring', async function (format, text) {
var clean = jsdom();
+ common.enableClipboard();
$('body').html(
'
+++ no paste text ' +
@@ -23,23 +24,23 @@ describe('CopyToClipboard', function() {
$.PrivateBin.PasteViewer.run();
$.PrivateBin.CopyToClipboard.init();
- $.PrivateBin.CopyToClipboard.enableTestMode();
$('#prettyMessageCopyBtn').trigger('click');
-
- const copiedText = $.PrivateBin.CopyToClipboard.readFromClipboard();
+
+ const savedToClipboardText = await navigator.clipboard.readText();
clean();
- return text === copiedText;
+ return text === savedToClipboardText;
});
/**
* Unfortunately in JSVerify impossible to check if copy with shortcut when user selected some text on the page
* (the copy paste to clipboard should not work in this case) due to lucking window.getSelection() in jsdom.
*/
- jsc.property('Copy with keyboard shortcut', common.jscFormats(), 'nestring', function (format, text) {
+ jsc.property('Copy with keyboard shortcut', common.jscFormats(), 'nestring', async function (format, text) {
var clean = jsdom();
+ common.enableClipboard();
$('body').html(
'
+++ no paste text ' +
@@ -56,11 +57,10 @@ describe('CopyToClipboard', function() {
$.PrivateBin.PasteViewer.run();
$.PrivateBin.CopyToClipboard.init();
- $.PrivateBin.CopyToClipboard.enableTestMode();
$('body').trigger('copy');
- const copiedTextWithoutSelectedText = $.PrivateBin.CopyToClipboard.readFromClipboard();
+ const copiedTextWithoutSelectedText = await navigator.clipboard.readText();
clean();
@@ -69,18 +69,18 @@ describe('CopyToClipboard', function() {
});
- jsc.property('Copy link to clipboard', 'nestring', function (text) {
+ jsc.property('Copy link to clipboard', 'nestring', async function (text) {
var clean = jsdom();
+ common.enableClipboard();
$('body').html(' ');
$.PrivateBin.CopyToClipboard.init();
- $.PrivateBin.CopyToClipboard.enableTestMode();
$.PrivateBin.CopyToClipboard.setUrl(text);
$('#copyLink').trigger('click');
- const copiedText = $.PrivateBin.CopyToClipboard.readFromClipboard();
+ const copiedText = await navigator.clipboard.readText();
clean();
diff --git a/lib/Configuration.php b/lib/Configuration.php
index b09c6433..d181cf99 100644
--- a/lib/Configuration.php
+++ b/lib/Configuration.php
@@ -108,7 +108,7 @@ class Configuration
'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==',
'js/legacy.js' => 'sha512-UxW/TOZKon83n6dk/09GsYKIyeO5LeBHokxyIq+r7KFS5KMBeIB/EM7NrkVYIezwZBaovnyNtY2d9tKFicRlXg==',
'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==',
- 'js/privatebin.js' => 'sha512-RbRvz3FPpNO23J/RQUvPfH118Yugz0nBSsqGnMlbr0rfTYR0G0/PIhJTymlR8P2p3sdmtd80m1fUrbdY7/gbEA==',
+ 'js/privatebin.js' => 'sha512-POa+8KNXFFwJFsqp7r9APmR5Rc1w2l363y+OScSzLCySrHN7UhOOgt1VH/o8mVddFvvUozj3FZVmdkTxRlrS5g==',
'js/purify-3.2.3.js' => 'sha512-m8Wa/I//YoYMiIahBxDDwYfTnycl+i2DwH58nR8ps1o4KWqXzF8k1K4qHDgAz2HSQFNCNNKH/Qcbfu/jLOuhuQ==',
'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==',
'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',