Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cool#8292 browser, clipboard: fix navigator.clipboard error handling #8306

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions browser/src/map/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ L.Clipboard = L.Class.extend({
return;
}

this._afterCopyCutPaste(operation);
},

_afterCopyCutPaste: function(operation) {
var serial = this._clipboardSerial;
this._unoCommandForCopyCutPaste = null;

// try a hidden div
Expand Down Expand Up @@ -762,18 +767,25 @@ L.Clipboard = L.Class.extend({
return false;
}

if (isSpecial) {
this._navigatorClipboardPasteSpecial = true;
}
var that = this;
var clipboard = navigator.clipboard;
if (L.Browser.cypressTest) {
clipboard = this._dummyClipboard;
}
clipboard.read().then(function(clipboardContents) {
if (isSpecial) {
that._navigatorClipboardPasteSpecial = true;
}
that._navigatorClipboardReadCallback(clipboardContents);
}, function(error) {
window.app.console.log('navigator.clipboard.read() failed: ' + error.message);
if (isSpecial) {
// Fallback to the old code, as in filterExecCopyPaste().
that._openPasteSpecialPopup();
} else {
// Fallback to the old code, as in _execCopyCutPaste().
that._afterCopyCutPaste('paste');
}
});
return true;
},
Expand Down
35 changes: 31 additions & 4 deletions cypress_test/integration_tests/desktop/calc/clipboard_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Calc clipboard tests.', fu
helper.afterAll(testFileName, this.currentTest.state);
});

function setDummyClipboard(type, content, image = false) {
function setDummyClipboard(type, content, image = false, fail = false) {
cy.window().then(win => {
var app = win['0'].app;
var metaURL = encodeURIComponent(app.map._clip.getMetaURL());
Expand All @@ -42,8 +42,14 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Calc clipboard tests.', fu
clipboard._dummyClipboard = {
read: function() {
return {
then: function(resolve/*, reject*/) {
resolve(clipboardItems);
then: function(resolve, reject) {
if (fail) {
reject({
message: 'rejected',
});
} else {
resolve(clipboardItems);
}
},
};
},
Expand Down Expand Up @@ -120,7 +126,28 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Calc clipboard tests.', fu
cy.cGet('#home-paste-button').click();
cy.cGet('#w2ui-overlay-pastemenu tr[title="Ctrl + V"]').click();

// Then make the paste happened:
// Then make sure the paste happened:
cy.cGet('.leaflet-pane.leaflet-overlay-pane svg g').should('exist');
});

it('HTML paste, internal case failing', function() {
// Given a document with an A1 cell copied to the clipboard:
cy.cGet('#map').focus();
calcHelper.clickOnFirstCell();
helper.typeIntoInputField('input#addressInput', 'A1');
cy.window().then(win => {
var app = win['0'].app;
app.socket.sendMessage('uno .uno:Copy');
});
var html = '<div id="meta-origin" data-coolorigin="%META_URL%">ignored</div>';
setDummyClipboard('text/html', html, /*image=*/false, /*fail=*/true);

// When pasting the clipboard to B1, which fails:
helper.typeIntoInputField('input#addressInput', 'B1');
cy.cGet('#home-paste-button').click();
cy.cGet('#w2ui-overlay-pastemenu tr[title="Ctrl + V"]').click();

// Then make sure a warning popup is shown:
cy.cGet('#copy_paste_warning-box').should('exist');
});
});
Loading