diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-06-15 15:35:32 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-06-15 15:35:32 +0200 |
commit | 5e5bf56f7be019478741a571aa433ff34f7ac928 (patch) | |
tree | e793792199cf1c052b7ce9b54f94b28ee7b97055 | |
parent | ad87ad529947e29adbee0dc2016069b71495a609 (diff) | |
parent | 67bdce8805063717bfdbc449e5d8974f32f288a2 (diff) | |
download | bugzilla-triage-5e5bf56f7be019478741a571aa433ff34f7ac928.tar.gz |
Merged in r187.
-rw-r--r-- | .hgignore | 1 | ||||
-rw-r--r-- | lib/clipboard.js | 17 | ||||
-rw-r--r-- | lib/rhbzpage.js | 5 | ||||
-rw-r--r-- | tests/test-clipboard.js | 42 |
4 files changed, 55 insertions, 10 deletions
diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..b6261c9 --- /dev/null +++ b/.hgignore @@ -0,0 +1 @@ +.*~ diff --git a/lib/clipboard.js b/lib/clipboard.js index e5b4ac8..b87c477 100644 --- a/lib/clipboard.js +++ b/lib/clipboard.js @@ -14,9 +14,8 @@ // https://wiki.mozilla.org/Labs/Jetpack/JEP/10 function getClipboard() { - const kClipboardContractID = "@mozilla.org/widget/clipboard;1"; - const kClipboardIID = Ci.nsIClipboard; - var clip = Cc[kClipboardContractID].getService(kClipboardIID); + var clip = Cc["@mozilla.org/widget/clipboard;1"]. + getService(Ci.nsIClipboard); if (!clip) { throw new Error("No access to the clipboard!"); } @@ -24,9 +23,8 @@ function getClipboard() { } function createTransferable() { - const kTransferableContractID = "@mozilla.org/widget/transferable;1"; - const kTransferableIID = Ci.nsITransferable - var trans = Cc[kTransferableContractID].createInstance(kTransferableIID); + var trans = Cc["@mozilla.org/widget/transferable;1"]. + createInstance(Ci.nsITransferable); if (!trans) { throw new Error("No access to the transfer object during the set of clipboard!"); } @@ -102,6 +100,7 @@ var setMethod = exports.set = function setMethod(content, flavor) { trans.setTransferData(mimeType, stuff, content.length * 2); clip.setData(trans, null, clip.kGlobalClipboard); + return true; }; function createSupportsWString() { @@ -118,11 +117,13 @@ var flavorsMethod = exports.getCurrentFlavors = function flavorsMethod() { "text/plain": "plain", "text/html": "html" }; - var flavourArray = createSupportsArray(); + var flavourArray = []; for (mime in possibleTypes) { var kSuppString = createSupportsWString(); kSuppString.data = mime; - flavourArray.AppendElement(kSuppString); + // FIXME Missing some kind of if (mime in flavors) ... + flavourArray.add(possibleTypes[mime]); } + return flavourArray; }; diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index c885699..c9d9b9f 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -6,6 +6,7 @@ var util = require("util"); var xrpc = require("xmlrpc"); var xhr = require("xhr"); +var clip = require("clipboard"); // var TriagedDistro = 13; // var NumberOfFrames = 7; // var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi"; @@ -589,7 +590,7 @@ RHBugzillaPage.prototype.queryForSelection = function() { let text = jetpack.selection.text; console.log("selection = " + text); if (!text) { - text = jetpack.clipboard.get(); + text = clip.get(); console.log("clipboard = " + text); } console.log("text = " + text); @@ -604,7 +605,7 @@ RHBugzillaPage.prototype.queryForSelection = function() { RHBugzillaPage.prototype.queryUpstream = function() { let text = jetpack.selection.text; if (!text) { - text = jetpack.clipboard.get(); + text = clip.get(); } if (text) { let text = encodeURIComponent(text.trim()); diff --git a/tests/test-clipboard.js b/tests/test-clipboard.js new file mode 100644 index 0000000..56cfeb8 --- /dev/null +++ b/tests/test-clipboard.js @@ -0,0 +1,42 @@ +/*global exports: false, require: false */ +/*jslint plusplus: false */ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php + +// TODO: add some failing tests as well +"use strict"; +var clip = require("clipboard"); + +var testString = "When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.\n"; +var pushkinTestString = "Byl pozdní večer první máj!\n\nАРИОН.\n\nНас было много на челне;\nИные парус напрягали,\nДругие дружно упирали\nВ глубь мощны веслы. В тишине\nНа руль склонясь, наш кормщик умный\nВ молчаньи правил грузный чолн;\nА я — беспечной веры полн —\nПловцам я пел … Вдруг лоно волн\nИзмял с налету вихорь шумный …\nПогиб и кормщик и пловец! –\nЛишь я, таинственный певец,\nНа берег выброшен грозою,\nЯ гимны прежние пою\nИ ризу влажную мою\nСушу на солнце под скалою.\n" + +// TODO: VERY insufficient test, needs to be extended +exports.ensureClipboardASCII = function ensureClipboard(test) { + var text = ""; + var req = clip.set(testString); + if (req) { + text = clip.get(); + if (!text) { + throw "Cannot read a string from the clipboard"; + } + } else { + throw "Cannot copy string to the clipboard;" + } + test.assertEqual(text, testString, + "checking set and get clipboard methods (ASCII)"); +}; + +exports.ensureClipboardUnicode = function ensureClipboard(test) { + var text = ""; + var req = clip.set(pushkinTestString); + if (req) { + text = clip.get(); + if (!text) { + throw "Cannot read a string from the clipboard"; + } + } else { + throw "Cannot copy string to the clipboard;" + } + test.assertEqual(text, pushkinTestString, + "checking set and get clipboard methods (Unicode)"); +}; |