Bug 1543071 - Test remote Target.closeTarget and targetDestroyed event r=ochameau
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 19 Jun 2019 00:15:34 +0000
changeset 479201 b16a957f53f7be1b7414ba1c00d74328f640e7e2
parent 479200 430bb08ecd6872db4566caf39380685f53be78b5
child 479202 5fc7054fc05d67438c05a9adab43c6a7a217a07e
push id36173
push userrgurzau@mozilla.com
push dateWed, 19 Jun 2019 15:50:11 +0000
treeherdermozilla-central@10e3ed789e2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1543071
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543071 - Test remote Target.closeTarget and targetDestroyed event r=ochameau Depends on D35107 Differential Revision: https://phabricator.services.mozilla.com/D35108
remote/test/browser/browser.ini
remote/test/browser/browser_target_close.js
--- a/remote/test/browser/browser.ini
+++ b/remote/test/browser/browser.ini
@@ -15,8 +15,9 @@ support-files =
 [browser_runtime_evaluate.js]
 [browser_runtime_remote_objects.js]
 [browser_runtime_callFunctionOn.js]
 [browser_runtime_executionContext.js]
 skip-if = os == "mac" || (verify && os == 'win') # bug 1547961
 [browser_session.js]
 [browser_tabs.js]
 [browser_target.js]
+[browser_target_close.js]
new file mode 100644
--- /dev/null
+++ b/remote/test/browser/browser_target_close.js
@@ -0,0 +1,42 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const TEST_URI = "data:text/html;charset=utf-8,default-test-page";
+
+// Test the Target closeTarget method and the targetDestroyed event.
+add_task(async function() {
+  info("Start the CDP server");
+  RemoteAgent.listen(Services.io.newURI("http://localhost:9222"));
+  const CDP = await getCDP();
+  const client = await CDP({});
+
+  info("Setup Target domain");
+  const { Target } = client;
+  const targetCreated = Target.targetCreated();
+  Target.setDiscoverTargets({ discover: true });
+  await targetCreated;
+
+  info("Create a new tab and wait for the target to be created");
+  const otherTargetCreated = Target.targetCreated();
+  const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_URI);
+  const {targetInfo} = await otherTargetCreated;
+
+  const onTabClose = BrowserTestUtils.waitForEvent(tab, "TabClose");
+  const targetDestroyed = Target.targetDestroyed();
+
+  info("Close the target");
+  Target.closeTarget({ targetId: targetInfo.targetId });
+
+  await onTabClose;
+  ok(true, "Tab was closed");
+
+  await targetDestroyed;
+  ok(true, "Received the expected Target.targetDestroyed event");
+
+  await client.close();
+  ok(true, "The client is closed");
+
+  await RemoteAgent.close();
+});