Can't copy to the native clipboard in xpcshell based tests

NEW
Unassigned

Status

()

Core
Widget
10 years ago
10 years ago

People

(Reporter: Ehsan, Unassigned)

Tracking

({testcase})

Trunk
x86
Windows Vista
testcase
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(URL)

(Reporter)

Description

10 years ago
The following code, if run inside an xpcshell based test, would run without any exceptions, but will not copy anything to the native clipboard:

function copy(str) {
  Cc["@mozilla.org/widget/clipboardhelper;1"].
  getService(Ci.nsIClipboardHelper).
  copyString(str);
}

Neither does this code:

function copy(str_to_copy) {
  let str = Cc["@mozilla.org/supports-string;1"].
            createInstance(Ci.nsISupportsString);
  str.data = str_to_copy;
  let trans = Cc["@mozilla.org/widget/transferable;1"].
              createInstance(Ci.nsITransferable);
  trans.addDataFlavor("text/unicode");
  trans.setTransferData("text/unicode", str, str_to_copy.length * 2);
  let clip = Cc["@mozilla.org/widget/clipboard;1"].
             getService(Ci.nsIClipboard);
  clip.setData(trans, null, Ci.nsIClipboard.kGlobalClipboard);
}

I faced this when I was trying to write the test for bug 462106 as an xpcshell test.  Eventually I gave up.

I tried debugging the clipboard implementation while running these two pieces of code, and I went on to make sure that OleSetClipboard is being called in both cases without error.  I'm not sure what's going wrong here at all.
Probably unlikely, but I don't suppose you're relying on our APIs to detect whether it was copied? Marco's discovered some issues with that in bug 474081.
(Reporter)

Comment 2

10 years ago
(In reply to comment #1)
> Probably unlikely, but I don't suppose you're relying on our APIs to detect
> whether it was copied? Marco's discovered some issues with that in bug 474081.

Nope, I see this problem with good ol' Ctrl+V.  :-)  The contents of the clipboard do not change.
You need to log in before you can comment on or make changes to this bug.