PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/packages/addon-kit/tests/test-clipboard.js

https://github.com/CoderPuppy/chromeless
JavaScript | 55 lines | 40 code | 4 blank | 11 comment | 0 complexity | 33498e6538d9abee0316cf1cf2714573 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. // Test the typical use case, setting & getting with no flavors specified
  2. exports.testWithNoFlavor = function(test) {
  3. var contents = "hello there";
  4. var flavor = "text";
  5. var fullFlavor = "text/unicode";
  6. var clip = require("clipboard");
  7. // Confirm we set the clipboard
  8. test.assert(clip.set(contents));
  9. // Confirm flavor is set
  10. test.assertEqual(clip.currentFlavors[0], flavor);
  11. // Confirm we set the clipboard
  12. test.assertEqual(clip.get(), contents);
  13. // Confirm we can get the clipboard using the flavor
  14. test.assertEqual(clip.get(flavor), contents);
  15. // Confirm we can still get the clipboard using the full flavor
  16. test.assertEqual(clip.get(fullFlavor), contents);
  17. };
  18. // Test the slightly less common case where we specify the flavor
  19. exports.testWithFlavor = function(test) {
  20. var contents = "<b>hello there</b>";
  21. var flavor = "html";
  22. var fullFlavor = "text/html";
  23. var clip = require("clipboard");
  24. test.assert(clip.set(contents, flavor));
  25. test.assertEqual(clip.currentFlavors[0], flavor);
  26. // Confirm default flavor returns null
  27. test.assertEqual(clip.get(), null);
  28. test.assertEqual(clip.get(flavor), contents);
  29. test.assertEqual(clip.get(fullFlavor), contents);
  30. };
  31. // Test that the typical case still works when we specify the flavor to set
  32. exports.testWithRedundantFlavor = function(test) {
  33. var contents = "<b>hello there</b>";
  34. var flavor = "text";
  35. var fullFlavor = "text/unicode";
  36. var clip = require("clipboard");
  37. test.assert(clip.set(contents, flavor));
  38. test.assertEqual(clip.currentFlavors[0], flavor);
  39. test.assertEqual(clip.get(), contents);
  40. test.assertEqual(clip.get(flavor), contents);
  41. test.assertEqual(clip.get(fullFlavor), contents);
  42. };
  43. exports.testNotInFlavor = function(test) {
  44. var contents = "hello there";
  45. var flavor = "html";
  46. var clip = require("clipboard");
  47. test.assert(clip.set(contents));
  48. // If there's nothing on the clipboard with this flavor, should return null
  49. test.assertEqual(clip.get(flavor), null);
  50. };
  51. // TODO: Test error cases.