browser_jsonview_copy_rawdata.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. "use strict";
  5. const TEST_JSON_URL = URL_ROOT + "simple_json.json";
  6. let jsonText = "{\"name\": \"value\"}\n";
  7. let prettyJson = "{\n \"name\": \"value\"\n}";
  8. add_task(function* () {
  9. info("Test copy raw data started");
  10. yield addJsonViewTab(TEST_JSON_URL);
  11. // Select the RawData tab
  12. yield selectJsonViewContentTab("rawdata");
  13. // Check displayed JSON
  14. let text = yield getElementText(".textPanelBox .data");
  15. is(text, jsonText, "Proper JSON must be displayed in DOM");
  16. let browser = gBrowser.selectedBrowser;
  17. // Verify JSON copy into the clipboard.
  18. yield waitForClipboardPromise(function setup() {
  19. BrowserTestUtils.synthesizeMouseAtCenter(
  20. ".textPanelBox .toolbar button.copy",
  21. {}, browser);
  22. }, jsonText);
  23. // Click 'Pretty Print' button
  24. yield BrowserTestUtils.synthesizeMouseAtCenter(
  25. ".textPanelBox .toolbar button.prettyprint",
  26. {}, browser);
  27. let prettyText = yield getElementText(".textPanelBox .data");
  28. prettyText = normalizeNewLines(prettyText);
  29. ok(prettyText.startsWith(prettyJson),
  30. "Pretty printed JSON must be displayed");
  31. // Verify JSON copy into the clipboard.
  32. yield waitForClipboardPromise(function setup() {
  33. BrowserTestUtils.synthesizeMouseAtCenter(
  34. ".textPanelBox .toolbar button.copy",
  35. {}, browser);
  36. }, function validator(value) {
  37. let str = normalizeNewLines(value);
  38. return str == prettyJson;
  39. });
  40. });