summaryrefslogtreecommitdiffstats
path: root/devtools/client/jsonview/test/doc_frame_script.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/client/jsonview/test/doc_frame_script.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/client/jsonview/test/doc_frame_script.js')
-rw-r--r--devtools/client/jsonview/test/doc_frame_script.js98
1 files changed, 98 insertions, 0 deletions
diff --git a/devtools/client/jsonview/test/doc_frame_script.js b/devtools/client/jsonview/test/doc_frame_script.js
new file mode 100644
index 000000000..3d19b3433
--- /dev/null
+++ b/devtools/client/jsonview/test/doc_frame_script.js
@@ -0,0 +1,98 @@
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* globals Services, sendAsyncMessage, addMessageListener */
+
+// XXX Some helper API could go to:
+// testing/mochitest/tests/SimpleTest/AsyncContentUtils.js
+// (or at least to share test API in devtools)
+
+// Set up a dummy environment so that EventUtils works. We need to be careful to
+// pass a window object into each EventUtils method we call rather than having
+// it rely on the |window| global.
+let EventUtils = {};
+EventUtils.window = content;
+EventUtils.parent = EventUtils.window;
+EventUtils._EU_Ci = Components.interfaces; // eslint-disable-line
+EventUtils._EU_Cc = Components.classes; // eslint-disable-line
+EventUtils.navigator = content.navigator;
+EventUtils.KeyboardEvent = content.KeyboardEvent;
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochikit/content/tests/SimpleTest/EventUtils.js", EventUtils);
+
+/**
+ * When the JSON View is done rendering it triggers custom event
+ * "JSONViewInitialized", then the Test:TestPageProcessingDone message
+ * will be sent to the parent process for tests to wait for this event
+ * if needed.
+ */
+content.addEventListener("JSONViewInitialized", () => {
+ sendAsyncMessage("Test:JsonView:JSONViewInitialized");
+}, false);
+
+addMessageListener("Test:JsonView:GetElementCount", function (msg) {
+ let {selector} = msg.data;
+ let nodeList = content.document.querySelectorAll(selector);
+ sendAsyncMessage(msg.name, {count: nodeList.length});
+});
+
+addMessageListener("Test:JsonView:GetElementText", function (msg) {
+ let {selector} = msg.data;
+ let element = content.document.querySelector(selector);
+ let text = element ? element.textContent : null;
+ sendAsyncMessage(msg.name, {text: text});
+});
+
+addMessageListener("Test:JsonView:FocusElement", function (msg) {
+ let {selector} = msg.data;
+ let element = content.document.querySelector(selector);
+ if (element) {
+ element.focus();
+ }
+ sendAsyncMessage(msg.name);
+});
+
+addMessageListener("Test:JsonView:SendString", function (msg) {
+ let {selector, str} = msg.data;
+ if (selector) {
+ let element = content.document.querySelector(selector);
+ if (element) {
+ element.focus();
+ }
+ }
+
+ EventUtils.sendString(str, content);
+
+ sendAsyncMessage(msg.name);
+});
+
+addMessageListener("Test:JsonView:WaitForFilter", function (msg) {
+ let firstRow = content.document.querySelector(
+ ".jsonPanelBox .treeTable .treeRow");
+
+ // Check if the filter is already set.
+ if (firstRow.classList.contains("hidden")) {
+ sendAsyncMessage(msg.name);
+ return;
+ }
+
+ // Wait till the first row has 'hidden' class set.
+ let observer = new content.MutationObserver(function (mutations) {
+ for (let i = 0; i < mutations.length; i++) {
+ let mutation = mutations[i];
+ if (mutation.attributeName == "class") {
+ if (firstRow.classList.contains("hidden")) {
+ observer.disconnect();
+ sendAsyncMessage(msg.name);
+ break;
+ }
+ }
+ }
+ });
+
+ observer.observe(firstRow, { attributes: true });
+});