From 5c5a3822feae050d2b8e1dc42068e6557c56cd2f Mon Sep 17 00:00:00 2001 From: Ognjen Galic Date: Wed, 9 May 2018 10:10:51 +0200 Subject: [PATCH] Bug 1264557 - Add test cases for expand/collapse buttons. r=honza --HG-- extra : histedit_source : 0c3c6197f3fbce7ff7c3f3f7d90131775eceac4e --- devtools/client/jsonview/test/browser.ini | 1 + .../test/browser_jsonview_expand_collapse.js | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 devtools/client/jsonview/test/browser_jsonview_expand_collapse.js diff --git a/devtools/client/jsonview/test/browser.ini b/devtools/client/jsonview/test/browser.ini index 22d4522dad01..de359e19ba76 100644 --- a/devtools/client/jsonview/test/browser.ini +++ b/devtools/client/jsonview/test/browser.ini @@ -58,3 +58,4 @@ support-files = [browser_jsonview_theme.js] [browser_jsonview_url_linkification.js] [browser_jsonview_valid_json.js] +[browser_jsonview_expand_collapse.js] diff --git a/devtools/client/jsonview/test/browser_jsonview_expand_collapse.js b/devtools/client/jsonview/test/browser_jsonview_expand_collapse.js new file mode 100644 index 000000000000..2e6107fa3829 --- /dev/null +++ b/devtools/client/jsonview/test/browser_jsonview_expand_collapse.js @@ -0,0 +1,39 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const TEST_JSON_URL = URL_ROOT + "array_json.json"; +const EXPAND_THRESHOLD = 100 * 1024; + +add_task(async function() { + info("Test expand/collapse JSON started"); + + await addJsonViewTab(TEST_JSON_URL); + let browser = gBrowser.selectedBrowser, selector, countAfter, countBefore, json; + + /* Initial sanity check */ + countBefore = await getElementCount(".treeRow"); + ok(countBefore == 6, "There must be six rows"); + + /* Test the "Collapse All" button */ + selector = ".jsonPanelBox .toolbar button.collapse"; + await BrowserTestUtils.synthesizeMouseAtCenter(selector, {}, browser); + countAfter = await getElementCount(".treeRow"); + ok(countAfter == 3, "There must be three rows"); + + /* Test the "Expand All" button */ + selector = ".jsonPanelBox .toolbar button.expand"; + await BrowserTestUtils.synthesizeMouseAtCenter(selector, {}, browser); + countAfter = await getElementCount(".treeRow"); + ok(countAfter == 6, "There must be six expanded rows"); + + /* Test big file handling */ + json = JSON.stringify({data: Array(1e5).fill().map(x => "hoot"), status: "ok"}); + ok(json.length > EXPAND_THRESHOLD, "The generated JSON must be larger than 100kB"); + await addJsonViewTab("data:application/json," + json); + ok(document.querySelector(selector) == null, "The Expand All button must be gone"); + +});