From 7dd365784dfcad32e7086cbaf9dc4cc7712f9c33 Mon Sep 17 00:00:00 2001 From: Robo Date: Wed, 8 Jul 2020 15:02:42 -0700 Subject: [PATCH] fix: clipboard.readBuffer returning empty value (#24454) --- shell/common/api/electron_api_clipboard.cc | 5 ++--- spec/api-clipboard-spec.js | 24 ++-------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/shell/common/api/electron_api_clipboard.cc b/shell/common/api/electron_api_clipboard.cc index 4d3cabcb3138..28afc2dbb56e 100644 --- a/shell/common/api/electron_api_clipboard.cc +++ b/shell/common/api/electron_api_clipboard.cc @@ -71,9 +71,8 @@ void Clipboard::WriteBuffer(const std::string& format, base::span payload_span( reinterpret_cast(node::Buffer::Data(buffer)), node::Buffer::Length(buffer)); - writer.WriteData( - base::UTF8ToUTF16(ui::ClipboardFormatType::GetType(format).Serialize()), - mojo_base::BigBuffer(payload_span)); + writer.WriteData(base::UTF8ToUTF16(format), + mojo_base::BigBuffer(payload_span)); } void Clipboard::Write(const gin_helper::Dictionary& data, diff --git a/spec/api-clipboard-spec.js b/spec/api-clipboard-spec.js index 4ba2c3848897..243e38fa2916 100644 --- a/spec/api-clipboard-spec.js +++ b/spec/api-clipboard-spec.js @@ -112,17 +112,11 @@ describe('clipboard module', () => { }); }); - describe('clipboard.writeBuffer(format, buffer)', () => { + describe('clipboard.readBuffer(format)', () => { it('writes a Buffer for the specified format', function () { - if (process.platform !== 'darwin') { - // FIXME(alexeykuzmin): Skip the test. - // this.skip() - return; - } - const buffer = Buffer.from('writeBuffer', 'utf8'); clipboard.writeBuffer('public.utf8-plain-text', buffer); - expect(clipboard.readText()).to.equal('writeBuffer'); + expect(buffer.equals(clipboard.readBuffer('public.utf8-plain-text'))).to.equal(true); }); it('throws an error when a non-Buffer is specified', () => { @@ -131,18 +125,4 @@ describe('clipboard module', () => { }).to.throw(/buffer must be a node Buffer/); }); }); - - describe('clipboard.readBuffer(format)', () => { - before(function () { - if (process.platform !== 'darwin') { - this.skip(); - } - }); - - it('returns a Buffer of the content for the specified format', () => { - const buffer = Buffer.from('this is binary', 'utf8'); - clipboard.writeText(buffer.toString()); - expect(buffer.equals(clipboard.readBuffer('public.utf8-plain-text'))).to.equal(true); - }); - }); });