summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/test/browser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/client/aboutdebugging/test/browser
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/aboutdebugging/test/browser')
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser.ini167
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_console.js440
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_debugger.js87
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_inspector.js86
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_nobg.js78
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js246
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_reload.js136
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_storage.js90
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_toolbox.js122
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_actions_and_status.js153
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_terminate_on_idle.js200
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_manifest_url.js73
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_popup_picker.js99
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_remote_runtime.js145
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_addon_buttons.js116
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_id_message.js70
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_error.js89
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_path.js65
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_reload_error.js68
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_warnings.js49
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_networklocations.js103
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_toggle_usb_devices.js81
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connection_prompt_setting.js70
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js62
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js40
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_empty.js83
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js72
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtools.js51
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_breakpoint.js74
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu.js102
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu_markupview.js45
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_focus.js122
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_menubar.js74
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_back_forward.js63
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_reload_button.js53
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_to_url.js56
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_reload.js74
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_shortcuts.js106
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_splitconsole_key.js46
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_target_destroyed.js36
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_tooltip_markupview.js102
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_zoom.js65
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js141
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_node_picker.js83
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_hidden_addons.js106
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_message_close.js82
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_navigate.js112
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js91
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_category.js53
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main.js87
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main_local.js44
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_profiler_dialog.js238
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_runtime_page_runtime_info.js62
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_sidebar.js34
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_routes.js114
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_rtl.js62
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_compatibility_warning.js90
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js65
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_remote_runtime_buttons.js56
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_usbclient_closed.js109
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_network_runtime.js52
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_page_with_serviceworker.js78
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_console.js131
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_fetch_flag.js68
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_not_compatible.js124
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_push.js61
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_pushservice_url.js118
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_runtime-page.js70
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_start.js71
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_status.js104
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_timeout.js104
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_unregister.js48
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_connection_state.js192
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js43
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime.js38
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_connect.js54
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js50
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_select.js44
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_status.js50
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unavailable_runtime.js65
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unplugged_device.js69
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_favicons.js57
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_navigate.js31
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_zombietab.js108
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_basic.js46
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_connection_attempt.js274
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_inspect.js67
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_navigate.js67
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_actions.js97
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_connected_details.js69
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates.js154
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_multi.js111
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_network.js90
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox.js121
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_runtime_info.js54
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_worker_inspection.js68
-rw-r--r--devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_workers_remote_runtime.js160
-rw-r--r--devtools/client/aboutdebugging/test/browser/empty.html1
-rw-r--r--devtools/client/aboutdebugging/test/browser/head.js505
-rw-r--r--devtools/client/aboutdebugging/test/browser/helper-adb.js59
-rw-r--r--devtools/client/aboutdebugging/test/browser/helper-addons.js262
-rw-r--r--devtools/client/aboutdebugging/test/browser/helper-collapsibilities.js54
-rw-r--r--devtools/client/aboutdebugging/test/browser/helper-mocks.js262
-rw-r--r--devtools/client/aboutdebugging/test/browser/helper-real-usb.js54
-rw-r--r--devtools/client/aboutdebugging/test/browser/helper-serviceworker.js111
-rw-r--r--devtools/client/aboutdebugging/test/browser/helper-telemetry.js115
-rw-r--r--devtools/client/aboutdebugging/test/browser/mocks/helper-adb-mock.js137
-rw-r--r--devtools/client/aboutdebugging/test/browser/mocks/helper-client-wrapper-mock.js138
-rw-r--r--devtools/client/aboutdebugging/test/browser/mocks/helper-runtime-client-factory-mock.js76
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-json/manifest.json1
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-property/manifest.json23
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/doc_aboutdebugging_devtoolstoolbox_breakpoint.html9
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/packaged-extension/packaged-extension.xpibin0 -> 4580 bytes
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/real/usb-runtimes-sample.json14
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/script_aboutdebugging_devtoolstoolbox_breakpoint.js12
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.html38
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.js31
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.html30
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.js1
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.html30
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.js6
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html61
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.js35
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux.xpibin0 -> 495578 bytes
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux64.xpibin0 -> 824421 bytes
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-mac64.xpibin0 -> 782572 bytes
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-win32.xpibin0 -> 713900 bytes
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/manifest.json13
-rw-r--r--devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/script.js8
-rw-r--r--devtools/client/aboutdebugging/test/browser/test-tab-favicons.html8
130 files changed, 11090 insertions, 0 deletions
diff --git a/devtools/client/aboutdebugging/test/browser/browser.ini b/devtools/client/aboutdebugging/test/browser/browser.ini
new file mode 100644
index 0000000000..4b471537bc
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser.ini
@@ -0,0 +1,167 @@
+[DEFAULT]
+tags = devtools
+subsuite = devtools
+prefs =
+ # showHiddenAddons has different values depending on the build flags, ensure consistent
+ # test behavior by always setting it to false.
+ devtools.aboutdebugging.showHiddenAddons=false
+support-files =
+ empty.html
+ head.js
+ helper-adb.js
+ helper-addons.js
+ helper-collapsibilities.js
+ helper-mocks.js
+ helper-real-usb.js
+ helper-serviceworker.js
+ helper-telemetry.js
+ mocks/*
+ resources/bad-extensions/*
+ resources/packaged-extension/*
+ resources/service-workers/*
+ resources/test-adb-extension/*
+ resources/test-temporary-extension/*
+ resources/doc_aboutdebugging_devtoolstoolbox_breakpoint.html
+ resources/script_aboutdebugging_devtoolstoolbox_breakpoint.js
+ test-tab-favicons.html
+ !/devtools/client/debugger/test/mochitest/shared-head.js
+ !/devtools/client/shared/test/shared-head.js
+ !/devtools/client/shared/test/telemetry-test-helpers.js
+ !/devtools/client/webconsole/test/browser/shared-head.js
+
+[browser_aboutdebugging_addons_debug_console.js]
+tags = webextensions
+[browser_aboutdebugging_addons_debug_debugger.js]
+tags = webextensions
+[browser_aboutdebugging_addons_debug_inspector.js]
+tags = webextensions
+[browser_aboutdebugging_addons_debug_nobg.js]
+tags = webextensions
+[browser_aboutdebugging_addons_debug_popup.js]
+skip-if =
+ verify && debug # verify: crashes on shutdown, timeouts
+ os == "linux" && debug # linux debug Bug 1299001
+ win10_2004 && !debug # Bug 1744778
+tags = webextensions
+[browser_aboutdebugging_addons_debug_reload.js]
+tags = webextensions
+[browser_aboutdebugging_addons_debug_storage.js]
+tags = webextensions
+[browser_aboutdebugging_addons_debug_toolbox.js]
+tags = webextensions
+[browser_aboutdebugging_addons_eventpage_actions_and_status.js]
+tags = webextensions
+[browser_aboutdebugging_addons_eventpage_terminate_on_idle.js]
+tags = webextensions
+[browser_aboutdebugging_addons_manifest_url.js]
+skip-if =
+ os == "mac" && debug # ADB start() fails on linux 32, see Bug 1499638, macosx1014 debug due to 1514751
+[browser_aboutdebugging_addons_remote_runtime.js]
+[browser_aboutdebugging_addons_temporary_addon_buttons.js]
+skip-if =
+ os == "win" # On windows the AddonManager locks the XPI file loaded as a temporary extension and we can not test the reload of the extension.
+[browser_aboutdebugging_addons_temporary_id_message.js]
+[browser_aboutdebugging_addons_temporary_install_error.js]
+[browser_aboutdebugging_addons_temporary_install_path.js]
+[browser_aboutdebugging_addons_temporary_reload_error.js]
+skip-if =
+ os == "win" # On windows the AddonManager locks the XPI file loaded as a temporary extension and we can not test the reload of the extension.
+[browser_aboutdebugging_addons_warnings.js]
+[browser_aboutdebugging_connect_networklocations.js]
+[browser_aboutdebugging_connect_toggle_usb_devices.js]
+[browser_aboutdebugging_connection_prompt_setting.js]
+[browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js]
+[browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js]
+[browser_aboutdebugging_debug-target-pane_empty.js]
+[browser_aboutdebugging_debug-target-pane_usb_runtime.js]
+[browser_aboutdebugging_devtools.js]
+[browser_aboutdebugging_devtoolstoolbox_breakpoint.js]
+[browser_aboutdebugging_devtoolstoolbox_contextmenu.js]
+[browser_aboutdebugging_devtoolstoolbox_contextmenu_markupview.js]
+[browser_aboutdebugging_devtoolstoolbox_focus.js]
+[browser_aboutdebugging_devtoolstoolbox_menubar.js]
+[browser_aboutdebugging_devtoolstoolbox_navigate_back_forward.js]
+[browser_aboutdebugging_devtoolstoolbox_navigate_reload_button.js]
+[browser_aboutdebugging_devtoolstoolbox_navigate_to_url.js]
+[browser_aboutdebugging_devtoolstoolbox_reload.js]
+skip-if =
+ verify
+ ccov
+ os == "linux" && debug #bug 1544828, test loads the toolbox 2 times for each panel, might timeout or OOM
+[browser_aboutdebugging_devtoolstoolbox_shortcuts.js]
+skip-if =
+ ccov
+ os == "linux" # Bug 1521349, Bug 1548015, Bug 1544828
+[browser_aboutdebugging_devtoolstoolbox_splitconsole_key.js]
+[browser_aboutdebugging_devtoolstoolbox_target_destroyed.js]
+skip-if =
+ debug
+ asan # This test leaks. See bug 1529005
+[browser_aboutdebugging_devtoolstoolbox_tooltip_markupview.js]
+[browser_aboutdebugging_devtoolstoolbox_zoom.js]
+[browser_aboutdebugging_fenix_runtime_display.js]
+[browser_aboutdebugging_fenix_runtime_node_picker.js]
+[browser_aboutdebugging_message_close.js]
+[browser_aboutdebugging_navigate.js]
+[browser_aboutdebugging_persist_connection.js]
+[browser_aboutdebugging_addons_popup_picker.js]
+[browser_aboutdebugging_process_category.js]
+[browser_aboutdebugging_process_main.js]
+[browser_aboutdebugging_process_main_local.js]
+skip-if = debug
+[browser_aboutdebugging_profiler_dialog.js]
+support-files =
+ !/devtools/client/performance-new/test/browser/helpers.js
+[browser_aboutdebugging_real_usb_runtime_page_runtime_info.js]
+[browser_aboutdebugging_real_usb_sidebar.js]
+[browser_aboutdebugging_routes.js]
+[browser_aboutdebugging_rtl.js]
+[browser_aboutdebugging_runtime_compatibility_warning.js]
+[browser_aboutdebugging_runtime_disconnect_remote_runtime.js]
+[browser_aboutdebugging_runtime_remote_runtime_buttons.js]
+[browser_aboutdebugging_runtime_usbclient_closed.js]
+[browser_aboutdebugging_select_network_runtime.js]
+[browser_aboutdebugging_select_page_with_serviceworker.js]
+[browser_aboutdebugging_serviceworker_console.js]
+[browser_aboutdebugging_serviceworker_fetch_flag.js]
+skip-if =
+ os == "win" && debug
+ os == "mac"
+ os == "linux" #Bug 1529824
+[browser_aboutdebugging_serviceworker_not_compatible.js]
+[browser_aboutdebugging_serviceworker_push.js]
+[browser_aboutdebugging_serviceworker_pushservice_url.js]
+[browser_aboutdebugging_serviceworker_runtime-page.js]
+[browser_aboutdebugging_serviceworker_start.js]
+[browser_aboutdebugging_serviceworker_status.js]
+[browser_aboutdebugging_serviceworker_timeout.js]
+skip-if =
+ debug
+ asan # Frequent intermittent failures, Bug 1522800
+[browser_aboutdebugging_serviceworker_unregister.js]
+[browser_aboutdebugging_sidebar_connection_state.js]
+[browser_aboutdebugging_sidebar_network_runtimes.js]
+[browser_aboutdebugging_sidebar_usb_runtime.js]
+[browser_aboutdebugging_sidebar_usb_runtime_connect.js]
+[browser_aboutdebugging_sidebar_usb_runtime_refresh.js]
+[browser_aboutdebugging_sidebar_usb_runtime_select.js]
+[browser_aboutdebugging_sidebar_usb_status.js]
+[browser_aboutdebugging_sidebar_usb_unavailable_runtime.js]
+[browser_aboutdebugging_sidebar_usb_unplugged_device.js]
+[browser_aboutdebugging_hidden_addons.js]
+[browser_aboutdebugging_tab_favicons.js]
+[browser_aboutdebugging_tab_navigate.js]
+[browser_aboutdebugging_tab_zombietab.js]
+[browser_aboutdebugging_telemetry_basic.js]
+[browser_aboutdebugging_telemetry_connection_attempt.js]
+[browser_aboutdebugging_telemetry_inspect.js]
+[browser_aboutdebugging_telemetry_navigate.js]
+[browser_aboutdebugging_telemetry_runtime_actions.js]
+[browser_aboutdebugging_telemetry_runtime_connected_details.js]
+[browser_aboutdebugging_telemetry_runtime_updates.js]
+[browser_aboutdebugging_telemetry_runtime_updates_multi.js]
+[browser_aboutdebugging_telemetry_runtime_updates_network.js]
+[browser_aboutdebugging_thisfirefox.js]
+[browser_aboutdebugging_thisfirefox_runtime_info.js]
+[browser_aboutdebugging_thisfirefox_worker_inspection.js]
+[browser_aboutdebugging_workers_remote_runtime.js]
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_console.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_console.js
new file mode 100644
index 0000000000..1ed16dd1b0
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_console.js
@@ -0,0 +1,440 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// There are shutdown issues for which multiple rejections are left uncaught.
+// See bug 1018184 for resolving these issues.
+const { PromiseTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PromiseTestUtils.sys.mjs"
+);
+PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
+
+// Avoid test timeouts that can occur while waiting for the "addon-console-works" message.
+requestLongerTimeout(2);
+
+const ADDON_ID = "test-devtools-webextension@mozilla.org";
+const ADDON_NAME = "test-devtools-webextension";
+
+const OTHER_ADDON_ID = "other-test-devtools-webextension@mozilla.org";
+const OTHER_ADDON_NAME = "other-test-devtools-webextension";
+
+const POPUPONLY_ADDON_ID = "popuponly-test-devtools-webextension@mozilla.org";
+const POPUPONLY_ADDON_NAME = "popuponly-test-devtools-webextension";
+
+const BACKGROUND_ADDON_ID = "background-test-devtools-webextension@mozilla.org";
+const BACKGROUND_ADDON_NAME = "background-test-devtools-webextension";
+
+/**
+ * This test file ensures that the webextension addon developer toolbox:
+ * - when the debug button is clicked on a webextension, the opened toolbox
+ * has a working webconsole with the background page as default target;
+ */
+add_task(async function testWebExtensionsToolboxWebConsole() {
+ await pushPref("devtools.webconsole.filter.css", true);
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ window.myWebExtensionAddonFunction = function () {
+ console.log(
+ "Background page function called",
+ this.browser.runtime.getManifest()
+ );
+ };
+
+ const style = document.createElement("style");
+ style.textContent = "* { color: error; }";
+ document.documentElement.appendChild(style);
+
+ throw new Error("Background page exception");
+ },
+ extraProperties: {
+ browser_action: {
+ default_title: "WebExtension Popup Debugging",
+ default_popup: "popup.html",
+ default_area: "navbar",
+ },
+ },
+ files: {
+ "popup.html": `<!DOCTYPE html>
+ <html>
+ <head>
+ <meta charset="utf-8">
+ <script src="popup.js"></script>
+ </head>
+ <body>
+ Popup
+ </body>
+ </html>
+ `,
+ "popup.js": function () {
+ console.log("Popup log");
+
+ const style = document.createElement("style");
+ style.textContent = "* { color: popup-error; }";
+ document.documentElement.appendChild(style);
+
+ throw new Error("Popup exception");
+ },
+ },
+ id: ADDON_ID,
+ name: ADDON_NAME,
+ },
+ document
+ );
+
+ // Install another addon in order to ensure we don't get its logs
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ console.log("Other addon log");
+
+ const style = document.createElement("style");
+ style.textContent = "* { background-color: error; }";
+ document.documentElement.appendChild(style);
+
+ throw new Error("Other addon exception");
+ },
+ extraProperties: {
+ browser_action: {
+ default_title: "Other addon popup",
+ default_popup: "other-popup.html",
+ default_area: "navbar",
+ },
+ },
+ files: {
+ "other-popup.html": `<!DOCTYPE html>
+ <html>
+ <head>
+ <meta charset="utf-8">
+ <script src="other-popup.js"></script>
+ </head>
+ <body>
+ Other popup
+ </body>
+ </html>
+ `,
+ "other-popup.js": function () {
+ console.log("Other popup log");
+
+ const style = document.createElement("style");
+ style.textContent = "* { background-color: popup-error; }";
+ document.documentElement.appendChild(style);
+
+ throw new Error("Other popup exception");
+ },
+ },
+ id: OTHER_ADDON_ID,
+ name: OTHER_ADDON_NAME,
+ },
+ document
+ );
+
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ ADDON_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+ const webconsole = await toolbox.selectTool("webconsole");
+ const { hud } = webconsole;
+
+ info("Trigger some code in the background page logging some stuff");
+ const onMessage = waitUntil(() => {
+ return !!findMessagesByType(hud, "Background page exception", ".error")
+ .length;
+ });
+ hud.ui.wrapper.dispatchEvaluateExpression("myWebExtensionAddonFunction()");
+ await onMessage;
+
+ info("Open the two add-ons popups to cover popups messages");
+ const onPopupMessage = waitUntil(() => {
+ return !!findMessagesByType(hud, "Popup exception", ".error").length;
+ });
+ clickOnAddonWidget(OTHER_ADDON_ID);
+ clickOnAddonWidget(ADDON_ID);
+ await onPopupMessage;
+
+ info("Wait a bit to catch unexpected duplicates or mixed up messages");
+ await wait(1000);
+
+ is(
+ findMessagesByType(hud, "Background page exception", ".error").length,
+ 1,
+ "We get the background page exception"
+ );
+ is(
+ findMessagesByType(hud, "Popup exception", ".error").length,
+ 1,
+ "We get the popup exception"
+ );
+ is(
+ findMessagesByType(
+ hud,
+ "Expected color but found ‘error’. Error in parsing value for ‘color’. Declaration dropped.",
+ ".warn"
+ ).length,
+ 1,
+ "We get the addon's background page CSS error message"
+ );
+ is(
+ findMessagesByType(
+ hud,
+ "Expected color but found ‘popup-error’. Error in parsing value for ‘color’. Declaration dropped.",
+ ".warn"
+ ).length,
+ 1,
+ "We get the addon's popup CSS error message"
+ );
+
+ // Verify that we don't get the other addon log and errors
+ ok(
+ !findMessageByType(hud, "Other addon log", ".console-api"),
+ "We don't get the other addon log"
+ );
+ ok(
+ !findMessageByType(hud, "Other addon exception", ".console-api"),
+ "We don't get the other addon exception"
+ );
+ ok(
+ !findMessageByType(hud, "Other popup log", ".console-api"),
+ "We don't get the other addon popup log"
+ );
+ ok(
+ !findMessageByType(hud, "Other popup exception", ".error"),
+ "We don't get the other addon popup exception"
+ );
+ ok(
+ !findMessageByType(
+ hud,
+ "Expected color but found ‘error’. Error in parsing value for ‘background-color’. Declaration dropped.",
+ ".warn"
+ ),
+ "We don't get the other addon's background page CSS error message"
+ );
+ ok(
+ !findMessageByType(
+ hud,
+ "Expected color but found ‘popup-error’. Error in parsing value for ‘background-color’. Declaration dropped.",
+ ".warn"
+ ),
+ "We don't get the other addon's popup CSS error message"
+ );
+
+ // Verify that console evaluations still work after reloading the page
+ info("Reload the webextension document");
+ const { onDomCompleteResource } =
+ await waitForNextTopLevelDomCompleteResource(toolbox.commands);
+ hud.ui.wrapper.dispatchEvaluateExpression("location.reload()");
+ await onDomCompleteResource;
+
+ info("Try to evaluate something after reload");
+
+ const onEvaluationResultAfterReload = waitUntil(() =>
+ findMessageByType(hud, "result:2", ".result")
+ );
+ const onMessageAfterReload = waitUntil(() =>
+ findMessageByType(hud, "message after reload", ".console-api")
+ );
+ hud.ui.wrapper.dispatchEvaluateExpression(
+ "console.log('message after reload'); 'result:' + (1 + 1)"
+ );
+ // Both cover that the console.log worked
+ await onMessageAfterReload;
+ // And we received the evaluation result
+ await onEvaluationResultAfterReload;
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+
+ // Note that it seems to be important to remove the addons in the reverse order
+ // from which they were installed...
+ await removeTemporaryExtension(OTHER_ADDON_NAME, document);
+ await removeTemporaryExtension(ADDON_NAME, document);
+ await removeTab(tab);
+});
+
+add_task(async function testWebExtensionNoBgScript() {
+ await pushPref("devtools.webconsole.filter.css", true);
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ extraProperties: {
+ browser_action: {
+ default_title: "WebExtension Popup Only",
+ default_popup: "popup.html",
+ default_area: "navbar",
+ },
+ },
+ files: {
+ "popup.html": `<!DOCTYPE html>
+ <html>
+ <head>
+ <meta charset="utf-8">
+ <script src="popup.js"></script>
+ </head>
+ <body>
+ Popup
+ </body>
+ </html>
+ `,
+ "popup.js": function () {
+ console.log("Popup-only log");
+
+ const style = document.createElement("style");
+ style.textContent = "* { color: popup-only-error; }";
+ document.documentElement.appendChild(style);
+
+ throw new Error("Popup-only exception");
+ },
+ },
+ id: POPUPONLY_ADDON_ID,
+ name: POPUPONLY_ADDON_NAME,
+ },
+ document
+ );
+
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ POPUPONLY_ADDON_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+ const webconsole = await toolbox.selectTool("webconsole");
+ const { hud } = webconsole;
+
+ info("Open the add-on popup");
+ const onPopupMessage = waitUntil(() => {
+ return !!findMessagesByType(hud, "Popup-only exception", ".error").length;
+ });
+ clickOnAddonWidget(POPUPONLY_ADDON_ID);
+ await onPopupMessage;
+
+ info("Wait a bit to catch unexpected duplicates or mixed up messages");
+ await wait(1000);
+ is(
+ findMessagesByType(hud, "Popup-only exception", ".error").length,
+ 1,
+ "We get the popup exception"
+ );
+ is(
+ findMessagesByType(hud, "Popup-only log", ".console-api").length,
+ 1,
+ "We get the addon's popup log"
+ );
+ is(
+ findMessagesByType(
+ hud,
+ "Expected color but found ‘popup-only-error’. Error in parsing value for ‘color’. Declaration dropped.",
+ ".warn"
+ ).length,
+ 1,
+ "We get the addon's popup CSS error message"
+ );
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(POPUPONLY_ADDON_NAME, document);
+ await removeTab(tab);
+});
+
+// Check that reloading the addon several times does not break the console,
+// see Bug 1778951.
+add_task(async function testWebExtensionTwoReloads() {
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ console.log("Background page log");
+ },
+ extraProperties: {
+ browser_action: {
+ default_title: "WebExtension with background script",
+ default_popup: "popup.html",
+ default_area: "navbar",
+ },
+ },
+ files: {
+ "popup.html": `<!DOCTYPE html>
+ <html>
+ <body>
+ Popup
+ </body>
+ </html>
+ `,
+ },
+ id: BACKGROUND_ADDON_ID,
+ name: BACKGROUND_ADDON_NAME,
+ },
+ document
+ );
+
+ // Retrieve the addonTarget element before calling `openAboutDevtoolsToolbox`,
+ // otherwise it will pick the about:devtools-toolbox tab with the same name
+ // instead.
+ const addonTarget = findDebugTargetByText(BACKGROUND_ADDON_NAME, document);
+
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ BACKGROUND_ADDON_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+ const webconsole = await toolbox.selectTool("webconsole");
+ const { hud } = webconsole;
+
+ // Verify that console evaluations still work after reloading the addon
+ info("Reload the webextension itself");
+ let { onDomCompleteResource } = await waitForNextTopLevelDomCompleteResource(
+ toolbox.commands
+ );
+ const reloadButton = addonTarget.querySelector(
+ ".qa-temporary-extension-reload-button"
+ );
+ reloadButton.click();
+ await onDomCompleteResource;
+
+ info("Try to evaluate something after 1st addon reload");
+ // Wait before evaluating the message, otherwise they might be cleaned up by
+ // the console UI.
+ info("Wait until the background script log is visible");
+ await waitUntil(() =>
+ findMessageByType(hud, "Background page log", ".message")
+ );
+
+ hud.ui.wrapper.dispatchEvaluateExpression("40+1");
+ await waitUntil(() => findMessageByType(hud, "41", ".result"));
+
+ info("Reload the extension a second time");
+ ({ onDomCompleteResource } = await waitForNextTopLevelDomCompleteResource(
+ toolbox.commands
+ ));
+ reloadButton.click();
+ await onDomCompleteResource;
+
+ info("Wait until the background script log is visible - after reload");
+ await waitUntil(() =>
+ findMessageByType(hud, "Background page log", ".message")
+ );
+
+ info("Try to evaluate something after 2nd addon reload");
+ hud.ui.wrapper.dispatchEvaluateExpression("40+2");
+ await waitUntil(() => findMessageByType(hud, "42", ".result"));
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(BACKGROUND_ADDON_NAME, document);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_debugger.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_debugger.js
new file mode 100644
index 0000000000..0e100931a7
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_debugger.js
@@ -0,0 +1,87 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
+const L10N = new LocalizationHelper(
+ "devtools/client/locales/toolbox.properties"
+);
+
+add_task(async () => {
+ const EXTENSION_NAME = "temporary-web-extension";
+ const EXTENSION_ID = "test-devtools@mozilla.org";
+
+ await enableExtensionDebugging();
+
+ info(
+ "The debugger should show the source codes of extension even if " +
+ "devtools.chrome.enabled and devtools.debugger.remote-enabled are off"
+ );
+ await pushPref("devtools.chrome.enabled", false);
+ await pushPref("devtools.debugger.remote-enabled", false);
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ window.someRandomMethodName = () => {
+ // This will not be referred from anywhere.
+ // However this is necessary to show as the source code in the debugger.
+ };
+ },
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ },
+ document
+ );
+
+ // Select the debugger right away to avoid any noise coming from the inspector.
+ await pushPref("devtools.toolbox.selectedTool", "jsdebugger");
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ EXTENSION_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+ const { panelWin } = toolbox.getCurrentPanel();
+
+ info("Check the state of redux");
+ ok(
+ panelWin.dbg.store.getState().sourcesTree.isWebExtension,
+ "isWebExtension flag in sourcesTree is true"
+ );
+
+ info("Check whether the element displays correctly");
+ let sourceList = panelWin.document.querySelector(".sources-list");
+ ok(sourceList, "Source list element displays correctly");
+ ok(
+ sourceList.textContent.includes("temporary-web-extension"),
+ "Extension name displays correctly"
+ );
+
+ const waitForLoadedPanelsReload = await watchForLoadedPanelsReload(toolbox);
+
+ info("Reload the addon using a toolbox reload shortcut");
+ toolbox.win.focus();
+ synthesizeKeyShortcut(L10N.getStr("toolbox.reload.key"), toolbox.win);
+
+ await waitForLoadedPanelsReload();
+
+ info("Wait until a new background log message is logged");
+ await waitFor(() => {
+ // As React may re-create a new sources-list element,
+ // fetch the latest instance
+ sourceList = panelWin.document.querySelector(".sources-list");
+ return sourceList?.textContent.includes("temporary-web-extension");
+ }, "Wait for the source to re-appear");
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_inspector.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_inspector.js
new file mode 100644
index 0000000000..a652ab41a8
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_inspector.js
@@ -0,0 +1,86 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// There are shutdown issues for which multiple rejections are left uncaught.
+// See bug 1018184 for resolving these issues.
+const { PromiseTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PromiseTestUtils.sys.mjs"
+);
+PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
+
+// Avoid test timeouts that can occur while waiting for the "addon-console-works" message.
+requestLongerTimeout(2);
+
+const ADDON_ID = "test-devtools-webextension@mozilla.org";
+const ADDON_NAME = "test-devtools-webextension";
+
+/**
+ * This test file ensures that the webextension addon developer toolbox:
+ * - the webextension developer toolbox has a working Inspector panel, with the
+ * background page as default target;
+ */
+add_task(async function testWebExtensionsToolboxWebConsole() {
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ document.body.innerText = "Background Page Body Test Content";
+ },
+ id: ADDON_ID,
+ name: ADDON_NAME,
+ },
+ document
+ );
+
+ info("Open a toolbox to debug the addon");
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ ADDON_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+
+ const inspector = await toolbox.selectTool("inspector");
+ const nodeActor = await inspector.walker.querySelector(
+ inspector.walker.rootNode,
+ "body"
+ );
+ ok(nodeActor, "Got a nodeActor");
+ ok(nodeActor.inlineTextChild, "Got a nodeActor with an inline text child");
+
+ const actualValue = nodeActor.inlineTextChild._form.nodeValue;
+
+ is(
+ String(actualValue).trim(),
+ "Background Page Body Test Content",
+ "nodeActor has the expected inlineTextChild value"
+ );
+
+ info("Check that the color scheme simulation buttons are hidden");
+ const lightButtonIsHidden = inspector.panelDoc
+ .querySelector("#color-scheme-simulation-light-toggle")
+ ?.hasAttribute("hidden");
+ const darkButtonIsHidded = inspector.panelDoc
+ .querySelector("#color-scheme-simulation-dark-toggle")
+ ?.hasAttribute("hidden");
+ ok(
+ lightButtonIsHidden,
+ "The light color scheme simulation button exists and is hidden"
+ );
+ ok(
+ darkButtonIsHidded,
+ "The dark color scheme simulation button exists and is hidden"
+ );
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(ADDON_NAME, document);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_nobg.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_nobg.js
new file mode 100644
index 0000000000..4f8f35acd2
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_nobg.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// There are shutdown issues for which multiple rejections are left uncaught.
+// See bug 1018184 for resolving these issues.
+const { PromiseTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PromiseTestUtils.sys.mjs"
+);
+PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
+
+const ADDON_NOBG_ID = "test-devtools-webextension-nobg@mozilla.org";
+const ADDON_NOBG_NAME = "test-devtools-webextension-nobg";
+
+/**
+ * This test file ensures that the webextension addon developer toolbox:
+ * - the webextension developer toolbox is connected to a fallback page when the
+ * background page is not available (and in the fallback page document body contains
+ * the expected message, which warns the user that the current page is not a real
+ * webextension context);
+ */
+add_task(async function testWebExtensionsToolboxNoBackgroundPage() {
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ // Do not pass any `background` script.
+ id: ADDON_NOBG_ID,
+ name: ADDON_NOBG_NAME,
+ },
+ document
+ );
+
+ info("Open a toolbox to debug the addon");
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ ADDON_NOBG_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+
+ ok(
+ toolbox.commands.descriptorFront.isWebExtensionDescriptor,
+ "Toolbox is debugging an addon"
+ );
+ const targetName = toolbox.target.name;
+ is(targetName, ADDON_NOBG_NAME, "Toolbox has the expected target");
+
+ const inspector = await toolbox.selectTool("inspector");
+
+ let nodeActor;
+ info(`Wait the fallback window to be fully loaded`);
+ await asyncWaitUntil(async () => {
+ nodeActor = await inspector.walker.querySelector(
+ inspector.walker.rootNode,
+ "h1"
+ );
+ return nodeActor && nodeActor.inlineTextChild;
+ });
+
+ info("Got a nodeActor with an inline text child");
+ const actualValue = nodeActor.inlineTextChild._form.nodeValue;
+ is(
+ actualValue,
+ "Your addon does not have any document opened yet.",
+ "nodeActor has the expected inlineTextChild value"
+ );
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(ADDON_NOBG_NAME, document);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js
new file mode 100644
index 0000000000..c205ecbfe3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js
@@ -0,0 +1,246 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// There are shutdown issues for which multiple rejections are left uncaught.
+// See bug 1018184 for resolving these issues.
+const { PromiseTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PromiseTestUtils.sys.mjs"
+);
+PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
+
+// Avoid test timeouts that can occur while waiting for the "addon-console-works" message.
+requestLongerTimeout(2);
+
+const ADDON_ID = "test-devtools-webextension@mozilla.org";
+const ADDON_NAME = "test-devtools-webextension";
+
+/**
+ * This test file ensures that the webextension addon developer toolbox:
+ * - has a frame list menu and the noautohide toolbar toggle button, and they
+ * can be used to switch the current target to the extension popup page.
+ */
+add_task(async function testWebExtensionsToolboxWebConsole() {
+ await enableExtensionDebugging();
+
+ // Bug 1686922: Disable the error count button to avoid intermittent failures.
+ await pushPref("devtools.command-button-errorcount.enabled", false);
+
+ is(
+ Services.prefs.getBoolPref("ui.popup.disable_autohide"),
+ false,
+ "disable_autohide should be initially false"
+ );
+
+ const {
+ document,
+ tab,
+ window: aboutDebuggingWindow,
+ } = await openAboutDebugging();
+ await selectThisFirefoxPage(
+ document,
+ aboutDebuggingWindow.AboutDebugging.store
+ );
+
+ const extension = await installTestAddon(document);
+
+ const onBackgroundFunctionCalled = waitForExtensionTestMessage(
+ extension,
+ "onBackgroundFunctionCalled"
+ );
+ const onPopupPageFunctionCalled = waitForExtensionTestMessage(
+ extension,
+ "onPopupPageFunctionCalled"
+ );
+
+ info("Open a toolbox to debug the addon");
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ aboutDebuggingWindow,
+ ADDON_NAME
+ );
+
+ const toolbox = getToolbox(devtoolsWindow);
+ const webconsole = await toolbox.selectTool("webconsole");
+
+ info("Clicking the menu button to disable autohide");
+ await disablePopupAutohide(toolbox);
+
+ info("Check that console messages are evaluated in the background context");
+ const consoleWrapper = webconsole.hud.ui.wrapper;
+ consoleWrapper.dispatchEvaluateExpression("backgroundFunction()");
+ await onBackgroundFunctionCalled;
+
+ clickOnAddonWidget(ADDON_ID);
+
+ info("Wait until the frames list button is displayed");
+ const btn = await waitFor(() =>
+ toolbox.doc.getElementById("command-button-frames")
+ );
+
+ info("Clicking the frame list button");
+ btn.click();
+
+ const menuList = toolbox.doc.getElementById("toolbox-frame-menu");
+ const frames = Array.from(menuList.querySelectorAll(".command"));
+ is(frames.length, 2, "Has the expected number of frames");
+
+ const popupFrameBtn = frames
+ .filter(frame => {
+ return frame.querySelector(".label").textContent.endsWith("popup.html");
+ })
+ .pop();
+
+ ok(popupFrameBtn, "Extension Popup frame found in the listed frames");
+
+ info(
+ "Click on the extension popup frame and wait for a `dom-complete` resource"
+ );
+ const { onDomCompleteResource } =
+ await waitForNextTopLevelDomCompleteResource(toolbox.commands);
+ popupFrameBtn.click();
+ await onDomCompleteResource;
+
+ info("Execute `popupPageFunction()`");
+ consoleWrapper.dispatchEvaluateExpression("popupPageFunction()");
+
+ const args = await onPopupPageFunctionCalled;
+ ok(true, "Received console message from the popup page function as expected");
+ is(args[0], "onPopupPageFunctionCalled", "Got the expected console message");
+ is(
+ args[1] && args[1].name,
+ ADDON_NAME,
+ "Got the expected manifest from WebExtension API"
+ );
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, aboutDebuggingWindow);
+
+ is(
+ Services.prefs.getBoolPref("ui.popup.disable_autohide"),
+ false,
+ "disable_autohide should be reset to false when the toolbox is closed"
+ );
+
+ await removeTemporaryExtension(ADDON_NAME, document);
+ await removeTab(tab);
+});
+
+/**
+ * Helper to wait for a specific message on an Extension instance.
+ */
+function waitForExtensionTestMessage(extension, expectedMessage) {
+ return new Promise(done => {
+ extension.on("test-message", function testLogListener(evt, ...args) {
+ const [message] = args;
+
+ if (message !== expectedMessage) {
+ return;
+ }
+
+ extension.off("test-message", testLogListener);
+ done(args);
+ });
+ });
+}
+
+/**
+ * Install the addon used for this test.
+ * Returns a Promise that resolve the Extension instance that was just
+ * installed.
+ */
+async function installTestAddon(doc) {
+ // Start watching for the extension on the Extension Management before we
+ // install it.
+ const onExtensionReady = waitForExtension(ADDON_NAME);
+
+ // Install the extension.
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ const { browser } = this;
+ window.backgroundFunction = function () {
+ browser.test.sendMessage("onBackgroundFunctionCalled");
+ };
+ },
+ extraProperties: {
+ browser_action: {
+ default_title: "WebExtension Popup Debugging",
+ default_popup: "popup.html",
+ },
+ },
+ files: {
+ "popup.html": `<!DOCTYPE html>
+ <html>
+ <head>
+ <meta charset="utf-8">
+ <script src="popup.js"></script>
+ </head>
+ <body>
+ Background Page Body Test Content
+ </body>
+ </html>
+ `,
+ "popup.js": function () {
+ const { browser } = this;
+ window.popupPageFunction = function () {
+ browser.test.sendMessage(
+ "onPopupPageFunctionCalled",
+ browser.runtime.getManifest()
+ );
+ };
+ },
+ },
+ id: ADDON_ID,
+ name: ADDON_NAME,
+ },
+ doc
+ );
+
+ // The onExtensionReady promise will resolve the extension instance.
+ return onExtensionReady;
+}
+
+/**
+ * Helper to retrieve the Extension instance.
+ */
+async function waitForExtension(addonName) {
+ const { Management } = ChromeUtils.importESModule(
+ "resource://gre/modules/Extension.sys.mjs"
+ );
+
+ return new Promise(resolve => {
+ Management.on("startup", function listener(event, extension) {
+ if (extension.name != addonName) {
+ return;
+ }
+
+ Management.off("startup", listener);
+ resolve(extension);
+ });
+ });
+}
+
+/**
+ * Disables the popup autohide feature, which is mandatory to debug webextension
+ * popups.
+ */
+function disablePopupAutohide(toolbox) {
+ return new Promise(resolve => {
+ toolbox.doc.addEventListener(
+ "popupshown",
+ () => {
+ const menuItem = toolbox.doc.getElementById(
+ "toolbox-meatball-menu-noautohide"
+ );
+ menuItem.click();
+ resolve();
+ },
+ { once: true }
+ );
+ toolbox.doc.getElementById("toolbox-meatball-menu-button").click();
+ });
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_reload.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_reload.js
new file mode 100644
index 0000000000..2293eaca0e
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_reload.js
@@ -0,0 +1,136 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// There are shutdown issues for which multiple rejections are left uncaught.
+// See bug 1018184 for resolving these issues.
+const { PromiseTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PromiseTestUtils.sys.mjs"
+);
+PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
+
+// Avoid test timeouts that can occur while waiting for the "addon-console-works" message.
+requestLongerTimeout(2);
+
+const ADDON_ID = "test-devtools-webextension@mozilla.org";
+const ADDON_NAME = "test-devtools-webextension";
+
+const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
+const L10N = new LocalizationHelper(
+ "devtools/client/locales/toolbox.properties"
+);
+
+// Check that addon browsers can be reloaded via the toolbox reload shortcuts
+add_task(async function testWebExtensionToolboxReload() {
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ console.log("background script executed " + Math.random());
+ },
+ id: ADDON_ID,
+ name: ADDON_NAME,
+ },
+ document
+ );
+
+ // Select the debugger right away to avoid any noise coming from the inspector.
+ await pushPref("devtools.toolbox.selectedTool", "webconsole");
+ const { devtoolsDocument, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ ADDON_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+
+ ok(
+ devtoolsDocument.querySelector(".qa-reload-button"),
+ "Reload button is visible"
+ );
+ ok(
+ !devtoolsDocument.querySelector(".qa-back-button"),
+ "Back button is hidden"
+ );
+ ok(
+ !devtoolsDocument.querySelector(".qa-forward-button"),
+ "Forward button is hidden"
+ );
+ ok(
+ !devtoolsDocument.querySelector(".debug-target-url-form"),
+ "URL form is hidden"
+ );
+ ok(
+ devtoolsDocument.getElementById("toolbox-meatball-menu-noautohide"),
+ "Disable popup autohide button is displayed"
+ );
+ ok(
+ !devtoolsDocument.getElementById(
+ "toolbox-meatball-menu-pseudo-locale-accented"
+ ),
+ "Accented locale is not displayed (only on browser toolbox)"
+ );
+
+ const webconsole = await toolbox.selectTool("webconsole");
+ const { hud } = webconsole;
+
+ info("Wait for the initial background message to appear in the console");
+ const initialMessage = await waitFor(() =>
+ findMessagesByType(hud, "background script executed", ".console-api")
+ );
+ ok(initialMessage, "Found the expected message from the background script");
+
+ const waitForLoadedPanelsReload = await watchForLoadedPanelsReload(toolbox);
+
+ info("Reload the addon using a toolbox reload shortcut");
+ toolbox.win.focus();
+ synthesizeKeyShortcut(L10N.getStr("toolbox.reload.key"), toolbox.win);
+
+ info("Wait until a new background log message is logged");
+ const secondMessage = await waitFor(() => {
+ const newMessage = findMessagesByType(
+ hud,
+ "background script executed",
+ ".console-api"
+ );
+ if (newMessage && newMessage !== initialMessage) {
+ return newMessage;
+ }
+ return false;
+ });
+
+ await waitForLoadedPanelsReload();
+
+ info("Reload via the debug target info bar button");
+ clickReload(devtoolsDocument);
+
+ info("Wait until yet another background log message is logged");
+ await waitFor(() => {
+ const newMessage = findMessagesByType(
+ hud,
+ "background script executed",
+ ".console-api"
+ );
+ return (
+ newMessage &&
+ newMessage !== initialMessage &&
+ newMessage !== secondMessage
+ );
+ });
+
+ await waitForLoadedPanelsReload();
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(ADDON_NAME, document);
+ await removeTab(tab);
+});
+
+function clickReload(devtoolsDocument) {
+ devtoolsDocument.querySelector(".qa-reload-button").click();
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_storage.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_storage.js
new file mode 100644
index 0000000000..56f1b0befb
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_storage.js
@@ -0,0 +1,90 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+add_task(async () => {
+ const EXTENSION_NAME = "temporary-web-extension";
+ const EXTENSION_ID = "test-devtools@mozilla.org";
+
+ await enableExtensionDebugging();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const { extension } = await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ const open = indexedDB.open("TestDatabase", 1);
+
+ open.onupgradeneeded = function () {
+ const db = open.result;
+ db.createObjectStore("TestStore", { keyPath: "id" });
+ };
+
+ open.onsuccess = function () {
+ const db = open.result;
+ const tx = db.transaction("TestStore", "readwrite");
+ const store = tx.objectStore("TestStore");
+
+ store.put({ id: 1, name: "John", age: 12 });
+ store.put({ id: 2, name: "Bob", age: 24 });
+ tx.oncomplete = () => db.close();
+ };
+ },
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ },
+ document
+ );
+
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ EXTENSION_NAME
+ );
+
+ info("Select the storage panel");
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool("storage");
+ const storage = toolbox.getCurrentPanel();
+
+ info("Check the content of the storage panel treeview");
+ const ids = [
+ "indexedDB",
+ `moz-extension://${extension.uuid}`,
+ "TestDatabase (default)",
+ "TestStore",
+ ];
+ ok(
+ !!storage.panelWindow.document.querySelector(
+ `[data-id='${JSON.stringify(ids)}']`
+ ),
+ "The indexedDB database for the extension is visible"
+ );
+
+ info("Select the indexedDB database for the extension");
+ const updated = storage.UI.once("store-objects-updated");
+ storage.UI.tree.selectedItem = ids;
+ await updated;
+
+ info("Wait until table populated");
+ await waitUntil(() => storage.UI.table.items.size === 2);
+ const items = storage.UI.table.items;
+
+ info("Check the content of the storage panel table");
+ is(items.size, 2);
+ const user1 = JSON.parse(items.get(1).value);
+ const user2 = JSON.parse(items.get(2).value);
+ is(user1.name, "John", "user 1 has the expected name");
+ is(user1.age, 12, "user 1 has the expected age");
+ is(user2.name, "Bob", "user 2 has the expected name");
+ is(user2.age, 24, "user 2 has the expected age");
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_toolbox.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_toolbox.js
new file mode 100644
index 0000000000..f21e7d9c4a
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_toolbox.js
@@ -0,0 +1,122 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// There are shutdown issues for which multiple rejections are left uncaught.
+// See bug 1018184 for resolving these issues.
+const { PromiseTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PromiseTestUtils.sys.mjs"
+);
+PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
+
+const ADDON_ID = "test-devtools-webextension@mozilla.org";
+const ADDON_NAME = "test-devtools-webextension";
+
+/**
+ * This test file ensures that the webextension addon developer toolbox:
+ * - always on top is enabled by default and can be toggled off
+ */
+add_task(async function testWebExtensionsToolbox() {
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ background() {
+ document.body.innerText = "Background Page Body Test Content";
+ },
+ id: ADDON_ID,
+ name: ADDON_NAME,
+ },
+ document
+ );
+
+ info("Open a toolbox to debug the addon");
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ ADDON_NAME
+ );
+
+ const toolbox = getToolbox(devtoolsWindow);
+
+ ok(
+ isWindowAlwaysOnTop(devtoolsWindow),
+ "The toolbox window is always on top"
+ );
+ const toggleButton = toolbox.doc.querySelector(".toolbox-always-on-top");
+ ok(!!toggleButton, "The always on top toggle button is visible");
+ ok(
+ toggleButton.classList.contains("checked"),
+ "The button is highlighted to report that always on top is enabled"
+ );
+
+ // When running the test, the devtools window might not be focused, while it does IRL.
+ // Force it to be focused to better reflect the default behavior.
+ info("Force focusing the devtools window");
+ devtoolsWindow.focus();
+
+ // As we update the button with a debounce, we have to wait for it to updates
+ await waitFor(
+ () => toggleButton.classList.contains("toolbox-is-focused"),
+ "Wait for the button to be highlighting that the toolbox is focused (the button isn't highlighted)"
+ );
+ ok(true, "Expected class is added when toolbox is focused");
+
+ info("Focus the browser window");
+ window.focus();
+
+ await waitFor(
+ () => !toggleButton.classList.contains("toolbox-is-focused"),
+ "Wait for the button to be highlighting that the toolbox is no longer focused (the button is highlighted)"
+ );
+ ok(true, "Focused class is removed when browser window gets focused");
+
+ info("Re-focus the DevTools window");
+ devtoolsWindow.focus();
+
+ await waitFor(
+ () => toggleButton.classList.contains("toolbox-is-focused"),
+ "Wait for the button to be re-highlighting that the toolbox is focused"
+ );
+
+ const onToolboxReady = gDevTools.once("toolbox-ready");
+ info("Click on the button");
+ toggleButton.click();
+
+ info("Wait for a new toolbox to be created");
+ const secondToolbox = await onToolboxReady;
+
+ ok(
+ !isWindowAlwaysOnTop(secondToolbox.win),
+ "The toolbox window is no longer always on top"
+ );
+ const secondToggleButton = secondToolbox.doc.querySelector(
+ ".toolbox-always-on-top"
+ );
+ ok(!!secondToggleButton, "The always on top toggle button is still visible");
+
+ ok(
+ !secondToggleButton.classList.contains("checked"),
+ "The button is no longer highlighted to report that always on top is disabled"
+ );
+
+ await closeWebExtAboutDevtoolsToolbox(secondToolbox.win, window);
+ await removeTemporaryExtension(ADDON_NAME, document);
+ await removeTab(tab);
+});
+
+// Check if the window has the "alwaysontop" chrome flag
+function isWindowAlwaysOnTop(window) {
+ return (
+ window.docShell.treeOwner
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIAppWindow).chromeFlags &
+ Ci.nsIWebBrowserChrome.CHROME_ALWAYS_ON_TOP
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_actions_and_status.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_actions_and_status.js
new file mode 100644
index 0000000000..0e395704f2
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_actions_and_status.js
@@ -0,0 +1,153 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+add_setup(async function () {
+ await SpecialPowers.pushPrefEnv({
+ set: [["extensions.eventPages.enabled", true]],
+ });
+});
+
+// Test that the terminate button is shutting down the background script as expected
+// and the background script status is updated occordingly.
+add_task(async function test_eventpage_terminate_and_status_updates() {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const EXTENSION_ID = "test-devtools-eventpage@mozilla.org";
+ const EXTENSION_NAME = "Temporary EventPage-based web extension";
+
+ const EXTENSION2_ID = "test-devtools-persistentbg@mozilla.org";
+ const EXTENSION2_NAME =
+ "Temporary PersistentBackgroundPage-based web extension";
+
+ const promiseBackgroundLoaded = promiseBackgroundContextLoaded(EXTENSION_ID);
+ const promiseBackgroundUnloaded =
+ promiseBackgroundContextUnloaded(EXTENSION_ID);
+
+ let waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+
+ // Install the extension using an event page (non persistent background page).
+ await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ // The extension is expected to have a non persistent background script.
+ extraProperties: {
+ background: {
+ scripts: ["bgpage.js"],
+ persistent: false,
+ },
+ },
+ files: {
+ "bgpage.js": function () {
+ // Emit a dump when the script is loaded to make it easier
+ // to investigate intermittents.
+ dump(`Background script loaded: ${window.location}\n`);
+ },
+ },
+ },
+ document
+ );
+
+ // Install the extension using a persistent background page.
+ await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION2_ID,
+ name: EXTENSION2_NAME,
+ // The extension is expected to have a persistent background script.
+ extraProperties: {
+ background: {
+ page: "bppage.html",
+ persistent: true,
+ },
+ },
+ files: { "bgpage.html": "" },
+ },
+ document
+ );
+
+ const target = findDebugTargetByText(EXTENSION_NAME, document);
+ ok(
+ !!target,
+ "The EventPage-based extension is installed with the expected name"
+ );
+
+ const target2 = findDebugTargetByText(EXTENSION2_NAME, document);
+ ok(
+ !!target2,
+ "The PersistentBackgroundScript-based extension is installed with the expected name"
+ );
+
+ const terminateButton = target.querySelector(
+ ".qa-temporary-extension-terminate-bgscript-button"
+ );
+ ok(
+ !!terminateButton,
+ `${EXTENSION_NAME} is expected to have a terminate button`
+ );
+
+ const terminateButton2 = target2.querySelector(
+ ".qa-temporary-extension-terminate-bgscript-button"
+ );
+ ok(
+ !terminateButton2,
+ `${EXTENSION2_NAME} is expected to not have a terminate button`
+ );
+
+ info("Wait for the test extension background script to be loaded");
+ await promiseBackgroundLoaded;
+
+ info("Wait for the test extension background script status update");
+ await waitForBGStatusUpdate;
+
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "running",
+ });
+
+ // Verify in the card related to extensions with a persistent background page
+ // the background script status is not being rendered at all.
+ const backgroundStatus2 = target2.querySelector(
+ ".extension-backgroundscript__status"
+ );
+ ok(
+ !backgroundStatus2,
+ `${EXTENSION2_NAME} should not be showing background script status`
+ );
+
+ info(`Click on the terminate button for ${EXTENSION_NAME}`);
+ const waitForTerminateSuccess = waitForDispatch(
+ window.AboutDebugging.store,
+ "TERMINATE_EXTENSION_BGSCRIPT_SUCCESS"
+ );
+ waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+ terminateButton.click();
+ await waitForTerminateSuccess;
+
+ info("Wait for the extension background script to be unloaded");
+ await promiseBackgroundUnloaded;
+ await waitForBGStatusUpdate;
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "stopped",
+ });
+
+ // Uninstall the test extensions.
+ await Promise.all([
+ AddonManager.getAddonByID(EXTENSION_ID).then(addon => addon.uninstall()),
+ AddonManager.getAddonByID(EXTENSION2_ID).then(addon => addon.uninstall()),
+ ]);
+
+ info("Wait until the debug targets with test extensions disappears");
+ await waitUntil(
+ () =>
+ !findDebugTargetByText(EXTENSION_NAME, document) &&
+ !findDebugTargetByText(EXTENSION2_NAME, document)
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_terminate_on_idle.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_terminate_on_idle.js
new file mode 100644
index 0000000000..1b43808fa2
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_eventpage_terminate_on_idle.js
@@ -0,0 +1,200 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+add_setup(async function () {
+ await SpecialPowers.pushPrefEnv({
+ set: [["extensions.eventPages.enabled", true]],
+ });
+});
+
+// Test that an extension event page isn't terminated on idle when a DevTools
+// Toolbox is attached to the extension.
+add_task(
+ async function test_eventpage_no_idle_shutdown_with_toolbox_attached() {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const EXTENSION_ID = "test-devtools-eventpage@mozilla.org";
+ const EXTENSION_NAME = "Temporary EventPage-based web extension";
+
+ const promiseBackgroundLoaded =
+ promiseBackgroundContextLoaded(EXTENSION_ID);
+
+ let waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+
+ // Install the extension using an event page (non persistent background page).
+ await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ // The extension is expected to have a non persistent background script.
+ extraProperties: {
+ background: {
+ scripts: ["bgpage.js"],
+ persistent: false,
+ },
+ },
+ files: {
+ "bgpage.js": function () {
+ // Emit a dump when the script is loaded to make it easier
+ // to investigate intermittents.
+ dump(`Background script loaded: ${window.location}\n`);
+ },
+ },
+ },
+ document
+ );
+
+ const target = findDebugTargetByText(EXTENSION_NAME, document);
+ ok(
+ !!target,
+ "The EventPage-based extension is installed with the expected name"
+ );
+
+ info("Wait for the test extension background script to be loaded");
+ await promiseBackgroundLoaded;
+
+ info("Wait for the test extension background script status update");
+ await waitForBGStatusUpdate;
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "running",
+ });
+
+ waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+ await triggerExtensionEventPageIdleTimeout(EXTENSION_ID);
+ await waitForBGStatusUpdate;
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "stopped",
+ });
+
+ info(
+ "Respawn the extension background script on new WebExtension API event"
+ );
+ waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+ await wakeupExtensionEventPage(EXTENSION_ID);
+ await waitForBGStatusUpdate;
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "running",
+ });
+
+ info("Open a DevTools toolbox on the target extension");
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ EXTENSION_NAME
+ );
+
+ info(
+ "Verify event page terminated on terminate button clicked while the DevTools toolbox is open"
+ );
+ const terminateButton = target.querySelector(
+ ".qa-temporary-extension-terminate-bgscript-button"
+ );
+ ok(
+ !!terminateButton,
+ `${EXTENSION_NAME} is expected to have a terminate button`
+ );
+
+ info(`Click on the terminate button for ${EXTENSION_NAME}`);
+ const promiseBackgroundUnloaded =
+ promiseBackgroundContextUnloaded(EXTENSION_ID);
+ const waitForTerminateSuccess = waitForDispatch(
+ window.AboutDebugging.store,
+ "TERMINATE_EXTENSION_BGSCRIPT_SUCCESS"
+ );
+ waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+ terminateButton.click();
+ await waitForTerminateSuccess;
+
+ info("Wait for the extension background script to be unloaded");
+ await promiseBackgroundUnloaded;
+ await waitForBGStatusUpdate;
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "stopped",
+ targetElement: target,
+ });
+
+ info(
+ "Verify event page isn't terminated on idle while the DevTools toolbox is open"
+ );
+
+ // Make sure the event page is running again.
+ waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+ await wakeupExtensionEventPage(EXTENSION_ID);
+ await waitForBGStatusUpdate;
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "running",
+ targetElement: target,
+ });
+
+ const waitForBGSuspendIgnored =
+ promiseTerminateBackgroundScriptIgnored(EXTENSION_ID);
+ waitForBGStatusUpdate = promiseBackgroundStatusUpdate(window);
+ await triggerExtensionEventPageIdleTimeout(EXTENSION_ID);
+ await Promise.race([waitForBGStatusUpdate, waitForBGSuspendIgnored]);
+
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "running",
+ // After opening the toolbox there will be an additional target listed
+ // for the devtools toolbox tab, its card includes the extension name
+ // and so while the toolbox is open we should make sure to look for
+ // the background status inside the extension target card instead of
+ // the one associated to the devtools toolbox tab.
+ targetElement: target,
+ });
+
+ info(
+ "Wait for warning message expected to be logged for the event page not terminated on idle"
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+ const webconsole = await toolbox.selectTool("webconsole");
+ const { hud } = webconsole;
+ const expectedWarning =
+ "Background event page was not terminated on idle because a DevTools toolbox is attached to the extension.";
+ let consoleElements;
+ await waitUntil(() => {
+ consoleElements = findMessagesByType(hud, expectedWarning, ".warn");
+ return !!consoleElements.length;
+ });
+
+ const locationElement = consoleElements[0].querySelector(
+ ".frame-link-filename"
+ );
+ ok(
+ locationElement.textContent.endsWith("_generated_background_page.html"),
+ "The warning message is associated to the event page url"
+ );
+
+ info(
+ "Verify event page is terminated on idle after closing the DevTools toolbox"
+ );
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await triggerExtensionEventPageIdleTimeout(EXTENSION_ID);
+ await waitForBGStatusUpdate;
+ await assertBackgroundStatus(EXTENSION_NAME, {
+ document,
+ expectedStatus: "stopped",
+ });
+
+ // Uninstall the test extensions.
+ info("Unload extension and remove about:debugging tab");
+ await AddonManager.getAddonByID(EXTENSION_ID).then(addon =>
+ addon.uninstall()
+ );
+ info("Wait until the debug targets with test extensions disappears");
+ await waitUntil(() => !findDebugTargetByText(EXTENSION_NAME, document));
+ await removeTab(tab);
+ }
+);
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_manifest_url.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_manifest_url.js
new file mode 100644
index 0000000000..6420a076b0
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_manifest_url.js
@@ -0,0 +1,73 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const {
+ adbAddon,
+} = require("resource://devtools/client/shared/remote-debugging/adb/adb-addon.js");
+
+const ABD_ADDON_NAME = "ADB binary provider";
+
+/* import-globals-from helper-adb.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-adb.js", this);
+
+// Test that manifest URLs for addon targets show the manifest correctly in a new tab.
+// This test reuses the ADB extension to be sure to have a valid manifest URL to open.
+add_task(async function () {
+ await pushPref(
+ "devtools.remote.adb.extensionURL",
+ CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi"
+ );
+ await checkAdbNotRunning();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const usbStatusElement = document.querySelector(".qa-sidebar-usb-status");
+
+ info("Install ADB");
+ adbAddon.install("internal");
+ await waitUntil(() => usbStatusElement.textContent.includes("USB enabled"));
+ await waitForAdbStart();
+
+ info("Wait until the debug target for ADB appears");
+ await waitUntil(() => findDebugTargetByText(ABD_ADDON_NAME, document));
+ const adbExtensionItem = findDebugTargetByText(ABD_ADDON_NAME, document);
+
+ const manifestUrlElement = adbExtensionItem.querySelector(".qa-manifest-url");
+ ok(manifestUrlElement, "A link to the manifest is displayed");
+
+ info("Click on the manifest URL and wait for the new tab to open");
+ const onTabOpened = once(gBrowser.tabContainer, "TabOpen");
+ manifestUrlElement.click();
+ const { target } = await onTabOpened;
+ await BrowserTestUtils.browserLoaded(target.linkedBrowser);
+
+ info("Retrieve the text content of the new tab");
+ const textContent = await SpecialPowers.spawn(
+ target.linkedBrowser,
+ [],
+ function () {
+ return content.wrappedJSObject.document.body.textContent;
+ }
+ );
+
+ const manifestObject = JSON.parse(textContent);
+ ok(manifestObject, "The displayed content is a valid JSON object");
+ is(
+ manifestObject.name,
+ ABD_ADDON_NAME,
+ "Manifest tab shows the expected content"
+ );
+
+ info("Close the manifest.json tab");
+ await removeTab(target);
+
+ info("Uninstall the adb extension and wait for the message to udpate");
+ adbAddon.uninstall();
+ await waitUntil(() => usbStatusElement.textContent.includes("USB disabled"));
+ await stopAdbProcess();
+
+ await waitForAboutDebuggingRequests(window.AboutDebugging.store);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_popup_picker.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_popup_picker.js
new file mode 100644
index 0000000000..fc67bc7f7c
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_popup_picker.js
@@ -0,0 +1,99 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// There are shutdown issues for which multiple rejections are left uncaught.
+// See bug 1018184 for resolving these issues.
+const { PromiseTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PromiseTestUtils.sys.mjs"
+);
+PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
+
+const ADDON_ID = "test-devtools-webextension@mozilla.org";
+const ADDON_NAME = "test-devtools-webextension";
+
+/**
+ * Check that the node picker can be used when dynamically navigating to a
+ * webextension popup.
+ */
+add_task(async function testNodePickerInExtensionPopup() {
+ await enableExtensionDebugging();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Note that this extension should not define a background script in order to
+ // reproduce the issue. Otherwise opening the popup does not trigger an auto
+ // navigation from DevTools and you have to use the "Disable Popup Auto Hide"
+ // feature which works around the bug tested here.
+ await installTemporaryExtensionFromXPI(
+ {
+ extraProperties: {
+ browser_action: {
+ default_title: "WebExtension with popup",
+ default_popup: "popup.html",
+ },
+ },
+ files: {
+ "popup.html": `<!DOCTYPE html>
+ <html>
+ <body>
+ <div id="pick-me"
+ style="width:100px; height: 60px; background-color: #f5e8fc">
+ Pick me!
+ </div>
+ </body>
+ </html>
+ `,
+ },
+ id: ADDON_ID,
+ name: ADDON_NAME,
+ },
+ document
+ );
+
+ const { devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ ADDON_NAME
+ );
+ const toolbox = getToolbox(devtoolsWindow);
+ const inspector = await toolbox.getPanel("inspector");
+
+ info("Start the node picker");
+ await toolbox.nodePicker.start();
+
+ info("Open the webextension popup");
+ // Clicking on the addon popup will trigger a navigation between the DevTools
+ // fallback document and the popup document.
+ // Wait until the inspector was fully reloaded and for the node-picker to be
+ // restarted.
+ const nodePickerRestarted = toolbox.nodePicker.once(
+ "node-picker-webextension-target-restarted"
+ );
+ const reloaded = inspector.once("reloaded");
+ clickOnAddonWidget(ADDON_ID);
+ await reloaded;
+ await nodePickerRestarted;
+
+ const popup = await waitFor(() =>
+ gBrowser.ownerDocument.querySelector(".webextension-popup-browser")
+ );
+
+ info("Pick an element inside the webextension popup");
+ const onNewNodeFront = inspector.selection.once("new-node-front");
+ BrowserTestUtils.synthesizeMouseAtCenter(
+ "#pick-me",
+ {},
+ popup.browsingContext
+ );
+ const nodeFront = await onNewNodeFront;
+ is(nodeFront.id, "pick-me", "The expected node front was selected");
+
+ await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
+ await removeTemporaryExtension(ADDON_NAME, document);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_remote_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_remote_runtime.js
new file mode 100644
index 0000000000..607b8e15b4
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_remote_runtime.js
@@ -0,0 +1,145 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+const USB_RUNTIME_ID = "test-runtime-id";
+const USB_RUNTIME_DEVICE_NAME = "test device name";
+const USB_RUNTIME_APP_NAME = "TestUsbApp";
+
+// Test that addons are displayed and updated for USB runtimes when expected.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Prepare USB client mock");
+ const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ deviceName: USB_RUNTIME_DEVICE_NAME,
+ name: USB_RUNTIME_APP_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Test addons in runtime page for USB client");
+ await connectToRuntime(USB_RUNTIME_DEVICE_NAME, document);
+ await selectRuntime(USB_RUNTIME_DEVICE_NAME, USB_RUNTIME_APP_NAME, document);
+ await testAddonsOnMockedRemoteClient(
+ usbClient,
+ mocks.thisFirefoxClient,
+ document
+ );
+
+ info("Prepare Network client mock");
+ const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+ name: NETWORK_RUNTIME_APP_NAME,
+ });
+
+ info("Test addons in runtime page for Network client");
+ await connectToRuntime(NETWORK_RUNTIME_HOST, document);
+ await selectRuntime(NETWORK_RUNTIME_HOST, NETWORK_RUNTIME_APP_NAME, document);
+ await testAddonsOnMockedRemoteClient(
+ networkClient,
+ mocks.thisFirefoxClient,
+ document
+ );
+
+ await removeTab(tab);
+});
+
+/**
+ * Check that addons are visible in the runtime page for a remote client (USB or network).
+ */
+async function testAddonsOnMockedRemoteClient(
+ remoteClient,
+ firefoxClient,
+ document
+) {
+ const extensionPane = getDebugTargetPane("Extensions", document);
+ info("Check an empty target pane message is displayed");
+ ok(
+ extensionPane.querySelector(".qa-debug-target-list-empty"),
+ "Extensions list is empty"
+ );
+
+ info("Add an extension to the remote client");
+ const addon = { name: "Test extension name", debuggable: true };
+ const temporaryAddon = {
+ name: "Test temporary extension",
+ debuggable: true,
+ temporarilyInstalled: true,
+ };
+ remoteClient.listAddons = () => [addon, temporaryAddon];
+ remoteClient._eventEmitter.emit("addonListChanged");
+
+ info("Wait until the extension appears");
+ await waitUntil(
+ () => !extensionPane.querySelector(".qa-debug-target-list-empty")
+ );
+
+ const extensionTarget = findDebugTargetByText(
+ "Test extension name",
+ document
+ );
+ ok(extensionTarget, "Extension target appeared for the remote runtime");
+
+ const temporaryExtensionTarget = findDebugTargetByText(
+ "Test temporary extension",
+ document
+ );
+ ok(
+ temporaryExtensionTarget,
+ "Temporary Extension target appeared for the remote runtime"
+ );
+
+ const removeButton = temporaryExtensionTarget.querySelector(
+ ".qa-temporary-extension-remove-button"
+ );
+ ok(removeButton, "Remove button expected for the temporary extension");
+
+ const reloadButton = temporaryExtensionTarget.querySelector(
+ ".qa-temporary-extension-reload-button"
+ );
+ ok(reloadButton, "Reload button expected for the temporary extension");
+
+ // The goal here is to check that runtimes addons are only updated when the remote
+ // runtime is sending addonListChanged events. The reason for this test is because the
+ // previous implementation was updating the remote runtime extensions list when the
+ // _local_ AddonManager was updated.
+ info("Remove the extension from the remote client WITHOUT sending an event");
+ remoteClient.listAddons = () => [];
+
+ info("Simulate an addon update on the ThisFirefox client");
+ firefoxClient._eventEmitter.emit("addonListChanged");
+
+ // To avoid wait for a set period of time we trigger another async update, adding a new
+ // tab. We assume that if the addon update mechanism had started, it would also be done
+ // when the new tab was processed.
+ info("Wait until the tab target for 'http://some.random/url.com' appears");
+ const testTab = {
+ retrieveFavicon: () => {},
+ outerWindowID: 0,
+ traits: {},
+ url: "http://some.random/url.com",
+ };
+ remoteClient.listTabs = () => [testTab];
+ remoteClient._eventEmitter.emit("tabListChanged");
+ await waitUntil(() =>
+ findDebugTargetByText("http://some.random/url.com", document)
+ );
+
+ ok(
+ findDebugTargetByText("Test extension name", document),
+ "The test extension is still visible"
+ );
+
+ info(
+ "Emit `addonListChanged` on remoteClient and wait for the target list to update"
+ );
+ remoteClient._eventEmitter.emit("addonListChanged");
+ await waitUntil(
+ () => !findDebugTargetByText("Test extension name", document)
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_addon_buttons.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_addon_buttons.js
new file mode 100644
index 0000000000..26b558ff37
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_addon_buttons.js
@@ -0,0 +1,116 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// Test that the reload button updates the addon list with the correct metadata.
+add_task(async function () {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const ORIGINAL_EXTENSION_NAME = "Temporary web extension (original)";
+ const UPDATED_EXTENSION_NAME = "Temporary web extension (updated)";
+ const EXTENSION_ID = "test-devtools@mozilla.org";
+
+ const { xpiFile: addonFile } = await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION_ID,
+ name: ORIGINAL_EXTENSION_NAME,
+ },
+ document
+ );
+
+ const originalTarget = findDebugTargetByText(
+ ORIGINAL_EXTENSION_NAME,
+ document
+ );
+ ok(
+ !!originalTarget,
+ "The temporary extension isinstalled with the expected name"
+ );
+
+ info("Update the name of the temporary extension in the manifest");
+ updateTemporaryXPI(
+ { id: EXTENSION_ID, name: UPDATED_EXTENSION_NAME },
+ addonFile
+ );
+
+ info("Click on the reload button for the temporary extension");
+ const reloadButton = originalTarget.querySelector(
+ ".qa-temporary-extension-reload-button"
+ );
+ reloadButton.click();
+
+ info(
+ "Wait until the debug target with the original extension name disappears"
+ );
+ await waitUntil(
+ () => !findDebugTargetByText(ORIGINAL_EXTENSION_NAME, document)
+ );
+
+ info("Wait until the debug target with the updated extension name appears");
+ await waitUntil(() =>
+ findDebugTargetByText(UPDATED_EXTENSION_NAME, document)
+ );
+
+ const updatedTarget = findDebugTargetByText(UPDATED_EXTENSION_NAME, document);
+ ok(!!updatedTarget, "The temporary extension name has been updated");
+
+ info("Click on the remove button for the temporary extension");
+ const removeButton = updatedTarget.querySelector(
+ ".qa-temporary-extension-remove-button"
+ );
+ removeButton.click();
+
+ info(
+ "Wait until the debug target with the updated extension name disappears"
+ );
+ await waitUntil(
+ () => !findDebugTargetByText(UPDATED_EXTENSION_NAME, document)
+ );
+
+ await removeTab(tab);
+});
+
+add_task(async function () {
+ const PACKAGED_EXTENSION_ID = "packaged-extension@tests";
+ const PACKAGED_EXTENSION_NAME = "Packaged extension";
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installRegularExtension(
+ "resources/packaged-extension/packaged-extension.xpi"
+ );
+
+ info("Wait until extension appears in about:debugging");
+ await waitUntil(() =>
+ findDebugTargetByText(PACKAGED_EXTENSION_NAME, document)
+ );
+ const target = findDebugTargetByText(PACKAGED_EXTENSION_NAME, document);
+
+ const reloadButton = target.querySelector(
+ ".qa-temporary-extension-reload-button"
+ );
+ ok(
+ !reloadButton,
+ "No reload button displayed for a regularly installed extension"
+ );
+
+ const removeButton = target.querySelector(
+ ".qa-temporary-extension-remove-button"
+ );
+ ok(
+ !removeButton,
+ "No remove button displayed for a regularly installed extension"
+ );
+
+ await removeExtension(
+ PACKAGED_EXTENSION_ID,
+ PACKAGED_EXTENSION_NAME,
+ document
+ );
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_id_message.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_id_message.js
new file mode 100644
index 0000000000..6e0b21fb20
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_id_message.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// Test that temporary extensions show a message about temporary ids, with a learn more
+// link.
+add_task(async function () {
+ const EXTENSION_NAME = "Temporary web extension";
+ const EXTENSION_ID = "test-devtools@mozilla.org";
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ },
+ document
+ );
+
+ info("Wait until a debug target item appears");
+ await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, document));
+
+ const target = findDebugTargetByText(EXTENSION_NAME, document);
+
+ const message = target.querySelector(".qa-temporary-id-message");
+ ok(!!message, "Temporary id message is displayed for temporary extensions");
+
+ const link = target.querySelector(".qa-temporary-id-link");
+ ok(!!link, "Temporary id link is displayed for temporary extensions");
+
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+ await removeTab(tab);
+});
+
+// Test that the message and the link are not displayed for a regular extension.
+add_task(async function () {
+ const PACKAGED_EXTENSION_ID = "packaged-extension@tests";
+ const PACKAGED_EXTENSION_NAME = "Packaged extension";
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installRegularExtension(
+ "resources/packaged-extension/packaged-extension.xpi"
+ );
+
+ info("Wait until extension appears in about:debugging");
+ await waitUntil(() =>
+ findDebugTargetByText(PACKAGED_EXTENSION_NAME, document)
+ );
+ const target = findDebugTargetByText(PACKAGED_EXTENSION_NAME, document);
+
+ const tmpIdMessage = target.querySelector(".qa-temporary-id-message");
+ ok(
+ !tmpIdMessage,
+ "No temporary id message is displayed for a regular extension"
+ );
+
+ await removeExtension(
+ PACKAGED_EXTENSION_ID,
+ PACKAGED_EXTENSION_NAME,
+ document
+ );
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_error.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_error.js
new file mode 100644
index 0000000000..21a30ab3bf
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_error.js
@@ -0,0 +1,89 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+/**
+ * Test that the installation error messages are displayed when installing temporary
+ * extensions.
+ */
+
+const INVALID_JSON_EXTENSION_PATH =
+ "resources/bad-extensions/invalid-json/manifest.json";
+const INVALID_PROP_EXTENSION_PATH =
+ "resources/bad-extensions/invalid-property/manifest.json";
+const EXTENSION_PATH = "resources/test-temporary-extension/manifest.json";
+const EXTENSION_NAME = "test-temporary-extension";
+
+// Extension with an invalid JSON manifest will not be parsed. We check the expected
+// error message is displayed
+add_task(async function testInvalidJsonExtension() {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const installError = await installBadExtension(
+ INVALID_JSON_EXTENSION_PATH,
+ document
+ );
+ ok(
+ installError.textContent.includes("JSON.parse: unexpected keyword"),
+ "The expected installation error is displayed: " + installError.textContent
+ );
+
+ info("Install a valid extension to make the message disappear");
+ await installTemporaryExtension(EXTENSION_PATH, EXTENSION_NAME, document);
+
+ info("Wait until the error message disappears");
+ await waitUntil(
+ () => !document.querySelector(".qa-tmp-extension-install-error")
+ );
+
+ info("Wait for the temporary addon to be displayed as a debug target");
+ await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, document));
+
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+
+ await removeTab(tab);
+});
+
+// Extension with a valid JSON manifest but containing an invalid property should display
+// a detailed error message coming from the Addon Manager.
+add_task(async function testInvalidPropertyExtension() {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const installError = await installBadExtension(
+ INVALID_PROP_EXTENSION_PATH,
+ document
+ );
+
+ ok(
+ installError.textContent.includes("Extension is invalid"),
+ "The basic installation error is displayed: " + installError.textContent
+ );
+ ok(
+ installError.textContent.includes(
+ "Reading manifest: Error processing content_scripts.0.matches"
+ ),
+ "The detailed installation error is also displayed: " +
+ installError.textContent
+ );
+
+ await removeTab(tab);
+});
+
+async function installBadExtension(path, document) {
+ info("Install a bad extension at path: " + path);
+ // Do not use installTemporaryAddon here since the install will fail.
+ prepareMockFilePicker(path);
+ document.querySelector(".qa-temporary-extension-install-button").click();
+
+ info("Wait until the install error message appears");
+ await waitUntil(() =>
+ document.querySelector(".qa-tmp-extension-install-error")
+ );
+ return document.querySelector(".qa-tmp-extension-install-error");
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_path.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_path.js
new file mode 100644
index 0000000000..a6f9fde0c1
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_install_path.js
@@ -0,0 +1,65 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+/**
+ * Test the the path used to install a temporary addon is saved in a preference and reused
+ * next time the feature is used.
+ */
+
+const EXTENSION_PATH = "resources/test-temporary-extension/manifest.json";
+const EXTENSION_NAME = "test-temporary-extension";
+const LAST_DIR_PREF = "devtools.aboutdebugging.tmpExtDirPath";
+
+// Check that the preference is updated when trying to install a temporary extension.
+add_task(async function testPreferenceUpdatedAfterInstallingExtension() {
+ registerCleanupFunction(() => {
+ Services.prefs.clearUserPref(LAST_DIR_PREF);
+ });
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await installTemporaryExtension(EXTENSION_PATH, EXTENSION_NAME, document);
+
+ info("Check whether the selected dir sets into the pref");
+ const lastDirPath = Services.prefs.getCharPref(LAST_DIR_PREF, "");
+ const expectedPath = getTestFilePath("resources/test-temporary-extension");
+ is(lastDirPath, expectedPath, "The selected dir should set into the pref");
+
+ await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, document));
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+ await removeTab(tab);
+});
+
+// Check that the preference is updated when trying to install a temporary extension.
+add_task(async function testPreferenceRetrievedWhenInstallingExtension() {
+ const selectedDir = getTestFilePath("resources/packaged-extension");
+
+ await pushPref(LAST_DIR_PREF, selectedDir);
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const MockFilePicker = SpecialPowers.MockFilePicker;
+ MockFilePicker.init(window);
+ const onFilePickerShown = new Promise(resolve => {
+ MockFilePicker.showCallback = fp => {
+ resolve(fp);
+ };
+ });
+ document.querySelector(".qa-temporary-extension-install-button").click();
+
+ info("Check whether the shown dir is same as the pref");
+ const fp = await onFilePickerShown;
+ is(
+ fp.displayDirectory.path,
+ selectedDir,
+ "Shown directory sets as same as the pref"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_reload_error.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_reload_error.js
new file mode 100644
index 0000000000..da09727d9e
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_temporary_reload_error.js
@@ -0,0 +1,68 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// Test that the reload button updates the addon list with the correct metadata.
+add_task(async function () {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const EXTENSION_ID = "test-devtools@mozilla.org";
+ const EXTENSION_NAME = "Temporary web extension";
+
+ let { xpiFile: addonFile } = await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ },
+ document
+ );
+
+ const target = findDebugTargetByText(EXTENSION_NAME, document);
+ ok(!!target, "The temporary extension is installed with the expected name");
+
+ info("Update the name of the temporary extension in the manifest");
+ addonFile = updateTemporaryXPI({ id: EXTENSION_ID }, addonFile);
+
+ info("Click on the reload button for the invalid temporary extension");
+ const waitForError = waitForDispatch(
+ window.AboutDebugging.store,
+ "TEMPORARY_EXTENSION_RELOAD_FAILURE"
+ );
+ const reloadButton = target.querySelector(
+ ".qa-temporary-extension-reload-button"
+ );
+ reloadButton.click();
+ await waitForError;
+ ok(
+ target.querySelector(".qa-temporary-extension-reload-error"),
+ "The error message of reloading appears"
+ );
+
+ info("Click on the reload button for the valid temporary extension");
+ const waitForSuccess = waitForDispatch(
+ window.AboutDebugging.store,
+ "TEMPORARY_EXTENSION_RELOAD_SUCCESS"
+ );
+ updateTemporaryXPI({ id: EXTENSION_ID, name: EXTENSION_NAME }, addonFile);
+ reloadButton.click();
+ await waitForSuccess;
+ ok(
+ !target.querySelector(".qa-temporary-extension-reload-error"),
+ "The error message of reloading disappears"
+ );
+
+ info("Click on the remove button for the temporary extension");
+ const removeButton = target.querySelector(
+ ".qa-temporary-extension-remove-button"
+ );
+ removeButton.click();
+
+ info("Wait until the debug target with the extension disappears");
+ await waitUntil(() => !findDebugTargetByText(EXTENSION_NAME, document));
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_warnings.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_warnings.js
new file mode 100644
index 0000000000..db46754caa
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_warnings.js
@@ -0,0 +1,49 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+// Test that extension warnings are displayed in about:debugging.
+add_task(async function () {
+ const EXTENSION_NAME = "Temporary web extension";
+ const EXTENSION_ID = "test-devtools@mozilla.org";
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await pushPref("extensions.webextensions.warnings-as-errors", false);
+ await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ extraProperties: {
+ // This property is not expected in the manifest and should trigger a warning!
+ wrongProperty: {},
+ },
+ },
+ document
+ );
+ await SpecialPowers.popPrefEnv();
+
+ info("Wait until a debug target item appears");
+ await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, document));
+ const target = findDebugTargetByText(EXTENSION_NAME, document);
+
+ const warningMessage = target.querySelector(".qa-message");
+ ok(
+ !!warningMessage,
+ "A warning message is displayed for the installed addon"
+ );
+
+ const warningText = warningMessage.textContent;
+ ok(
+ warningText.includes("wrongProperty"),
+ "The warning message mentions wrongProperty"
+ );
+
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_networklocations.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_networklocations.js
new file mode 100644
index 0000000000..92096703ac
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_networklocations.js
@@ -0,0 +1,103 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Test the network locations form of the Connect page.
+ * Check that a network location can be added and removed.
+ */
+
+const TEST_NETWORK_LOCATION = "localhost:1111";
+const TEST_NETWORK_LOCATION_INVALID = "testnetwork";
+
+add_task(async function () {
+ const { document, tab } = await openAboutDebugging();
+
+ await selectConnectPage(document);
+
+ let networkLocations = document.querySelectorAll(".qa-network-location");
+ is(
+ networkLocations.length,
+ 0,
+ "By default, no network locations are displayed"
+ );
+
+ info("Check whether error message should show if the input value is invalid");
+ addNetworkLocation(TEST_NETWORK_LOCATION_INVALID, document);
+ await waitUntil(() =>
+ document.querySelector(".qa-connect-page__network-form__error-message")
+ );
+
+ info("Wait until the new network location is visible in the list");
+ addNetworkLocation(TEST_NETWORK_LOCATION, document);
+ await waitUntil(
+ () => document.querySelectorAll(".qa-network-location").length === 1
+ );
+ await waitUntil(
+ () =>
+ !document.querySelector(".qa-connect-page__network-form__error-message")
+ );
+
+ networkLocations = document.querySelectorAll(".qa-network-location");
+ const networkLocationValue = networkLocations[0].querySelector(
+ ".qa-network-location-value"
+ );
+ is(
+ networkLocationValue.textContent,
+ TEST_NETWORK_LOCATION,
+ "Added network location has the expected value"
+ );
+
+ info(
+ "Check whether error message should show if the input value was duplicate"
+ );
+ addNetworkLocation(TEST_NETWORK_LOCATION, document);
+ await waitUntil(() =>
+ document.querySelector(".qa-connect-page__network-form__error-message")
+ );
+
+ info("Wait until the new network location is removed from the list");
+ removeNetworkLocation(TEST_NETWORK_LOCATION, document);
+ await waitUntil(
+ () => document.querySelectorAll(".qa-network-location").length === 0
+ );
+
+ await removeTab(tab);
+});
+
+function addNetworkLocation(location, document) {
+ info("Setting a value in the network form input");
+ const networkLocationInput = document.querySelector(".qa-network-form-input");
+ networkLocationInput.value = "";
+ networkLocationInput.focus();
+ EventUtils.sendString(location, networkLocationInput.ownerGlobal);
+
+ info("Click on network form submit button");
+ const networkLocationSubmitButton = document.querySelector(
+ ".qa-network-form-submit-button"
+ );
+ networkLocationSubmitButton.click();
+}
+
+function removeNetworkLocation(location, document) {
+ const networkLocation = getNetworkLocation(location, document);
+ ok(networkLocation, "Network location container found.");
+
+ info("Click on the remove button for the provided network location");
+ const removeButton = networkLocation.querySelector(
+ ".qa-network-location-remove-button"
+ );
+ removeButton.click();
+}
+
+function getNetworkLocation(location, document) {
+ info("Find the container for network location: " + location);
+ const networkLocations = document.querySelectorAll(".qa-network-location");
+ return [...networkLocations].find(element => {
+ return (
+ element.querySelector(".qa-network-location-value").textContent ===
+ location
+ );
+ });
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_toggle_usb_devices.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_toggle_usb_devices.js
new file mode 100644
index 0000000000..e0d7303669
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connect_toggle_usb_devices.js
@@ -0,0 +1,81 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-adb.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-adb.js", this);
+
+/**
+ * Check that USB Devices scanning can be enabled and disabled from the connect page.
+ */
+add_task(async function () {
+ await pushPref(
+ "devtools.remote.adb.extensionURL",
+ CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi"
+ );
+ await checkAdbNotRunning();
+
+ const { document, tab } = await openAboutDebugging();
+
+ await selectConnectPage(document);
+
+ info("Wait until Connect page is displayed");
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+
+ info("Check that by default USB devices are disabled");
+ const usbDisabledMessage = document.querySelector(
+ ".qa-connect-usb-disabled-message"
+ );
+ ok(usbDisabledMessage, "A message about enabling USB devices is rendered");
+
+ const usbToggleButton = document.querySelector(
+ ".qa-connect-usb-toggle-button"
+ );
+ ok(usbToggleButton, "The button to toggle USB devices debugging is rendered");
+ ok(
+ usbToggleButton.textContent.includes("Enable"),
+ "The text of the toggle USB button is correct"
+ );
+
+ info("Click on the toggle button");
+ usbToggleButton.click();
+
+ info("Wait until the toggle button text is updated");
+ await waitUntil(() => usbToggleButton.textContent.includes("Disable"));
+ ok(
+ !document.querySelector(".qa-connect-usb-disabled-message"),
+ "The message about enabling USB devices is no longer rendered"
+ );
+
+ info("Check that the addon was installed with the proper source");
+ const adbExtensionId = Services.prefs.getCharPref(
+ "devtools.remote.adb.extensionID"
+ );
+ const addon = await AddonManager.getAddonByID(adbExtensionId);
+ Assert.deepEqual(
+ addon.installTelemetryInfo,
+ { source: "about:debugging" },
+ "Got the expected addon.installTelemetryInfo"
+ );
+
+ // Right now we are resuming as soon as "USB enabled" is displayed, but ADB
+ // might still be starting up. If we move to uninstall directly, the ADB startup will
+ // fail and we will have an unhandled promise rejection.
+ // See Bug 1498469.
+ await waitForAdbStart();
+
+ info("Click on the toggle button");
+ usbToggleButton.click();
+
+ info("Wait until the toggle button text is updated");
+ await waitUntil(() => usbToggleButton.textContent.includes("Enable"));
+ ok(
+ document.querySelector(".qa-connect-usb-disabled-message"),
+ "The message about enabling USB devices is rendered again"
+ );
+
+ await stopAdbProcess();
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connection_prompt_setting.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connection_prompt_setting.js
new file mode 100644
index 0000000000..dfee0c1ba0
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_connection_prompt_setting.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const USB_RUNTIME_ID = "1337id";
+const USB_DEVICE_NAME = "Fancy Phone";
+const USB_APP_NAME = "Lorem ipsum";
+
+/**
+ * Check whether can toggle enable/disable connection prompt setting.
+ */
+add_task(async function () {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ const runtime = mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ deviceName: USB_DEVICE_NAME,
+ name: USB_APP_NAME,
+ });
+
+ info("Set initial state for test");
+ await pushPref("devtools.debugger.prompt-connection", true);
+
+ // open a remote runtime page
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ mocks.emitUSBUpdate();
+ await connectToRuntime(USB_DEVICE_NAME, document);
+ await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);
+
+ info("Check whether connection prompt toggle button exists");
+ let connectionPromptToggleButton = document.querySelector(
+ ".qa-connection-prompt-toggle-button"
+ );
+ ok(connectionPromptToggleButton, "Toggle button existed");
+ ok(
+ connectionPromptToggleButton.textContent.includes("Disable"),
+ "Toggle button shows 'Disable'"
+ );
+
+ info("Click on the toggle button");
+ connectionPromptToggleButton = document.querySelector(
+ ".qa-connection-prompt-toggle-button"
+ );
+ connectionPromptToggleButton.click();
+ info("Wait until the toggle button text is updated");
+ await waitUntil(() =>
+ connectionPromptToggleButton.textContent.includes("Enable")
+ );
+ info("Check the preference");
+ const disabledPref = runtime.getPreference(
+ "devtools.debugger.prompt-connection"
+ );
+ is(disabledPref, false, "The preference should be updated");
+
+ info("Click on the toggle button again");
+ connectionPromptToggleButton.click();
+ info("Wait until the toggle button text is updated");
+ await waitUntil(() =>
+ connectionPromptToggleButton.textContent.includes("Disable")
+ );
+ info("Check the preference");
+ const enabledPref = runtime.getPreference(
+ "devtools.debugger.prompt-connection"
+ );
+ is(enabledPref, true, "The preference should be updated");
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js
new file mode 100644
index 0000000000..7b25e02a9b
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_interaction.js
@@ -0,0 +1,62 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test that collapsibilities of DebugTargetPane on RuntimePage by mouse clicking.
+ */
+
+add_task(async function () {
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ for (const { title } of TARGET_PANES) {
+ info("Check whether this pane is collapsed after clicking the title");
+ await toggleCollapsibility(getDebugTargetPane(title, document));
+ assertDebugTargetCollapsed(getDebugTargetPane(title, document), title);
+
+ info("Check whether this pane is expanded after clicking the title again");
+ await toggleCollapsibility(getDebugTargetPane(title, document));
+ await assertDebugTargetExpanded(getDebugTargetPane(title, document), title);
+ }
+
+ await removeTab(tab);
+});
+
+async function assertDebugTargetCollapsed(paneEl, title) {
+ info("Check debug target is collapsed");
+
+ // check list height
+ const targetEl = paneEl.querySelector(".qa-debug-target-pane__collapsable");
+ is(targetEl.clientHeight, 0, "Height of list element is zero");
+ // check title
+ const titleEl = paneEl.querySelector(".qa-debug-target-pane-title");
+ const expectedTitle = `${title} (${
+ targetEl.querySelectorAll(".qa-debug-target-item").length
+ })`;
+ is(titleEl.textContent, expectedTitle, "Collapsed title is correct");
+}
+
+async function assertDebugTargetExpanded(paneEl, title) {
+ info("Check debug target is expanded");
+
+ // check list height
+ const targetEl = paneEl.querySelector(".qa-debug-target-pane__collapsable");
+ await waitUntil(() => targetEl.clientHeight > 0);
+ ok(true, "Height of list element is greater than zero");
+ // check title
+ const titleEl = paneEl.querySelector(".qa-debug-target-pane-title");
+ const expectedTitle = `${title} (${
+ targetEl.querySelectorAll(".qa-debug-target-item").length
+ })`;
+ is(titleEl.textContent, expectedTitle, "Expanded title is correct");
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js
new file mode 100644
index 0000000000..50857ee617
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_collapsibilities_preference.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test for preference of DebugTargetPane collapsibilities.
+ */
+
+add_task(async function () {
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Collapse all pane");
+ for (const { title } of TARGET_PANES) {
+ const debugTargetPaneEl = getDebugTargetPane(title, document);
+ await toggleCollapsibility(debugTargetPaneEl);
+ }
+
+ info("Check preference of collapsibility after closing about:debugging page");
+ await removeTab(tab);
+ // Wait until unmount.
+ await waitUntil(() => document.querySelector(".app") === null);
+
+ for (const { pref } of TARGET_PANES) {
+ is(
+ Services.prefs.getBoolPref(pref),
+ true,
+ `${pref} preference should be true`
+ );
+ }
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_empty.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_empty.js
new file mode 100644
index 0000000000..301be26a32
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_empty.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test that an "empty" message is displayed when there are no debug targets in a debug
+ * target pane.
+ */
+
+const EXTENSION_PATH = "resources/test-temporary-extension/manifest.json";
+const EXTENSION_NAME = "test-temporary-extension";
+
+add_task(async function () {
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Check that the temporary extensions pane is empty");
+ const temporaryExtensionPane = getDebugTargetPane(
+ "Temporary Extensions",
+ document
+ );
+ ok(
+ !temporaryExtensionPane.querySelector(".qa-debug-target-item"),
+ "Temporary Extensions pane contains no debug target"
+ );
+
+ info("Check an empty target pane message is displayed");
+ ok(
+ temporaryExtensionPane.querySelector(".qa-debug-target-list-empty"),
+ "An empty target list message is displayed"
+ );
+
+ info("Install a temporary extension");
+ await installTemporaryExtension(EXTENSION_PATH, EXTENSION_NAME, document);
+
+ info("Wait until a debug target item appears");
+ await waitUntil(() =>
+ temporaryExtensionPane.querySelector(".qa-debug-target-item")
+ );
+
+ info("Check the empty target pane message is no longer displayed");
+ ok(
+ !temporaryExtensionPane.querySelector(".qa-debug-target-list-empty"),
+ "The empty target list message is no longer displayed"
+ );
+
+ const temporaryExtensionItem = temporaryExtensionPane.querySelector(
+ ".qa-debug-target-item"
+ );
+ ok(
+ temporaryExtensionItem,
+ "Temporary Extensions pane now shows debug target"
+ );
+
+ info("Remove the temporary extension");
+ temporaryExtensionItem
+ .querySelector(".qa-temporary-extension-remove-button")
+ .click();
+
+ info("Wait until the debug target item disappears");
+ await waitUntil(
+ () => !temporaryExtensionPane.querySelector(".qa-debug-target-item")
+ );
+
+ info("Check the empty target pane message is displayed again");
+ ok(
+ temporaryExtensionPane.querySelector(".qa-debug-target-list-empty"),
+ "An empty target list message is displayed again"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
new file mode 100644
index 0000000000..0f50b9454b
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_debug-target-pane_usb_runtime.js
@@ -0,0 +1,72 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_DEVICE_NAME = "test device name";
+const RUNTIME_APP_NAME = "TestApp";
+
+// Test that the expected supported categories are displayed for USB runtimes.
+add_task(async function () {
+ const mocks = new Mocks();
+ await checkTargetPanes({ enableLocalTabs: false }, mocks);
+
+ info(
+ "Check that enableLocalTabs has no impact on the categories displayed for remote" +
+ " runtimes."
+ );
+ await checkTargetPanes({ enableLocalTabs: true }, mocks);
+});
+
+async function checkTargetPanes({ enableLocalTabs }, mocks) {
+ const { document, tab, window } = await openAboutDebugging({
+ enableLocalTabs,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: RUNTIME_DEVICE_NAME,
+ name: RUNTIME_APP_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+ await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+
+ const SUPPORTED_TARGET_PANES = [
+ "Temporary Extensions",
+ "Extensions",
+ "Other Workers",
+ "Shared Workers",
+ "Service Workers",
+ "Tabs",
+ ];
+
+ for (const { title } of TARGET_PANES) {
+ const debugTargetPaneEl = getDebugTargetPane(title, document);
+ if (SUPPORTED_TARGET_PANES.includes(title)) {
+ ok(debugTargetPaneEl, `Supported target pane [${title}] is displayed`);
+ } else {
+ ok(!debugTargetPaneEl, `Unsupported target pane [${title}] is hidden`);
+ }
+ }
+
+ const installButton = document.querySelector(
+ ".qa-temporary-extension-install-button"
+ );
+ ok(!installButton, "Temporary Extensions install button is hidden");
+
+ info("Remove USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+ await removeTab(tab);
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtools.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtools.js
new file mode 100644
index 0000000000..4ea3238ea3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtools.js
@@ -0,0 +1,51 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Check that DevTools are not closed when leaving This Firefox runtime page.
+ */
+
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const connectSidebarItem = findSidebarItemByText("Setup", document);
+ const connectLink = connectSidebarItem.querySelector(".qa-sidebar-link");
+ ok(connectSidebarItem, "Found the Connect sidebar item");
+
+ info("Open devtools on the current about:debugging tab");
+ const toolbox = await openToolboxForTab(tab, "inspector");
+ const inspector = toolbox.getPanel("inspector");
+
+ info("DevTools starts workers, wait for requests to settle");
+ const store = window.AboutDebugging.store;
+ await waitForAboutDebuggingRequests(store);
+
+ info("Click on the Connect item in the sidebar");
+ connectLink.click();
+ await waitForDispatch(store, "UNWATCH_RUNTIME_SUCCESS");
+
+ info("Wait until Connect page is displayed");
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+
+ const markupViewElement = inspector.panelDoc.getElementById("markup-box");
+ ok(markupViewElement, "Inspector is still rendered");
+
+ // We explicitely destroy the toolbox in order to ensure waiting for its full destruction
+ // and avoid leak / pending requests
+ info("Destroy the opened toolbox");
+ await toolbox.destroy();
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_breakpoint.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_breakpoint.js
new file mode 100644
index 0000000000..925d40b643
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_breakpoint.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/devtools/client/debugger/test/mochitest/shared-head.js",
+ this
+);
+
+const SCRIPT_FILE = "script_aboutdebugging_devtoolstoolbox_breakpoint.js";
+const TAB_URL =
+ "https://example.com/browser/devtools/client/aboutdebugging/" +
+ "test/browser/resources/doc_aboutdebugging_devtoolstoolbox_breakpoint.html";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test breakpoints in about:devtools-toolbox tabs (ie non localTab tab target).
+ */
+add_task(async function () {
+ const testTab = await addTab(TAB_URL);
+
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ TAB_URL
+ );
+ info("Select performance panel");
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool("jsdebugger");
+
+ info("Add a breakpoint at line 10 in the test script");
+ const debuggerContext = createDebuggerContext(toolbox);
+ await selectSource(debuggerContext, SCRIPT_FILE);
+ await addBreakpoint(debuggerContext, SCRIPT_FILE, 10);
+
+ info("Invoke testMethod, expect the script to pause on line 10");
+ const onContentTaskDone = ContentTask.spawn(
+ testTab.linkedBrowser,
+ {},
+ function () {
+ content.wrappedJSObject.testMethod();
+ }
+ );
+
+ info("Wait for the debugger to pause");
+ await waitForPaused(debuggerContext);
+ const script = findSource(debuggerContext, SCRIPT_FILE);
+ assertPausedAtSourceAndLine(debuggerContext, script.id, 10);
+
+ info("Resume");
+ await resume(debuggerContext);
+
+ info("Wait for the paused content task to also resolve");
+ await onContentTaskDone;
+
+ info("Remove breakpoint");
+ await removeBreakpoint(debuggerContext, script.id, 10);
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(testTab);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu.js
new file mode 100644
index 0000000000..eb8f233d12
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu.js
@@ -0,0 +1,102 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test context menu on about:devtools-toolbox page.
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsBrowser, devtoolsTab } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window
+ );
+
+ info("Check whether the menu item which opens devtools is disabled");
+ const rootDocument = devtoolsTab.ownerDocument;
+ await assertContextMenu(
+ rootDocument,
+ devtoolsBrowser,
+ ".debug-target-info",
+ false
+ );
+
+ info("Force to select about:debugging page");
+ await updateSelectedTab(gBrowser, tab, window.AboutDebugging.store);
+
+ info("Check whether the menu item which opens devtools is enabled");
+ await assertContextMenu(rootDocument, devtoolsBrowser, "#mount", true);
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
+
+async function assertContextMenu(
+ rootDocument,
+ browser,
+ targetSelector,
+ shouldBeEnabled
+) {
+ if (shouldBeEnabled) {
+ await assertContextMenuEnabled(rootDocument, browser, targetSelector);
+ } else {
+ await assertContextMenuDisabled(rootDocument, browser, targetSelector);
+ }
+}
+
+async function assertContextMenuDisabled(
+ rootDocument,
+ browser,
+ targetSelector
+) {
+ const contextMenu = rootDocument.getElementById("contentAreaContextMenu");
+ let isPopupShown = false;
+ const listener = () => {
+ isPopupShown = true;
+ };
+ contextMenu.addEventListener("popupshown", listener);
+ BrowserTestUtils.synthesizeMouseAtCenter(
+ targetSelector,
+ { type: "contextmenu" },
+ browser
+ );
+ await wait(1000);
+ ok(!isPopupShown, `Context menu should not be shown`);
+ contextMenu.removeEventListener("popupshown", listener);
+}
+
+async function assertContextMenuEnabled(rootDocument, browser, targetSelector) {
+ // Show content context menu.
+ const contextMenu = rootDocument.getElementById("contentAreaContextMenu");
+ const popupShownPromise = BrowserTestUtils.waitForEvent(
+ contextMenu,
+ "popupshown"
+ );
+ BrowserTestUtils.synthesizeMouseAtCenter(
+ targetSelector,
+ { type: "contextmenu" },
+ browser
+ );
+ await popupShownPromise;
+ ok(true, `Context menu should be shown`);
+
+ // Hide content context menu.
+ const popupHiddenPromise = BrowserTestUtils.waitForEvent(
+ contextMenu,
+ "popuphidden"
+ );
+ contextMenu.hidePopup();
+ await popupHiddenPromise;
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu_markupview.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu_markupview.js
new file mode 100644
index 0000000000..bc46b828fd
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_contextmenu_markupview.js
@@ -0,0 +1,45 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test context menu of markup view on about:devtools-toolbox page.
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window
+ );
+
+ info("Select inspector tool");
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool("inspector");
+
+ info("Show context menu of markup view");
+ const markupDocument = toolbox.getPanel("inspector").markup.doc;
+ EventUtils.synthesizeMouseAtCenter(
+ markupDocument.body,
+ { type: "contextmenu" },
+ markupDocument.ownerGlobal
+ );
+
+ info("Check whether proper context menu of markup view will be shown");
+ await waitUntil(() => toolbox.topDoc.querySelector("#node-menu-edithtml"));
+ ok(true, "Context menu of markup view should be shown");
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_focus.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_focus.js
new file mode 100644
index 0000000000..a3fa63c340
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_focus.js
@@ -0,0 +1,122 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test whether the focus transfers to a tab which is already inspected .
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ info(
+ "Select 'performance' panel as the initial tool since the tool does not listen " +
+ "any changes of the document without user action"
+ );
+ await pushPref("devtools.toolbox.selectedTool", "performance");
+
+ const { document, tab, window } = await openAboutDebugging();
+ const { store } = window.AboutDebugging;
+ await selectThisFirefoxPage(document, store);
+
+ const inspectionTarget = "about:debugging";
+ info(`Open ${inspectionTarget} as inspection target`);
+ await waitUntil(() => findDebugTargetByText(inspectionTarget, document));
+ info(`Inspect ${inspectionTarget} page in about:devtools-toolbox`);
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ inspectionTarget
+ );
+
+ info(
+ "Check the tab state after clicking inspect button " +
+ "when another tab was selected"
+ );
+ await updateSelectedTab(gBrowser, tab, store);
+ clickInspectButton(inspectionTarget, document);
+ const devtoolsURL = devtoolsWindow.location.href;
+ assertDevtoolsToolboxTabState(devtoolsURL);
+
+ info(
+ "Check the tab state after clicking inspect button " +
+ "when the toolbox tab is in another window"
+ );
+ const newNavigator = gBrowser.replaceTabWithWindow(devtoolsTab);
+ await waitUntil(
+ () =>
+ newNavigator.gBrowser &&
+ newNavigator.gBrowser.selectedTab.linkedBrowser.contentWindow.location
+ .href === devtoolsURL
+ );
+
+ info(
+ "Create a tab in the window and select the tab " +
+ "so that the about:devtools-toolbox tab loses focus"
+ );
+ const newTestTab = newNavigator.gBrowser.addTab(
+ "data:text/html,<title>TEST_TAB</title>",
+ {
+ triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
+ }
+ );
+ await waitUntil(() => findDebugTargetByText("TEST_TAB", document));
+
+ await updateSelectedTab(newNavigator.gBrowser, newTestTab, store);
+
+ let onTabsSuccess = waitForDispatch(store, "REQUEST_TABS_SUCCESS");
+ clickInspectButton(inspectionTarget, document);
+ assertDevtoolsToolboxTabState(devtoolsURL);
+ await onTabsSuccess;
+
+ info("Close new navigator and wait until the debug target disappears");
+ onTabsSuccess = waitForDispatch(store, "REQUEST_TABS_SUCCESS");
+ const onToolboxDestroyed = gDevTools.once("toolbox-destroyed");
+ newNavigator.close();
+ await onToolboxDestroyed;
+ await onTabsSuccess;
+
+ await waitUntil(() => !findDebugTargetByText("Toolbox - ", document));
+
+ info("Remove test tab");
+ await removeTab(tab);
+});
+
+function clickInspectButton(inspectionTarget, doc) {
+ const target = findDebugTargetByText(inspectionTarget, doc);
+ const button = target.querySelector(".qa-debug-target-inspect-button");
+ button.click();
+}
+
+// Check that only one tab is currently opened for the provided URL.
+// Also check that this tab and the tab's window are focused.
+function assertDevtoolsToolboxTabState(devtoolsURL) {
+ const existingTabs = [];
+
+ for (const navigator of Services.wm.getEnumerator("navigator:browser")) {
+ for (const browser of navigator.gBrowser.browsers) {
+ if (
+ browser.contentWindow &&
+ browser.contentWindow.location.href === devtoolsURL
+ ) {
+ const tab = navigator.gBrowser.getTabForBrowser(browser);
+ existingTabs.push(tab);
+ }
+ }
+ }
+
+ is(existingTabs.length, 1, `Only one tab is opened for ${devtoolsURL}`);
+ const tab = existingTabs[0];
+ const navigator = tab.ownerGlobal;
+ is(navigator.gBrowser.selectedTab, tab, "The tab is selected");
+ const focusedNavigator = Services.wm.getMostRecentWindow("navigator:browser");
+ is(navigator, focusedNavigator, "The navigator is focused");
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_menubar.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_menubar.js
new file mode 100644
index 0000000000..c2f0c5e362
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_menubar.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test the status of menu items when open about:devtools-toolbox.
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window
+ );
+
+ info("Check whether the menu items are disabled");
+ const rootDocument = devtoolsTab.ownerDocument;
+ await assertMenusItems(rootDocument, false);
+
+ info("Select the inspector");
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool("inspector");
+
+ info("Force to select about:debugging page");
+ await updateSelectedTab(gBrowser, tab, window.AboutDebugging.store);
+
+ info("Check whether the menu items are enabled");
+ await assertMenusItems(rootDocument, true);
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
+
+async function assertMenusItems(rootDocument, shouldBeEnabled) {
+ info("Wait for the Toggle Tools menu-item hidden attribute to change");
+ const menuItem = rootDocument.getElementById("menu_devToolbox");
+ await waitUntil(() => menuItem.hidden === !shouldBeEnabled);
+
+ info(
+ "Check that the state of the Toggle Tools menu-item depends on the page"
+ );
+ assertMenuItem(rootDocument, "menu_devToolbox", shouldBeEnabled);
+
+ info(
+ "Check that the tools menu-items are always enabled regardless of the page"
+ );
+ for (const toolDefinition of gDevTools.getToolDefinitionArray()) {
+ if (!toolDefinition.inMenu) {
+ continue;
+ }
+
+ assertMenuItem(rootDocument, "menuitem_" + toolDefinition.id, true);
+ }
+}
+
+function assertMenuItem(rootDocument, menuItemId, shouldBeEnabled) {
+ const menuItem = rootDocument.getElementById(menuItemId);
+ is(
+ menuItem.hidden,
+ !shouldBeEnabled,
+ `"hidden" attribute of menu item(${menuItemId}) should be correct`
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_back_forward.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_back_forward.js
new file mode 100644
index 0000000000..79428ae8da
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_back_forward.js
@@ -0,0 +1,63 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const ORIGINAL_URL = "https://example.com/document-builder.sjs?html=page1";
+const OTHER_URL = "https://example.org/document-builder.sjs?html=page2";
+
+async function waitForUrl(url, toolbox, browserTab, win) {
+ const { onDomCompleteResource } =
+ await waitForNextTopLevelDomCompleteResource(toolbox.commands);
+
+ return Promise.all([
+ waitUntil(
+ () =>
+ toolbox.target.url === url &&
+ browserTab.linkedBrowser.currentURI.spec === url
+ ),
+ onDomCompleteResource,
+ toolbox.commands.client.waitForRequestsToSettle(),
+ waitForAboutDebuggingRequests(win.AboutDebugging.store),
+ ]);
+}
+
+// Test that ensures the remote page can go forward and back via UI buttons
+add_task(async function () {
+ const browserTab = await addTab(ORIGINAL_URL);
+
+ const { document, tab, window } = await openAboutDebugging();
+
+ // go to This Firefox and inspect the new tab
+ info("Inspecting a new tab in This Firefox");
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const devToolsToolbox = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ ORIGINAL_URL
+ );
+ const { devtoolsDocument, devtoolsWindow } = devToolsToolbox;
+ const toolbox = getToolbox(devtoolsWindow);
+
+ info("Navigating to another URL");
+ let onTargetSwitched = toolbox.commands.targetCommand.once("switched-target");
+ const urlInput = devtoolsDocument.querySelector(".devtools-textinput");
+ await synthesizeUrlKeyInput(devToolsToolbox, urlInput, OTHER_URL);
+ await waitForUrl(OTHER_URL, toolbox, browserTab, window);
+ await onTargetSwitched;
+
+ info("Clicking back button");
+ onTargetSwitched = toolbox.commands.targetCommand.once("switched-target");
+ devtoolsDocument.querySelector(".qa-back-button").click();
+ await waitForUrl(ORIGINAL_URL, toolbox, browserTab, window);
+ await onTargetSwitched;
+
+ info("Clicking the forward button");
+ onTargetSwitched = toolbox.commands.targetCommand.once("switched-target");
+ devtoolsDocument.querySelector(".qa-forward-button").click();
+ await waitForUrl(OTHER_URL, toolbox, browserTab, window);
+ await onTargetSwitched;
+
+ ok(true, "Clicking back and forward works!");
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_reload_button.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_reload_button.js
new file mode 100644
index 0000000000..fbd46101a2
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_reload_button.js
@@ -0,0 +1,53 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+function clickReload(devtoolsDocument) {
+ devtoolsDocument.querySelector(".qa-reload-button").click();
+}
+
+// Test that ensures the remote page is reloaded when the button is clicked
+add_task(async function () {
+ const debug_tab = await addTab("about:home");
+
+ const { document, tab, window } = await openAboutDebugging();
+
+ // go to This Firefox and inspect the new tab
+ info("Inspecting a new tab in This Firefox");
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsDocument, devtoolsTab, devtoolsWindow } =
+ await openAboutDevtoolsToolbox(document, tab, window, "about:home");
+
+ info("Clicking reload button and waiting for requests to complete");
+ const toolbox = getToolbox(devtoolsWindow);
+ const { onDomCompleteResource } =
+ await waitForNextTopLevelDomCompleteResource(toolbox.commands);
+
+ // Watch for navigation promises.
+ const refreshes = Promise.all([
+ onDomCompleteResource,
+ toolbox.commands.client.waitForRequestsToSettle(),
+ waitForAboutDebuggingRequests(window.AboutDebugging.store),
+ ]);
+
+ // We cannot include this one in the Promise.all array, as it needs to be
+ // explicitly called after navigation started.
+ const waitForLoadedPanelsReload = await watchForLoadedPanelsReload(toolbox);
+
+ clickReload(devtoolsDocument);
+ await refreshes;
+ await waitForLoadedPanelsReload();
+
+ ok(true, "Clicked refresh; both page and devtools reloaded");
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+
+ info("Remove the debugged tab");
+ await removeTab(debug_tab);
+ await waitUntil(() => !findDebugTargetByText("about:home", document));
+ await waitForAboutDebuggingRequests(window.AboutDebugging.store);
+
+ info("Remove the about:debugging tab.");
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_to_url.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_to_url.js
new file mode 100644
index 0000000000..055db0586c
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_navigate_to_url.js
@@ -0,0 +1,56 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NEW_TAB_TITLE = "PAGE 2";
+const TAB_URL = "data:text/html,<title>PAGE</title>";
+const NEW_TAB_URL = `data:text/html,<title>${NEW_TAB_TITLE}</title>`;
+
+/**
+ * This test file ensures that the URL input for DebugTargetInfo navigates the target to
+ * the specified URL.
+ */
+add_task(async function () {
+ const { document, tab, window } = await openAboutDebugging();
+
+ info("Open a new background tab.");
+ const debug_tab = await addTab(TAB_URL, { background: true });
+
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const devToolsToolbox = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ "PAGE"
+ );
+ const { devtoolsDocument, devtoolsTab, devtoolsWindow } = devToolsToolbox;
+ const toolbox = getToolbox(devtoolsWindow);
+
+ const urlInput = devtoolsDocument.querySelector(".devtools-textinput");
+ const waitForLoadedPanelsReload = await watchForLoadedPanelsReload(toolbox);
+
+ await synthesizeUrlKeyInput(devToolsToolbox, urlInput, NEW_TAB_URL);
+
+ await waitForLoadedPanelsReload();
+
+ info("Test that the debug target navigated to the specified URL.");
+ await waitUntil(
+ () =>
+ toolbox.target.url === NEW_TAB_URL &&
+ debug_tab.linkedBrowser.currentURI.spec === NEW_TAB_URL
+ );
+ ok(true, "Target navigated.");
+ ok(toolbox.target.title.includes(NEW_TAB_TITLE), "Target's title updated.");
+ is(urlInput.value, NEW_TAB_URL, "Input url updated.");
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+
+ info("Remove the background tab");
+ await removeTab(debug_tab);
+ await waitUntil(() => !findDebugTargetByText("NEW_TAB_TITLE", document));
+ await waitForAboutDebuggingRequests(window.AboutDebugging.store);
+
+ info("Remove the about:debugging tab.");
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_reload.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_reload.js
new file mode 100644
index 0000000000..3eba6bcd7e
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_reload.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test can run for a long time on debug platforms.
+requestLongerTimeout(5);
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+const TOOLS = [
+ "inspector",
+ "webconsole",
+ "jsdebugger",
+ "styleeditor",
+ "memory",
+ "netmonitor",
+ "storage",
+ "accessibility",
+];
+
+/**
+ * Test whether about:devtools-toolbox display correctly after reloading.
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ for (const toolId of TOOLS) {
+ await testReloadAboutDevToolsToolbox(toolId);
+ }
+});
+
+async function testReloadAboutDevToolsToolbox(toolId) {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ // We set the options panel to be the default one because slower panels might lead to
+ // race conditions which create leaks in debug mode.
+ await pushPref("devtools.toolbox.selectedTool", "options");
+ const { devtoolsBrowser, devtoolsTab, devtoolsWindow } =
+ await openAboutDevtoolsToolbox(document, tab, window);
+
+ info(`Select tool: ${toolId}`);
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool(toolId);
+
+ info("Wait for requests to settle before reloading");
+ await toolbox.commands.client.waitForRequestsToSettle();
+
+ info("Reload about:devtools-toolbox page");
+ devtoolsBrowser.reload();
+ await gDevTools.once("toolbox-ready");
+ ok(true, "Toolbox is re-created again");
+
+ // Check that about:devtools-toolbox is still selected tab. See Bug 1570692.
+ is(
+ devtoolsBrowser,
+ gBrowser.selectedBrowser,
+ "about:devtools-toolbox is still selected"
+ );
+
+ info("Check whether about:devtools-toolbox page displays correctly");
+ ok(
+ devtoolsBrowser.contentDocument.querySelector(".debug-target-info"),
+ "about:devtools-toolbox page displays correctly"
+ );
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_shortcuts.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_shortcuts.js
new file mode 100644
index 0000000000..b03a206350
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_shortcuts.js
@@ -0,0 +1,106 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test shortcut keys on about:devtools-toolbox page.
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsBrowser, devtoolsTab, devtoolsWindow } =
+ await openAboutDevtoolsToolbox(document, tab, window);
+
+ info("Check whether the shortcut keys which opens devtools is disabled");
+ await assertShortcutKeys(devtoolsBrowser, false);
+
+ info("Switch to the inspector programmatically");
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool("inspector");
+
+ info(
+ "Use the Webconsole keyboard shortcut and wait for the panel to be selected"
+ );
+ const onToolReady = toolbox.once("webconsole-ready");
+ EventUtils.synthesizeKey(
+ "K",
+ {
+ accelKey: true,
+ shiftKey: !navigator.userAgent.match(/Mac/),
+ altKey: navigator.userAgent.match(/Mac/),
+ },
+ devtoolsWindow
+ );
+ await onToolReady;
+
+ info("Force to select about:debugging page");
+ await updateSelectedTab(gBrowser, tab, window.AboutDebugging.store);
+
+ info("Check whether the shortcut keys which opens devtools is enabled");
+ await assertShortcutKeys(tab.linkedBrowser, true);
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
+
+async function assertShortcutKeys(browser, shouldBeEnabled) {
+ await assertShortcutKey(browser.contentWindow, "VK_F12", {}, shouldBeEnabled);
+ await assertShortcutKey(
+ browser.contentWindow,
+ "I",
+ {
+ accelKey: true,
+ shiftKey: !navigator.userAgent.match(/Mac/),
+ altKey: navigator.userAgent.match(/Mac/),
+ },
+ shouldBeEnabled
+ );
+}
+
+async function assertShortcutKey(win, key, modifiers, shouldBeEnabled) {
+ info(`Assert shortcut key [${key}]`);
+
+ if (shouldBeEnabled) {
+ await assertShortcutKeyEnabled(win, key, modifiers);
+ } else {
+ await assertShortcutKeyDisabled(win, key, modifiers);
+ }
+}
+
+async function assertShortcutKeyDisabled(win, key, modifiers) {
+ let isReadyCalled = false;
+ const toolboxListener = () => {
+ isReadyCalled = true;
+ };
+ gDevTools.on("toolbox-ready", toolboxListener);
+
+ EventUtils.synthesizeKey(key, modifiers, win);
+ await wait(1000);
+ ok(!isReadyCalled, `Devtools should not be opened by ${key}`);
+
+ gDevTools.off("toolbox-ready", toolboxListener);
+}
+
+async function assertShortcutKeyEnabled(win, key, modifiers) {
+ // Open devtools
+ const onToolboxReady = gDevTools.once("toolbox-ready");
+ EventUtils.synthesizeKey(key, modifiers, win);
+ await onToolboxReady;
+ ok(true, `Devtools should be opened by ${key}`);
+
+ // Close devtools
+ const onToolboxDestroyed = gDevTools.once("toolbox-destroyed");
+ EventUtils.synthesizeKey(key, modifiers, win);
+ await onToolboxDestroyed;
+ ok(true, `Devtopls should be closed by ${key}`);
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_splitconsole_key.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_splitconsole_key.js
new file mode 100644
index 0000000000..44e83b8c43
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_splitconsole_key.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test that the split console key shortcut works on about:devtools-toolbox.
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window
+ );
+
+ // Select any tool that is not the Webconsole, since we will assert the split-console.
+ info("Select inspector tool");
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool("inspector");
+
+ info("Press Escape and wait for the split console to be opened");
+ const onSplitConsole = toolbox.once("split-console");
+ EventUtils.synthesizeKey("VK_ESCAPE", {}, devtoolsWindow);
+ await onSplitConsole;
+ await waitUntil(() => toolbox.isSplitConsoleFocused());
+ ok(true, "Split console is opened and focused");
+
+ info("Press Escape again and wait for the split console to be closed");
+ EventUtils.synthesizeKey("VK_ESCAPE", {}, devtoolsWindow);
+ await waitUntil(() => !toolbox.isSplitConsoleFocused());
+ ok(true, "Split console is closed and no longer focused");
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_target_destroyed.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_target_destroyed.js
new file mode 100644
index 0000000000..d0001d1c03
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_target_destroyed.js
@@ -0,0 +1,36 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that the expected supported categories are displayed for USB runtimes.
+add_task(async function () {
+ const targetTab = await addTab("about:home");
+
+ const { document, tab, window } = await openAboutDebugging();
+
+ // go to This Firefox and inspect the new tab
+ info("Inspecting a new tab in This Firefox");
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsDocument, devtoolsTab, devtoolsWindow } =
+ await openAboutDevtoolsToolbox(document, tab, window, "about:home");
+ const targetUrl = devtoolsDocument.querySelector(".devtools-textinput");
+ ok(
+ targetUrl.value.includes("about:home"),
+ "about:devtools-toolbox is open for the target"
+ );
+
+ // close the inspected tab and check that error page is shown
+ info("removing the inspected tab");
+ await removeTab(targetTab);
+ await waitUntil(() =>
+ devtoolsWindow.document.querySelector(".qa-error-page")
+ );
+
+ info("closing the toolbox");
+ await removeTab(devtoolsTab);
+ await waitUntil(() => !findDebugTargetByText("Toolbox -", document));
+
+ info("removing about:debugging tab");
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_tooltip_markupview.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_tooltip_markupview.js
new file mode 100644
index 0000000000..047b309740
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_tooltip_markupview.js
@@ -0,0 +1,102 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test can run for a long time on asan or debug platforms.
+requestLongerTimeout(3);
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Test tooltip of markup view on about:devtools-toolbox page.
+ */
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ info("Turn on devtools.chrome.enabled to show event badges");
+ await pushPref("devtools.chrome.enabled", true);
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsDocument, devtoolsTab, devtoolsWindow } =
+ await openAboutDevtoolsToolbox(document, tab, window);
+
+ info("Select inspector tool");
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.selectTool("inspector");
+
+ const inspector = toolbox.getPanel("inspector");
+ const markupDocument = inspector.markup.doc;
+ const eventBadge = markupDocument.querySelector(
+ ".inspector-badge.interactive"
+ );
+
+ info(
+ "Check tooltip visibility after clicking on an element in the markup view"
+ );
+ await checkTooltipVisibility(inspector, eventBadge, markupDocument.body);
+
+ info(
+ "Check tooltip visibility after clicking on an element in the DevTools document"
+ );
+ await checkTooltipVisibility(
+ inspector,
+ eventBadge,
+ devtoolsDocument.querySelector(".debug-target-info")
+ );
+
+ info(
+ "Check tooltip visibility after clicking on an element in the root document"
+ );
+ const rootDocument = devtoolsWindow.windowRoot.ownerGlobal.document;
+ await checkTooltipVisibility(
+ inspector,
+ eventBadge,
+ rootDocument.querySelector("#titlebar")
+ );
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
+
+async function checkTooltipVisibility(
+ inspector,
+ elementForShowing,
+ elementForHiding
+) {
+ info("Show event tooltip");
+ elementForShowing.click();
+ const tooltip = inspector.markup.eventDetailsTooltip;
+ await tooltip.once("shown");
+ is(
+ tooltip.container.classList.contains("tooltip-visible"),
+ true,
+ "The tooltip should be shown"
+ );
+
+ info("Hide event tooltip");
+ EventUtils.synthesizeMouse(
+ elementForHiding,
+ 1,
+ 1,
+ {},
+ elementForHiding.ownerGlobal
+ );
+ await tooltip.once("hidden");
+ is(
+ tooltip.container.classList.contains("tooltip-visible"),
+ false,
+ "Tooltip should be hidden"
+ );
+
+ if (inspector._updateProgress) {
+ info("Need to wait for the inspector to update");
+ await inspector.once("inspector-updated");
+ }
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_zoom.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_zoom.js
new file mode 100644
index 0000000000..425efee8f1
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_devtoolstoolbox_zoom.js
@@ -0,0 +1,65 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
+const L10N = new LocalizationHelper(
+ "devtools/client/locales/toolbox.properties"
+);
+
+// Check that the about:devtools-toolbox tab can be zoomed in and that the zoom
+// persists after switching tabs.
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window
+ );
+
+ is(getZoom(devtoolsWindow), 1, "default zoom level correct");
+
+ info("Increase the zoom level");
+
+ // Note that we read the shortcut from the toolbox properties, but that should
+ // match the default browser shortcut `full-zoom-enlarge-shortcut`.
+ synthesizeKeyShortcut(L10N.getStr("toolbox.zoomIn.key"));
+ await waitFor(() => getZoom(devtoolsWindow) > 1);
+ is(getZoom(devtoolsWindow).toFixed(2), "1.10", "zoom level increased");
+
+ info("Switch tabs between about:debugging and the toolbox tab");
+ gBrowser.selectedTab = tab;
+ gBrowser.selectedTab = devtoolsTab;
+
+ info("Wait for the browser to reapply the zoom");
+ await wait(500);
+
+ is(
+ getZoom(devtoolsWindow).toFixed(2),
+ "1.10",
+ "zoom level was restored after switching tabs"
+ );
+
+ info("Restore the default zoom level");
+ synthesizeKeyShortcut(L10N.getStr("toolbox.zoomReset.key"));
+ await waitFor(() => getZoom(devtoolsWindow) === 1);
+ is(getZoom(devtoolsWindow), 1, "default zoom level restored");
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
+
+function getZoom(win) {
+ return win.browsingContext.fullZoom;
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js
new file mode 100644
index 0000000000..778b1bb967
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_display.js
@@ -0,0 +1,141 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_ID = "1337id";
+const DEVICE_NAME = "Fancy Phone";
+const SERVER_RUNTIME_NAME = "Mozilla Firefox";
+const ADB_RUNTIME_NAME = "Firefox Preview";
+const SERVER_VERSION = "v7.3.31";
+const ADB_VERSION = "v1.3.37";
+
+const FENIX_RELEASE_ICON_SRC =
+ "chrome://devtools/skin/images/aboutdebugging-fenix.svg";
+const FENIX_NIGHTLY_ICON_SRC =
+ "chrome://devtools/skin/images/aboutdebugging-fenix-nightly.svg";
+
+/**
+ * Check that Fenix runtime information is correctly displayed in about:debugging.
+ */
+add_task(async function () {
+ const mocks = new Mocks();
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: DEVICE_NAME,
+ isFenix: true,
+ name: SERVER_RUNTIME_NAME,
+ shortName: ADB_RUNTIME_NAME,
+ versionName: ADB_VERSION,
+ version: SERVER_VERSION,
+ });
+
+ // open a remote runtime page
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ mocks.emitUSBUpdate();
+ await connectToRuntime(DEVICE_NAME, document);
+ await selectRuntime(DEVICE_NAME, ADB_RUNTIME_NAME, document);
+
+ info("Check that the runtime information is displayed as expected");
+ const runtimeInfo = document.querySelector(".qa-runtime-name");
+ ok(runtimeInfo, "Runtime info for the Fenix runtime is displayed");
+ const runtimeInfoText = runtimeInfo.textContent;
+
+ ok(runtimeInfoText.includes(ADB_RUNTIME_NAME), "Name is the ADB name");
+ ok(
+ !runtimeInfoText.includes(SERVER_RUNTIME_NAME),
+ "Name does not include the server name"
+ );
+
+ ok(runtimeInfoText.includes(ADB_VERSION), "Version contains the ADB version");
+ ok(
+ !runtimeInfoText.includes(SERVER_VERSION),
+ "Version does not contain the server version"
+ );
+
+ const runtimeIcon = document.querySelector(".qa-runtime-icon");
+ is(
+ runtimeIcon.src,
+ FENIX_RELEASE_ICON_SRC,
+ "The runtime icon is the Fenix icon"
+ );
+
+ info("Remove USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);
+
+ await removeTab(tab);
+});
+
+/**
+ * Check that Fenix runtime information is correctly displayed in about:devtools-toolbox.
+ */
+add_task(async function () {
+ // We use a real local client combined with a mocked USB runtime to be able to open
+ // about:devtools-toolbox on a real target.
+ const clientWrapper = await createLocalClientWrapper();
+
+ const mocks = new Mocks();
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ channel: "nightly",
+ clientWrapper,
+ deviceName: DEVICE_NAME,
+ isFenix: true,
+ name: SERVER_RUNTIME_NAME,
+ shortName: ADB_RUNTIME_NAME,
+ versionName: ADB_VERSION,
+ version: SERVER_VERSION,
+ });
+
+ // open a remote runtime page
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ mocks.emitUSBUpdate();
+ info("Select the runtime page for the USB runtime");
+ const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store);
+ await connectToRuntime(DEVICE_NAME, document);
+ await selectRuntime(DEVICE_NAME, ADB_RUNTIME_NAME, document);
+ info(
+ "Wait for requests to finish the USB runtime is backed by a real local client"
+ );
+ await onRequestSuccess;
+
+ info("Wait for the about:debugging target to be available");
+ await waitUntil(() => findDebugTargetByText("about:debugging", document));
+ const { devtoolsDocument, devtoolsTab } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window
+ );
+
+ const runtimeInfo = devtoolsDocument.querySelector(".qa-runtime-info");
+ const runtimeInfoText = runtimeInfo.textContent;
+ ok(
+ runtimeInfoText.includes(ADB_RUNTIME_NAME),
+ "Name is the ADB runtime name"
+ );
+ ok(runtimeInfoText.includes(ADB_VERSION), "Version is the ADB version");
+
+ const runtimeIcon = devtoolsDocument.querySelector(".qa-runtime-icon");
+ is(
+ runtimeIcon.src,
+ FENIX_NIGHTLY_ICON_SRC,
+ "The runtime icon is the Fenix icon"
+ );
+
+ info("Wait for all pending requests to settle on the DevToolsClient");
+ await clientWrapper.client.waitForRequestsToSettle();
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+
+ info("Remove USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);
+
+ await removeTab(tab);
+ await clientWrapper.close();
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_node_picker.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_node_picker.js
new file mode 100644
index 0000000000..59bdbd765d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_fenix_runtime_node_picker.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_ID = "1337id";
+const DEVICE_NAME = "Fancy Phone";
+const SERVER_RUNTIME_NAME = "Mozilla Firefox";
+const ADB_RUNTIME_NAME = "Firefox Preview";
+const SERVER_VERSION = "v7.3.31";
+const ADB_VERSION = "v1.3.37";
+
+/**
+ * Check that the node picker button in about:devtools-toolbox has the expected class when
+ * connecting to an Android phone.
+ */
+add_task(async function () {
+ // We use a real local client combined with a mocked USB runtime to be able to open
+ // about:devtools-toolbox on a real target.
+ const clientWrapper = await createLocalClientWrapper();
+
+ const mocks = new Mocks();
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ channel: "nightly",
+ clientWrapper,
+ deviceName: DEVICE_NAME,
+ isFenix: true,
+ name: SERVER_RUNTIME_NAME,
+ shortName: ADB_RUNTIME_NAME,
+ versionName: ADB_VERSION,
+ version: SERVER_VERSION,
+ });
+
+ // open a remote runtime page
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ mocks.emitUSBUpdate();
+ info("Select the runtime page for the USB runtime");
+ const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store);
+ await connectToRuntime(DEVICE_NAME, document);
+ await selectRuntime(DEVICE_NAME, ADB_RUNTIME_NAME, document);
+ info(
+ "Wait for requests to finish the USB runtime is backed by a real local client"
+ );
+ await onRequestSuccess;
+
+ info("Wait for the about:debugging target to be available");
+ await waitUntil(() => findDebugTargetByText("about:debugging", document));
+ const { devtoolsDocument, devtoolsTab } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window
+ );
+
+ const pickerButton = devtoolsDocument.querySelector("#command-button-pick");
+ ok(
+ pickerButton.classList.contains("remote-fenix"),
+ "The node picker does have the expected additional className when debugging an android phone"
+ );
+ const pickerButtonTitle = pickerButton.getAttribute("title");
+ const expectedKeyboardShortcut =
+ Services.appinfo.OS === "Darwin"
+ ? `Cmd+Shift+C or Cmd+Opt+C`
+ : `Ctrl+Shift+C`;
+ is(
+ pickerButtonTitle,
+ `Pick an element from the Android phone (${expectedKeyboardShortcut})`,
+ `The node picker does have the expected tooltip when debugging an android phone`
+ );
+
+ info("Wait for all pending requests to settle on the DevToolsClient");
+ await clientWrapper.client.waitForRequestsToSettle();
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+
+ info("Remove USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);
+
+ await removeTab(tab);
+ await clientWrapper.close();
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_hidden_addons.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_hidden_addons.js
new file mode 100644
index 0000000000..69f75ef75e
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_hidden_addons.js
@@ -0,0 +1,106 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Test that system and hidden addons are only displayed when the showSystemAddons
+// preferences is true.
+
+const SYSTEM_ADDON = createAddonData({
+ id: "system",
+ name: "System Addon",
+ isSystem: true,
+ hidden: true,
+});
+const HIDDEN_ADDON = createAddonData({
+ id: "hidden",
+ name: "Hidden Addon",
+ isSystem: false,
+ hidden: true,
+});
+const NORMAL_ADDON = createAddonData({
+ id: "normal",
+ name: "Normal Addon",
+ isSystem: false,
+ hidden: false,
+});
+
+add_task(async function testShowSystemAddonsTrue() {
+ info("Test with showHiddenAddons set to true");
+ await testAddonsDisplay(true);
+
+ info("Test with showHiddenAddons set to false");
+ await testAddonsDisplay(false);
+});
+
+async function testAddonsDisplay(showHidden) {
+ const thisFirefoxClient = setupThisFirefoxMock();
+ thisFirefoxClient.listAddons = () => [
+ SYSTEM_ADDON,
+ HIDDEN_ADDON,
+ NORMAL_ADDON,
+ ];
+
+ info("Set showHiddenAddons to " + showHidden);
+ await pushPref("devtools.aboutdebugging.showHiddenAddons", showHidden);
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const hasSystemAddon = !!findDebugTargetByText("System Addon", document);
+ const hasHiddenAddon = !!findDebugTargetByText("Hidden Addon", document);
+ const hasInstalledAddon = !!findDebugTargetByText("Normal Addon", document);
+ is(
+ hasSystemAddon,
+ showHidden,
+ "System addon display is correct when showHiddenAddons is " + showHidden
+ );
+ is(
+ hasHiddenAddon,
+ showHidden,
+ "Hidden addon display is correct when showHiddenAddons is " + showHidden
+ );
+ ok(hasInstalledAddon, "Installed addon is always displayed");
+
+ await removeTab(tab);
+}
+
+// Create a basic mock for this-firefox client, and setup a runtime-client-factory mock
+// to return our mock client when needed.
+function setupThisFirefoxMock() {
+ const runtimeClientFactoryMock = createRuntimeClientFactoryMock();
+ const thisFirefoxClient = createThisFirefoxClientMock();
+ runtimeClientFactoryMock.createClientForRuntime = runtime => {
+ const {
+ RUNTIMES,
+ } = require("resource://devtools/client/aboutdebugging/src/constants.js");
+ if (runtime.id === RUNTIMES.THIS_FIREFOX) {
+ return thisFirefoxClient;
+ }
+ throw new Error("Unexpected runtime id " + runtime.id);
+ };
+
+ info("Enable mocks");
+ enableRuntimeClientFactoryMock(runtimeClientFactoryMock);
+ registerCleanupFunction(() => {
+ disableRuntimeClientFactoryMock();
+ });
+
+ return thisFirefoxClient;
+}
+
+// Create basic addon data as the DevToolsClient would return it (debuggable and non
+// temporary).
+function createAddonData({ id, name, isSystem, hidden }) {
+ return {
+ actor: `actorid-${id}`,
+ hidden,
+ iconURL: `moz-extension://${id}/icon-url.png`,
+ id,
+ manifestURL: `moz-extension://${id}/manifest-url.json`,
+ name,
+ isSystem,
+ temporarilyInstalled: false,
+ debuggable: true,
+ };
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_message_close.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_message_close.js
new file mode 100644
index 0000000000..58ae2db6a3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_message_close.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-addons.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
+
+const EXTENSION_NAME = "Temporary web extension";
+const EXTENSION_ID = "test-devtools@mozilla.org";
+
+// Test that Message component can be closed with the X button
+add_task(async function () {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Check that the message can be closed with icon");
+ let warningMessage = await installExtensionWithWarning(document);
+ await testCloseMessageWithIcon(warningMessage, document);
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+
+ info("Check that the message can be closed with the button around the icon");
+ warningMessage = await installExtensionWithWarning(document);
+ await testCloseMessageWithButton(warningMessage, document);
+ await removeTemporaryExtension(EXTENSION_NAME, document);
+
+ await removeTab(tab);
+});
+
+async function testCloseMessageWithIcon(warningMessage, doc) {
+ const closeIcon = warningMessage.querySelector(
+ ".qa-message-button-close-icon"
+ );
+ ok(!!closeIcon, "The warning message has a close icon");
+
+ info("Closing the message and waiting for it to disappear");
+ closeIcon.click();
+
+ const target = findDebugTargetByText(EXTENSION_NAME, doc);
+ await waitUntil(() => target.querySelector(".qa-message") === null);
+}
+
+async function testCloseMessageWithButton(warningMessage, doc) {
+ const closeButton = warningMessage.querySelector(
+ ".qa-message-button-close-button"
+ );
+ ok(!!closeButton, "The warning message has a close button");
+
+ info("Click on the button and wait for the message to disappear");
+ EventUtils.synthesizeMouse(closeButton, 1, 1, {}, doc.defaultView);
+
+ const target = findDebugTargetByText(EXTENSION_NAME, doc);
+ await waitUntil(() => target.querySelector(".qa-message") === null);
+}
+
+async function installExtensionWithWarning(doc) {
+ await pushPref("extensions.webextensions.warnings-as-errors", false);
+ await installTemporaryExtensionFromXPI(
+ {
+ id: EXTENSION_ID,
+ name: EXTENSION_NAME,
+ extraProperties: {
+ // This property is not expected in the manifest and should trigger a warning!
+ wrongProperty: {},
+ },
+ },
+ doc
+ );
+ await SpecialPowers.popPrefEnv();
+
+ info("Wait until a debug target item appears");
+ await waitUntil(() => findDebugTargetByText(EXTENSION_NAME, doc));
+
+ const target = findDebugTargetByText(EXTENSION_NAME, doc);
+ const warningMessage = target.querySelector(".qa-message");
+ ok(
+ !!warningMessage,
+ "A warning message is displayed for the installed addon"
+ );
+
+ return warningMessage;
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_navigate.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_navigate.js
new file mode 100644
index 0000000000..281f01dbdc
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_navigate.js
@@ -0,0 +1,112 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+/**
+ * Check that navigating from This Firefox to Connect and back to This Firefox works and
+ * does not leak.
+ */
+
+const TAB_URL_1 = "data:text/html,<title>TAB1</title>";
+const TAB_URL_2 = "data:text/html,<title>TAB2</title>";
+
+add_task(async function () {
+ info("Force all debug target panes to be expanded");
+ prepareCollapsibilitiesTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ const AboutDebugging = window.AboutDebugging;
+ await selectThisFirefoxPage(document, AboutDebugging.store);
+
+ const connectSidebarItem = findSidebarItemByText("Setup", document);
+ const connectLink = connectSidebarItem.querySelector(".qa-sidebar-link");
+ ok(connectSidebarItem, "Found the Connect sidebar item");
+
+ const thisFirefoxString = getThisFirefoxString(window);
+ const thisFirefoxSidebarItem = findSidebarItemByText(
+ thisFirefoxString,
+ document
+ );
+ const thisFirefoxLink =
+ thisFirefoxSidebarItem.querySelector(".qa-sidebar-link");
+ ok(thisFirefoxSidebarItem, "Found the ThisFirefox sidebar item");
+ ok(
+ isSidebarItemSelected(thisFirefoxSidebarItem),
+ "ThisFirefox sidebar item is selected by default"
+ );
+
+ info("Open a new background tab TAB1");
+ const backgroundTab1 = await addTab(TAB_URL_1, { background: true });
+
+ info("Wait for the tab to appear in the debug targets with the correct name");
+ await waitUntil(() => findDebugTargetByText("TAB1", document));
+
+ await waitForAboutDebuggingRequests(AboutDebugging.store);
+ info("Click on the Connect item in the sidebar");
+ connectLink.click();
+
+ info("Wait until Connect page is displayed");
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+ // we need to wait here because the sidebar isn't updated after mounting the page
+ info("Wait until Connect sidebar item is selected");
+ await waitUntil(() => isSidebarItemSelected(connectSidebarItem));
+ ok(
+ !document.querySelector(".qa-runtime-page"),
+ "Runtime page no longer rendered"
+ );
+
+ info("Open a new tab which should be listed when we go back to This Firefox");
+ const backgroundTab2 = await addTab(TAB_URL_2, { background: true });
+
+ info("Click on the ThisFirefox item in the sidebar");
+ const requestsSuccess = waitForRequestsSuccess(AboutDebugging.store);
+ thisFirefoxLink.click();
+
+ info("Wait for all target requests to complete");
+ await requestsSuccess;
+
+ info("Wait until ThisFirefox page is displayed");
+ await waitUntil(() => document.querySelector(".qa-runtime-page"));
+ ok(
+ isSidebarItemSelected(thisFirefoxSidebarItem),
+ "ThisFirefox sidebar item is selected again"
+ );
+ ok(
+ !document.querySelector(".qa-connect-page"),
+ "Connect page no longer rendered"
+ );
+
+ info("TAB2 should already be displayed in the debug targets");
+ await waitUntil(() => findDebugTargetByText("TAB2", document));
+
+ info("Remove first background tab");
+ await removeTab(backgroundTab1);
+
+ info(
+ "Check TAB1 disappears, meaning ThisFirefox client is correctly connected"
+ );
+ await waitUntil(() => !findDebugTargetByText("TAB1", document));
+
+ info("Remove second background tab");
+ await removeTab(backgroundTab2);
+
+ info(
+ "Check TAB2 disappears, meaning ThisFirefox client is correctly connected"
+ );
+ await waitUntil(() => !findDebugTargetByText("TAB2", document));
+
+ await waitForAboutDebuggingRequests(AboutDebugging.store);
+
+ await removeTab(tab);
+});
+
+function isSidebarItemSelected(item) {
+ return item.classList.contains("qa-sidebar-item-selected");
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js
new file mode 100644
index 0000000000..5ac1c2e188
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_persist_connection.js
@@ -0,0 +1,91 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+const USB_RUNTIME_ID = "test-runtime-id";
+const USB_DEVICE_NAME = "test device name";
+const USB_APP_NAME = "TestApp";
+
+// Test that remote runtime connections are persisted across about:debugging reloads.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ info("Test with a USB runtime");
+ const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ name: USB_APP_NAME,
+ deviceName: USB_DEVICE_NAME,
+ });
+
+ await testRemoteClientPersistConnection(mocks, {
+ client: usbClient,
+ id: USB_RUNTIME_ID,
+ runtimeName: USB_APP_NAME,
+ sidebarName: USB_DEVICE_NAME,
+ type: "usb",
+ });
+
+ info("Test with a network runtime");
+ const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+ name: NETWORK_RUNTIME_APP_NAME,
+ });
+
+ await testRemoteClientPersistConnection(mocks, {
+ client: networkClient,
+ id: NETWORK_RUNTIME_HOST,
+ runtimeName: NETWORK_RUNTIME_APP_NAME,
+ sidebarName: NETWORK_RUNTIME_HOST,
+ type: "network",
+ });
+});
+
+async function testRemoteClientPersistConnection(
+ mocks,
+ { client, id, runtimeName, sidebarName, type }
+) {
+ info("Open about:debugging and connect to the test runtime");
+ let { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await connectToRuntime(sidebarName, document);
+ await selectRuntime(sidebarName, runtimeName, document);
+
+ info("Reload about:debugging");
+ document = await reloadAboutDebugging(tab);
+
+ info("Wait until the remote runtime appears as connected");
+ await waitUntil(() => {
+ const sidebarItem = findSidebarItemByText(sidebarName, document);
+ return sidebarItem && !sidebarItem.querySelector(".qa-connect-button");
+ });
+
+ info("Wait until the remote runtime page is selected");
+ await waitUntil(() => {
+ const runtimeInfo = document.querySelector(".qa-runtime-name");
+ return runtimeInfo && runtimeInfo.textContent.includes(runtimeName);
+ });
+
+ // Remove the runtime without emitting an update.
+ // This is what happens today when we simply close Firefox for Android.
+ info("Remove the runtime from the list of remote runtimes");
+ mocks.removeRuntime(id);
+
+ info(
+ "Emit 'closed' on the client and wait for the sidebar item to disappear"
+ );
+ client._eventEmitter.emit("closed");
+ if (type === "usb") {
+ await waitUntilUsbDeviceIsUnplugged(sidebarName, document);
+ } else {
+ await waitUntil(
+ () =>
+ !findSidebarItemByText(sidebarName, document) &&
+ !findSidebarItemByText(runtimeName, document)
+ );
+ }
+
+ info("Remove the tab");
+ await removeTab(tab);
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_category.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_category.js
new file mode 100644
index 0000000000..fd7fb9a852
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_category.js
@@ -0,0 +1,53 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const CATEGORY_NAME = "Processes";
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_DEVICE_NAME = "test device name";
+const RUNTIME_APP_NAME = "TestApp";
+
+// Test whether process category exists by the runtime type.
+add_task(async function () {
+ await pushPref("devtools.aboutdebugging.process-debugging", true);
+
+ const mocks = new Mocks();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const usbRuntime = mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: RUNTIME_DEVICE_NAME,
+ name: RUNTIME_APP_NAME,
+ });
+ usbRuntime.getMainProcess = () => {
+ return {
+ getTarget: () => {
+ return { actorID: 0 };
+ },
+ };
+ };
+ mocks.emitUSBUpdate();
+
+ info("Check the process category existence for this firefox");
+ ok(
+ !getDebugTargetPane(CATEGORY_NAME, document),
+ "Process category should not display for this firefox"
+ );
+
+ info("Check the process category existence for USB runtime");
+ await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+ await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+ ok(
+ getDebugTargetPane(CATEGORY_NAME, document),
+ "Process category should display for USB runtime"
+ );
+
+ info("Remove USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main.js
new file mode 100644
index 0000000000..bd88545d58
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main.js
@@ -0,0 +1,87 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+const MULTIPROCESS_TOOLBOX_NAME = "Multiprocess Toolbox";
+const MULTIPROCESS_TOOLBOX_DESCRIPTION =
+ "Main Process and Content Processes for the target browser";
+
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_DEVICE_NAME = "test device name";
+const RUNTIME_APP_NAME = "TestApp";
+
+// Test for main process.
+add_task(async function () {
+ await pushPref("devtools.aboutdebugging.process-debugging", true);
+ const mocks = new Mocks();
+
+ const { document, tab, window } = await openAboutDebugging();
+
+ const usbRuntime = mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: RUNTIME_DEVICE_NAME,
+ name: RUNTIME_APP_NAME,
+ });
+
+ // Note: about:debugging assumes that the main process has the id 0 and will
+ // rely on it to create the about:devtools-toolbox URL.
+ // Only check that about:debugging doesn't create a target unnecessarily.
+ usbRuntime.getMainProcess = () => {
+ return {
+ getTarget: () => {
+ ok(false, "about:debugging should not create the main process target");
+ },
+ };
+ };
+ mocks.emitUSBUpdate();
+
+ info("Select USB runtime");
+ await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+ await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+
+ info("Check debug target item of the main process");
+ await waitUntil(() =>
+ findDebugTargetByText(MULTIPROCESS_TOOLBOX_NAME, document)
+ );
+ const mainProcessItem = findDebugTargetByText(
+ MULTIPROCESS_TOOLBOX_NAME,
+ document
+ );
+ ok(mainProcessItem, "Debug target item of the main process should display");
+ ok(
+ mainProcessItem.textContent.includes(MULTIPROCESS_TOOLBOX_DESCRIPTION),
+ "Debug target item of the main process should contains the description"
+ );
+
+ info("Inspect main process");
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ MULTIPROCESS_TOOLBOX_NAME,
+ false
+ );
+
+ const url = new window.URL(devtoolsWindow.location.href);
+ const type = url.searchParams.get("type");
+ is(type, "process", "Correct type argument");
+ const remoteID = url.searchParams.get("remoteId");
+ is(remoteID, `${RUNTIME_ID}-usb`, "Correct remote runtime id");
+
+ info("Remove USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+ // Note that we can't use `closeAboutDevtoolsToolbox` because the toolbox init
+ // is expected to fail, and we are redirected to the error page.
+ await removeTab(devtoolsTab);
+ await waitUntil(() => !findDebugTargetByText("Toolbox - ", document));
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main_local.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main_local.js
new file mode 100644
index 0000000000..06bd29095c
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_process_main_local.js
@@ -0,0 +1,44 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+// Test for main process against This Firefox.
+//
+// The main added value for this test is to check that listing processes
+// and opening a toolbox targeting a process works, even though debugging
+// the main process of This Firefox is not really supported.
+add_task(async function () {
+ await pushPref("devtools.aboutdebugging.process-debugging", true);
+ await pushPref("devtools.aboutdebugging.test-local-process-debugging", true);
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Check debug target item of the main process");
+ const mainProcessItem = findDebugTargetByText("Multiprocess", document);
+ ok(mainProcessItem, "Debug target item of the main process should display");
+ ok(
+ mainProcessItem.textContent.includes(
+ "Main Process and Content Processes for the target browser"
+ ),
+ "Debug target item of the main process should contains the description"
+ );
+
+ info("Inspect main process and wait for DevTools to open");
+ const { devtoolsTab } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ "Main Process"
+ );
+
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_profiler_dialog.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_profiler_dialog.js
new file mode 100644
index 0000000000..02995492c0
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_profiler_dialog.js
@@ -0,0 +1,238 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/devtools/client/performance-new/test/browser/helpers.js",
+ this
+);
+
+const BackgroundJSM = ChromeUtils.import(
+ "resource://devtools/client/performance-new/shared/background.jsm.js"
+);
+
+registerCleanupFunction(() => {
+ BackgroundJSM.revertRecordingSettings();
+});
+
+const RUNTIME_ID = "1337id";
+const DEVICE_NAME = "Fancy Phone";
+const RUNTIME_NAME = "Lorem ipsum";
+
+/**
+ * Test opening and closing the profiler dialog.
+ */
+add_task(async function test_opening_profiler_dialog() {
+ const { mocks } = await connectToLocalFirefox();
+ const { document, tab, window } = await openAboutDebugging();
+
+ mocks.emitUSBUpdate();
+ await connectToRuntime(DEVICE_NAME, document);
+ await selectRuntime(DEVICE_NAME, RUNTIME_NAME, document);
+
+ info("Open the profiler dialog");
+ await openProfilerDialogWithRealClient(document);
+ assertDialogVisible(document);
+
+ info("Click on the close button and wait until the dialog disappears");
+ const closeDialogButton = document.querySelector(".qa-profiler-dialog-close");
+ closeDialogButton.click();
+ await waitUntil(() => !document.querySelector(".qa-profiler-dialog"));
+ assertDialogHidden(document);
+
+ info("Open the profiler dialog again");
+ await openProfilerDialogWithRealClient(document);
+ assertDialogVisible(document);
+
+ info("Click on the mask element and wait until the dialog disappears");
+ const mask = document.querySelector(".qa-profiler-dialog-mask");
+ EventUtils.synthesizeMouse(mask, 5, 5, {}, window);
+ await waitUntil(() => !document.querySelector(".qa-profiler-dialog"));
+ assertDialogHidden(document);
+
+ info("Open the profiler dialog again");
+ await openProfilerDialogWithRealClient(document);
+ assertDialogVisible(document);
+
+ info("Navigate to this-firefox and wait until the dialog disappears");
+ document.location.hash = "#/runtime/this-firefox";
+ await waitUntil(() => !document.querySelector(".qa-profiler-dialog"));
+ assertDialogHidden(document);
+
+ info("Select the remote runtime again, check the dialog is still hidden");
+ await selectRuntime(DEVICE_NAME, RUNTIME_NAME, document);
+ assertDialogHidden(document);
+
+ await disconnectFromLocalFirefox({ mocks, doc: document });
+ await removeTab(tab);
+});
+
+add_task(async function test_set_profiler_settings() {
+ const { mocks } = await connectToLocalFirefox();
+ const { document, tab } = await openAboutDebugging();
+
+ mocks.emitUSBUpdate();
+ await connectToRuntime(DEVICE_NAME, document);
+ await selectRuntime(DEVICE_NAME, RUNTIME_NAME, document);
+
+ info("Open the profiler dialog");
+ await openProfilerDialogWithRealClient(document);
+ assertDialogVisible(document);
+
+ const profilerSettingsDocument = await openProfilerSettings(document);
+ const radioButtonForCustomPreset = await getNearestInputFromText(
+ profilerSettingsDocument,
+ "Custom"
+ );
+ ok(
+ radioButtonForCustomPreset.checked,
+ "The radio button for the preset 'custom' is checked."
+ );
+
+ info("Change the preset to Graphics.");
+ const radioButtonForGraphicsPreset = await getNearestInputFromText(
+ profilerSettingsDocument,
+ "Graphics"
+ );
+ radioButtonForGraphicsPreset.click();
+
+ const profilerDocument = await saveSettingsAndGoBack(document);
+ const perfPresetsSelect = await getNearestInputFromText(
+ profilerDocument,
+ "Settings"
+ );
+ is(
+ perfPresetsSelect.value,
+ "graphics",
+ "The preset has been changed in the devtools panel UI as well."
+ );
+
+ await disconnectFromLocalFirefox({ mocks, doc: document });
+ await removeTab(tab);
+});
+
+async function connectToLocalFirefox() {
+ // This is a client to the current Firefox.
+ const clientWrapper = await createLocalClientWrapper();
+
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ const usbClient = mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: DEVICE_NAME,
+ name: RUNTIME_NAME,
+ clientWrapper,
+ });
+
+ return { mocks, usbClient };
+}
+
+async function disconnectFromLocalFirefox({ doc, mocks }) {
+ info("Remove USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, doc);
+}
+
+function assertDialogVisible(doc) {
+ ok(doc.querySelector(".qa-profiler-dialog"), "Dialog is displayed");
+ ok(doc.querySelector(".qa-profiler-dialog-mask"), "Dialog mask is displayed");
+}
+
+function assertDialogHidden(doc) {
+ ok(!doc.querySelector(".qa-profiler-dialog"), "Dialog is removed");
+ ok(!doc.querySelector(".qa-profiler-dialog-mask"), "Dialog mask is removed");
+}
+
+/**
+ * Retrieve the iframe containing the profiler UIs.
+ * Be careful as it's completely replaced when switching UIs.
+ */
+function getProfilerIframe(doc) {
+ return doc.querySelector(".profiler-dialog__frame");
+}
+
+/**
+ * This waits for the full render of the UI inside the profiler iframe, and
+ * returns the content document object.
+ */
+async function waitForProfilerUiRendering(doc, selector) {
+ // The iframe is replaced completely, so we need to retrieve a new reference
+ // each time.
+ const profilerIframe = getProfilerIframe(doc);
+ // Wait for the settings to render.
+ await TestUtils.waitForCondition(
+ () =>
+ profilerIframe.contentDocument &&
+ profilerIframe.contentDocument.querySelector(selector)
+ );
+
+ return profilerIframe.contentDocument;
+}
+
+/**
+ * Open the performance profiler dialog with a real client.
+ */
+async function openProfilerDialogWithRealClient(doc) {
+ info("Click on the Profile Runtime button");
+ const profileButton = doc.querySelector(".qa-profile-runtime-button");
+ profileButton.click();
+
+ info("Wait for the rendering of the profiler UI");
+ const contentDocument = await waitForProfilerUiRendering(
+ doc,
+ ".perf-presets"
+ );
+ await getActiveButtonFromText(contentDocument, "Start recording");
+ info("The profiler UI is rendered!");
+ return contentDocument;
+}
+
+/**
+ * Open the performance profiler settings. This assumes the profiler dialog is
+ * already open by the previous function openProfilerDialog.
+ */
+async function openProfilerSettings(doc) {
+ const profilerDocument = getProfilerIframe(doc).contentDocument;
+
+ // Select the custom preset.
+ const perfPresetsSelect = await getNearestInputFromText(
+ profilerDocument,
+ "Settings"
+ );
+ setReactFriendlyInputValue(perfPresetsSelect, "custom");
+
+ // Click on "Edit Settings".
+ const editSettingsLink = await getElementFromDocumentByText(
+ profilerDocument,
+ "Edit Settings"
+ );
+ editSettingsLink.click();
+
+ info("Wait for the rendering of the profiler settings UI");
+ const contentDocument = await waitForProfilerUiRendering(
+ doc,
+ ".perf-aboutprofiling-remote"
+ );
+ info("The profiler settings UI is rendered!");
+ return contentDocument;
+}
+
+async function saveSettingsAndGoBack(doc) {
+ const profilerDocument = getProfilerIframe(doc).contentDocument;
+
+ const saveSettingsAndGoBackButton = await getActiveButtonFromText(
+ profilerDocument,
+ "Save settings"
+ );
+ saveSettingsAndGoBackButton.click();
+
+ info("Wait for the rendering of the profiler UI");
+ const contentDocument = await waitForProfilerUiRendering(
+ doc,
+ ".perf-presets"
+ );
+ await getActiveButtonFromText(contentDocument, "Start recording");
+ info("The profiler UI is rendered!");
+ return contentDocument;
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_runtime_page_runtime_info.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_runtime_page_runtime_info.js
new file mode 100644
index 0000000000..16462fd2b3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_runtime_page_runtime_info.js
@@ -0,0 +1,62 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-real-usb.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-real-usb.js",
+ this
+);
+
+// Test that runtime info of USB runtime appears on main pane.
+// Documentation for real usb tests in /documentation/TESTS_REAL_DEVICES.md
+add_task(async function () {
+ if (!isAvailable()) {
+ ok(true, "Real usb runtime test is not available");
+ return;
+ }
+
+ const { document, tab } = await openAboutDebuggingWithADB();
+
+ const expectedRuntime = await getExpectedRuntime();
+ const { runtimeDetails, sidebarInfo } = expectedRuntime;
+
+ info("Connect a USB runtime");
+ await Promise.race([
+ connectToRuntime(sidebarInfo.deviceName, document),
+ /* eslint-disable mozilla/no-arbitrary-setTimeout */
+ new Promise(resolve =>
+ setTimeout(() => {
+ ok(
+ false,
+ "Failed to connect, did you disable the connection prompt for this runtime?"
+ );
+ resolve();
+ }, 5000)
+ ),
+ /* eslint-enable mozilla/no-arbitrary-setTimeout */
+ ]);
+
+ info("Select a USB runtime");
+ await selectRuntime(
+ sidebarInfo.deviceName,
+ runtimeDetails.info.name,
+ document
+ );
+
+ info("Check that runtime info is properly displayed");
+ const runtimeInfo = document.querySelector(".qa-runtime-name");
+ ok(runtimeInfo, "Runtime info is displayed");
+ const runtimeInfoText = runtimeInfo.textContent;
+ ok(
+ runtimeInfoText.includes(runtimeDetails.info.name),
+ "Runtime info shows the correct runtime name: " + runtimeInfoText
+ );
+ ok(
+ runtimeInfoText.includes(runtimeDetails.info.version),
+ "Runtime info shows the correct version number: " + runtimeInfoText
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_sidebar.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_sidebar.js
new file mode 100644
index 0000000000..0b091dff87
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_real_usb_sidebar.js
@@ -0,0 +1,34 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-real-usb.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-real-usb.js",
+ this
+);
+
+// Test that USB runtimes appear from the sidebar.
+// Documentation for real usb tests in /documentation/TESTS_REAL_DEVICES.md
+add_task(async function () {
+ if (!isAvailable()) {
+ ok(true, "Real usb runtime test is not available");
+ return;
+ }
+
+ const { document, tab } = await openAboutDebuggingWithADB();
+
+ for (const { sidebarInfo } of await getExpectedRuntimeAll()) {
+ const { deviceName, shortName } = sidebarInfo;
+ await waitUntil(() => findSidebarItemByText(deviceName, document));
+ const usbRuntimeSidebarItem = findSidebarItemByText(deviceName, document);
+ ok(
+ usbRuntimeSidebarItem.textContent.includes(shortName),
+ "The device name and short name of the usb runtime are visible in sidebar item " +
+ `[${usbRuntimeSidebarItem.textContent}]`
+ );
+ }
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_routes.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_routes.js
new file mode 100644
index 0000000000..6295d37503
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_routes.js
@@ -0,0 +1,114 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Test that the initial route is /setup
+ */
+add_task(async function () {
+ info("Check root route redirects to setup page");
+ const { document, tab } = await openAboutDebugging();
+ is(document.location.hash, "#/setup");
+
+ await removeTab(tab);
+});
+
+/**
+ * Test that the routes in about:debugging show the proper views and document.title
+ */
+add_task(async function () {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+
+ const { document, tab } = await openAboutDebugging();
+
+ info("Check 'This Firefox' route");
+ document.location.hash = "#/runtime/this-firefox";
+ await waitUntil(() => document.querySelector(".qa-runtime-page"));
+ const infoLabel = document.querySelector(".qa-runtime-name").textContent;
+ // NOTE: when using USB Mocks, we see only "Firefox" as the device name
+ ok(infoLabel.includes("Firefox"), "Runtime is displayed as Firefox");
+ ok(!infoLabel.includes(" on "), "Runtime is not associated to any device");
+ is(
+ document.title,
+ "Debugging - Runtime / this-firefox",
+ "Checking title for 'runtime' page"
+ );
+
+ info("Check 'Setup' page");
+ document.location.hash = "#/setup";
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+ ok(true, "Setup page has been shown");
+ is(document.title, "Debugging - Setup", "Checking title for 'setup' page");
+
+ info("Check 'USB device runtime' page");
+ // connect to a mocked USB runtime
+ mocks.createUSBRuntime("1337id", {
+ deviceName: "Fancy Phone",
+ name: "Lorem ipsum",
+ });
+ mocks.emitUSBUpdate();
+ await connectToRuntime("Fancy Phone", document);
+ // navigate to it via URL
+ document.location.hash = "#/runtime/1337id";
+ await waitUntil(() => document.querySelector(".qa-runtime-page"));
+ const runtimeLabel = document.querySelector(".qa-runtime-name").textContent;
+ is(
+ document.title,
+ "Debugging - Runtime / 1337id",
+ "Checking title for 'runtime' page with USB device"
+ );
+ ok(
+ runtimeLabel.includes("Lorem ipsum"),
+ "Runtime is displayed with the mocked name"
+ );
+
+ await removeTab(tab);
+});
+
+/**
+ * Test that an invalid route redirects to / (currently This Firefox page)
+ */
+add_task(async function () {
+ info("Check an invalid route redirects to root");
+ const { document, tab } = await openAboutDebugging();
+
+ info("Waiting for a non setup page to load");
+ document.location.hash = "#/runtime/this-firefox";
+ await waitUntil(() => document.querySelector(".qa-runtime-page"));
+
+ info("Update hash & wait for a redirect to root (connect page)");
+ document.location.hash = "#/lorem-ipsum";
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+ is(document.title, "Debugging - Setup", "Checking title for 'setup' page");
+ is(document.location.hash, "#/setup", "Redirected to root");
+
+ await removeTab(tab);
+});
+
+/**
+ * Test that routes from old about:debugging redirect to this Firefox.
+ */
+add_task(async function testOldAboutDebuggingRoutes() {
+ info("Check that routes from old about:debugging redirect to this Firefox");
+ const { document, tab } = await openAboutDebugging();
+
+ const routes = ["addons", "tabs", "workers"];
+ for (const route of routes) {
+ info("Move to setup page before testing the route");
+ document.location.hash = "#/setup";
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+
+ info(`Check that navigating to ${route} redirects to This Firefox`);
+ document.location.hash = route;
+ await waitUntil(() => document.querySelector(".qa-runtime-page"));
+ is(
+ document.location.hash,
+ "#/runtime/this-firefox",
+ `${route} was redirected to This Firefox`
+ );
+ }
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_rtl.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_rtl.js
new file mode 100644
index 0000000000..4424df6ea8
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_rtl.js
@@ -0,0 +1,62 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+// Test that the about:debugging document and the profiler dialog document
+// use the expected document direction.
+add_task(async function test_direction_is_ltr_by_default() {
+ await testAboutDebuggingDocsDirection("ltr");
+});
+
+add_task(async function test_direction_is_rtl_for_bidi_pseudolocale() {
+ await pushPref("intl.l10n.pseudo", "bidi");
+ await testAboutDebuggingDocsDirection("rtl");
+});
+
+async function testAboutDebuggingDocsDirection(expectedDir) {
+ const mocks = new Mocks();
+ const { document, usbClient } = await setupTestForMockUSBRuntime(mocks);
+
+ is(document.dir, expectedDir, "document dir is " + expectedDir);
+
+ info("Open the profiler dialog");
+ await openProfilerDialog(usbClient, document);
+
+ const profilerDialogFrame = document.querySelector(
+ ".qa-profiler-dialog iframe"
+ );
+ ok(profilerDialogFrame, "Found Profiler dialog iframe");
+
+ const profilerDoc = profilerDialogFrame.contentWindow.document;
+ is(profilerDoc.dir, expectedDir, "Profiler document dir is " + expectedDir);
+
+ await teardownTestForMockUSBRuntime(mocks, document);
+}
+
+async function setupTestForMockUSBRuntime(mocks) {
+ info("Setup mock USB runtime");
+
+ const usbClient = mocks.createUSBRuntime("runtimeId", {
+ deviceName: "deviceName",
+ name: "runtimeName",
+ });
+
+ info("Open about:debugging and select runtime page for mock USB runtime");
+ const { document } = await openAboutDebugging();
+
+ mocks.emitUSBUpdate();
+ await connectToRuntime("deviceName", document);
+ await selectRuntime("deviceName", "runtimeName", document);
+
+ return { document, usbClient };
+}
+
+async function teardownTestForMockUSBRuntime(mocks, doc) {
+ info("Remove mock USB runtime");
+
+ mocks.removeUSBRuntime("runtimeId");
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged("deviceName", doc);
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_compatibility_warning.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_compatibility_warning.js
new file mode 100644
index 0000000000..3f45fa10d2
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_compatibility_warning.js
@@ -0,0 +1,90 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const COMPATIBLE_RUNTIME = "Compatible Runtime";
+const COMPATIBLE_DEVICE = "Compatible Device";
+const OLD_RUNTIME = "Old Runtime";
+const OLD_DEVICE = "Old Device";
+const FENNEC_68_RUNTIME = "Bad Runtime Fennec 68";
+const FENNEC_68_DEVICE = "Bad Device Fennec 68";
+const RECENT_RUNTIME = "Recent Runtime";
+const RECENT_DEVICE = "Recent Device";
+
+add_task(async function () {
+ const {
+ COMPATIBILITY_STATUS,
+ } = require("resource://devtools/client/shared/remote-debugging/version-checker.js");
+ const { COMPATIBLE, TOO_OLD, TOO_OLD_FENNEC, TOO_RECENT } =
+ COMPATIBILITY_STATUS;
+
+ info("Create several mocked runtimes, with different compatibility reports");
+ const mocks = new Mocks();
+ createRuntimeWithReport(
+ mocks,
+ COMPATIBLE_RUNTIME,
+ COMPATIBLE_DEVICE,
+ COMPATIBLE
+ );
+ createRuntimeWithReport(mocks, OLD_RUNTIME, OLD_DEVICE, TOO_OLD);
+ createRuntimeWithReport(mocks, RECENT_RUNTIME, RECENT_DEVICE, TOO_RECENT);
+ createRuntimeWithReport(
+ mocks,
+ FENNEC_68_RUNTIME,
+ FENNEC_68_DEVICE,
+ TOO_OLD_FENNEC
+ );
+
+ const { document, tab } = await openAboutDebugging();
+ mocks.emitUSBUpdate();
+
+ info("Connect to all runtimes");
+ await connectToRuntime(COMPATIBLE_DEVICE, document);
+ await connectToRuntime(OLD_DEVICE, document);
+ await connectToRuntime(RECENT_DEVICE, document);
+ await connectToRuntime(FENNEC_68_DEVICE, document);
+
+ info("Select the compatible runtime and check that no warning is displayed");
+ await selectRuntime(COMPATIBLE_DEVICE, COMPATIBLE_RUNTIME, document);
+ ok(
+ !document.querySelector(".qa-compatibility-warning"),
+ "Compatibility warning is not displayed"
+ );
+
+ info(
+ "Select the old runtime and check that the too-old warning is displayed"
+ );
+ await selectRuntime(OLD_DEVICE, OLD_RUNTIME, document);
+ ok(
+ document.querySelector(".qa-compatibility-warning-too-old"),
+ "Expected compatibility warning is displayed (too-old)"
+ );
+
+ info(
+ "Select the recent runtime and check that the too-recent warning is displayed"
+ );
+ await selectRuntime(RECENT_DEVICE, RECENT_RUNTIME, document);
+ ok(
+ document.querySelector(".qa-compatibility-warning-too-recent"),
+ "Expected compatibility warning is displayed (too-recent)"
+ );
+
+ info(
+ "Select the Fennec 68 runtime and check that the correct warning is displayed"
+ );
+ await selectRuntime(FENNEC_68_DEVICE, FENNEC_68_RUNTIME, document);
+ ok(document.querySelector(".qa-compatibility-warning-too-old-fennec"));
+
+ await removeTab(tab);
+});
+
+function createRuntimeWithReport(mocks, name, deviceName, status) {
+ const runtimeId = [name, deviceName].join("-");
+ const compatibleUsbClient = mocks.createUSBRuntime(runtimeId, {
+ deviceName,
+ name,
+ });
+ const report = { status };
+ compatibleUsbClient.checkVersionCompatibility = () => report;
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js
new file mode 100644
index 0000000000..e7cae28d29
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_disconnect_remote_runtime.js
@@ -0,0 +1,65 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const USB_RUNTIME_ID = "1337id";
+const USB_DEVICE_NAME = "Fancy Phone";
+const USB_APP_NAME = "Lorem ipsum";
+
+const DEFAULT_PAGE = "#/runtime/this-firefox";
+
+/**
+ * Check if the disconnect button disconnects the remote runtime
+ * and redirects to the default page.
+ */
+add_task(async function () {
+ // Create a real local client and use it as the remote USB client for this
+ // test.
+ const clientWrapper = await createLocalClientWrapper();
+
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ clientWrapper,
+ deviceName: USB_DEVICE_NAME,
+ name: USB_APP_NAME,
+ });
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ mocks.emitUSBUpdate();
+
+ const onRequestSuccess = waitForRequestsSuccess(window.AboutDebugging.store);
+ await connectToRuntime(USB_DEVICE_NAME, document);
+ await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);
+ await onRequestSuccess;
+
+ const disconnectRemoteRuntimeButton = document.querySelector(
+ ".qa-runtime-info__action"
+ );
+
+ info("Check whether disconnect remote runtime button exists");
+ ok(!!disconnectRemoteRuntimeButton, "Runtime contains the disconnect button");
+
+ info("Click on the disconnect button");
+ disconnectRemoteRuntimeButton.click();
+
+ info("Wait until the runtime is disconnected");
+ await waitUntil(() => document.querySelector(".qa-connect-button"));
+
+ is(
+ document.location.hash,
+ DEFAULT_PAGE,
+ "Redirection to the default page (this-firefox)"
+ );
+
+ info("Wait until the Runtime name is displayed");
+ await waitUntil(() => {
+ const runtimeInfo = document.querySelector(".qa-runtime-name");
+ return runtimeInfo && runtimeInfo.textContent.includes("Firefox");
+ });
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_remote_runtime_buttons.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_remote_runtime_buttons.js
new file mode 100644
index 0000000000..563fe659ce
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_remote_runtime_buttons.js
@@ -0,0 +1,56 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const USB_RUNTIME_ID = "1337id";
+const USB_DEVICE_NAME = "Fancy Phone";
+const USB_APP_NAME = "Lorem ipsum";
+
+/**
+ * Test that remote runtimes show action buttons that are hidden for 'This Firefox'.
+ */
+add_task(async function () {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ deviceName: USB_DEVICE_NAME,
+ name: USB_APP_NAME,
+ });
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Checking This Firefox");
+ ok(
+ !document.querySelector(".qa-connection-prompt-toggle-button"),
+ "This Firefox does not contain the connection prompt button"
+ );
+ ok(
+ !document.querySelector(".qa-profile-runtime-button"),
+ "This Firefox does not contain the profile runtime button"
+ );
+ ok(
+ !document.querySelector(".qa-runtime-info__action"),
+ "This Firefox does not contain the disconnect button"
+ );
+
+ info("Checking a USB runtime");
+ mocks.emitUSBUpdate();
+ await connectToRuntime(USB_DEVICE_NAME, document);
+ await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);
+ ok(
+ !!document.querySelector(".qa-connection-prompt-toggle-button"),
+ "Runtime contains the connection prompt button"
+ );
+ ok(
+ !!document.querySelector(".qa-profile-runtime-button"),
+ "Remote runtime contains the profile runtime button"
+ );
+ ok(
+ !!document.querySelector(".qa-runtime-info__action"),
+ "Runtime contains the disconnect button"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_usbclient_closed.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_usbclient_closed.js
new file mode 100644
index 0000000000..9e9715a46b
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_runtime_usbclient_closed.js
@@ -0,0 +1,109 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+const USB_RUNTIME_ID = "test-runtime-id";
+const USB_DEVICE_NAME = "test device name";
+const USB_APP_NAME = "TestApp";
+
+// Test that about:debugging navigates back to the default page when a USB device is
+// unplugged.
+add_task(async function testUsbDeviceUnplugged() {
+ const mocks = new Mocks();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ deviceName: USB_DEVICE_NAME,
+ name: USB_APP_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Connect to and select the USB device");
+ await connectToRuntime(USB_DEVICE_NAME, document);
+ await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);
+
+ info("Simulate a device unplugged");
+ mocks.removeUSBRuntime(USB_RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(USB_DEVICE_NAME, document);
+
+ is(
+ document.location.hash,
+ `#/runtime/this-firefox`,
+ "Redirection to the default page (this-firefox)"
+ );
+
+ await removeTab(tab);
+});
+
+// Test that about:debugging navigates back to the default page when the server for the
+// current USB runtime is closed.
+add_task(async function testUsbClientDisconnected() {
+ const mocks = new Mocks();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ deviceName: USB_DEVICE_NAME,
+ name: USB_APP_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Connect to and select the USB device");
+ await connectToRuntime(USB_DEVICE_NAME, document);
+ await selectRuntime(USB_DEVICE_NAME, USB_APP_NAME, document);
+
+ info("Simulate a client disconnection");
+ usbClient.isClosed = () => true;
+ usbClient._eventEmitter.emit("closed");
+
+ info("Wait until the connect button for this runtime appears");
+ await waitUntil(() => {
+ const item = findSidebarItemByText(USB_DEVICE_NAME, document);
+ return item && item.querySelector(".qa-connect-button");
+ });
+
+ is(
+ document.location.hash,
+ `#/runtime/this-firefox`,
+ "Redirection to the default page (this-firefox)"
+ );
+ await removeTab(tab);
+});
+
+// Test that about:debugging navigates back to the default page when the server for the
+// current network runtime is closed.
+add_task(async function testNetworkClientDisconnected() {
+ const mocks = new Mocks();
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+ name: NETWORK_RUNTIME_APP_NAME,
+ });
+
+ info("Connect to and select the network runtime");
+ await connectToRuntime(NETWORK_RUNTIME_HOST, document);
+ await selectRuntime(NETWORK_RUNTIME_HOST, NETWORK_RUNTIME_APP_NAME, document);
+
+ info("Simulate a client disconnection");
+ networkClient.isClosed = () => true;
+ networkClient._eventEmitter.emit("closed");
+
+ info("Wait until the connect button for this runtime appears");
+ await waitUntil(() => {
+ const item = findSidebarItemByText(NETWORK_RUNTIME_HOST, document);
+ return item && item.querySelector(".qa-connect-button");
+ });
+
+ is(
+ document.location.hash,
+ `#/runtime/this-firefox`,
+ "Redirection to the default page (this-firefox)"
+ );
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_network_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_network_runtime.js
new file mode 100644
index 0000000000..e3f770f948
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_network_runtime.js
@@ -0,0 +1,52 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+const NETWORK_RUNTIME_CHANNEL = "SomeChannel";
+const NETWORK_RUNTIME_VERSION = "12.3";
+
+// Test that network runtimes can be selected.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Prepare Network client mock");
+ const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+ name: NETWORK_RUNTIME_APP_NAME,
+ });
+ networkClient.getDeviceDescription = () => {
+ return {
+ name: NETWORK_RUNTIME_APP_NAME,
+ channel: NETWORK_RUNTIME_CHANNEL,
+ version: NETWORK_RUNTIME_VERSION,
+ };
+ };
+
+ info("Test addons in runtime page for Network client");
+ await connectToRuntime(NETWORK_RUNTIME_HOST, document);
+ await selectRuntime(NETWORK_RUNTIME_HOST, NETWORK_RUNTIME_APP_NAME, document);
+
+ info("Check that the network runtime mock is properly displayed");
+ const thisFirefoxRuntimeInfo = document.querySelector(".qa-runtime-name");
+ ok(
+ thisFirefoxRuntimeInfo,
+ "Runtime info for this-firefox runtime is displayed"
+ );
+ const runtimeInfoText = thisFirefoxRuntimeInfo.textContent;
+
+ ok(
+ runtimeInfoText.includes(NETWORK_RUNTIME_APP_NAME),
+ "network runtime info shows the correct runtime name: " + runtimeInfoText
+ );
+ ok(
+ runtimeInfoText.includes(NETWORK_RUNTIME_VERSION),
+ "network runtime info shows the correct version number: " + runtimeInfoText
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_page_with_serviceworker.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_page_with_serviceworker.js
new file mode 100644
index 0000000000..41e69a0d42
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_select_page_with_serviceworker.js
@@ -0,0 +1,78 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+const WORKER_NAME = "testserviceworker";
+
+// Test that navigating from:
+// - a remote runtime page that contains a service worker
+// to:
+// - this firefox
+// does not crash. See Bug 1519088.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Prepare Network client mock");
+ const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+ name: NETWORK_RUNTIME_APP_NAME,
+ });
+
+ info("Connect and select the network runtime");
+ await connectToRuntime(NETWORK_RUNTIME_HOST, document);
+ await selectRuntime(NETWORK_RUNTIME_HOST, NETWORK_RUNTIME_APP_NAME, document);
+
+ info(`Add a service worker to the network client`);
+ const workers = {
+ otherWorkers: [],
+ serviceWorkers: [
+ {
+ name: WORKER_NAME,
+ workerDescriptorFront: { actorID: WORKER_NAME },
+ },
+ ],
+ sharedWorkers: [],
+ };
+ networkClient.listWorkers = () => workers;
+ networkClient._eventEmitter.emit("workersUpdated");
+
+ info("Wait until the service worker is displayed");
+ await waitUntil(() => findDebugTargetByText(WORKER_NAME, document));
+
+ info("Go to This Firefox again");
+ const thisFirefoxString = getThisFirefoxString(window);
+ const thisFirefoxSidebarItem = findSidebarItemByText(
+ thisFirefoxString,
+ document
+ );
+ const thisFirefoxLink =
+ thisFirefoxSidebarItem.querySelector(".qa-sidebar-link");
+ info("Click on the ThisFirefox item in the sidebar");
+ const requestsSuccess = waitForRequestsSuccess(window.AboutDebugging.store);
+ thisFirefoxLink.click();
+
+ info("Wait for all target requests to complete");
+ await requestsSuccess;
+
+ info("Check that the runtime info is rendered for This Firefox");
+ const thisFirefoxRuntimeInfo = document.querySelector(".qa-runtime-name");
+ ok(
+ thisFirefoxRuntimeInfo,
+ "Runtime info for this-firefox runtime is displayed"
+ );
+
+ const text = thisFirefoxRuntimeInfo.textContent;
+ ok(
+ text.includes("Firefox") && text.includes("63.0"),
+ "this-firefox runtime info shows the correct values"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_console.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_console.js
new file mode 100644
index 0000000000..742791668d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_console.js
@@ -0,0 +1,131 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/devtools/client/debugger/test/mochitest/shared-head.js",
+ this
+);
+
+const SW_TAB_URL =
+ URL_ROOT_SSL + "resources/service-workers/controlled-sw.html";
+const SW_URL = URL_ROOT_SSL + "resources/service-workers/controlled-sw.js";
+
+/**
+ * Test various simple debugging operation against service workers debugged through about:debugging.
+ */
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Open a tab that registers a basic service worker.
+ const swTab = await addTab(SW_TAB_URL);
+
+ // Wait for the registration to make sure service worker has been started, and that we
+ // are not just reading STOPPED as the initial state.
+ await waitForRegistration(swTab);
+
+ info("Open a toolbox to debug the worker");
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ SW_URL
+ );
+
+ const toolbox = getToolbox(devtoolsWindow);
+
+ info("Assert the default tools displayed in worker toolboxes");
+ const toolTabs = toolbox.doc.querySelectorAll(".devtools-tab");
+ const activeTools = [...toolTabs].map(toolTab =>
+ toolTab.getAttribute("data-id")
+ );
+
+ is(
+ activeTools.join(","),
+ "webconsole,jsdebugger",
+ "Correct set of tools supported by worker"
+ );
+
+ const webconsole = await toolbox.selectTool("webconsole");
+ const { hud } = webconsole;
+
+ info("Evaluate location in the console");
+ await executeAndWaitForMessage(hud, "this.location.toString()", SW_URL);
+ ok(true, "Got the location logged in the console");
+
+ info(
+ "Evaluate Date and RegExp to ensure their formater also work from worker threads"
+ );
+ await executeAndWaitForMessage(
+ hud,
+ "new Date(2013, 3, 1)",
+ "Mon Apr 01 2013 00:00:00"
+ );
+ ok(true, "Date object has expected text content");
+ await executeAndWaitForMessage(hud, "new RegExp('.*')", "/.*/");
+ ok(true, "RegExp has expected text content");
+
+ await toolbox.selectTool("jsdebugger");
+ const dbg = createDebuggerContext(toolbox);
+ const {
+ selectors: { getIsWaitingOnBreak, getCurrentThread },
+ } = dbg;
+
+ info("Wait for next interupt in the worker thread");
+ await clickElement(dbg, "pause");
+ await waitForState(dbg, state => getIsWaitingOnBreak(getCurrentThread()));
+
+ info("Trigger some code in the worker and wait for pause");
+ await SpecialPowers.spawn(swTab.linkedBrowser, [], async function () {
+ content.wrappedJSObject.installServiceWorker();
+ });
+ await waitForPaused(dbg);
+ ok(true, "successfully paused");
+
+ info(
+ "Evaluate some variable only visible if we execute in the breakpoint frame"
+ );
+ await executeAndWaitForMessage(hud, "event.data", "install-service-worker");
+
+ info("Resume execution");
+ await resume(dbg);
+
+ info("Test pausing from console evaluation");
+ hud.ui.wrapper.dispatchEvaluateExpression("debugger; 42");
+ await waitForPaused(dbg);
+ ok(true, "successfully paused");
+ info("Immediately resume");
+ await resume(dbg);
+ await waitFor(() => findMessagesByType(hud, "42", ".result"));
+ ok("The paused console evaluation resumed and logged its magic number");
+
+ info("Destroy the toolbox");
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+
+ info("Unregister service worker");
+ await unregisterServiceWorker(swTab);
+
+ info("Wait until the service worker disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(SW_URL, document));
+
+ info("Remove tabs");
+ await removeTab(swTab);
+ await removeTab(tab);
+});
+
+async function executeAndWaitForMessage(hud, evaluationString, expectedResult) {
+ hud.ui.wrapper.dispatchEvaluateExpression();
+ await waitFor(() => findMessagesByType(hud, expectedResult, ".result"));
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_fetch_flag.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_fetch_flag.js
new file mode 100644
index 0000000000..960635a56d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_fetch_flag.js
@@ -0,0 +1,68 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+const FETCH_SW_JS = URL_ROOT_SSL + "resources/service-workers/fetch-sw.js";
+const FETCH_SW_HTML = URL_ROOT_SSL + "resources/service-workers/fetch-sw.html";
+
+const EMPTY_SW_JS = URL_ROOT_SSL + "resources/service-workers/empty-sw.js";
+const EMPTY_SW_HTML = URL_ROOT_SSL + "resources/service-workers/empty-sw.html";
+
+/**
+ * Test that the appropriate fetch flag is displayed for service workers.
+ */
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Test fetch status for a service worker listening to fetch events");
+ await testServiceWorkerFetchStatus(
+ document,
+ FETCH_SW_HTML,
+ FETCH_SW_JS,
+ true
+ );
+
+ info("Test fetch status for a service worker not listening to fetch events");
+ await testServiceWorkerFetchStatus(
+ document,
+ EMPTY_SW_HTML,
+ EMPTY_SW_JS,
+ false
+ );
+
+ await removeTab(tab);
+});
+
+async function testServiceWorkerFetchStatus(doc, url, workerUrl, isListening) {
+ // Open a tab that registers a fetch service worker.
+ const swTab = await addTab(url);
+
+ info("Wait until the service worker appears and is running");
+ const targetElement = await waitForServiceWorkerRunning(workerUrl, doc);
+
+ const expectedClassName = isListening
+ ? ".qa-worker-fetch-listening"
+ : ".qa-worker-fetch-not-listening";
+ const fetchStatus = targetElement.querySelector(expectedClassName);
+ ok(!!fetchStatus, "Found the expected fetch status: " + expectedClassName);
+
+ info("Unregister the service worker");
+ await unregisterServiceWorker(swTab);
+
+ info("Wait until the service worker disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(workerUrl, doc));
+
+ info("Remove the service worker tab");
+ await removeTab(swTab);
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_not_compatible.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_not_compatible.js
new file mode 100644
index 0000000000..d1a6782c09
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_not_compatible.js
@@ -0,0 +1,124 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// This test started running during a GC and timing out on coverage platforms.
+// See Bug 1526153.
+requestLongerTimeout(2);
+
+const TEST_DATA = [
+ {
+ serviceWorkersEnabled: true,
+ privateBrowsingEnabled: false,
+ expectedMessage: false,
+ },
+ {
+ serviceWorkersEnabled: false,
+ privateBrowsingEnabled: false,
+ expectedMessage: true,
+ },
+ {
+ serviceWorkersEnabled: true,
+ privateBrowsingEnabled: true,
+ expectedMessage: true,
+ },
+ {
+ serviceWorkersEnabled: false,
+ privateBrowsingEnabled: true,
+ expectedMessage: true,
+ },
+];
+
+/**
+ * Check that the warning message for service workers is displayed if permanent private
+ * browsing is enabled or/and if service workers are disabled.
+ */
+add_task(async function testLocalRuntime() {
+ for (const testData of TEST_DATA) {
+ const { serviceWorkersEnabled, privateBrowsingEnabled, expectedMessage } =
+ testData;
+
+ info(
+ `Test warning message on this-firefox ` +
+ `with serviceWorkersEnabled: ${serviceWorkersEnabled} ` +
+ `and with privateBrowsingEnabled: ${privateBrowsingEnabled}`
+ );
+
+ await pushPref("dom.serviceWorkers.enabled", serviceWorkersEnabled);
+ await pushPref("browser.privatebrowsing.autostart", privateBrowsingEnabled);
+
+ const { document, tab, window } = await openAboutDebugging({
+ // Even though this is a service worker test, we are not adding/removing
+ // workers here. Since the test is really fast it can create intermittent
+ // failures due to pending requests to update the worker list
+ // We are updating the worker list whenever the list of processes changes
+ // and this can happen very frequently, and it's hard to control from
+ // DevTools.
+ // Set enableWorkerUpdates to false to avoid intermittent failures.
+ enableWorkerUpdates: false,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+ assertWarningMessage(document, expectedMessage);
+ await removeTab(tab);
+ }
+});
+
+add_task(async function testRemoteRuntime() {
+ const {
+ remoteClientManager,
+ } = require("resource://devtools/client/shared/remote-debugging/remote-client-manager.js");
+
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ const client = mocks.createUSBRuntime("1337id", {
+ deviceName: "Fancy Phone",
+ name: "Lorem ipsum",
+ });
+
+ for (const testData of TEST_DATA) {
+ const { serviceWorkersEnabled, privateBrowsingEnabled, expectedMessage } =
+ testData;
+
+ info(
+ `Test warning message on mocked USB runtime ` +
+ `with serviceWorkersEnabled: ${serviceWorkersEnabled} ` +
+ `and with privateBrowsingEnabled: ${privateBrowsingEnabled}`
+ );
+
+ client.setPreference("dom.serviceWorkers.enabled", serviceWorkersEnabled);
+ client.setPreference(
+ "browser.privatebrowsing.autostart",
+ privateBrowsingEnabled
+ );
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: false,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Checking a USB runtime");
+ mocks.emitUSBUpdate();
+ await connectToRuntime("Fancy Phone", document);
+ await selectRuntime("Fancy Phone", "Lorem ipsum", document);
+
+ assertWarningMessage(document, expectedMessage);
+
+ // We remove all clients in order to be able to simply connect to the runtime at
+ // every iteration of the loop without checking of the runtime is already connected.
+ info("Remove all remote clients");
+ await remoteClientManager.removeAllClients();
+
+ await removeTab(tab);
+ }
+});
+
+function assertWarningMessage(doc, expectedMessage) {
+ const hasMessage = !!doc.querySelector(".qa-service-workers-warning");
+ ok(
+ hasMessage === expectedMessage,
+ expectedMessage
+ ? "Warning message is displayed"
+ : "Warning message is not displayed"
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_push.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_push.js
new file mode 100644
index 0000000000..740f066903
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_push.js
@@ -0,0 +1,61 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+const SERVICE_WORKER = URL_ROOT_SSL + "resources/service-workers/push-sw.js";
+const TAB_URL = URL_ROOT_SSL + "resources/service-workers/push-sw.html";
+
+// Test that clicking on the Push button next to a Service Worker works as intended.
+// It should trigger a "push" notification in the worker.
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Open a tab that registers a push service worker.
+ const swTab = await addTab(TAB_URL);
+
+ info(
+ "Wait for the service worker to claim the test window before proceeding."
+ );
+ await SpecialPowers.spawn(
+ swTab.linkedBrowser,
+ [],
+ () => content.wrappedJSObject.onSwClaimed
+ );
+
+ info("Wait until the service worker appears and is running");
+ const targetElement = await waitForServiceWorkerRunning(
+ SERVICE_WORKER,
+ document
+ );
+
+ // Retrieve the Push button for the worker.
+ const pushButton = targetElement.querySelector(".qa-push-button");
+ ok(pushButton, "Found its push button");
+
+ info("Click on the Push button and wait for the push notification");
+ const onPushNotification = onServiceWorkerMessage(swTab, "sw-pushed");
+ pushButton.click();
+ await onPushNotification;
+
+ info("Unregister the service worker");
+ await unregisterServiceWorker(swTab);
+
+ info("Wait until the service worker disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(SERVICE_WORKER, document));
+
+ info("Remove the service worker tab");
+ await removeTab(swTab);
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_pushservice_url.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_pushservice_url.js
new file mode 100644
index 0000000000..9581a493d9
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_pushservice_url.js
@@ -0,0 +1,118 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+const SERVICE_WORKER = URL_ROOT_SSL + "resources/service-workers/push-sw.js";
+const TAB_URL = URL_ROOT_SSL + "resources/service-workers/push-sw.html";
+
+const FAKE_ENDPOINT = "https://fake/endpoint";
+
+// Test that the push service url is displayed for service workers subscribed to a push
+// service.
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+
+ info("Mock the push service");
+ mockPushService(FAKE_ENDPOINT);
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Open a tab that registers a push service worker.
+ const swTab = await addTab(TAB_URL);
+
+ info(
+ "Wait for the service worker to claim the test window before proceeding."
+ );
+ await SpecialPowers.spawn(
+ swTab.linkedBrowser,
+ [],
+ () => content.wrappedJSObject.onSwClaimed
+ );
+
+ info("Wait until the service worker appears and is running");
+ const targetElement = await waitForServiceWorkerRunning(
+ SERVICE_WORKER,
+ document
+ );
+
+ info("Subscribe from the push service");
+ SpecialPowers.spawn(swTab.linkedBrowser, [], () => {
+ content.wrappedJSObject.subscribeToPush();
+ });
+
+ info("Wait until the push service appears");
+ await waitUntil(() =>
+ targetElement.querySelector(".qa-worker-push-service-value")
+ );
+ const pushUrl = targetElement.querySelector(".qa-worker-push-service-value");
+
+ ok(!!pushUrl, "Push URL is displayed for the serviceworker");
+ is(pushUrl.textContent, FAKE_ENDPOINT, "Push URL shows the expected content");
+
+ info("Unsubscribe from the push service");
+ SpecialPowers.spawn(swTab.linkedBrowser, [], () => {
+ content.wrappedJSObject.unsubscribeToPush();
+ });
+
+ info("Wait until the push service disappears");
+ await waitUntil(
+ () => !targetElement.querySelector(".qa-worker-push-service-value")
+ );
+
+ info("Unregister the service worker");
+ await unregisterServiceWorker(swTab);
+
+ info("Wait until the service worker disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(SERVICE_WORKER, document));
+
+ info("Remove the service worker tab");
+ await removeTab(swTab);
+
+ await removeTab(tab);
+});
+
+function mockPushService(endpoint) {
+ const PushService = Cc["@mozilla.org/push/Service;1"].getService(
+ Ci.nsIPushService
+ ).wrappedJSObject;
+
+ PushService.service = {
+ _registrations: new Map(),
+ _notify(scope) {
+ Services.obs.notifyObservers(
+ null,
+ PushService.subscriptionModifiedTopic,
+ scope
+ );
+ },
+ init() {},
+ register(pageRecord) {
+ const registration = {
+ endpoint,
+ };
+ this._registrations.set(pageRecord.scope, registration);
+ this._notify(pageRecord.scope);
+ return Promise.resolve(registration);
+ },
+ registration(pageRecord) {
+ return Promise.resolve(this._registrations.get(pageRecord.scope));
+ },
+ unregister(pageRecord) {
+ const deleted = this._registrations.delete(pageRecord.scope);
+ if (deleted) {
+ this._notify(pageRecord.scope);
+ }
+ return Promise.resolve(deleted);
+ },
+ };
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_runtime-page.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_runtime-page.js
new file mode 100644
index 0000000000..410cbadefd
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_runtime-page.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+/* import-globals-from helper-collapsibilities.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-collapsibilities.js",
+ this
+);
+
+const SW_TAB_URL = URL_ROOT_SSL + "resources/service-workers/push-sw.html";
+const SW_URL = URL_ROOT_SSL + "resources/service-workers/push-sw.js";
+
+/**
+ * Test that service workers appear and dissapear from the runtime page when they
+ * are registered / unregistered.
+ */
+add_task(async function () {
+ prepareCollapsibilitiesTest();
+ await enableServiceWorkerDebugging();
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ const store = window.AboutDebugging.store;
+
+ await selectThisFirefoxPage(document, store);
+
+ // check that SW list is empty
+ info("Check that the SW pane is empty");
+ let swPane = getDebugTargetPane("Service Workers", document);
+ ok(!swPane.querySelector(".qa-debug-target-item"), "SW list is empty");
+
+ // open a tab and register service worker
+ info("Register a service worker");
+ const swTab = await addTab(SW_TAB_URL);
+
+ // check that service worker is rendered
+ info("Wait until the service worker appears and is running");
+ await waitForServiceWorkerRunning(SW_URL, document);
+
+ swPane = getDebugTargetPane("Service Workers", document);
+ ok(
+ swPane.querySelectorAll(".qa-debug-target-item").length === 1,
+ "Service worker list has one element"
+ );
+ ok(
+ swPane.querySelector(".qa-debug-target-item").textContent.includes(SW_URL),
+ "Service worker list is the one we registered"
+ );
+
+ // unregister the service worker
+ info("Unregister service worker");
+ await unregisterServiceWorker(swTab);
+ // check that service worker is not rendered anymore
+ info("Wait for service worker to disappear");
+ await waitUntil(() => {
+ swPane = getDebugTargetPane("Service Workers", document);
+ return swPane.querySelectorAll(".qa-debug-target-item").length === 0;
+ });
+
+ info("Remove tabs");
+ await removeTab(swTab);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_start.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_start.js
new file mode 100644
index 0000000000..483a1cad43
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_start.js
@@ -0,0 +1,71 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+const SW_TAB_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.html";
+const SW_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.js";
+
+/**
+ * Test that service workers can be started using about:debugging.
+ */
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+
+ // Setting a low idle_timeout and idle_extended_timeout will allow the service worker
+ // to reach the STOPPED state quickly, which will allow us to test the start button.
+ // The default value is 30000 milliseconds.
+ info("Set a low service worker idle timeout");
+ await pushPref("dom.serviceWorkers.idle_timeout", 1000);
+ await pushPref("dom.serviceWorkers.idle_extended_timeout", 1000);
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Open a tab that registers a basic service worker.
+ const swTab = await addTab(SW_TAB_URL);
+
+ // Wait for the registration to make sure service worker has been started, and that we
+ // are not just reading STOPPED as the initial state.
+ await waitForRegistration(swTab);
+
+ info("Wait until the service worker stops");
+ const targetElement = await waitForServiceWorkerStopped(SW_URL, document);
+
+ // Retrieve the Start button for the worker.
+ const startButton = targetElement.querySelector(".qa-start-button");
+ ok(startButton, "Found its start button");
+
+ info(
+ "Click on the start button and wait for the service worker to be running"
+ );
+ const onServiceWorkerRunning = waitForServiceWorkerRunning(SW_URL, document);
+ startButton.click();
+ const updatedTarget = await onServiceWorkerRunning;
+
+ // Check that the buttons are displayed as expected.
+ const hasInspectButton = updatedTarget.querySelector(
+ ".qa-debug-target-inspect-button"
+ );
+ const hasStartButton = updatedTarget.querySelector(".qa-start-button");
+ ok(hasInspectButton, "Service worker has an inspect button");
+ ok(!hasStartButton, "Service worker does not have a start button");
+
+ info("Unregister service worker");
+ await unregisterServiceWorker(swTab);
+
+ info("Wait until the service worker disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(SW_URL, document));
+
+ info("Remove tabs");
+ await removeTab(swTab);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_status.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_status.js
new file mode 100644
index 0000000000..50426dcb47
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_status.js
@@ -0,0 +1,104 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+const SW_TAB_URL =
+ URL_ROOT_SSL + "resources/service-workers/controlled-sw.html";
+const SW_URL = URL_ROOT_SSL + "resources/service-workers/controlled-sw.js";
+
+/**
+ * Test that the service worker has the status "registering" when the service worker is
+ * not installed yet. Other states (stopped, running) are covered by the existing tests.
+ */
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Open tab with a service worker that never leaves `registering` status");
+ const swTab = await addTab(SW_TAB_URL);
+
+ // Wait for the registration to make sure service worker has been started, and that we
+ // are not just reading STOPPED as the initial state.
+ await waitForRegistration(swTab);
+
+ info("Wait until the service worker is in registering status");
+ await waitForServiceWorkerRegistering(SW_URL, document);
+
+ // Check that the buttons are displayed as expected.
+ checkButtons(
+ { inspect: true, push: false, start: false, unregister: false },
+ SW_URL,
+ document
+ );
+
+ info("Install the service worker");
+ SpecialPowers.spawn(swTab.linkedBrowser, [], () =>
+ content.wrappedJSObject.installServiceWorker()
+ );
+
+ info("Wait until the service worker is running");
+ await waitForServiceWorkerRunning(SW_URL, document);
+
+ checkButtons(
+ { inspect: true, push: true, start: false, unregister: true },
+ SW_URL,
+ document
+ );
+
+ info("Unregister service worker");
+ await unregisterServiceWorker(swTab);
+
+ info("Wait until the service worker disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(SW_URL, document));
+
+ info("Remove tabs");
+ await removeTab(swTab);
+ await removeTab(tab);
+});
+
+function checkButtons(
+ { inspect, push, start, unregister },
+ workerText,
+ document
+) {
+ const targetElement = findDebugTargetByText(SW_URL, document);
+
+ const inspectButton = targetElement.querySelector(
+ ".qa-debug-target-inspect-button"
+ );
+ const pushButton = targetElement.querySelector(".qa-push-button");
+ const startButton = targetElement.querySelector(".qa-start-button");
+ const unregisterButton = targetElement.querySelector(".qa-unregister-button");
+
+ is(
+ !!inspectButton,
+ inspect,
+ "Inspect button should be " + (inspect ? "visible" : "hidden")
+ );
+ is(
+ !!pushButton,
+ push,
+ "Push button should be " + (push ? "visible" : "hidden")
+ );
+ is(
+ !!startButton,
+ start,
+ "Start button should be " + (start ? "visible" : "hidden")
+ );
+ is(
+ !!unregisterButton,
+ unregister,
+ "Unregister button should be " + (unregister ? "visible" : "hidden")
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_timeout.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_timeout.js
new file mode 100644
index 0000000000..f4fc04d229
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_timeout.js
@@ -0,0 +1,104 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// This test will be idle for a long period to give a chance to the service worker to
+// timeout.
+requestLongerTimeout(3);
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+const SW_TAB_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.html";
+const SW_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.js";
+const SW_TIMEOUT = 4000;
+
+/**
+ * Test that service workers will _not_ timeout and be stopped when a toolbox is attached
+ * to them. Feature implemented in Bug 1228382.
+ */
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+
+ // Setting a low idle_timeout and idle_extended_timeout will allow the service worker
+ // to reach the STOPPED state quickly, which will allow us to test the start button.
+ // The default value is 30000 milliseconds.
+ info("Set a low service worker idle timeout");
+ await pushPref("dom.serviceWorkers.idle_timeout", SW_TIMEOUT);
+ await pushPref("dom.serviceWorkers.idle_extended_timeout", SW_TIMEOUT);
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Open a tab that registers a basic service worker.
+ const swTab = await addTab(SW_TAB_URL);
+
+ // Wait for the registration to make sure service worker has been started, and that we
+ // are not just reading STOPPED as the initial state.
+ await waitForRegistration(swTab);
+
+ info("Wait until the service worker stops");
+ await waitForServiceWorkerStopped(SW_URL, document);
+
+ info(
+ "Click on the start button and wait for the service worker to be running"
+ );
+ const onServiceWorkerRunning = waitForServiceWorkerRunning(SW_URL, document);
+ const startButton = getStartButton(SW_URL, document);
+ startButton.click();
+ await onServiceWorkerRunning;
+
+ const inspectButton = getInspectButton(SW_URL, document);
+ ok(!!inspectButton, "Service worker target has an inspect button");
+
+ info("Click on inspect and wait for the toolbox to open");
+ const onToolboxReady = gDevTools.once("toolbox-ready");
+ inspectButton.click();
+ await onToolboxReady;
+
+ // Wait for more 5 times the service worker timeout to check that the toolbox prevents
+ // the worker from being destroyed.
+ await wait(SW_TIMEOUT * 5);
+
+ // Check that the service worker is still running, even after waiting 5 times the
+ // service worker timeout.
+ const hasInspectButton = !!getInspectButton(SW_URL, document);
+ ok(hasInspectButton, "Service worker target still has an inspect button");
+
+ info("Destroy the toolbox");
+ const devtoolsTab = gBrowser.selectedTab;
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+
+ // After stopping the toolbox, the service worker instance should be released and the
+ // service worker registration should be displayed as stopped again.
+ info("Wait until the service worker stops after closing the toolbox");
+ await waitForServiceWorkerStopped(SW_URL, document);
+
+ info("Unregister service worker");
+ await unregisterServiceWorker(swTab);
+
+ info("Wait until the service worker disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(SW_URL, document));
+
+ info("Remove tabs");
+ await removeTab(swTab);
+ await removeTab(tab);
+});
+
+function getStartButton(workerText, doc) {
+ const target = findDebugTargetByText(workerText, doc);
+ return target ? target.querySelector(".qa-start-button") : null;
+}
+
+function getInspectButton(workerText, doc) {
+ const target = findDebugTargetByText(workerText, doc);
+ return target
+ ? target.querySelector(".qa-debug-target-inspect-button")
+ : null;
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_unregister.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_unregister.js
new file mode 100644
index 0000000000..f9237e1795
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_serviceworker_unregister.js
@@ -0,0 +1,48 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-serviceworker.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-serviceworker.js",
+ this
+);
+
+const SW_TAB_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.html";
+const SW_URL = URL_ROOT_SSL + "resources/service-workers/empty-sw.js";
+
+/**
+ * Test that service workers can be started using about:debugging.
+ */
+add_task(async function () {
+ await enableServiceWorkerDebugging();
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Open a tab that registers a basic service worker.
+ const swTab = await addTab(SW_TAB_URL);
+
+ info("Wait until the service worker appears and is running");
+ const targetElement = await waitForServiceWorkerRunning(SW_URL, document);
+
+ // Retrieve the Start button for the worker.
+ const unregisterButton = targetElement.querySelector(".qa-unregister-button");
+ ok(unregisterButton, "Found its unregister button");
+
+ info(
+ "Click on the unregister button and wait for the service worker to disappear"
+ );
+ unregisterButton.click();
+ await waitUntil(() => !findDebugTargetByText(SW_URL, document));
+
+ const hasServiceWorkerTarget = !!findDebugTargetByText(SW_URL, document);
+ ok(!hasServiceWorkerTarget, "Service worker was successfully unregistered");
+
+ info("Remove tabs");
+ await removeTab(swTab);
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_connection_state.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_connection_state.js
new file mode 100644
index 0000000000..d4d31a7522
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_connection_state.js
@@ -0,0 +1,192 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_NAME = "test runtime name";
+const RUNTIME_DEVICE_NAME = "test device name";
+const RUNTIME_SHORT_NAME = "test short name";
+
+const CONNECTION_TIMING_OUT_DELAY = 1000;
+const CONNECTION_CANCEL_DELAY = 2000;
+
+// Test following connection state tests.
+// * Connect button label and state will change during connecting.
+// * Show error message if connection failed.
+// * Show warninng if connection has been taken time.
+add_task(async function () {
+ await setupPreferences();
+
+ const mocks = new Mocks();
+
+ const { document, tab } = await openAboutDebugging();
+
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ name: RUNTIME_NAME,
+ deviceName: RUNTIME_DEVICE_NAME,
+ shortName: RUNTIME_SHORT_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
+ const usbRuntimeSidebarItem = findSidebarItemByText(
+ RUNTIME_DEVICE_NAME,
+ document
+ );
+ const connectButton =
+ usbRuntimeSidebarItem.querySelector(".qa-connect-button");
+
+ info("Simulate to happen connection error");
+ mocks.runtimeClientFactoryMock.createClientForRuntime = async runtime => {
+ throw new Error("Dummy connection error");
+ };
+
+ info(
+ "Check whether the error message displayed after clicking connect button"
+ );
+ connectButton.click();
+ await waitUntil(() => document.querySelector(".qa-connection-error"));
+ ok(true, "Error message displays when connection failed");
+
+ info("Simulate to wait for the connection prompt on remote runtime");
+ let resumeConnection;
+ const resumeConnectionPromise = new Promise(r => {
+ resumeConnection = r;
+ });
+ mocks.runtimeClientFactoryMock.createClientForRuntime = async runtime => {
+ await resumeConnectionPromise;
+ return mocks._clients[runtime.type][runtime.id];
+ };
+
+ info("Click on the connect button and wait until it disappears");
+ connectButton.click();
+ info("Check whether a warning of connection not responding displays");
+ await waitUntil(() =>
+ document.querySelector(".qa-connection-not-responding")
+ );
+ ok(
+ document.querySelector(".qa-connection-not-responding"),
+ "A warning of connection not responding displays"
+ );
+ ok(connectButton.disabled, "Connect button is disabled");
+ ok(
+ connectButton.textContent.startsWith("Connecting"),
+ "Label of the connect button changes"
+ );
+ ok(
+ !document.querySelector(".qa-connection-error"),
+ "Error message disappears"
+ );
+
+ info(
+ "Unblock the connection and check the message and connect button disappear"
+ );
+ resumeConnection();
+ await waitUntil(
+ () => !usbRuntimeSidebarItem.querySelector(".qa-connect-button")
+ );
+ ok(!document.querySelector(".qa-connection-error"), "Error disappears");
+ ok(
+ !document.querySelector(".qa-connection-not-responding"),
+ "Warning disappears"
+ );
+
+ info("Remove a USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+ await removeTab(tab);
+});
+
+// Test whether the status of all will be reverted after a certain period of time during
+// waiting connection.
+add_task(async function () {
+ await setupPreferences();
+
+ const mocks = new Mocks();
+
+ const { document, tab } = await openAboutDebugging();
+
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ name: RUNTIME_NAME,
+ deviceName: RUNTIME_DEVICE_NAME,
+ shortName: RUNTIME_SHORT_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
+ const usbRuntimeSidebarItem = findSidebarItemByText(
+ RUNTIME_DEVICE_NAME,
+ document
+ );
+ const connectButton =
+ usbRuntimeSidebarItem.querySelector(".qa-connect-button");
+
+ let resumeConnection;
+ const resumeConnectionPromise = new Promise(r => {
+ resumeConnection = r;
+ });
+ mocks.runtimeClientFactoryMock.createClientForRuntime = async runtime => {
+ await resumeConnectionPromise;
+ return mocks._clients[runtime.type][runtime.id];
+ };
+
+ info("Click on the connect button and wait until it disappears");
+ connectButton.click();
+ await waitUntil(() =>
+ document.querySelector(".qa-connection-not-responding")
+ );
+ info("Check whether the all status will be reverted");
+ await waitUntil(
+ () => !document.querySelector(".qa-connection-not-responding")
+ );
+ ok(
+ document.querySelector(".qa-connection-timeout"),
+ "Connection timeout message displays"
+ );
+ ok(!connectButton.disabled, "Connect button is enabled");
+ is(
+ connectButton.textContent,
+ "Connect",
+ "Label of the connect button reverted"
+ );
+ ok(
+ !document.querySelector(".qa-connection-error"),
+ "Error message disappears"
+ );
+
+ info("Check whether the timeout message disappears");
+ resumeConnection();
+ await waitUntil(() => !document.querySelector(".qa-connection-timeout"));
+
+ info("Remove a USB runtime");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item disappears");
+ await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+ await removeTab(tab);
+});
+
+async function setupPreferences() {
+ if (SpecialPowers.isDebugBuild) {
+ // On debug builds, reducing the timings might lead to skip the "warning"
+ // state and will block the test execution.
+ // Do not change the timings in debug builds.
+ return;
+ }
+
+ await pushPref(
+ "devtools.aboutdebugging.test-connection-timing-out-delay",
+ CONNECTION_TIMING_OUT_DELAY
+ );
+ await pushPref(
+ "devtools.aboutdebugging.test-connection-cancel-delay",
+ CONNECTION_CANCEL_DELAY
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js
new file mode 100644
index 0000000000..0482aa70c2
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_network_runtimes.js
@@ -0,0 +1,43 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const networkLocationsModule = require("resource://devtools/client/aboutdebugging/src/modules/network-locations.js");
+
+/**
+ * Test the sidebar is updated correctly when network runtimes are added/removed.
+ */
+
+add_task(async function () {
+ registerCleanupFunction(() => {
+ Services.prefs.clearUserPref("devtools.aboutdebugging.network-locations");
+ });
+
+ const { document, tab } = await openAboutDebugging();
+
+ const noDevicesElement = document.querySelector(".qa-sidebar-no-devices");
+ ok(noDevicesElement, "Sidebar shows the 'no devices' element");
+
+ info("Add a network location");
+ networkLocationsModule.addNetworkLocation("localhost:6080");
+
+ info("Wait for 'no devices' element to disappear");
+ waitUntil(() => !document.querySelector(".qa-sidebar-no-devices"));
+ ok(
+ findSidebarItemByText("localhost:6080", document),
+ "Found a sidebar item for localhost:6080"
+ );
+
+ info("Remove the network location");
+ networkLocationsModule.removeNetworkLocation("localhost:6080");
+
+ info("Wait for 'no devices' element to reappear");
+ waitUntil(() => document.querySelector(".qa-sidebar-no-devices"));
+ ok(
+ !findSidebarItemByText("localhost:6080", document),
+ "Sidebar item for localhost:6080 removed"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime.js
new file mode 100644
index 0000000000..b63b7ae08e
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime.js
@@ -0,0 +1,38 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_ID = "RUNTIME_ID";
+const RUNTIME_DEVICE_NAME = "RUNTIME_DEVICE_NAME";
+const RUNTIME_SHORT_NAME = "testshort";
+
+// Test that USB runtimes appear and disappear from the sidebar.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab } = await openAboutDebugging();
+
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: RUNTIME_DEVICE_NAME,
+ shortName: RUNTIME_SHORT_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
+ const usbRuntimeSidebarItem = findSidebarItemByText(
+ RUNTIME_DEVICE_NAME,
+ document
+ );
+ ok(
+ usbRuntimeSidebarItem.textContent.includes(RUNTIME_SHORT_NAME),
+ "The short name of the usb runtime is visible"
+ );
+
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_connect.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_connect.js
new file mode 100644
index 0000000000..f4978b0495
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_connect.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_NAME = "test runtime name";
+const RUNTIME_DEVICE_NAME = "test device name";
+const RUNTIME_SHORT_NAME = "test short name";
+
+// Test that USB runtimes appear and disappear from the sidebar,
+// as well as their connect button.
+// Also checks whether the label of item is updated after connecting.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab } = await openAboutDebugging();
+
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ name: RUNTIME_NAME,
+ deviceName: RUNTIME_DEVICE_NAME,
+ shortName: RUNTIME_SHORT_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
+ const usbRuntimeSidebarItem = findSidebarItemByText(
+ RUNTIME_DEVICE_NAME,
+ document
+ );
+ const connectButton =
+ usbRuntimeSidebarItem.querySelector(".qa-connect-button");
+ ok(connectButton, "Connect button is displayed for the USB runtime");
+
+ info("Click on the connect button and wait until it disappears");
+ connectButton.click();
+ await waitUntil(
+ () => !usbRuntimeSidebarItem.querySelector(".qa-connect-button")
+ );
+
+ info("Check whether the label of item is updated after connecting");
+ ok(
+ usbRuntimeSidebarItem.textContent.includes(RUNTIME_NAME),
+ "Label of item updated"
+ );
+
+ info("Remove all USB runtimes");
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(RUNTIME_DEVICE_NAME, document);
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
new file mode 100644
index 0000000000..47ecc03239
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_refresh.js
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_DEVICE_NAME = "test device name";
+const RUNTIME_APP_NAME = "TestApp";
+
+const OTHER_RUNTIME_ID = "other-runtime-id";
+const OTHER_RUNTIME_APP_NAME = "OtherApp";
+
+// Test that USB runtimes are not disconnected on refresh.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab } = await openAboutDebugging();
+
+ info("Create a first runtime and connect to it");
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: RUNTIME_DEVICE_NAME,
+ name: RUNTIME_APP_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+ await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_APP_NAME, document);
+
+ info("Create a second runtime and click on Refresh Devices");
+ mocks.createUSBRuntime(OTHER_RUNTIME_ID, {
+ deviceName: OTHER_RUNTIME_APP_NAME,
+ });
+
+ // adb.updateRuntimes should ultimately fire the "runtime-list-updated" event.
+ mocks.adbMock.adb.updateRuntimes = () => mocks.emitUSBUpdate();
+ document.querySelector(".qa-refresh-devices-button").click();
+
+ info(`Wait until the sidebar item for ${OTHER_RUNTIME_APP_NAME} appears`);
+ await waitUntil(() =>
+ findSidebarItemByText(OTHER_RUNTIME_APP_NAME, document)
+ );
+
+ const sidebarItem = findSidebarItemByText(RUNTIME_DEVICE_NAME, document);
+ ok(
+ !sidebarItem.querySelector(".qa-connect-button"),
+ "Original USB runtime is still connected"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_select.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_select.js
new file mode 100644
index 0000000000..66ca219bf3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_runtime_select.js
@@ -0,0 +1,44 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_DEVICE_ID = "1234";
+const RUNTIME_DEVICE_NAME = "A device";
+
+// Test that we can select a runtime in the sidebar
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab } = await openAboutDebugging();
+
+ mocks.createUSBRuntime(RUNTIME_DEVICE_ID, {
+ deviceName: RUNTIME_DEVICE_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(RUNTIME_DEVICE_NAME, document));
+ const sidebarItem = findSidebarItemByText(RUNTIME_DEVICE_NAME, document);
+ const connectButton = sidebarItem.querySelector(".qa-connect-button");
+ ok(connectButton, "Connect button is displayed for the USB runtime");
+
+ info(
+ "Click on the connect button and wait until the sidebar displays a link"
+ );
+ connectButton.click();
+ await waitUntil(() =>
+ findSidebarItemLinkByText(RUNTIME_DEVICE_NAME, document)
+ );
+
+ info("Click on the runtime link");
+ const link = findSidebarItemLinkByText(RUNTIME_DEVICE_NAME, document);
+ link.click();
+ is(
+ document.location.hash,
+ `#/runtime/${RUNTIME_DEVICE_ID}`,
+ "Redirection to runtime page"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_status.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_status.js
new file mode 100644
index 0000000000..e67cde31bb
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_status.js
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const {
+ adbAddon,
+} = require("resource://devtools/client/shared/remote-debugging/adb/adb-addon.js");
+
+/**
+ * This test asserts that the sidebar shows a message describing the status of the USB
+ * devices scanning.
+ */
+add_task(async function () {
+ const mocks = new Mocks();
+
+ await pushPref(
+ "devtools.remote.adb.extensionURL",
+ CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi"
+ );
+ const { document, tab } = await openAboutDebugging();
+
+ const usbStatusElement = document.querySelector(".qa-sidebar-usb-status");
+ ok(usbStatusElement, "Sidebar shows the USB status element");
+ ok(
+ usbStatusElement.textContent.includes("USB disabled"),
+ "USB status element has 'disabled' content"
+ );
+
+ info("Install the adb extension and wait for the message to udpate");
+ // Use "internal" as the install source to avoid triggering telemetry.
+ adbAddon.install("internal");
+ // When using mocks, we manually control the .start() call
+ await mocks.adbProcessMock.adbProcess.start();
+
+ info("Wait till the USB status element has 'enabled' content");
+ await waitUntil(() => {
+ const el = document.querySelector(".qa-sidebar-usb-status");
+ return el.textContent.includes("USB enabled");
+ });
+
+ info("Uninstall the adb extension and wait for USB status element to update");
+ adbAddon.uninstall();
+ await waitUntil(() => {
+ const el = document.querySelector(".qa-sidebar-usb-status");
+ return el.textContent.includes("USB disabled");
+ });
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unavailable_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unavailable_runtime.js
new file mode 100644
index 0000000000..e073939b6d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unavailable_runtime.js
@@ -0,0 +1,65 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_NAME = "Firefox 123";
+const DEVICE_NAME = "DEVICE_NAME";
+const DEVICE_ID = "DEVICE_ID";
+const RUNTIME_ID = "RUNTIME_ID";
+
+// Test that unavailable runtimes:
+// - are displayed without a connect button.
+// - cannot be selected
+// - display a specific text ("Waiting for runtime") instead of the runtime name
+add_task(async function () {
+ const mocks = new Mocks();
+ const { document, tab } = await openAboutDebugging();
+
+ info("Create a device without a corresponding runtime");
+ mocks.addDevice(DEVICE_ID, DEVICE_NAME);
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(DEVICE_NAME, document));
+
+ const usbRuntimeSidebarItem = findSidebarItemByText(DEVICE_NAME, document);
+
+ ok(
+ usbRuntimeSidebarItem.querySelector(".qa-runtime-item-waiting-for-browser"),
+ "Sidebar item shows as `Waiting for browser`"
+ );
+
+ const hasConnectButton =
+ usbRuntimeSidebarItem.querySelector(".qa-connect-button");
+ ok(!hasConnectButton, "Connect button is not displayed");
+
+ const hasLink = usbRuntimeSidebarItem.querySelector(".qa-sidebar-link");
+ ok(!hasLink, "Unavailable runtime is not selectable");
+
+ info("Add a valid runtime for the same device id and emit update event");
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceId: DEVICE_ID,
+ deviceName: DEVICE_NAME,
+ shortName: RUNTIME_NAME,
+ });
+ mocks.removeDevice(DEVICE_ID);
+ mocks.emitUSBUpdate();
+
+ info("Wait until connect button appears for the USB runtime");
+ let updatedSidebarItem = null;
+ await waitUntil(() => {
+ updatedSidebarItem = findSidebarItemByText(DEVICE_NAME, document);
+ return (
+ updatedSidebarItem &&
+ updatedSidebarItem.querySelector(".qa-connect-button")
+ );
+ });
+
+ ok(
+ updatedSidebarItem.querySelector(".qa-runtime-item-standard"),
+ "Sidebar item for the USB runtime is now a standard sidebar item"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unplugged_device.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unplugged_device.js
new file mode 100644
index 0000000000..5074538a94
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_sidebar_usb_unplugged_device.js
@@ -0,0 +1,69 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const RUNTIME_NAME = "RUNTIME_NAME_1";
+const DEVICE_NAME = "DEVICE_NAME_1";
+const DEVICE_ID = "DEVICE_ID_1";
+const RUNTIME_ID = "RUNTIME_ID_1";
+
+const RUNTIME_NAME_2 = "RUNTIME_NAME_2";
+const DEVICE_NAME_2 = "DEVICE_NAME_2";
+const DEVICE_ID_2 = "DEVICE_ID_2";
+const RUNTIME_ID_2 = "RUNTIME_ID_2";
+
+// Test that removed USB devices are still visible as "Unplugged devices", until
+// about:debugging is reloaded.
+add_task(async function () {
+ const mocks = new Mocks();
+ let { document, tab } = await openAboutDebugging();
+
+ info("Create a mocked USB runtime");
+ mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceId: DEVICE_ID,
+ deviceName: DEVICE_NAME,
+ shortName: RUNTIME_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait until the USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(DEVICE_NAME, document));
+ const sidebarItem = findSidebarItemByText(DEVICE_NAME, document);
+ ok(
+ sidebarItem.textContent.includes(RUNTIME_NAME),
+ "Sidebar item shows the runtime name"
+ );
+
+ mocks.removeUSBRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntilUsbDeviceIsUnplugged(DEVICE_NAME, document);
+
+ const unpluggedItem = findSidebarItemByText(DEVICE_NAME, document);
+ ok(
+ unpluggedItem.querySelector(".qa-runtime-item-unplugged"),
+ "Sidebar item is shown as `Unplugged…`"
+ );
+
+ info("Reload about:debugging");
+ document = await reloadAboutDebugging(tab);
+
+ info(
+ "Add another mocked USB runtime, to make sure the sidebar items are rendered."
+ );
+ mocks.createUSBRuntime(RUNTIME_ID_2, {
+ deviceId: DEVICE_ID_2,
+ deviceName: DEVICE_NAME_2,
+ shortName: RUNTIME_NAME_2,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait until the other USB sidebar item appears");
+ await waitUntil(() => findSidebarItemByText(DEVICE_NAME_2, document));
+ ok(
+ !findSidebarItemByText(DEVICE_NAME, document),
+ "Unplugged device is no longer displayed after reloading aboutdebugging"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_favicons.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_favicons.js
new file mode 100644
index 0000000000..e4acd1727d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_favicons.js
@@ -0,0 +1,57 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Check that about:debugging uses the favicon of tab targets as the icon of their debug
+ * target item, and doesn't always use the default globe icon.
+ */
+
+// PlaceUtils will not store any favicon for data: uris so we need to use a dedicated page
+// here.
+const TAB_URL =
+ "https://example.com/browser/devtools/client/aboutdebugging/" +
+ "test/browser/test-tab-favicons.html";
+
+// This is the same png data-url as the one used in test-tab-favicons.html.
+const EXPECTED_FAVICON =
+ "data:image/png;base64," +
+ "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAATklEQVRYhe3SIQ4AI" +
+ "BADwf7/04elBAtrVlSduGnSTDJ7cuT1PQJwwO+Hl7sAGAA07gjAAfgIBeAAoH" +
+ "FHAA7ARygABwCNOwJwAD5CATRgAYXh+kypw86nAAAAAElFTkSuQmCC";
+
+add_task(async function () {
+ const faviconTab = await addTab(TAB_URL, { background: true });
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ await waitUntil(() => {
+ const target = findDebugTargetByText("Favicon tab", document);
+ if (!target) {
+ return false;
+ }
+ // We may get a default globe.svg icon for a short period of time while
+ // the target tab is still loading.
+ return target
+ .querySelector(".qa-debug-target-item-icon")
+ .src.includes("data:");
+ });
+ const faviconTabTarget = findDebugTargetByText("Favicon tab", document);
+ const faviconTabIcon = faviconTabTarget.querySelector(
+ ".qa-debug-target-item-icon"
+ );
+
+ // Note this relies on PlaceUtils.promiseFaviconData returning the same data-url as the
+ // one provided in the test page. If the implementation changes and PlaceUtils returns a
+ // different base64 from the one we defined, we can instead load the image and check a
+ // few pixels to verify it matches the expected icon.
+ is(
+ faviconTabIcon.src,
+ EXPECTED_FAVICON,
+ "The debug target item for the tab shows the favicon of the tab"
+ );
+
+ await removeTab(tab);
+ await removeTab(faviconTab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_navigate.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_navigate.js
new file mode 100644
index 0000000000..45355203e3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_navigate.js
@@ -0,0 +1,31 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const TAB_1_URL =
+ "http://example.org/document-builder.sjs?html=<title>TITLE1</title>";
+const TAB_2_URL =
+ "http://example.org/document-builder.sjs?html=<title>TITLE2</title>";
+
+// Check that the list of tabs in about:debugging is updated when a page
+// navigates. This indirectly checks that the tabListChanged event is correctly
+// fired from the root actor.
+add_task(async function () {
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const testTab = await addTab(TAB_1_URL, { background: true });
+ await waitFor(() => findDebugTargetByText("TITLE1", document));
+
+ navigateTo(TAB_2_URL, { browser: testTab.linkedBrowser });
+ await waitFor(() => findDebugTargetByText("TITLE2", document));
+
+ ok(
+ !findDebugTargetByText("TITLE1", document),
+ "TITLE2 target replaced TITLE1"
+ );
+
+ await removeTab(tab);
+ await removeTab(testTab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_zombietab.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_zombietab.js
new file mode 100644
index 0000000000..1243d3374d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_tab_zombietab.js
@@ -0,0 +1,108 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+let gUniqueCounter = 0;
+
+const triggeringPrincipal_base64 = E10SUtils.SERIALIZED_SYSTEMPRINCIPAL;
+
+const BROWSER_STATE_TABS = [
+ "about:debugging",
+ "data:text/html,<title>TEST_TAB_1</title>",
+ "data:text/html,<title>TEST_TAB_2</title>",
+ "data:text/html,<title>TEST_TAB_3</title>",
+];
+const BROWSER_STATE = {
+ windows: [
+ {
+ tabs: BROWSER_STATE_TABS.map(url => {
+ return {
+ entries: [{ url, triggeringPrincipal_base64 }],
+ extData: { uniq: Date.now() + "-" + ++gUniqueCounter },
+ };
+ }),
+ selected: 1,
+ },
+ ],
+};
+
+// Check that the inspect action is disabled for lazy/zombie tabs, such as the
+// ones created after a session restore.
+add_task(async function () {
+ // This setup is normally handed by the openAboutDebugging helper, but here we
+ // open about:debugging via session restore.
+ silenceWorkerUpdates();
+ await pushPref("devtools.aboutdebugging.local-tab-debugging", true);
+
+ info("Restore 4 tabs including a selected about:debugging tab");
+ const onBrowserSessionRestored = Promise.all([
+ TestUtils.topicObserved("sessionstore-browser-state-restored"),
+ BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "SSTabRestored"),
+ ]);
+ SessionStore.setBrowserState(JSON.stringify(BROWSER_STATE));
+ await onBrowserSessionRestored;
+
+ const tab = gBrowser.selectedTab;
+ const browser = tab.linkedBrowser;
+ const doc = browser.contentDocument;
+ const win = browser.contentWindow;
+ const store = win.AboutDebugging.store;
+
+ info("Wait until Connect page is displayed");
+ await waitUntil(() => doc.querySelector(".qa-connect-page"));
+
+ await selectThisFirefoxPage(doc, store);
+
+ // Check that all inspect butttons are disabled.
+ checkInspectButton("TEST_TAB_1", doc, { expectDisabled: true });
+ checkInspectButton("TEST_TAB_2", doc, { expectDisabled: true });
+ checkInspectButton("TEST_TAB_3", doc, { expectDisabled: true });
+
+ info("Select the TEST_TAB_2 tab top restore it completely");
+ const onTabRestored = BrowserTestUtils.waitForEvent(
+ gBrowser.tabContainer,
+ "SSTabRestored"
+ );
+ gBrowser.selectedTab = gBrowser.tabs[2];
+ await onTabRestored;
+
+ const onTabsSuccess = waitForDispatch(store, "REQUEST_TABS_SUCCESS");
+
+ info("Select the about:debugging tab again");
+ gBrowser.selectedTab = tab;
+
+ info("Wait until the tabs update is finished");
+ await onTabsSuccess;
+
+ info("Wait until the inspect button for TEST_TAB_2 is enabled");
+ await waitUntil(() => {
+ const target = findDebugTargetByText("TEST_TAB_2", doc);
+ if (!target) {
+ // TEST_TAB_2 target might be missing while the tab target list updates.
+ return false;
+ }
+
+ const button = target.querySelector(".qa-debug-target-inspect-button");
+ return !button.disabled;
+ });
+
+ // Check that all inspect butttons are disabled, except for #2.
+ checkInspectButton("TEST_TAB_1", doc, { expectDisabled: true });
+ checkInspectButton("TEST_TAB_2", doc, { expectDisabled: false });
+ checkInspectButton("TEST_TAB_3", doc, { expectDisabled: true });
+});
+
+function checkInspectButton(targetText, doc, { expectDisabled }) {
+ const inspectButton = getInspectButton(targetText, doc);
+ if (expectDisabled) {
+ ok(inspectButton.disabled, `Inspect button is disabled for ${targetText}`);
+ } else {
+ ok(!inspectButton.disabled, `Inspect button is enabled for ${targetText}`);
+ }
+}
+
+function getInspectButton(targetText, doc) {
+ const targetElement = findDebugTargetByText(targetText, doc);
+ return targetElement.querySelector(".qa-debug-target-inspect-button");
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_basic.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_basic.js
new file mode 100644
index 0000000000..5970d6a70d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_basic.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+/**
+ * Check that telemetry events are recorded when opening and closing about debugging.
+ */
+add_task(async function () {
+ setupTelemetryTest();
+
+ const { tab } = await openAboutDebugging();
+
+ const openEvents = readAboutDebuggingEvents().filter(
+ e => e.method === "open_adbg"
+ );
+ is(
+ openEvents.length,
+ 1,
+ "Exactly one open event was logged for about:debugging"
+ );
+ const sessionId = openEvents[0].extras.session_id;
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ await removeTab(tab);
+
+ const closeEvents = readAboutDebuggingEvents().filter(
+ e => e.method === "close_adbg"
+ );
+ is(
+ closeEvents.length,
+ 1,
+ "Exactly one close event was logged for about:debugging"
+ );
+ is(
+ closeEvents[0].extras.session_id,
+ sessionId,
+ "Close event has the same session id as the open event"
+ );
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_connection_attempt.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_connection_attempt.js
new file mode 100644
index 0000000000..a5836ad50a
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_connection_attempt.js
@@ -0,0 +1,274 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+const USB_RUNTIME = {
+ id: "runtime-id-1",
+ deviceName: "Device A",
+ name: "Runtime 1",
+ shortName: "R1",
+};
+
+/**
+ * Check that telemetry events for connection attempts are correctly recorded in various
+ * scenarios:
+ * - successful connection
+ * - successful connection after showing the timeout warning
+ * - failed connection
+ * - connection timeout
+ */
+add_task(async function testSuccessfulConnectionAttempt() {
+ const { doc, mocks, runtimeId, sessionId, tab } =
+ await setupConnectionAttemptTest();
+
+ await connectToRuntime(USB_RUNTIME.deviceName, doc);
+
+ const connectionEvents = checkTelemetryEvents(
+ [
+ { method: "runtime_connected", extras: { runtime_id: runtimeId } },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("start", runtimeId),
+ },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("success", runtimeId),
+ },
+ ],
+ sessionId
+ ).filter(({ method }) => method === "connection_attempt");
+
+ checkConnectionId(connectionEvents);
+
+ await removeUsbRuntime(USB_RUNTIME, mocks, doc);
+ await removeTab(tab);
+});
+
+add_task(async function testFailedConnectionAttempt() {
+ const { doc, mocks, runtimeId, sessionId, tab } =
+ await setupConnectionAttemptTest();
+ mocks.runtimeClientFactoryMock.createClientForRuntime = async runtime => {
+ throw new Error("failed");
+ };
+
+ info(
+ "Try to connect to the runtime and wait for the connection error message"
+ );
+ const usbRuntimeSidebarItem = findSidebarItemByText(
+ USB_RUNTIME.deviceName,
+ doc
+ );
+ const connectButton =
+ usbRuntimeSidebarItem.querySelector(".qa-connect-button");
+ connectButton.click();
+ await waitUntil(() =>
+ usbRuntimeSidebarItem.querySelector(".qa-connection-error")
+ );
+
+ const connectionEvents = checkTelemetryEvents(
+ [
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("start", runtimeId),
+ },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("failed", runtimeId),
+ },
+ ],
+ sessionId
+ ).filter(({ method }) => method === "connection_attempt");
+
+ checkConnectionId(connectionEvents);
+
+ await removeUsbRuntime(USB_RUNTIME, mocks, doc);
+ await removeTab(tab);
+});
+
+add_task(async function testPendingConnectionAttempt() {
+ info("Set timeout preferences to avoid cancelling the connection");
+ await pushPref(
+ "devtools.aboutdebugging.test-connection-timing-out-delay",
+ 100
+ );
+ await pushPref(
+ "devtools.aboutdebugging.test-connection-cancel-delay",
+ 100000
+ );
+
+ const { doc, mocks, runtimeId, sessionId, tab } =
+ await setupConnectionAttemptTest();
+
+ info("Simulate a pending connection");
+ let resumeConnection;
+ const resumeConnectionPromise = new Promise(r => {
+ resumeConnection = r;
+ });
+ mocks.runtimeClientFactoryMock.createClientForRuntime = async runtime => {
+ await resumeConnectionPromise;
+ return mocks._clients[runtime.type][runtime.id];
+ };
+
+ info("Click on the connect button and wait for the warning message");
+ const usbRuntimeSidebarItem = findSidebarItemByText(
+ USB_RUNTIME.deviceName,
+ doc
+ );
+ const connectButton =
+ usbRuntimeSidebarItem.querySelector(".qa-connect-button");
+ connectButton.click();
+ await waitUntil(() => doc.querySelector(".qa-connection-not-responding"));
+
+ info("Resume the connection and wait for the connection to succeed");
+ resumeConnection();
+ await waitUntil(
+ () => !usbRuntimeSidebarItem.querySelector(".qa-connect-button")
+ );
+
+ const connectionEvents = checkTelemetryEvents(
+ [
+ { method: "runtime_connected", extras: { runtime_id: runtimeId } },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("start", runtimeId),
+ },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("not responding", runtimeId),
+ },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("success", runtimeId),
+ },
+ ],
+ sessionId
+ ).filter(({ method }) => method === "connection_attempt");
+ checkConnectionId(connectionEvents);
+
+ await removeUsbRuntime(USB_RUNTIME, mocks, doc);
+ await removeTab(tab);
+});
+
+add_task(async function testCancelledConnectionAttempt() {
+ info("Set timeout preferences to quickly cancel the connection");
+ await pushPref(
+ "devtools.aboutdebugging.test-connection-timing-out-delay",
+ 100
+ );
+ await pushPref("devtools.aboutdebugging.test-connection-cancel-delay", 1000);
+
+ const { doc, mocks, runtimeId, sessionId, tab } =
+ await setupConnectionAttemptTest();
+
+ info("Simulate a connection timeout");
+ mocks.runtimeClientFactoryMock.createClientForRuntime = async runtime => {
+ await new Promise(r => {});
+ };
+
+ info("Click on the connect button and wait for the error message");
+ const usbRuntimeSidebarItem = findSidebarItemByText(
+ USB_RUNTIME.deviceName,
+ doc
+ );
+ const connectButton =
+ usbRuntimeSidebarItem.querySelector(".qa-connect-button");
+ connectButton.click();
+ await waitUntil(() =>
+ usbRuntimeSidebarItem.querySelector(".qa-connection-timeout")
+ );
+
+ const connectionEvents = checkTelemetryEvents(
+ [
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("start", runtimeId),
+ },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("not responding", runtimeId),
+ },
+ {
+ method: "connection_attempt",
+ extras: getEventExtras("cancelled", runtimeId),
+ },
+ ],
+ sessionId
+ ).filter(({ method }) => method === "connection_attempt");
+ checkConnectionId(connectionEvents);
+
+ await removeUsbRuntime(USB_RUNTIME, mocks, doc);
+ await removeTab(tab);
+});
+
+function checkConnectionId(connectionEvents) {
+ const connectionId = connectionEvents[0].extras.connection_id;
+ ok(
+ !!connectionId,
+ "Found a valid connection id in the first connection_attempt event"
+ );
+ for (const evt of connectionEvents) {
+ is(
+ evt.extras.connection_id,
+ connectionId,
+ "All connection_attempt events share the same connection id"
+ );
+ }
+}
+
+// Small helper to create the expected event extras object for connection_attempt events
+function getEventExtras(status, runtimeId) {
+ return {
+ connection_type: "usb",
+ runtime_id: runtimeId,
+ status,
+ };
+}
+
+// Open about:debugging, setup telemetry, mocks and create a mocked USB runtime.
+async function setupConnectionAttemptTest() {
+ const mocks = new Mocks();
+ setupTelemetryTest();
+
+ const { tab, document } = await openAboutDebugging();
+
+ const sessionId = getOpenEventSessionId();
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ mocks.createUSBRuntime(USB_RUNTIME.id, {
+ deviceName: USB_RUNTIME.deviceName,
+ name: USB_RUNTIME.name,
+ shortName: USB_RUNTIME.shortName,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait for the runtime to appear in the sidebar");
+ await waitUntil(() => findSidebarItemByText(USB_RUNTIME.shortName, document));
+ const evts = checkTelemetryEvents(
+ [
+ { method: "device_added", extras: {} },
+ { method: "runtime_added", extras: {} },
+ ],
+ sessionId
+ );
+
+ const runtimeId = evts.filter(e => e.method === "runtime_added")[0].extras
+ .runtime_id;
+ return { doc: document, mocks, runtimeId, sessionId, tab };
+}
+
+async function removeUsbRuntime(runtime, mocks, doc) {
+ mocks.removeRuntime(runtime.id);
+ mocks.emitUSBUpdate();
+ await waitUntil(
+ () =>
+ !findSidebarItemByText(runtime.name, doc) &&
+ !findSidebarItemByText(runtime.shortName, doc)
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_inspect.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_inspect.js
new file mode 100644
index 0000000000..60176258b1
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_inspect.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+const TAB_URL = "data:text/html,<title>TEST_TAB</title>";
+
+/**
+ * Check that telemetry events are recorded when inspecting a target.
+ */
+add_task(async function () {
+ setupTelemetryTest();
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const sessionId = getOpenEventSessionId();
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ info("Open a new background tab TEST_TAB");
+ const backgroundTab1 = await addTab(TAB_URL, { background: true });
+
+ info("Wait for the tab to appear in the debug targets with the correct name");
+ await waitUntil(() => findDebugTargetByText("TEST_TAB", document));
+
+ const { devtoolsTab } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ "TEST_TAB"
+ );
+
+ const evts = readAboutDebuggingEvents().filter(e => e.method === "inspect");
+ is(evts.length, 1, "Exactly one Inspect event found");
+ is(
+ evts[0].extras.target_type,
+ "TAB",
+ "Inspect event has the expected target type"
+ );
+ is(
+ evts[0].extras.runtime_type,
+ "this-firefox",
+ "Inspect event has the expected runtime type"
+ );
+ is(
+ evts[0].extras.session_id,
+ sessionId,
+ "Inspect event has the expected session"
+ );
+
+ info("Close the about:devtools-toolbox tab");
+ await closeAboutDevtoolsToolbox(document, devtoolsTab, window);
+ await waitForAboutDebuggingRequests(window.AboutDebugging.store);
+
+ info("Remove first background tab");
+ await removeTab(backgroundTab1);
+ await waitUntil(() => !findDebugTargetByText("TEST_TAB", document));
+ await waitForAboutDebuggingRequests(window.AboutDebugging.store);
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_navigate.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_navigate.js
new file mode 100644
index 0000000000..946f5e9e43
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_navigate.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+/**
+ * Check that telemetry events are recorded when navigating between different
+ * about:debugging pages.
+ */
+add_task(async function () {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+
+ setupTelemetryTest();
+
+ const { tab, document, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ const sessionId = getOpenEventSessionId();
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ info("Navigate to 'Connect' page");
+ document.location.hash = "#/connect";
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+ checkSelectPageEvent("connect", sessionId);
+
+ info("Navigate to 'USB device runtime' page");
+ await navigateToUSBRuntime(mocks, document);
+ checkSelectPageEvent("runtime", sessionId);
+ await waitForAboutDebuggingRequests(window.AboutDebugging.store);
+
+ await removeTab(tab);
+});
+
+function checkSelectPageEvent(expectedType, expectedSessionId) {
+ const evts = readAboutDebuggingEvents().filter(
+ e => e.method === "select_page"
+ );
+ is(evts.length, 1, "Exactly one select_page event recorded");
+ is(
+ evts[0].extras.page_type,
+ expectedType,
+ "Select page event has the expected type"
+ );
+ is(
+ evts[0].extras.session_id,
+ expectedSessionId,
+ "Select page event has the expected session"
+ );
+}
+
+async function navigateToUSBRuntime(mocks, doc) {
+ mocks.createUSBRuntime("1337id", {
+ deviceName: "Fancy Phone",
+ name: "Lorem ipsum",
+ });
+ mocks.emitUSBUpdate();
+ await connectToRuntime("Fancy Phone", doc);
+ // navigate to it via URL
+ doc.location.hash = "#/runtime/1337id";
+ await waitUntil(() => doc.querySelector(".qa-runtime-page"));
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_actions.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_actions.js
new file mode 100644
index 0000000000..92d07a3d9c
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_actions.js
@@ -0,0 +1,97 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+const RUNTIME_ID = "test-runtime-id";
+const RUNTIME_NAME = "Test Runtime";
+const RUNTIME_DEVICE_NAME = "Test Device";
+
+/**
+ * Test that runtime specific actions are logged as telemetry events with the expected
+ * runtime id and action type.
+ */
+add_task(async function testUsbRuntimeUpdates() {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ setupTelemetryTest();
+
+ const { tab, document } = await openAboutDebugging();
+
+ const sessionId = getOpenEventSessionId();
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ const usbClient = mocks.createUSBRuntime(RUNTIME_ID, {
+ deviceName: RUNTIME_DEVICE_NAME,
+ name: RUNTIME_NAME,
+ shortName: RUNTIME_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait for the runtime to appear in the sidebar");
+ await waitUntil(() => findSidebarItemByText(RUNTIME_NAME, document));
+ await connectToRuntime(RUNTIME_DEVICE_NAME, document);
+ await selectRuntime(RUNTIME_DEVICE_NAME, RUNTIME_NAME, document);
+
+ info("Read telemetry events to flush unrelated events");
+ const evts = readAboutDebuggingEvents();
+ const runtimeAddedEvent = evts.filter(e => e.method === "runtime_added")[0];
+ const telemetryRuntimeId = runtimeAddedEvent.extras.runtime_id;
+
+ info("Click on the toggle button and wait until the text is updated");
+ const promptButton = document.querySelector(
+ ".qa-connection-prompt-toggle-button"
+ );
+ promptButton.click();
+ await waitUntil(() => promptButton.textContent.includes("Enable"));
+
+ checkTelemetryEvents(
+ [
+ {
+ method: "update_conn_prompt",
+ extras: { prompt_enabled: "false", runtime_id: telemetryRuntimeId },
+ },
+ ],
+ sessionId
+ );
+
+ info("Click on the toggle button again and check we log the correct value");
+ promptButton.click();
+ await waitUntil(() => promptButton.textContent.includes("Disable"));
+
+ checkTelemetryEvents(
+ [
+ {
+ method: "update_conn_prompt",
+ extras: { prompt_enabled: "true", runtime_id: telemetryRuntimeId },
+ },
+ ],
+ sessionId
+ );
+
+ info("Open the profiler dialog");
+ await openProfilerDialog(usbClient, document);
+
+ checkTelemetryEvents(
+ [
+ {
+ method: "show_profiler",
+ extras: { runtime_id: telemetryRuntimeId },
+ },
+ ],
+ sessionId
+ );
+
+ info("Remove runtime");
+ mocks.removeRuntime(RUNTIME_ID);
+ mocks.emitUSBUpdate();
+ await waitUntil(() => !findSidebarItemByText(RUNTIME_NAME, document));
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_connected_details.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_connected_details.js
new file mode 100644
index 0000000000..808cfdcae8
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_connected_details.js
@@ -0,0 +1,69 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+const REMOTE_RUNTIME_ID = "remote-runtime";
+const REMOTE_RUNTIME = "Remote Runtime";
+const REMOTE_DEVICE = "Remote Device";
+
+const REMOTE_VERSION = "12.0a1";
+const REMOTE_OS = "SOME_OS";
+
+/**
+ * Runtime connected events will log additional extras about the runtime connection that
+ * was established.
+ */
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const usbClient = mocks.createUSBRuntime(REMOTE_RUNTIME_ID, {
+ deviceName: REMOTE_DEVICE,
+ name: REMOTE_RUNTIME,
+ shortName: REMOTE_RUNTIME,
+ });
+ usbClient.getDeviceDescription = () => {
+ return {
+ os: REMOTE_OS,
+ version: REMOTE_VERSION,
+ };
+ };
+
+ const { document, tab } = await openAboutDebugging();
+
+ mocks.emitUSBUpdate();
+ await connectToRuntime(REMOTE_DEVICE, document);
+ const evts = readAboutDebuggingEvents().filter(
+ e => e.method === "runtime_connected"
+ );
+
+ is(
+ evts.length,
+ 1,
+ "runtime_connected event logged when connecting to remote runtime"
+ );
+ const {
+ connection_type,
+ device_name,
+ runtime_name,
+ runtime_os,
+ runtime_version,
+ } = evts[0].extras;
+ is(connection_type, "usb", "Expected value for `connection_type` extra");
+ is(device_name, REMOTE_DEVICE, "Expected value for `device_name` extra");
+ is(runtime_name, REMOTE_RUNTIME, "Expected value for `runtime_name` extra");
+ is(runtime_os, REMOTE_OS, "Expected value for `runtime_os` extra");
+ is(
+ runtime_version,
+ REMOTE_VERSION,
+ "Expected value for `runtime_version` extra"
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates.js
new file mode 100644
index 0000000000..51934550a8
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates.js
@@ -0,0 +1,154 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+const DEVICE_A = "Device A";
+const USB_RUNTIME_1 = {
+ id: "runtime-id-1",
+ deviceName: DEVICE_A,
+ name: "Runtime 1",
+ shortName: "R1",
+};
+
+const USB_RUNTIME_2 = {
+ id: "runtime-id-2",
+ deviceName: DEVICE_A,
+ name: "Runtime 2",
+ shortName: "R2",
+};
+
+const DEVICE_A_EXTRAS = {
+ connection_type: "usb",
+ device_name: DEVICE_A,
+};
+
+const RUNTIME_1_EXTRAS = {
+ connection_type: "usb",
+ device_name: USB_RUNTIME_1.deviceName,
+ runtime_name: USB_RUNTIME_1.shortName,
+};
+
+const RUNTIME_2_EXTRAS = {
+ connection_type: "usb",
+ device_name: USB_RUNTIME_2.deviceName,
+ runtime_name: USB_RUNTIME_2.shortName,
+};
+
+/**
+ * Check that telemetry events are recorded for USB runtimes when:
+ * - adding a device/runtime
+ * - removing a device/runtime
+ * - connecting to a runtime
+ */
+add_task(async function testUsbRuntimeUpdates() {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ setupTelemetryTest();
+
+ const { tab, document } = await openAboutDebugging();
+
+ const sessionId = getOpenEventSessionId();
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ await addUsbRuntime(USB_RUNTIME_1, mocks, document);
+
+ let evts = checkTelemetryEvents(
+ [
+ { method: "device_added", extras: DEVICE_A_EXTRAS },
+ { method: "runtime_added", extras: RUNTIME_1_EXTRAS },
+ ],
+ sessionId
+ );
+
+ // Now that a first telemetry event has been logged for RUNTIME_1, retrieve the id
+ // generated for telemetry, and check that we keep logging the same id for all events
+ // related to runtime 1.
+ const runtime1Id = evts.filter(e => e.method === "runtime_added")[0].extras
+ .runtime_id;
+ const runtime1Extras = Object.assign({}, RUNTIME_1_EXTRAS, {
+ runtime_id: runtime1Id,
+ });
+ // Same as runtime1Extras, but the runtime name should be the complete one.
+ const runtime1ConnectedExtras = Object.assign({}, runtime1Extras, {
+ runtime_name: USB_RUNTIME_1.name,
+ });
+
+ await connectToRuntime(USB_RUNTIME_1.deviceName, document);
+
+ checkTelemetryEvents(
+ [
+ { method: "runtime_connected", extras: runtime1ConnectedExtras },
+ { method: "connection_attempt", extras: { status: "start" } },
+ { method: "connection_attempt", extras: { status: "success" } },
+ ],
+ sessionId
+ );
+
+ info("Add a second runtime");
+ await addUsbRuntime(USB_RUNTIME_2, mocks, document);
+ evts = checkTelemetryEvents(
+ [{ method: "runtime_added", extras: RUNTIME_2_EXTRAS }],
+ sessionId
+ );
+
+ // Similar to what we did for RUNTIME_1,w e want to check we reuse the same telemetry id
+ // for all the events related to RUNTIME_2.
+ const runtime2Id = evts.filter(e => e.method === "runtime_added")[0].extras
+ .runtime_id;
+ const runtime2Extras = Object.assign({}, RUNTIME_2_EXTRAS, {
+ runtime_id: runtime2Id,
+ });
+
+ info("Remove runtime 1");
+ await removeUsbRuntime(USB_RUNTIME_1, mocks, document);
+
+ checkTelemetryEvents(
+ [
+ { method: "runtime_disconnected", extras: runtime1ConnectedExtras },
+ { method: "runtime_removed", extras: runtime1Extras },
+ ],
+ sessionId
+ );
+
+ info("Remove runtime 2");
+ await removeUsbRuntime(USB_RUNTIME_2, mocks, document);
+
+ checkTelemetryEvents(
+ [
+ { method: "runtime_removed", extras: runtime2Extras },
+ { method: "device_removed", extras: DEVICE_A_EXTRAS },
+ ],
+ sessionId
+ );
+
+ await removeTab(tab);
+});
+
+async function addUsbRuntime(runtime, mocks, doc) {
+ mocks.createUSBRuntime(runtime.id, {
+ deviceName: runtime.deviceName,
+ name: runtime.name,
+ shortName: runtime.shortName,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Wait for the runtime to appear in the sidebar");
+ await waitUntil(() => findSidebarItemByText(runtime.shortName, doc));
+}
+
+async function removeUsbRuntime(runtime, mocks, doc) {
+ mocks.removeRuntime(runtime.id);
+ mocks.emitUSBUpdate();
+ await waitUntil(
+ () =>
+ !findSidebarItemByText(runtime.name, doc) &&
+ !findSidebarItemByText(runtime.shortName, doc)
+ );
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_multi.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_multi.js
new file mode 100644
index 0000000000..707ddf4621
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_multi.js
@@ -0,0 +1,111 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+const DEVICE_A = "Device A";
+const USB_RUNTIME_1 = {
+ id: "runtime-id-1",
+ deviceName: DEVICE_A,
+ name: "Runtime 1",
+ shortName: "R1",
+};
+
+const USB_RUNTIME_2 = {
+ id: "runtime-id-2",
+ deviceName: DEVICE_A,
+ name: "Runtime 2",
+ shortName: "R2",
+};
+
+const DEVICE_A_EXTRAS = {
+ connection_type: "usb",
+ device_name: DEVICE_A,
+};
+
+const RUNTIME_1_EXTRAS = {
+ connection_type: "usb",
+ device_name: USB_RUNTIME_1.deviceName,
+ runtime_name: USB_RUNTIME_1.shortName,
+};
+
+const RUNTIME_2_EXTRAS = {
+ connection_type: "usb",
+ device_name: USB_RUNTIME_2.deviceName,
+ runtime_name: USB_RUNTIME_2.shortName,
+};
+
+/**
+ * Test runtime update events when a device is connected/disconnected with multiple
+ * runtimes available on the same device.
+ */
+add_task(async function () {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ setupTelemetryTest();
+
+ const { tab, document } = await openAboutDebugging();
+
+ const sessionId = getOpenEventSessionId();
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ info("Add two runtimes on the same device at the same time");
+ mocks.createUSBRuntime(USB_RUNTIME_1.id, {
+ deviceName: USB_RUNTIME_1.deviceName,
+ name: USB_RUNTIME_1.name,
+ shortName: USB_RUNTIME_1.shortName,
+ });
+ mocks.createUSBRuntime(USB_RUNTIME_2.id, {
+ deviceName: USB_RUNTIME_2.deviceName,
+ name: USB_RUNTIME_2.name,
+ shortName: USB_RUNTIME_2.shortName,
+ });
+ mocks.emitUSBUpdate();
+ await waitUntil(() =>
+ findSidebarItemByText(USB_RUNTIME_1.shortName, document)
+ );
+ await waitUntil(() =>
+ findSidebarItemByText(USB_RUNTIME_2.shortName, document)
+ );
+
+ checkTelemetryEvents(
+ [
+ { method: "device_added", extras: DEVICE_A_EXTRAS },
+ { method: "runtime_added", extras: RUNTIME_1_EXTRAS },
+ { method: "runtime_added", extras: RUNTIME_2_EXTRAS },
+ ],
+ sessionId
+ );
+
+ info("Remove both runtimes at once to simulate a device disconnection");
+ mocks.removeRuntime(USB_RUNTIME_1.id);
+ mocks.removeRuntime(USB_RUNTIME_2.id);
+ mocks.emitUSBUpdate();
+ await waitUntil(
+ () =>
+ !findSidebarItemByText(USB_RUNTIME_1.name, document) &&
+ !findSidebarItemByText(USB_RUNTIME_1.shortName, document)
+ );
+ await waitUntil(
+ () =>
+ !findSidebarItemByText(USB_RUNTIME_2.name, document) &&
+ !findSidebarItemByText(USB_RUNTIME_2.shortName, document)
+ );
+
+ checkTelemetryEvents(
+ [
+ { method: "runtime_removed", extras: RUNTIME_1_EXTRAS },
+ { method: "runtime_removed", extras: RUNTIME_2_EXTRAS },
+ { method: "device_removed", extras: DEVICE_A_EXTRAS },
+ ],
+ sessionId
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_network.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_network.js
new file mode 100644
index 0000000000..d33810dc59
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_telemetry_runtime_updates_network.js
@@ -0,0 +1,90 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-telemetry.js */
+Services.scriptloader.loadSubScript(
+ CHROME_URL_ROOT + "helper-telemetry.js",
+ this
+);
+
+const NETWORK_RUNTIME = {
+ host: "localhost:1234",
+ // No device name for network runtimes.
+ name: "Local Network Runtime",
+};
+
+/**
+ * Test runtime update events for network runtimes.
+ */
+add_task(async function testNetworkRuntimeUpdates() {
+ // enable USB devices mocks
+ const mocks = new Mocks();
+ setupTelemetryTest();
+
+ const { tab, document } = await openAboutDebugging();
+
+ const sessionId = getOpenEventSessionId();
+ ok(!isNaN(sessionId), "Open event has a valid session id");
+
+ info("Add a network runtime");
+ await addNetworkRuntime(NETWORK_RUNTIME, mocks, document);
+
+ // Before the connection, we don't have any information about the runtime.
+ // Device information is also not available to network runtimes.
+ const networkRuntimeExtras = {
+ connection_type: "network",
+ device_name: "",
+ runtime_name: "",
+ };
+
+ // Once connected we should be able to log a valid runtime name.
+ const connectedNetworkRuntimeExtras = Object.assign(
+ {},
+ networkRuntimeExtras,
+ {
+ runtime_name: NETWORK_RUNTIME.name,
+ }
+ );
+
+ // For network runtimes, we don't have any device information, so we shouldn't have any
+ // device_added event.
+ checkTelemetryEvents(
+ [{ method: "runtime_added", extras: networkRuntimeExtras }],
+ sessionId
+ );
+
+ await connectToRuntime(NETWORK_RUNTIME.host, document);
+ checkTelemetryEvents(
+ [
+ { method: "runtime_connected", extras: connectedNetworkRuntimeExtras },
+ { method: "connection_attempt", extras: { status: "start" } },
+ { method: "connection_attempt", extras: { status: "success" } },
+ ],
+ sessionId
+ );
+
+ info("Remove network runtime");
+ mocks.removeRuntime(NETWORK_RUNTIME.host);
+ await waitUntil(() => !findSidebarItemByText(NETWORK_RUNTIME.host, document));
+ // Similarly we should not have any device removed event.
+ checkTelemetryEvents(
+ [
+ { method: "runtime_disconnected", extras: connectedNetworkRuntimeExtras },
+ { method: "runtime_removed", extras: networkRuntimeExtras },
+ ],
+ sessionId
+ );
+
+ await removeTab(tab);
+});
+
+async function addNetworkRuntime(runtime, mocks, doc) {
+ mocks.createNetworkRuntime(runtime.host, {
+ name: runtime.name,
+ });
+
+ info("Wait for the Network Runtime to appear in the sidebar");
+ await waitUntil(() => findSidebarItemByText(runtime.host, doc));
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox.js
new file mode 100644
index 0000000000..3f673df758
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox.js
@@ -0,0 +1,121 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const EXPECTED_TARGET_PANES = [
+ "Tabs",
+ "Temporary Extensions",
+ "Extensions",
+ "Service Workers",
+ "Shared Workers",
+ "Other Workers",
+];
+
+/**
+ * Check that the This Firefox runtime page contains the expected categories if
+ * the preference to enable local tab debugging is true.
+ */
+add_task(async function testThisFirefoxWithLocalTab() {
+ const { document, tab, window } = await openAboutDebugging({
+ enableLocalTabs: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Expect all target panes to be displayed including tabs.
+ await checkThisFirefoxTargetPanes(document, EXPECTED_TARGET_PANES);
+
+ await removeTab(tab);
+});
+
+/**
+ * Check that the This Firefox runtime page contains the expected categories if
+ * the preference to enable local tab debugging is false.
+ */
+add_task(async function testThisFirefoxWithoutLocalTab() {
+ const { document, tab, window } = await openAboutDebugging({
+ enableLocalTabs: false,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Expect all target panes but tabs to be displayed.
+ const expectedTargetPanesWithoutTabs = EXPECTED_TARGET_PANES.filter(
+ p => p !== "Tabs"
+ );
+ await checkThisFirefoxTargetPanes(document, expectedTargetPanesWithoutTabs);
+
+ await removeTab(tab);
+});
+
+/**
+ * Check that the tab which is discarded keeps the state after open the aboutdebugging.
+ */
+add_task(async function testThisFirefoxKeepDiscardedTab() {
+ const targetTab = await addTab("https://example.com/");
+ const blankTab = await addTab("about:blank");
+ targetTab.ownerGlobal.gBrowser.discardBrowser(targetTab);
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableLocalTabs: false,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ ok(!targetTab.linkedPanel, "The target tab is still discarded");
+
+ await removeTab(blankTab);
+ await removeTab(targetTab);
+ await removeTab(tab);
+});
+
+/**
+ * Check that the Temporary Extensions is hidden if "xpinstall.enabled" is set to false.
+ */
+add_task(async function testThisFirefoxWithXpinstallDisabled() {
+ await pushPref("xpinstall.enabled", false);
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ // Expect all target panes but temporary extensions to be displayed.
+ const expectedTargetPanesWithXpinstallDisabled = EXPECTED_TARGET_PANES.filter(
+ p => p !== "Temporary Extensions"
+ );
+ await checkThisFirefoxTargetPanes(
+ document,
+ expectedTargetPanesWithXpinstallDisabled
+ );
+
+ await removeTab(tab);
+});
+
+async function checkThisFirefoxTargetPanes(doc, expectedTargetPanes) {
+ const win = doc.ownerGlobal;
+ // Check that the selected sidebar item is "This Firefox"/"This Nightly"/...
+ const selectedSidebarItem = doc.querySelector(".qa-sidebar-item-selected");
+ ok(selectedSidebarItem, "An item is selected in the sidebar");
+
+ const thisFirefoxString = getThisFirefoxString(win);
+ is(
+ selectedSidebarItem.textContent,
+ thisFirefoxString,
+ "The selected sidebar item is " + thisFirefoxString
+ );
+
+ const paneTitlesEls = doc.querySelectorAll(".qa-debug-target-pane-title");
+ is(
+ paneTitlesEls.length,
+ expectedTargetPanes.length,
+ "This Firefox has the expected number of debug target categories"
+ );
+
+ const paneTitles = [...paneTitlesEls].map(el => el.textContent);
+
+ for (let i = 0; i < expectedTargetPanes.length; i++) {
+ const expectedPaneTitle = expectedTargetPanes[i];
+ const actualPaneTitle = paneTitles[i];
+ ok(
+ actualPaneTitle.startsWith(expectedPaneTitle),
+ `Expected debug target category found: ${expectedPaneTitle}`
+ );
+ }
+}
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_runtime_info.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_runtime_info.js
new file mode 100644
index 0000000000..2475994fed
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_runtime_info.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Check that the runtime info is correctly displayed for ThisFirefox.
+ * Also acts as basic sanity check for the default mock of the this-firefox client.
+ */
+
+add_task(async function () {
+ // Setup a mock for our runtime client factory to return the default THIS_FIREFOX client
+ // when the client for the this-firefox runtime is requested.
+ const runtimeClientFactoryMock = createRuntimeClientFactoryMock();
+ const thisFirefoxClient = createThisFirefoxClientMock();
+ runtimeClientFactoryMock.createClientForRuntime = runtime => {
+ const {
+ RUNTIMES,
+ } = require("resource://devtools/client/aboutdebugging/src/constants.js");
+ if (runtime.id === RUNTIMES.THIS_FIREFOX) {
+ return thisFirefoxClient;
+ }
+ throw new Error("Unexpected runtime id " + runtime.id);
+ };
+
+ info("Enable mocks");
+ enableRuntimeClientFactoryMock(runtimeClientFactoryMock);
+ registerCleanupFunction(() => {
+ disableRuntimeClientFactoryMock();
+ });
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Check that the 'This Firefox' mock is properly displayed");
+ const thisFirefoxRuntimeInfo = document.querySelector(".qa-runtime-name");
+ ok(
+ thisFirefoxRuntimeInfo,
+ "Runtime info for this-firefox runtime is displayed"
+ );
+ const runtimeInfoText = thisFirefoxRuntimeInfo.textContent;
+ ok(
+ runtimeInfoText.includes("Firefox"),
+ "this-firefox runtime info shows the correct runtime name: " +
+ runtimeInfoText
+ );
+ ok(
+ runtimeInfoText.includes("63.0"),
+ "this-firefox runtime info shows the correct version number: " +
+ runtimeInfoText
+ );
+
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_worker_inspection.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_worker_inspection.js
new file mode 100644
index 0000000000..4d02c73b1b
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_thisfirefox_worker_inspection.js
@@ -0,0 +1,68 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function () {
+ const thisFirefoxClient = createThisFirefoxClientMock();
+ // Prepare a worker mock.
+ const testWorker = {
+ id: "test-worker-id",
+ name: "Test Worker",
+ };
+ // Add a worker mock as other worker.
+ thisFirefoxClient.listWorkers = () => ({
+ otherWorkers: [testWorker],
+ serviceWorkers: [],
+ sharedWorkers: [],
+ });
+ thisFirefoxClient.client.mainRoot = {
+ getWorker: id => {
+ return id === testWorker.id ? testWorker : null;
+ },
+ };
+
+ const runtimeClientFactoryMock = createRuntimeClientFactoryMock();
+ runtimeClientFactoryMock.createClientForRuntime = runtime => {
+ const {
+ RUNTIMES,
+ } = require("resource://devtools/client/aboutdebugging/src/constants.js");
+ if (runtime.id === RUNTIMES.THIS_FIREFOX) {
+ return thisFirefoxClient;
+ }
+ throw new Error("Unexpected runtime id " + runtime.id);
+ };
+
+ info("Enable mocks");
+ enableRuntimeClientFactoryMock(runtimeClientFactoryMock);
+ registerCleanupFunction(() => {
+ disableRuntimeClientFactoryMock();
+ });
+
+ const { document, tab, window } = await openAboutDebugging();
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Open a toolbox to debug the worker");
+ const { devtoolsTab, devtoolsWindow } = await openAboutDevtoolsToolbox(
+ document,
+ tab,
+ window,
+ testWorker.name,
+ false
+ );
+
+ info(
+ "Check whether the correct actor front will be opened in worker toolbox"
+ );
+ const url = new window.URL(devtoolsWindow.location.href);
+ const workerID = url.searchParams.get("id");
+ is(
+ workerID,
+ testWorker.id,
+ "Correct actor front will be opened in worker toolbox"
+ );
+
+ await removeTab(devtoolsTab);
+ await waitUntil(() => !findDebugTargetByText("Toolbox - ", document));
+ await removeTab(tab);
+});
diff --git a/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_workers_remote_runtime.js b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_workers_remote_runtime.js
new file mode 100644
index 0000000000..3e0ccf1532
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_workers_remote_runtime.js
@@ -0,0 +1,160 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const NETWORK_RUNTIME_HOST = "localhost:6080";
+const NETWORK_RUNTIME_APP_NAME = "TestNetworkApp";
+const USB_RUNTIME_ID = "test-runtime-id";
+const USB_RUNTIME_DEVICE_NAME = "test device name";
+const USB_RUNTIME_APP_NAME = "TestUsbApp";
+
+const TESTS = [
+ {
+ category: "Other Workers",
+ propertyName: "otherWorkers",
+ workerName: "other/worker/script.js",
+ },
+ {
+ category: "Service Workers",
+ propertyName: "serviceWorkers",
+ workerName: "service/worker/script.js",
+ },
+ {
+ category: "Shared Workers",
+ propertyName: "sharedWorkers",
+ workerName: "shared/worker/script.js",
+ },
+];
+
+const EMPTY_WORKERS_RESPONSE = {
+ otherWorkers: [],
+ serviceWorkers: [],
+ sharedWorkers: [],
+};
+
+// Test that workers are displayed and updated for remote runtimes when expected.
+add_task(async function () {
+ const mocks = new Mocks();
+
+ const { document, tab, window } = await openAboutDebugging({
+ enableWorkerUpdates: true,
+ });
+ await selectThisFirefoxPage(document, window.AboutDebugging.store);
+
+ info("Prepare USB client mock");
+ const usbClient = mocks.createUSBRuntime(USB_RUNTIME_ID, {
+ deviceName: USB_RUNTIME_DEVICE_NAME,
+ name: USB_RUNTIME_APP_NAME,
+ });
+ mocks.emitUSBUpdate();
+
+ info("Test addons in runtime page for USB client");
+ await connectToRuntime(USB_RUNTIME_DEVICE_NAME, document);
+ await selectRuntime(USB_RUNTIME_DEVICE_NAME, USB_RUNTIME_APP_NAME, document);
+ for (const testData of TESTS) {
+ await testWorkerOnMockedRemoteClient(
+ testData,
+ usbClient,
+ mocks.thisFirefoxClient,
+ document
+ );
+ }
+
+ info("Prepare Network client mock");
+ const networkClient = mocks.createNetworkRuntime(NETWORK_RUNTIME_HOST, {
+ name: NETWORK_RUNTIME_APP_NAME,
+ });
+
+ info("Test workers in runtime page for Network client");
+ await connectToRuntime(NETWORK_RUNTIME_HOST, document);
+ await selectRuntime(NETWORK_RUNTIME_HOST, NETWORK_RUNTIME_APP_NAME, document);
+
+ for (const testData of TESTS) {
+ await testWorkerOnMockedRemoteClient(
+ testData,
+ networkClient,
+ mocks.thisFirefoxClient,
+ document
+ );
+ }
+
+ await removeTab(tab);
+});
+
+/**
+ * Check that workers are visible in the runtime page for a remote client.
+ */
+async function testWorkerOnMockedRemoteClient(
+ testData,
+ remoteClient,
+ firefoxClient,
+ document
+) {
+ const { category, propertyName, workerName } = testData;
+ info(`Test workers for category [${category}] in remote runtime`);
+
+ const workersPane = getDebugTargetPane(category, document);
+ info("Check an empty target pane message is displayed");
+ ok(
+ workersPane.querySelector(".qa-debug-target-list-empty"),
+ "Workers list is empty"
+ );
+
+ info(`Add a worker of type [${propertyName}] to the remote client`);
+ const workers = Object.assign({}, EMPTY_WORKERS_RESPONSE, {
+ [propertyName]: [
+ {
+ name: workerName,
+ workerDescriptorFront: {
+ actorID: workerName,
+ },
+ },
+ ],
+ });
+ remoteClient.listWorkers = () => workers;
+ remoteClient._eventEmitter.emit("workersUpdated");
+
+ info("Wait until the worker appears");
+ await waitUntil(
+ () => !workersPane.querySelector(".qa-debug-target-list-empty")
+ );
+
+ const workerTarget = findDebugTargetByText(workerName, document);
+ ok(workerTarget, "Worker target appeared for the remote runtime");
+
+ // Check that the list of REMOTE workers are NOT updated when the local this-firefox
+ // emits a workersUpdated event.
+ info("Remove the worker from the remote client WITHOUT sending an event");
+ remoteClient.listWorkers = () => EMPTY_WORKERS_RESPONSE;
+
+ info("Simulate a worker update on the ThisFirefox client");
+ firefoxClient._eventEmitter.emit("workersUpdated");
+
+ // To avoid wait for a set period of time we trigger another async update, adding a new
+ // tab. We assume that if the worker update mechanism had started, it would also be done
+ // when the new tab was processed.
+ info("Wait until the tab target for 'http://some.random/url.com' appears");
+ const testTab = {
+ retrieveFavicon: () => {},
+ outerWindowID: 0,
+ traits: {},
+ url: "http://some.random/url.com",
+ };
+ remoteClient.listTabs = () => [testTab];
+ remoteClient._eventEmitter.emit("tabListChanged");
+ await waitUntil(() =>
+ findDebugTargetByText("http://some.random/url.com", document)
+ );
+
+ ok(
+ findDebugTargetByText(workerName, document),
+ "The test worker is still visible"
+ );
+
+ info(
+ "Emit `workersUpdated` on remoteClient and wait for the target list to update"
+ );
+ remoteClient._eventEmitter.emit("workersUpdated");
+ await waitUntil(() => !findDebugTargetByText(workerName, document));
+}
diff --git a/devtools/client/aboutdebugging/test/browser/empty.html b/devtools/client/aboutdebugging/test/browser/empty.html
new file mode 100644
index 0000000000..d0fd95ab08
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/empty.html
@@ -0,0 +1 @@
+<body>fake_profiler_page</body>
diff --git a/devtools/client/aboutdebugging/test/browser/head.js b/devtools/client/aboutdebugging/test/browser/head.js
new file mode 100644
index 0000000000..3c32e0b87b
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/head.js
@@ -0,0 +1,505 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* eslint-env browser */
+/* eslint no-unused-vars: [2, {"vars": "local"}] */
+
+// Load the shared-head file first.
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
+ this
+);
+
+/* import-globals-from helper-mocks.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-mocks.js", this);
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/devtools/client/webconsole/test/browser/shared-head.js",
+ this
+);
+
+// Make sure the ADB addon is removed and ADB is stopped when the test ends.
+registerCleanupFunction(async function () {
+ // Reset the selected tool in case we opened about:devtools-toolbox to
+ // avoid side effects between tests.
+ Services.prefs.clearUserPref("devtools.toolbox.selectedTool");
+
+ try {
+ const {
+ adbAddon,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-addon.js");
+ await adbAddon.uninstall();
+ } catch (e) {
+ // Will throw if the addon is already uninstalled, ignore exceptions here.
+ }
+ const {
+ adbProcess,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-process.js");
+ await adbProcess.kill();
+
+ const {
+ remoteClientManager,
+ } = require("resource://devtools/client/shared/remote-debugging/remote-client-manager.js");
+ await remoteClientManager.removeAllClients();
+});
+
+async function openAboutDebugging({
+ enableWorkerUpdates,
+ enableLocalTabs = true,
+} = {}) {
+ if (!enableWorkerUpdates) {
+ silenceWorkerUpdates();
+ }
+
+ // This preference changes value depending on the build type, tests need to use a
+ // consistent value regarless of the build used.
+ await pushPref(
+ "devtools.aboutdebugging.local-tab-debugging",
+ enableLocalTabs
+ );
+
+ info("opening about:debugging");
+
+ const tab = await addTab("about:debugging");
+ const browser = tab.linkedBrowser;
+ const document = browser.contentDocument;
+ const window = browser.contentWindow;
+
+ info("Wait until Connect page is displayed");
+ await waitUntil(() => document.querySelector(".qa-connect-page"));
+
+ return { tab, document, window };
+}
+
+async function openAboutDevtoolsToolbox(
+ doc,
+ tab,
+ win,
+ targetText = "about:debugging",
+ shouldWaitToolboxReady = true
+) {
+ info("Open about:devtools-toolbox page");
+
+ info("Wait for the target to appear: " + targetText);
+ await waitUntil(() => findDebugTargetByText(targetText, doc));
+
+ const target = findDebugTargetByText(targetText, doc);
+ ok(target, `${targetText} target appeared`);
+
+ const {
+ DEBUG_TARGETS,
+ } = require("resource://devtools/client/aboutdebugging/src/constants.js");
+ const isWebExtension = target.dataset.qaTargetType == DEBUG_TARGETS.EXTENSION;
+
+ const inspectButton = target.querySelector(".qa-debug-target-inspect-button");
+ ok(inspectButton, `Inspect button for ${targetText} appeared`);
+ inspectButton.click();
+ const onToolboxReady = gDevTools.once("toolbox-ready");
+ await Promise.all([
+ waitForAboutDebuggingRequests(win.AboutDebugging.store),
+ shouldWaitToolboxReady ? onToolboxReady : Promise.resolve(),
+ ]);
+
+ // WebExtension open a toolbox in a dedicated window
+ if (isWebExtension) {
+ const toolbox = await onToolboxReady;
+ // For some reason the test helpers prevents the toolbox from being automatically focused on opening,
+ // whereas it is IRL.
+ const focusedWin = Services.focus.focusedWindow;
+ if (focusedWin?.top != toolbox.win) {
+ info("Wait for the toolbox window to be focused");
+ await new Promise(r => {
+ // focus event only fired on the chrome event handler and in capture phase
+ toolbox.win.docShell.chromeEventHandler.addEventListener("focus", r, {
+ once: true,
+ capture: true,
+ });
+ toolbox.win.focus();
+ });
+ info("The toolbox is focused");
+ }
+ return {
+ devtoolsBrowser: null,
+ devtoolsDocument: toolbox.doc,
+ devtoolsTab: null,
+ devtoolsWindow: toolbox.win,
+ };
+ }
+
+ await waitUntil(() => tab.nextElementSibling);
+
+ info("Wait for about:devtools-toolbox tab will be selected");
+ const devtoolsTab = tab.nextElementSibling;
+ await waitUntil(() => gBrowser.selectedTab === devtoolsTab);
+ const devtoolsBrowser = gBrowser.selectedBrowser;
+ await waitUntil(() =>
+ devtoolsBrowser.contentWindow.location.href.startsWith(
+ "about:devtools-toolbox?"
+ )
+ );
+
+ if (!shouldWaitToolboxReady) {
+ // Wait for show error page.
+ await waitUntil(() =>
+ devtoolsBrowser.contentDocument.querySelector(".qa-error-page")
+ );
+ }
+
+ return {
+ devtoolsBrowser,
+ devtoolsDocument: devtoolsBrowser.contentDocument,
+ devtoolsTab,
+ devtoolsWindow: devtoolsBrowser.contentWindow,
+ };
+}
+
+async function closeAboutDevtoolsToolbox(
+ aboutDebuggingDocument,
+ devtoolsTab,
+ win
+) {
+ // Wait for all requests to settle on the opened about:devtools toolbox.
+ const devtoolsBrowser = devtoolsTab.linkedBrowser;
+ const devtoolsWindow = devtoolsBrowser.contentWindow;
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.commands.client.waitForRequestsToSettle();
+
+ info("Close about:devtools-toolbox page");
+ const onToolboxDestroyed = gDevTools.once("toolbox-destroyed");
+
+ info("Wait for removeTab");
+ await removeTab(devtoolsTab);
+
+ info("Wait for toolbox destroyed");
+ await onToolboxDestroyed;
+
+ // Changing the tab will also trigger a request to list tabs, so wait until the selected
+ // tab has changed to wait for requests to settle.
+ info("Wait until aboutdebugging is selected");
+ await waitUntil(() => gBrowser.selectedTab !== devtoolsTab);
+
+ // Wait for removing about:devtools-toolbox tab info from about:debugging.
+ info("Wait until about:devtools-toolbox is removed from debug targets");
+ await waitUntil(
+ () => !findDebugTargetByText("Toolbox - ", aboutDebuggingDocument)
+ );
+
+ await waitForAboutDebuggingRequests(win.AboutDebugging.store);
+}
+
+async function closeWebExtAboutDevtoolsToolbox(devtoolsWindow, win) {
+ // Wait for all requests to settle on the opened about:devtools toolbox.
+ const toolbox = getToolbox(devtoolsWindow);
+ await toolbox.commands.client.waitForRequestsToSettle();
+
+ info("Close the toolbox and wait for its destruction");
+ await toolbox.destroy();
+
+ await waitForAboutDebuggingRequests(win.AboutDebugging.store);
+}
+
+async function reloadAboutDebugging(tab) {
+ info("reload about:debugging");
+
+ await reloadBrowser(tab.linkedBrowser);
+ const browser = tab.linkedBrowser;
+ const document = browser.contentDocument;
+ const window = browser.contentWindow;
+ info("wait for the initial about:debugging requests to settle");
+ await waitForAboutDebuggingRequests(window.AboutDebugging.store);
+
+ return document;
+}
+
+// Wait for all about:debugging target request actions to succeed.
+// They will typically be triggered after watching a new runtime or loading
+// about:debugging.
+function waitForRequestsSuccess(store) {
+ return Promise.all([
+ waitForDispatch(store, "REQUEST_EXTENSIONS_SUCCESS"),
+ waitForDispatch(store, "REQUEST_TABS_SUCCESS"),
+ waitForDispatch(store, "REQUEST_WORKERS_SUCCESS"),
+ ]);
+}
+
+/**
+ * Wait for all aboutdebugging REQUEST_*_SUCCESS actions to settle, meaning here
+ * that no new request has been dispatched after the provided delay.
+ */
+async function waitForAboutDebuggingRequests(store, delay = 500) {
+ let hasSettled = false;
+
+ // After each iteration of this while loop, we check is the timerPromise had the time
+ // to resolve or if we captured a REQUEST_*_SUCCESS action before.
+ while (!hasSettled) {
+ let timer;
+
+ // This timer will be executed only if no REQUEST_*_SUCCESS action is dispatched
+ // during the delay. We consider that when no request are received for some time, it
+ // means there are no ongoing requests anymore.
+ const timerPromise = new Promise(resolve => {
+ timer = setTimeout(() => {
+ hasSettled = true;
+ resolve();
+ }, delay);
+ });
+
+ // Wait either for a REQUEST_*_SUCCESS to be dispatched, or for the timer to resolve.
+ await Promise.race([
+ waitForDispatch(store, "REQUEST_EXTENSIONS_SUCCESS"),
+ waitForDispatch(store, "REQUEST_TABS_SUCCESS"),
+ waitForDispatch(store, "REQUEST_WORKERS_SUCCESS"),
+ timerPromise,
+ ]);
+
+ // Clear the timer to avoid setting hasSettled to true accidently unless timerPromise
+ // was the first to resolve.
+ clearTimeout(timer);
+ }
+}
+
+/**
+ * Navigate to "This Firefox"
+ */
+async function selectThisFirefoxPage(doc, store) {
+ info("Select This Firefox page");
+
+ const onRequestSuccess = waitForRequestsSuccess(store);
+ doc.location.hash = "#/runtime/this-firefox";
+ info("Wait for requests to be complete");
+ await onRequestSuccess;
+
+ info("Wait for runtime page to be rendered");
+ await waitUntil(() => doc.querySelector(".qa-runtime-page"));
+
+ // Navigating to this-firefox will trigger a title change for the
+ // about:debugging tab. This title change _might_ trigger a tablist update.
+ // If it does, we should make sure to wait for pending tab requests.
+ await waitForAboutDebuggingRequests(store);
+}
+
+/**
+ * Navigate to the Connect page. Resolves when the Connect page is rendered.
+ */
+async function selectConnectPage(doc) {
+ const sidebarItems = doc.querySelectorAll(".qa-sidebar-item");
+ const connectSidebarItem = [...sidebarItems].find(element => {
+ return element.textContent === "Setup";
+ });
+ ok(connectSidebarItem, "Sidebar contains a Connect item");
+ const connectLink = connectSidebarItem.querySelector(".qa-sidebar-link");
+ ok(connectLink, "Sidebar contains a Connect link");
+
+ info("Click on the Connect link in the sidebar");
+ connectLink.click();
+
+ info("Wait until Connect page is displayed");
+ await waitUntil(() => doc.querySelector(".qa-connect-page"));
+}
+
+function getDebugTargetPane(title, document) {
+ // removes the suffix "(<NUMBER>)" in debug target pane's title, if needed
+ const sanitizeTitle = x => {
+ return x.replace(/\s+\(\d+\)$/, "");
+ };
+
+ const targetTitle = sanitizeTitle(title);
+ for (const titleEl of document.querySelectorAll(
+ ".qa-debug-target-pane-title"
+ )) {
+ if (sanitizeTitle(titleEl.textContent) !== targetTitle) {
+ continue;
+ }
+
+ return titleEl.closest(".qa-debug-target-pane");
+ }
+
+ return null;
+}
+
+function findDebugTargetByText(text, document) {
+ const targets = [...document.querySelectorAll(".qa-debug-target-item")];
+ return targets.find(target => target.textContent.includes(text));
+}
+
+function findSidebarItemByText(text, document) {
+ const sidebarItems = document.querySelectorAll(".qa-sidebar-item");
+ return [...sidebarItems].find(element => {
+ return element.textContent.includes(text);
+ });
+}
+
+function findSidebarItemLinkByText(text, document) {
+ const links = document.querySelectorAll(".qa-sidebar-link");
+ return [...links].find(element => {
+ return element.textContent.includes(text);
+ });
+}
+
+async function connectToRuntime(deviceName, document) {
+ info(`Wait until the sidebar item for ${deviceName} appears`);
+ await waitUntil(() => findSidebarItemByText(deviceName, document));
+ const sidebarItem = findSidebarItemByText(deviceName, document);
+ const connectButton = sidebarItem.querySelector(".qa-connect-button");
+ ok(
+ connectButton,
+ `Connect button is displayed for the runtime ${deviceName}`
+ );
+
+ info("Click on the connect button and wait until it disappears");
+ connectButton.click();
+ await waitUntil(() => !sidebarItem.querySelector(".qa-connect-button"));
+}
+
+async function selectRuntime(deviceName, name, document) {
+ const sidebarItem = findSidebarItemByText(deviceName, document);
+ const store = document.defaultView.AboutDebugging.store;
+ const onSelectPageSuccess = waitForDispatch(store, "SELECT_PAGE_SUCCESS");
+
+ sidebarItem.querySelector(".qa-sidebar-link").click();
+
+ await waitUntil(() => {
+ const runtimeInfo = document.querySelector(".qa-runtime-name");
+ return runtimeInfo && runtimeInfo.textContent.includes(name);
+ });
+
+ info("Wait for SELECT_PAGE_SUCCESS to be dispatched");
+ await onSelectPageSuccess;
+}
+
+function getToolbox(win) {
+ return gDevTools.getToolboxes().find(toolbox => toolbox.win === win);
+}
+
+/**
+ * Open the performance profiler dialog. Assumes the client is a mocked remote runtime
+ * client.
+ */
+async function openProfilerDialog(client, doc) {
+ const onProfilerLoaded = new Promise(r => {
+ client.loadPerformanceProfiler = r;
+ });
+
+ info("Click on the Profile Runtime button");
+ const profileButton = doc.querySelector(".qa-profile-runtime-button");
+ profileButton.click();
+
+ info(
+ "Wait for the loadPerformanceProfiler callback to be executed on client-wrapper"
+ );
+ return onProfilerLoaded;
+}
+
+/**
+ * The "This Firefox" string depends on the brandShortName, which will be different
+ * depending on the channel where tests are running.
+ */
+function getThisFirefoxString(aboutDebuggingWindow) {
+ const loader = aboutDebuggingWindow.getBrowserLoaderForWindow();
+ const { l10n } = loader.require(
+ "resource://devtools/client/aboutdebugging/src/modules/l10n.js"
+ );
+ return l10n.getString("about-debugging-this-firefox-runtime-name");
+}
+
+function waitUntilUsbDeviceIsUnplugged(deviceName, aboutDebuggingDocument) {
+ info("Wait until the USB sidebar item appears as unplugged");
+ return waitUntil(() => {
+ const sidebarItem = findSidebarItemByText(
+ deviceName,
+ aboutDebuggingDocument
+ );
+ return !!sidebarItem.querySelector(".qa-runtime-item-unplugged");
+ });
+}
+
+/**
+ * Changing the selected tab in the current browser will trigger a tablist
+ * update.
+ * If the currently selected page is "this-firefox", we should wait for the
+ * the corresponding REQUEST_TABS_SUCCESS that will be triggered by the change.
+ *
+ * @param {Browser} browser
+ * The browser instance to update.
+ * @param {XULTab} tab
+ * The tab to select.
+ * @param {Object} store
+ * The about:debugging redux store.
+ */
+async function updateSelectedTab(browser, tab, store) {
+ info("Update the selected tab");
+
+ const { runtimes, ui } = store.getState();
+ const isOnThisFirefox =
+ runtimes.selectedRuntimeId === "this-firefox" &&
+ ui.selectedPage === "runtime";
+
+ // A tabs request will only be issued if we are on this-firefox.
+ const onTabsSuccess = isOnThisFirefox
+ ? waitForDispatch(store, "REQUEST_TABS_SUCCESS")
+ : null;
+
+ // Update the selected tab.
+ browser.selectedTab = tab;
+
+ if (onTabsSuccess) {
+ info("Wait for the tablist update after updating the selected tab");
+ await onTabsSuccess;
+ }
+}
+
+/**
+ * Synthesizes key input inside the DebugTargetInfo's URL component.
+ *
+ * @param {DevToolsToolbox} toolbox
+ * The DevToolsToolbox debugging the target.
+ * @param {HTMLElement} inputEl
+ * The <input> element to submit the URL with.
+ * @param {String} url
+ * The URL to navigate to.
+ */
+async function synthesizeUrlKeyInput(toolbox, inputEl, url) {
+ const { devtoolsDocument, devtoolsWindow } = toolbox;
+ info("Wait for URL input to be focused.");
+ const onInputFocused = waitUntil(
+ () => devtoolsDocument.activeElement === inputEl
+ );
+ inputEl.focus();
+ await onInputFocused;
+
+ info("Synthesize entering URL into text field");
+ const onInputChange = waitUntil(() => inputEl.value === url);
+ for (const key of url.split("")) {
+ EventUtils.synthesizeKey(key, {}, devtoolsWindow);
+ }
+ await onInputChange;
+
+ info("Submit URL to navigate to");
+ EventUtils.synthesizeKey("KEY_Enter");
+}
+
+/**
+ * Click on a given add-on widget button so that its browser actor is fired.
+ * Typically a popup would open, or a listener would be called in the background page.
+ *
+ * @param {String} addonId
+ * The ID of the add-on to click on.
+ */
+function clickOnAddonWidget(addonId) {
+ // Devtools are in another window and may have the focus.
+ // Ensure focusing the browser window when clicking on the widget.
+ const focusedWin = Services.focus.focusedWindow;
+ if (focusedWin != window) {
+ window.focus();
+ }
+ // Find the browserAction button that will show the webextension popup.
+ const widgetId = addonId.toLowerCase().replace(/[^a-z0-9_-]/g, "_");
+ const browserActionId = widgetId + "-browser-action";
+ const browserActionEl = window.document.getElementById(browserActionId);
+ ok(browserActionEl, "Got the browserAction button from the browser UI");
+
+ info("Show the web extension popup");
+ browserActionEl.firstElementChild.click();
+}
diff --git a/devtools/client/aboutdebugging/test/browser/helper-adb.js b/devtools/client/aboutdebugging/test/browser/helper-adb.js
new file mode 100644
index 0000000000..f5e6adfc6b
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/helper-adb.js
@@ -0,0 +1,59 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from head.js */
+
+async function checkAdbNotRunning() {
+ info("Check if ADB is already running before the test starts");
+ const {
+ check,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-running-checker.js");
+ const isAdbAlreadyRunning = await check();
+ if (isAdbAlreadyRunning) {
+ throw new Error(
+ "The ADB process is already running on this machine, it should be " +
+ "stopped before running this test"
+ );
+ }
+}
+/* exported checkAdbNotRunning */
+
+// Returns a promise that resolves when the adb process exists and is running.
+async function waitForAdbStart() {
+ info("Wait for ADB to start");
+ const {
+ adbProcess,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-process.js");
+ const {
+ check,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-running-checker.js");
+ return asyncWaitUntil(async () => {
+ const isProcessReady = adbProcess.ready;
+ const isRunning = await check();
+ return isProcessReady && isRunning;
+ });
+}
+/* exported waitForAdbStart */
+
+// Attempt to stop ADB. Will only work if ADB was started by the current Firefox instance.
+// Returns a promise that resolves when the adb process is no longer running.
+async function stopAdbProcess() {
+ info("Attempt to stop ADB");
+ const {
+ adbProcess,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-process.js");
+ await adbProcess.stop();
+
+ info("Wait for ADB to stop");
+ const {
+ check,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-running-checker.js");
+ return asyncWaitUntil(async () => {
+ const isProcessReady = adbProcess.ready;
+ const isRunning = await check();
+ return !isProcessReady && !isRunning;
+ });
+}
+/* exported stopAdbProcess */
diff --git a/devtools/client/aboutdebugging/test/browser/helper-addons.js b/devtools/client/aboutdebugging/test/browser/helper-addons.js
new file mode 100644
index 0000000000..e3a8be3761
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/helper-addons.js
@@ -0,0 +1,262 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from head.js */
+
+function _getSupportsFile(path) {
+ const cr = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(
+ Ci.nsIChromeRegistry
+ );
+ const uri = Services.io.newURI(CHROME_URL_ROOT + path);
+ const fileurl = cr.convertChromeURL(uri);
+ return fileurl.QueryInterface(Ci.nsIFileURL);
+}
+
+async function enableExtensionDebugging() {
+ // Disable security prompt
+ await pushPref("devtools.debugger.prompt-connection", false);
+}
+/* exported enableExtensionDebugging */
+
+/**
+ * Install an extension using the AddonManager so it does not show up as temporary.
+ */
+async function installRegularExtension(pathOrFile) {
+ const isFile = typeof pathOrFile.isFile === "function" && pathOrFile.isFile();
+ const file = isFile ? pathOrFile : _getSupportsFile(pathOrFile).file;
+ const install = await AddonManager.getInstallForFile(file);
+ return new Promise((resolve, reject) => {
+ if (!install) {
+ throw new Error(`An install was not created for ${file.path}`);
+ }
+ install.addListener({
+ onDownloadFailed: reject,
+ onDownloadCancelled: reject,
+ onInstallFailed: reject,
+ onInstallCancelled: reject,
+ onInstallEnded: resolve,
+ });
+ install.install();
+ });
+}
+/* exported installRegularExtension */
+
+/**
+ * Install a temporary extension at the provided path, with the provided name.
+ * Will use a mock file picker to select the file.
+ */
+async function installTemporaryExtension(pathOrFile, name, document) {
+ const { Management } = ChromeUtils.importESModule(
+ "resource://gre/modules/Extension.sys.mjs"
+ );
+
+ info("Install temporary extension named " + name);
+ // Mock the file picker to select a test addon
+ prepareMockFilePicker(pathOrFile);
+
+ const onAddonInstalled = new Promise(done => {
+ Management.on("startup", function listener(event, extension) {
+ if (extension.name != name) {
+ return;
+ }
+
+ Management.off("startup", listener);
+ done(extension);
+ });
+ });
+
+ // Trigger the file picker by clicking on the button
+ document.querySelector(".qa-temporary-extension-install-button").click();
+
+ info("Wait for addon to be installed");
+ return onAddonInstalled;
+}
+/* exported installTemporaryExtension */
+
+function createTemporaryXPI(xpiData) {
+ const { ExtensionTestCommon } = ChromeUtils.importESModule(
+ "resource://testing-common/ExtensionTestCommon.sys.mjs"
+ );
+
+ const { background, files, id, name, extraProperties } = xpiData;
+ info("Generate XPI file for " + id);
+
+ const manifest = Object.assign(
+ {},
+ {
+ browser_specific_settings: { gecko: { id } },
+ manifest_version: 2,
+ name,
+ version: "1.0",
+ },
+ extraProperties
+ );
+
+ const xpiFile = ExtensionTestCommon.generateXPI({
+ background,
+ files,
+ manifest,
+ });
+ registerCleanupFunction(() => xpiFile.exists() && xpiFile.remove(false));
+ return xpiFile;
+}
+/* exported createTemporaryXPI */
+
+/**
+ * Remove the existing temporary XPI file generated by ExtensionTestCommon and create a
+ * new one at the same location.
+ * @return {File} the temporary extension XPI file created
+ */
+function updateTemporaryXPI(xpiData, existingXPI) {
+ info("Delete and regenerate XPI for " + xpiData.id);
+
+ // Store the current name to check the xpi is correctly replaced.
+ const existingName = existingXPI.leafName;
+ info("Delete existing XPI named: " + existingName);
+ existingXPI.exists() && existingXPI.remove(false);
+
+ const xpiFile = createTemporaryXPI(xpiData);
+ // Check that the name of the new file is correct
+ if (xpiFile.leafName !== existingName) {
+ throw new Error(
+ "New XPI created with unexpected name: " + xpiFile.leafName
+ );
+ }
+ return xpiFile;
+}
+/* exported updateTemporaryXPI */
+
+/**
+ * Install a fake temporary extension by creating a temporary in-memory XPI file.
+ * @return {File} the temporary extension XPI file created
+ */
+async function installTemporaryExtensionFromXPI(xpiData, document) {
+ const xpiFile = createTemporaryXPI(xpiData);
+ const extension = await installTemporaryExtension(
+ xpiFile,
+ xpiData.name,
+ document
+ );
+
+ info("Wait until the addon debug target appears");
+ await waitUntil(() => findDebugTargetByText(xpiData.name, document));
+ return { extension, xpiFile };
+}
+/* exported installTemporaryExtensionFromXPI */
+
+async function removeTemporaryExtension(name, document) {
+ info(`Wait for removable extension with name: '${name}'`);
+ const buttonName = ".qa-temporary-extension-remove-button";
+ await waitUntil(() => {
+ const extension = findDebugTargetByText(name, document);
+ return extension && extension.querySelector(buttonName);
+ });
+ info(`Remove the temporary extension with name: '${name}'`);
+ const temporaryExtensionItem = findDebugTargetByText(name, document);
+ temporaryExtensionItem.querySelector(buttonName).click();
+
+ info("Wait until the debug target item disappears");
+ await waitUntil(() => !findDebugTargetByText(name, document));
+}
+/* exported removeTemporaryExtension */
+
+async function removeExtension(id, name, document) {
+ info(
+ "Retrieve the extension instance from the addon manager, and uninstall it"
+ );
+ const extension = await AddonManager.getAddonByID(id);
+ extension.uninstall();
+
+ info("Wait until the addon disappears from about:debugging");
+ await waitUntil(() => !findDebugTargetByText(name, document));
+}
+/* exported removeExtension */
+
+function prepareMockFilePicker(pathOrFile) {
+ const isFile = typeof pathOrFile.isFile === "function" && pathOrFile.isFile();
+ const file = isFile ? pathOrFile : _getSupportsFile(pathOrFile).file;
+
+ // Mock the file picker to select a test addon
+ const MockFilePicker = SpecialPowers.MockFilePicker;
+ MockFilePicker.init(window);
+ MockFilePicker.setFiles([file]);
+}
+/* exported prepareMockFilePicker */
+
+function promiseBackgroundContextEvent(extensionId, eventName) {
+ const { Management } = ChromeUtils.importESModule(
+ "resource://gre/modules/Extension.sys.mjs"
+ );
+
+ return new Promise(resolve => {
+ Management.on(eventName, function listener(_evtName, context) {
+ if (context.extension.id === extensionId) {
+ Management.off(eventName, listener);
+ resolve();
+ }
+ });
+ });
+}
+
+function promiseBackgroundContextLoaded(extensionId) {
+ return promiseBackgroundContextEvent(extensionId, "proxy-context-load");
+}
+/* exported promiseBackgroundContextLoaded */
+
+function promiseBackgroundContextUnloaded(extensionId) {
+ return promiseBackgroundContextEvent(extensionId, "proxy-context-unload");
+}
+/* exported promiseBackgroundContextUnloaded */
+
+async function assertBackgroundStatus(
+ extName,
+ { document, expectedStatus, targetElement }
+) {
+ const target = targetElement || findDebugTargetByText(extName, document);
+ const getBackgroundStatusElement = () =>
+ target.querySelector(".extension-backgroundscript__status");
+ await waitFor(
+ () =>
+ getBackgroundStatusElement()?.classList.contains(
+ `extension-backgroundscript__status--${expectedStatus}`
+ ),
+ `Wait ${extName} Background script status "${expectedStatus}" to be rendered`
+ );
+}
+/* exported assertBackgroundStatus */
+
+function getExtensionInstance(extensionId) {
+ const policy = WebExtensionPolicy.getByID(extensionId);
+ ok(policy, `Got a WebExtensionPolicy instance for ${extensionId}`);
+ ok(policy.extension, `Got an Extension class instance for ${extensionId}`);
+ return policy.extension;
+}
+/* exported getExtensionInstance */
+
+async function triggerExtensionEventPageIdleTimeout(extensionId) {
+ await getExtensionInstance(extensionId).terminateBackground();
+}
+/* exported triggerExtensionEventPageIdleTimeout */
+
+async function wakeupExtensionEventPage(extensionId) {
+ await getExtensionInstance(extensionId).wakeupBackground();
+}
+/* exported wakeupExtensionEventPage */
+
+function promiseTerminateBackgroundScriptIgnored(extensionId) {
+ const extension = getExtensionInstance(extensionId);
+ return new Promise(resolve => {
+ extension.once("background-script-suspend-ignored", resolve);
+ });
+}
+/* exported promiseTerminateBackgroundScriptIgnored */
+
+async function promiseBackgroundStatusUpdate(window) {
+ waitForDispatch(
+ window.AboutDebugging.store,
+ "EXTENSION_BGSCRIPT_STATUS_UPDATED"
+ );
+}
+/* exported promiseBackgroundStatusUpdate */
diff --git a/devtools/client/aboutdebugging/test/browser/helper-collapsibilities.js b/devtools/client/aboutdebugging/test/browser/helper-collapsibilities.js
new file mode 100644
index 0000000000..0f0d28da1d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/helper-collapsibilities.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const TARGET_PANES = [
+ {
+ title: "Temporary Extensions",
+ pref: "devtools.aboutdebugging.collapsibilities.temporaryExtension",
+ },
+ {
+ title: "Extensions",
+ pref: "devtools.aboutdebugging.collapsibilities.installedExtension",
+ },
+ {
+ title: "Tabs",
+ pref: "devtools.aboutdebugging.collapsibilities.tab",
+ },
+ {
+ title: "Service Workers",
+ pref: "devtools.aboutdebugging.collapsibilities.serviceWorker",
+ },
+ {
+ title: "Shared Workers",
+ pref: "devtools.aboutdebugging.collapsibilities.sharedWorker",
+ },
+ {
+ title: "Other Workers",
+ pref: "devtools.aboutdebugging.collapsibilities.otherWorker",
+ },
+];
+/* exported TARGET_PANES */
+
+function prepareCollapsibilitiesTest() {
+ // Make all collapsibilities to be expanded.
+ for (const { pref } of TARGET_PANES) {
+ Services.prefs.setBoolPref(pref, false);
+ }
+}
+/* exported prepareCollapsibilitiesTest */
+
+async function toggleCollapsibility(debugTargetPane) {
+ debugTargetPane.querySelector(".qa-debug-target-pane-title").click();
+ // Wait for animation of collapse/expand.
+ const animations = debugTargetPane.ownerDocument.getAnimations();
+ await Promise.all(animations.map(animation => animation.finished));
+}
+/* exported toggleCollapsibility */
+
+registerCleanupFunction(() => {
+ for (const { pref } of TARGET_PANES) {
+ Services.prefs.clearUserPref(pref);
+ }
+});
diff --git a/devtools/client/aboutdebugging/test/browser/helper-mocks.js b/devtools/client/aboutdebugging/test/browser/helper-mocks.js
new file mode 100644
index 0000000000..76fc414ae8
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/helper-mocks.js
@@ -0,0 +1,262 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from ../../../shared/test/shared-head.js */
+
+const MOCKS_ROOT = CHROME_URL_ROOT + "mocks/";
+/* import-globals-from mocks/helper-adb-mock.js */
+Services.scriptloader.loadSubScript(MOCKS_ROOT + "helper-adb-mock.js", this);
+/* import-globals-from mocks/helper-client-wrapper-mock.js */
+Services.scriptloader.loadSubScript(
+ MOCKS_ROOT + "helper-client-wrapper-mock.js",
+ this
+);
+/* import-globals-from mocks/helper-runtime-client-factory-mock.js */
+Services.scriptloader.loadSubScript(
+ MOCKS_ROOT + "helper-runtime-client-factory-mock.js",
+ this
+);
+
+const {
+ RUNTIMES,
+} = require("resource://devtools/client/aboutdebugging/src/constants.js");
+
+/**
+ * This wrapper around the mocks used in about:debugging tests provides helpers to
+ * quickly setup mocks for runtime tests involving USB, network or wifi runtimes that can
+ * are difficult to setup in a test environment.
+ */
+class Mocks {
+ constructor() {
+ // Setup the adb mock to rely on internal arrays.
+ this.adbMock = createAdbMock();
+ this.adbProcessMock = createAdbProcessMock();
+ this._usbRuntimes = [];
+ this._usbDevices = [];
+ this.adbMock.adb.getRuntimes = () => {
+ return this._usbRuntimes;
+ };
+ this.adbMock.adb.getDevices = () => {
+ const runtimeDevices = this._usbRuntimes.map(r => {
+ return { id: r.deviceId, name: r.deviceName };
+ });
+ return runtimeDevices.concat(this._usbDevices);
+ };
+
+ // adb.updateRuntimes should ultimately fire the "runtime-list-updated" event.
+ this.adbMock.adb.updateRuntimes = () => {
+ this.emitUSBUpdate();
+ };
+
+ this.adbMock.adb.isProcessStarted = () => true;
+
+ // Prepare a fake observer to be able to emit events from this mock.
+ this._observerMock = addObserverMock(this.adbMock.adb);
+
+ // Setup the runtime-client-factory mock to rely on the internal _clients map.
+ this.runtimeClientFactoryMock = createRuntimeClientFactoryMock();
+ this._clients = {
+ [RUNTIMES.NETWORK]: {},
+ [RUNTIMES.THIS_FIREFOX]: {},
+ [RUNTIMES.USB]: {},
+ };
+ this.runtimeClientFactoryMock.createClientForRuntime = runtime => {
+ return this._clients[runtime.type][runtime.id];
+ };
+
+ // Add a client for THIS_FIREFOX, since about:debugging will start on the This Firefox
+ // page.
+ this._thisFirefoxClient = createThisFirefoxClientMock();
+ this._clients[RUNTIMES.THIS_FIREFOX][RUNTIMES.THIS_FIREFOX] =
+ this._thisFirefoxClient;
+
+ // Enable mocks and remove them after the test.
+ this.enableMocks();
+ registerCleanupFunction(() => this.disableMocks());
+ }
+
+ get thisFirefoxClient() {
+ return this._thisFirefoxClient;
+ }
+
+ enableMocks() {
+ enableAdbMock(this.adbMock);
+ enableAdbProcessMock(this.adbProcessMock);
+ enableRuntimeClientFactoryMock(this.runtimeClientFactoryMock);
+ }
+
+ disableMocks() {
+ disableAdbMock();
+ disableAdbProcessMock();
+ disableRuntimeClientFactoryMock();
+
+ for (const host of Object.keys(this._clients[RUNTIMES.NETWORK])) {
+ this.removeNetworkRuntime(host);
+ }
+ }
+
+ createNetworkRuntime(host, runtimeInfo) {
+ const {
+ addNetworkLocation,
+ } = require("resource://devtools/client/aboutdebugging/src/modules/network-locations.js");
+ addNetworkLocation(host);
+
+ // Add a valid client that can be returned for this particular runtime id.
+ const mockNetworkClient = createClientMock();
+ mockNetworkClient.getDeviceDescription = () => {
+ return {
+ name: runtimeInfo.name || "TestBrand",
+ channel: runtimeInfo.channel || "release",
+ version: runtimeInfo.version || "1.0",
+ };
+ };
+ this._clients[RUNTIMES.NETWORK][host] = mockNetworkClient;
+
+ return mockNetworkClient;
+ }
+
+ removeNetworkRuntime(host) {
+ const {
+ removeNetworkLocation,
+ } = require("resource://devtools/client/aboutdebugging/src/modules/network-locations.js");
+ removeNetworkLocation(host);
+
+ delete this._clients[RUNTIMES.NETWORK][host];
+ }
+
+ emitUSBUpdate() {
+ this._observerMock.emit("runtime-list-updated");
+ }
+
+ /**
+ * Creates a USB runtime for which a client conenction can be established.
+ * @param {String} id
+ * The id of the runtime.
+ * @param {Object} optional object used to create the fake runtime & device
+ * - channel: {String} Release channel, for instance "release", "nightly"
+ * - clientWrapper: {ClientWrapper} optional ClientWrapper for this runtime
+ * - deviceId: {String} Device id
+ * - deviceName: {String} Device name
+ * - isFenix: {Boolean} set by ADB if the package name matches a Fenix package
+ * - name: {String} Application name, for instance "Firefox"
+ * - shortName: {String} Short name for the device
+ * - socketPath: {String} (should only be used for connecting, so not here)
+ * - version: {String} Version, for instance "63.0a"
+ * - versionName: {String} Version return by ADB "63.0a"
+ * @return {Object} Returns the mock client created for this runtime so that methods
+ * can be overridden on it.
+ */
+ createUSBRuntime(id, runtimeInfo = {}) {
+ // Add a new runtime to the list of scanned runtimes.
+ this._usbRuntimes.push({
+ deviceId: runtimeInfo.deviceId || "test device id",
+ deviceName: runtimeInfo.deviceName || "test device name",
+ id,
+ isFenix: runtimeInfo.isFenix,
+ shortName: runtimeInfo.shortName || "testshort",
+ socketPath: runtimeInfo.socketPath || "test/path",
+ versionName: runtimeInfo.versionName || "1.0",
+ });
+
+ // Add a valid client that can be returned for this particular runtime id.
+ let mockUsbClient = runtimeInfo.clientWrapper;
+ if (mockUsbClient) {
+ const originalGetDeviceDescription =
+ mockUsbClient.getDeviceDescription.bind(mockUsbClient);
+ mockUsbClient.getDeviceDescription = async () => {
+ const deviceDescription = await originalGetDeviceDescription();
+ return {
+ channel: runtimeInfo.channel || deviceDescription.channel,
+ name: runtimeInfo.name || deviceDescription.name,
+ version: runtimeInfo.version || deviceDescription.version,
+ };
+ };
+ } else {
+ // If no clientWrapper was provided, create a mock client here.
+ mockUsbClient = createClientMock();
+ mockUsbClient.getDeviceDescription = () => {
+ return {
+ channel: runtimeInfo.channel || "release",
+ name: runtimeInfo.name || "TestBrand",
+ version: runtimeInfo.version || "1.0",
+ };
+ };
+ }
+
+ this._clients[RUNTIMES.USB][id] = mockUsbClient;
+
+ return mockUsbClient;
+ }
+
+ removeUSBRuntime(id) {
+ this._usbRuntimes = this._usbRuntimes.filter(runtime => runtime.id !== id);
+ delete this._clients[RUNTIMES.USB][id];
+ }
+
+ addDevice(deviceId, deviceName) {
+ this._usbDevices.push({
+ id: deviceId,
+ name: deviceName,
+ });
+ }
+
+ removeDevice(deviceId) {
+ this._usbDevices = this._usbDevices.filter(d => {
+ return d.id !== deviceId;
+ });
+ }
+
+ removeRuntime(id) {
+ if (this._clients[RUNTIMES.USB][id]) {
+ this.removeUSBRuntime(id);
+ } else if (this._clients[RUNTIMES.NETWORK][id]) {
+ this.removeNetworkRuntime(id);
+ }
+ }
+}
+/* exported Mocks */
+
+const silenceWorkerUpdates = function () {
+ const {
+ removeMockedModule,
+ setMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+
+ const mock = {
+ WorkersListener: () => {
+ return {
+ addListener: () => {},
+ removeListener: () => {},
+ };
+ },
+ };
+ setMockedModule(mock, "devtools/client/shared/workers-listener");
+
+ registerCleanupFunction(() => {
+ removeMockedModule("devtools/client/shared/workers-listener");
+ });
+};
+/* exported silenceWorkerUpdates */
+
+async function createLocalClientWrapper() {
+ info("Create a local DevToolsClient");
+ const {
+ DevToolsServer,
+ } = require("resource://devtools/server/devtools-server.js");
+ const {
+ DevToolsClient,
+ } = require("resource://devtools/client/devtools-client.js");
+ const {
+ ClientWrapper,
+ } = require("resource://devtools/client/aboutdebugging/src/modules/client-wrapper.js");
+
+ DevToolsServer.init();
+ DevToolsServer.registerAllActors();
+ const client = new DevToolsClient(DevToolsServer.connectPipe());
+
+ await client.connect();
+ return new ClientWrapper(client);
+}
+/* exported createLocalClientWrapper */
diff --git a/devtools/client/aboutdebugging/test/browser/helper-real-usb.js b/devtools/client/aboutdebugging/test/browser/helper-real-usb.js
new file mode 100644
index 0000000000..dd6c8c263d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/helper-real-usb.js
@@ -0,0 +1,54 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from helper-adb.js */
+Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-adb.js", this);
+
+async function getExpectedRuntime() {
+ const runtimes = await getExpectedRuntimeAll();
+ return runtimes[0];
+}
+/* exported getExpectedRuntime */
+
+async function getExpectedRuntimeAll() {
+ const runtimesPath = _getExpectedRuntimesPath();
+ const currentPath = Services.env.get("PWD");
+ const path = `${currentPath}/${runtimesPath}`;
+ info(`Load ${path}`);
+ const buffer = await IOUtils.read(path);
+ const data = new TextDecoder().decode(buffer);
+ return JSON.parse(data);
+}
+/* exported getExpectedRuntimeAll */
+
+function isAvailable() {
+ return !!_getExpectedRuntimesPath();
+}
+/* exported isAvailable */
+
+async function openAboutDebuggingWithADB() {
+ const { document, tab, window } = await openAboutDebugging();
+
+ await pushPref(
+ "devtools.remote.adb.extensionURL",
+ CHROME_URL_ROOT + "resources/test-adb-extension/adb-extension-#OS#.xpi"
+ );
+ await checkAdbNotRunning();
+
+ const {
+ adbAddon,
+ } = require("resource://devtools/client/shared/remote-debugging/adb/adb-addon.js");
+ adbAddon.install("internal");
+ const usbStatusElement = document.querySelector(".qa-sidebar-usb-status");
+ await waitUntil(() => usbStatusElement.textContent.includes("USB enabled"));
+ await waitForAdbStart();
+
+ return { document, tab, window };
+}
+/* exported openAboutDebuggingWithADB */
+
+function _getExpectedRuntimesPath() {
+ return Services.env.get("USB_RUNTIMES");
+}
diff --git a/devtools/client/aboutdebugging/test/browser/helper-serviceworker.js b/devtools/client/aboutdebugging/test/browser/helper-serviceworker.js
new file mode 100644
index 0000000000..e57b62b7eb
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/helper-serviceworker.js
@@ -0,0 +1,111 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from head.js */
+
+/**
+ * Temporarily flip all the preferences necessary for service worker testing.
+ */
+async function enableServiceWorkerDebugging() {
+ // Enable service workers.
+ await pushPref("dom.serviceWorkers.enabled", true);
+
+ // Accept workers from mochitest's http (normally only available in https).
+ await pushPref("dom.serviceWorkers.testing.enabled", true);
+
+ // Force single content process. Necessary until sw e10s refactor is done (Bug 1231208).
+ await pushPref("dom.ipc.processCount", 1);
+ Services.ppmm.releaseCachedProcesses();
+}
+/* exported enableServiceWorkerDebugging */
+
+/**
+ * Helper to listen once on a message sent using postMessage from the provided tab.
+ *
+ * @param {Tab} tab
+ * The tab on which the message will be received.
+ * @param {String} message
+ * The name of the expected message.
+ */
+function onServiceWorkerMessage(tab, message) {
+ info("Make the test page notify us when the service worker sends a message.");
+ return SpecialPowers.spawn(
+ tab.linkedBrowser,
+ [message],
+ function (messageChild) {
+ return new Promise(resolve => {
+ const win = content.wrappedJSObject;
+ win.navigator.serviceWorker.addEventListener(
+ "message",
+ function (event) {
+ if (event.data == messageChild) {
+ resolve();
+ }
+ }
+ );
+ });
+ }
+ );
+}
+/* exported onServiceWorkerMessage */
+
+async function _waitForServiceWorkerStatus(workerText, status, document) {
+ await waitUntil(() => {
+ const target = findDebugTargetByText(workerText, document);
+ const statusElement = target && target.querySelector(".qa-worker-status");
+ return statusElement && statusElement.textContent === status;
+ });
+
+ return findDebugTargetByText(workerText, document);
+}
+/* exported waitForServiceWorkerRunning */
+
+async function waitForServiceWorkerStopped(workerText, document) {
+ return _waitForServiceWorkerStatus(workerText, "Stopped", document);
+}
+/* exported waitForServiceWorkerStopped */
+
+async function waitForServiceWorkerRunning(workerText, document) {
+ return _waitForServiceWorkerStatus(workerText, "Running", document);
+}
+/* exported waitForServiceWorkerRunning */
+
+async function waitForServiceWorkerRegistering(workerText, document) {
+ return _waitForServiceWorkerStatus(workerText, "Registering", document);
+}
+/* exported waitForServiceWorkerRegistering */
+
+async function waitForRegistration(tab) {
+ info("Wait until the registration appears on the window");
+ const swBrowser = tab.linkedBrowser;
+ await asyncWaitUntil(async () =>
+ SpecialPowers.spawn(swBrowser, [], async function () {
+ return !!(await content.wrappedJSObject.getRegistration());
+ })
+ );
+}
+/* exported waitForRegistration */
+
+/**
+ * Unregister the service worker from the content page. The content page should define
+ * `getRegistration` to allow this helper to retrieve the service worker registration that
+ * should be unregistered.
+ *
+ * @param {Tab} tab
+ * The tab on which the service worker should be removed.
+ */
+async function unregisterServiceWorker(tab) {
+ return SpecialPowers.spawn(tab.linkedBrowser, [], function () {
+ const win = content.wrappedJSObject;
+ // Check that the content page defines getRegistration.
+ is(
+ typeof win.getRegistration,
+ "function",
+ "getRegistration is a valid function"
+ );
+ win.getRegistration().unregister();
+ });
+}
+/* exported unregisterServiceWorker */
diff --git a/devtools/client/aboutdebugging/test/browser/helper-telemetry.js b/devtools/client/aboutdebugging/test/browser/helper-telemetry.js
new file mode 100644
index 0000000000..228f01aff3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/helper-telemetry.js
@@ -0,0 +1,115 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/* import-globals-from head.js */
+
+/**
+ * Reset all telemetry events.
+ */
+function setupTelemetryTest() {
+ // Let's reset the counts.
+ Services.telemetry.clearEvents();
+
+ // Ensure no events have been logged
+ const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
+ const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
+ ok(!snapshot.parent, "No events have been logged for the main process");
+}
+/* exported setupTelemetryTest */
+
+/**
+ * Check that the logged telemetry events exactly match the array of expected events.
+ * Will compare the number of events, the event methods, and the event extras including
+ * the about:debugging session id.
+ */
+function checkTelemetryEvents(expectedEvents, expectedSessionId) {
+ const evts = readAboutDebuggingEvents();
+ is(evts.length, expectedEvents.length, "Expected number of events");
+
+ function _eventHasExpectedExtras(e, expectedEvent) {
+ const expectedExtras = Object.keys(expectedEvent.extras);
+ return expectedExtras.every(extra => {
+ return e.extras[extra] === expectedEvent.extras[extra];
+ });
+ }
+
+ for (const expectedEvent of expectedEvents) {
+ const sameMethodEvents = evts.filter(
+ e => e.method === expectedEvent.method
+ );
+ ok(
+ !!sameMethodEvents.length,
+ "Found event for method: " + expectedEvent.method
+ );
+
+ const sameExtrasEvents = sameMethodEvents.filter(e =>
+ _eventHasExpectedExtras(e, expectedEvent)
+ );
+ ok(
+ sameExtrasEvents.length === 1,
+ "Found exactly one event matching the expected extras"
+ );
+ if (sameExtrasEvents.length === 0) {
+ info(JSON.stringify(sameMethodEvents));
+ }
+ is(
+ sameExtrasEvents[0].extras.session_id,
+ expectedSessionId,
+ "Select page event has the expected session"
+ );
+ }
+
+ return evts;
+}
+/* exported checkTelemetryEvents */
+
+/**
+ * Retrieve the session id from an "open" event.
+ * Note that calling this will "clear" all the events.
+ */
+function getOpenEventSessionId() {
+ const openEvents = readAboutDebuggingEvents().filter(
+ e => e.method === "open_adbg"
+ );
+ ok(!!openEvents[0], "Found an about:debugging open event");
+ return openEvents[0].extras.session_id;
+}
+/* exported getOpenEventSessionId */
+
+/**
+ * Read all the pending events that have "aboutdebugging" as their object property.
+ * WARNING: Calling this method also flushes/clears the events.
+ */
+function readAboutDebuggingEvents() {
+ const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
+ // Retrieve and clear telemetry events.
+ const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
+ // about:debugging events are logged in the parent process
+ const parentEvents = snapshot.parent || [];
+
+ return parentEvents
+ .map(_toEventObject)
+ .filter(e => e.object === "aboutdebugging");
+}
+/* exported getLoggedEvents */
+
+/**
+ * The telemetry event data structure is simply an array. This helper remaps the array to
+ * an object with more user friendly properties.
+ */
+function _toEventObject(rawEvent) {
+ return {
+ // Category is typically devtools.main for us.
+ category: rawEvent[1],
+ // Method is the event's name (eg open, select_page etc...)
+ method: rawEvent[2],
+ // Object will usually be aboutdebugging for our tests
+ object: rawEvent[3],
+ // Value is usually empty for devtools events
+ value: rawEvent[4],
+ // Extras contain all the details of the event, including the session_id.
+ extras: rawEvent[5],
+ };
+}
diff --git a/devtools/client/aboutdebugging/test/browser/mocks/helper-adb-mock.js b/devtools/client/aboutdebugging/test/browser/mocks/helper-adb-mock.js
new file mode 100644
index 0000000000..f02ca02ee3
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/mocks/helper-adb-mock.js
@@ -0,0 +1,137 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Setup the loader to return the provided mock object instead of the regular adb module.
+ *
+ * @param {Object}
+ * mock should implement the following methods:
+ * - registerListener(listener)
+ * - getRuntimes()
+ * - getDevices()
+ * - updateRuntimes()
+ * - unregisterListener(listener)
+ */
+function enableAdbMock(mock) {
+ const {
+ setMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+ setMockedModule(mock, "devtools/client/shared/remote-debugging/adb/adb");
+}
+/* exported enableAdbMock */
+
+/**
+ * Update the loader to clear the mock entry for the adb module.
+ */
+function disableAdbMock() {
+ const {
+ removeMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+ removeMockedModule("devtools/client/shared/remote-debugging/adb/adb");
+}
+/* exported disableAdbMock */
+
+/**
+ * Creates a simple mock version for adb, implementing all the expected methods
+ * with empty placeholders.
+ */
+function createAdbMock() {
+ const adbMock = {};
+ adbMock.registerListener = function (listener) {
+ console.log("MOCKED METHOD registerListener");
+ };
+
+ adbMock.getRuntimes = function () {
+ console.log("MOCKED METHOD getRuntimes");
+ };
+
+ adbMock.getDevices = function () {
+ console.log("MOCKED METHOD getDevices");
+ };
+
+ adbMock.updateRuntimes = function () {
+ console.log("MOCKED METHOD updateRuntimes");
+ };
+
+ adbMock.unregisterListener = function (listener) {
+ console.log("MOCKED METHOD unregisterListener");
+ };
+
+ adbMock.once = function () {
+ console.log("MOCKED METHOD once");
+ };
+
+ adbMock.isProcessStarted = function () {
+ console.log("MOCKED METHOD isProcessStarted");
+ };
+
+ return { adb: adbMock };
+}
+/* exported createAdbMock */
+
+/**
+ * The adb module allows to observe runtime updates. To simulate this behaviour
+ * the easiest is to use an EventEmitter-decorated object that can accept listeners and
+ * can emit events from the test.
+ *
+ * This method will update the registerListener method of the provided
+ * usbRuntimesMock in order to add listeners to a mockObserver, and returns said observer
+ * so that the test can emit "runtime-list-updated" when needed.
+ */
+function addObserverMock(adbMock) {
+ const EventEmitter = require("resource://devtools/shared/event-emitter.js");
+
+ const observerMock = {};
+ EventEmitter.decorate(observerMock);
+ adbMock.registerListener = function (listener) {
+ console.log("MOCKED METHOD registerListener with mock scanner");
+ observerMock.on("runtime-list-updated", listener);
+ };
+
+ // NOTE FOR REVIEW: Instead of emitting "runtime-list-updated" events in the test,
+ // this mock could have a emitObservedEvent method, that would just emit the correct
+ // event. This way if the event name changes, everything remains contained in this
+ // method.
+
+ return observerMock;
+}
+/* exported addObserverMock */
+
+function createAdbProcessMock() {
+ const EventEmitter = require("resource://devtools/shared/event-emitter.js");
+
+ const mock = {};
+ EventEmitter.decorate(mock);
+
+ mock.ready = false;
+
+ mock.start = async () => {
+ console.log("MOCKED METHOD start");
+ mock.ready = true;
+ mock.emit("adb-ready");
+ };
+
+ return { adbProcess: mock };
+}
+/* exported createAdbProcessMock */
+
+function enableAdbProcessMock(mock) {
+ const {
+ setMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+ setMockedModule(
+ mock,
+ "devtools/client/shared/remote-debugging/adb/adb-process"
+ );
+}
+/* exported enableAdbProcessMock */
+
+function disableAdbProcessMock() {
+ const {
+ removeMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+ removeMockedModule("devtools/client/shared/remote-debugging/adb/adb-process");
+}
+/* exported disableAdbProcessMock */
diff --git a/devtools/client/aboutdebugging/test/browser/mocks/helper-client-wrapper-mock.js b/devtools/client/aboutdebugging/test/browser/mocks/helper-client-wrapper-mock.js
new file mode 100644
index 0000000000..5748904bff
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/mocks/helper-client-wrapper-mock.js
@@ -0,0 +1,138 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict"; // defined in head.js
+
+/* global CHROME_URL_ROOT */
+
+// This head file contains helpers to create mock versions of the ClientWrapper class
+// defined at devtools/client/aboutdebugging/src/modules/client-wrapper.js .
+
+const {
+ RUNTIME_PREFERENCE,
+} = require("resource://devtools/client/aboutdebugging/src/constants.js");
+
+// Sensible default values for runtime preferences that should be usable in most
+// situations
+const DEFAULT_PREFERENCES = {
+ [RUNTIME_PREFERENCE.CONNECTION_PROMPT]: true,
+ [RUNTIME_PREFERENCE.PERMANENT_PRIVATE_BROWSING]: false,
+ [RUNTIME_PREFERENCE.SERVICE_WORKERS_ENABLED]: true,
+};
+
+// Creates a simple mock ClientWrapper.
+function createClientMock() {
+ const EventEmitter = require("resource://devtools/shared/event-emitter.js");
+ const eventEmitter = {};
+ EventEmitter.decorate(eventEmitter);
+
+ return {
+ // add a reference to the internal event emitter so that consumers can fire client
+ // events.
+ _eventEmitter: eventEmitter,
+ _preferences: {},
+ contentProcessFronts: [],
+ serviceWorkerRegistrationFronts: [],
+ once: (evt, listener) => {
+ eventEmitter.once(evt, listener);
+ },
+ on: (evt, listener) => {
+ eventEmitter.on(evt, listener);
+ },
+ off: (evt, listener) => {
+ eventEmitter.off(evt, listener);
+ },
+ client: {
+ once: (evt, listener) => {
+ eventEmitter.once(evt, listener);
+ },
+ on: (evt, listener) => {
+ eventEmitter.on(evt, listener);
+ },
+ off: (evt, listener) => {
+ eventEmitter.off(evt, listener);
+ },
+ },
+ // no-op
+ close: () => {},
+ // client is not closed
+ isClosed: () => false,
+ // no-op
+ connect: () => {},
+ // no-op
+ getDeviceDescription: () => {},
+ // Return default preference value or null if no match.
+ getPreference(prefName) {
+ if (prefName in this._preferences) {
+ return this._preferences[prefName];
+ }
+ if (prefName in DEFAULT_PREFERENCES) {
+ return DEFAULT_PREFERENCES[prefName];
+ }
+ return null;
+ },
+ // no-op
+ createRootResourceCommand: () => {
+ return {
+ watchResources: () => new Promise(r => r()),
+ unwatchResources: () => {},
+ };
+ },
+ // Empty array of addons
+ listAddons: () => [],
+ // Empty array of processes
+ listProcesses: () => [],
+ // Empty array of tabs
+ listTabs: () => [],
+ // Empty arrays of workers
+ listWorkers: () => ({
+ otherWorkers: [],
+ serviceWorkers: [],
+ sharedWorkers: [],
+ }),
+ // no-op
+ getMainProcess: () => {},
+ // no-op
+ getFront: () => {},
+ // stores the preference locally (doesn't update about:config)
+ setPreference(prefName, value) {
+ this._preferences[prefName] = value;
+ },
+ getPerformancePanelUrl: () => CHROME_URL_ROOT + "empty.html",
+ loadPerformanceProfiler: () => {},
+ // Valid compatibility report
+ checkVersionCompatibility: () => {
+ const {
+ COMPATIBILITY_STATUS,
+ } = require("resource://devtools/client/shared/remote-debugging/version-checker.js");
+ return { status: COMPATIBILITY_STATUS.COMPATIBLE };
+ },
+ // No traits by default but allow updates.
+ traits: {},
+ };
+}
+
+// Create a ClientWrapper mock that can be used to replace the this-firefox runtime.
+function createThisFirefoxClientMock() {
+ const mockThisFirefoxDescription = {
+ name: "Firefox",
+ channel: "nightly",
+ version: "63.0",
+ };
+
+ // Create a fake about:debugging tab because our test helper openAboutDebugging
+ // waits until about:debugging is displayed in the list of tabs.
+ const mockAboutDebuggingTab = {
+ retrieveFavicon: () => {},
+ outerWindowID: 0,
+ traits: {},
+ url: "about:debugging",
+ };
+
+ const mockThisFirefoxClient = createClientMock();
+ mockThisFirefoxClient.listTabs = () => [mockAboutDebuggingTab];
+ mockThisFirefoxClient.getDeviceDescription = () => mockThisFirefoxDescription;
+
+ return mockThisFirefoxClient;
+}
+/* exported createThisFirefoxClientMock */
diff --git a/devtools/client/aboutdebugging/test/browser/mocks/helper-runtime-client-factory-mock.js b/devtools/client/aboutdebugging/test/browser/mocks/helper-runtime-client-factory-mock.js
new file mode 100644
index 0000000000..b74c229fcf
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/mocks/helper-runtime-client-factory-mock.js
@@ -0,0 +1,76 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+/**
+ * Setup the loader to return the provided mock object instead of the regular
+ * runtime-client-factory module.
+ *
+ * @param {Object}
+ * mock should implement the following methods:
+ * - createClientForRuntime(runtime)
+ */
+function enableRuntimeClientFactoryMock(mock) {
+ const {
+ setMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+ setMockedModule(
+ mock,
+ "devtools/client/aboutdebugging/src/modules/runtime-client-factory"
+ );
+
+ // When using a mocked client, we should not attempt to check default
+ // preferences.
+ mockRuntimeDefaultPreferences();
+}
+/* exported enableRuntimeClientFactoryMock */
+
+const mockRuntimeDefaultPreferences = function () {
+ const {
+ removeMockedModule,
+ setMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+
+ const mock = {
+ setDefaultPreferencesIfNeeded: () => {},
+ DEFAULT_PREFERENCES: [],
+ };
+ setMockedModule(
+ mock,
+ "devtools/client/aboutdebugging/src/modules/runtime-default-preferences"
+ );
+
+ registerCleanupFunction(() => {
+ removeMockedModule(
+ "devtools/client/aboutdebugging/src/modules/runtime-default-preferences"
+ );
+ });
+};
+
+/**
+ * Update the loader to clear the mock entry for the runtime-client-factory module.
+ */
+function disableRuntimeClientFactoryMock() {
+ const {
+ removeMockedModule,
+ } = require("resource://devtools/shared/loader/browser-loader-mocks.js");
+ removeMockedModule(
+ "devtools/client/aboutdebugging/src/modules/runtime-client-factory"
+ );
+}
+/* exported disableRuntimeClientFactoryMock */
+
+/**
+ * Creates a simple mock version for runtime-client-factory, implementing all the expected
+ * methods with empty placeholders.
+ */
+function createRuntimeClientFactoryMock() {
+ const RuntimeClientFactoryMock = {};
+ RuntimeClientFactoryMock.createClientForRuntime = function (runtime) {
+ console.log("MOCKED METHOD createClientForRuntime");
+ };
+
+ return RuntimeClientFactoryMock;
+}
+/* exported createRuntimeClientFactoryMock */
diff --git a/devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-json/manifest.json b/devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-json/manifest.json
new file mode 100644
index 0000000000..4ab10b4de7
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-json/manifest.json
@@ -0,0 +1 @@
+this is not valid json
diff --git a/devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-property/manifest.json b/devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-property/manifest.json
new file mode 100644
index 0000000000..992818bd77
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/bad-extensions/invalid-property/manifest.json
@@ -0,0 +1,23 @@
+{
+ "manifest_version": 2,
+ "name": "test-invalid-extension",
+ "version": "1",
+ "description": "the name says it all",
+ "permissions": ["*://*.foo.com/*", "alarms", "notifications", "tabs"],
+ "background": {
+ "scripts": ["background.js"]
+ },
+ "content_scripts": [
+ {
+ "matches": "*://*.foo.com/*",
+ "js": ["content.js"]
+ }
+ ],
+ "browser_action": {
+ "default_icon": {
+ "32": "home.svg"
+ },
+ "default_title": "foobarbaz (v1)",
+ "browser_style": true
+ }
+}
diff --git a/devtools/client/aboutdebugging/test/browser/resources/doc_aboutdebugging_devtoolstoolbox_breakpoint.html b/devtools/client/aboutdebugging/test/browser/resources/doc_aboutdebugging_devtoolstoolbox_breakpoint.html
new file mode 100644
index 0000000000..bb28556775
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/doc_aboutdebugging_devtoolstoolbox_breakpoint.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>BREAKPOINT TEST PAGE</title>
+</head>
+<body>
+ <script type="text/javascript" src="script_aboutdebugging_devtoolstoolbox_breakpoint.js"></script>
+</body>
+</html>
diff --git a/devtools/client/aboutdebugging/test/browser/resources/packaged-extension/packaged-extension.xpi b/devtools/client/aboutdebugging/test/browser/resources/packaged-extension/packaged-extension.xpi
new file mode 100644
index 0000000000..c1c7af9600
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/packaged-extension/packaged-extension.xpi
Binary files differ
diff --git a/devtools/client/aboutdebugging/test/browser/resources/real/usb-runtimes-sample.json b/devtools/client/aboutdebugging/test/browser/resources/real/usb-runtimes-sample.json
new file mode 100644
index 0000000000..bce334e95a
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/real/usb-runtimes-sample.json
@@ -0,0 +1,14 @@
+[
+ {
+ "sidebarInfo": {
+ "deviceName": "Pixel 2",
+ "shortName": "Firefox Nightly"
+ },
+ "runtimeDetails": {
+ "info": {
+ "name": "Mozilla Nightly",
+ "version": "64.0a1"
+ }
+ }
+ }
+]
diff --git a/devtools/client/aboutdebugging/test/browser/resources/script_aboutdebugging_devtoolstoolbox_breakpoint.js b/devtools/client/aboutdebugging/test/browser/resources/script_aboutdebugging_devtoolstoolbox_breakpoint.js
new file mode 100644
index 0000000000..99401016e4
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/script_aboutdebugging_devtoolstoolbox_breakpoint.js
@@ -0,0 +1,12 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// Random method on which a breakpoint will be set from the DevTools UI in the
+// test.
+window.testMethod = function () {
+ const a = 1;
+ const b = 2;
+ return a + b;
+};
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.html b/devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.html
new file mode 100644
index 0000000000..98d3bffd95
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.html
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>Service worker controlled</title>
+</head>
+<body>
+<script type="text/javascript">
+
+"use strict";
+
+let registration;
+
+const registerServiceWorker = async function() {
+ try {
+ registration = await navigator.serviceWorker.register("controlled-sw.js");
+ dump("Controlled service worker registered\n");
+ } catch (e) {
+ dump("Controlled service worker not registered: " + e + "\n");
+ }
+};
+
+// Helper called from helper-serviceworker.js to unregister the service worker.
+window.getRegistration = function() {
+ return registration;
+};
+
+// Called from browser_aboutdebugging_serviceworker_status.js
+window.installServiceWorker = function() {
+ registration.installing.postMessage("install-service-worker");
+};
+
+// Register the service worker.
+registerServiceWorker();
+
+</script>
+</body>
+</html>
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.js b/devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.js
new file mode 100644
index 0000000000..0a6d9cfdc6
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/controlled-sw.js
@@ -0,0 +1,31 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* eslint-env worker */
+
+"use strict";
+
+// Copied from shared-head.js
+function waitUntil(predicate, interval = 10) {
+ if (predicate()) {
+ return Promise.resolve(true);
+ }
+ return new Promise(resolve => {
+ setTimeout(function () {
+ waitUntil(predicate, interval).then(() => resolve(true));
+ }, interval);
+ });
+}
+
+// This flag will be flipped from controlled-sw.html::installServiceWorker()
+let canInstall = false;
+self.addEventListener("message", function (event) {
+ if (event.data === "install-service-worker") {
+ canInstall = true;
+ }
+});
+
+// Wait for the canInstall flag to be flipped before completing the install.
+self.addEventListener("install", function (event) {
+ event.waitUntil(waitUntil(() => canInstall));
+});
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.html b/devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.html
new file mode 100644
index 0000000000..ab862743a7
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>Service worker test</title>
+</head>
+<body>
+<script type="text/javascript">
+"use strict";
+
+let registration;
+
+const registerServiceWorker = async function() {
+ try {
+ registration = await navigator.serviceWorker.register("empty-sw.js");
+ dump("Empty service worker registered\n");
+ } catch (e) {
+ dump("Empty service worker not registered: " + e + "\n");
+ }
+};
+
+// Helper called from helper-serviceworker.js to unregister the service worker.
+window.getRegistration = function() {
+ return registration;
+};
+// Register the service worker.
+registerServiceWorker();
+</script>
+</body>
+</html>
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.js b/devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.js
new file mode 100644
index 0000000000..1e7226402c
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/empty-sw.js
@@ -0,0 +1 @@
+// Empty, just test registering.
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.html b/devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.html
new file mode 100644
index 0000000000..a1bb218341
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.html
@@ -0,0 +1,30 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>Service worker test</title>
+</head>
+<body>
+<script type="text/javascript">
+"use strict";
+
+let registration;
+
+const registerServiceWorker = async function() {
+ try {
+ registration = await navigator.serviceWorker.register("fetch-sw.js");
+ dump("Empty service worker registered\n");
+ } catch (e) {
+ dump("Empty service worker not registered: " + e + "\n");
+ }
+};
+
+// Helper called from helper-serviceworker.js to unregister the service worker.
+window.getRegistration = function() {
+ return registration;
+};
+// Register the service worker.
+registerServiceWorker();
+</script>
+</body>
+</html>
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.js b/devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.js
new file mode 100644
index 0000000000..de6ee1fb32
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/fetch-sw.js
@@ -0,0 +1,6 @@
+"use strict";
+
+// Bug 1328293
+self.onfetch = function (event) {
+ // do nothing.
+};
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html b/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html
new file mode 100644
index 0000000000..bf5b0b0b0a
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.html
@@ -0,0 +1,61 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="UTF-8">
+ <title>Service worker push test</title>
+</head>
+<body>
+<script type="text/javascript">
+
+"use strict";
+
+let registration;
+let subscription;
+
+const registerServiceWorker = async function() {
+ const perm = { type: "desktop-notification", allow: true, context: document };
+ await SpecialPowers.pushPermissions([perm]);
+
+ try {
+ registration = await navigator.serviceWorker.register("push-sw.js");
+ dump("Push service worker registered\n");
+ } catch (e) {
+ dump("Push service worker not registered: " + e + "\n");
+ }
+};
+
+// Helper called from helper-serviceworker.js to unregister the service worker.
+window.getRegistration = function() {
+ return registration;
+};
+
+// Helper called from browser_aboutdebugging_serviceworker_pushservice_url.js
+window.subscribeToPush = async function() {
+ try {
+ subscription = await registration.pushManager.subscribe();
+ dump("SW subscribed to push: " + subscription.endpoint + "\n");
+ } catch (e) {
+ dump("SW not subscribed to push: " + e + "\n");
+ }
+};
+
+// Helper called from browser_aboutdebugging_serviceworker_pushservice_url.js
+window.unsubscribeToPush = async function() {
+ subscription.unsubscribe();
+};
+
+// Expose a promise to wait until the service worker is claimed.
+window.onSwClaimed = new Promise(resolve => {
+ navigator.serviceWorker.addEventListener("message", function(event) {
+ if (event.data == "sw-claimed") {
+ resolve();
+ }
+ });
+});
+
+// Register the service worker.
+registerServiceWorker();
+
+</script>
+</body>
+</html>
diff --git a/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.js b/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.js
new file mode 100644
index 0000000000..1231697ddd
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/service-workers/push-sw.js
@@ -0,0 +1,35 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* eslint-env worker */
+/* global clients */
+
+"use strict";
+
+// Send a message to all controlled windows.
+function postMessage(message) {
+ return clients.matchAll().then(function (clientlist) {
+ clientlist.forEach(function (client) {
+ client.postMessage(message);
+ });
+ });
+}
+
+// Don't wait for the next page load to become the active service worker.
+self.addEventListener("install", function (event) {
+ event.waitUntil(self.skipWaiting());
+});
+
+// Claim control over the currently open test page when activating.
+self.addEventListener("activate", function (event) {
+ event.waitUntil(
+ self.clients.claim().then(function () {
+ return postMessage("sw-claimed");
+ })
+ );
+});
+
+// Forward all "push" events to the controlled window.
+self.addEventListener("push", function (event) {
+ event.waitUntil(postMessage("sw-pushed"));
+});
diff --git a/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux.xpi b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux.xpi
new file mode 100644
index 0000000000..56054c341c
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux.xpi
Binary files differ
diff --git a/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux64.xpi b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux64.xpi
new file mode 100644
index 0000000000..9cd737b017
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-linux64.xpi
Binary files differ
diff --git a/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-mac64.xpi b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-mac64.xpi
new file mode 100644
index 0000000000..5af9bc963d
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-mac64.xpi
Binary files differ
diff --git a/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-win32.xpi b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-win32.xpi
new file mode 100644
index 0000000000..0c10c8502c
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/test-adb-extension/adb-extension-win32.xpi
Binary files differ
diff --git a/devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/manifest.json b/devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/manifest.json
new file mode 100644
index 0000000000..c62b2ddbd6
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/manifest.json
@@ -0,0 +1,13 @@
+{
+ "manifest_version": 2,
+ "name": "test-temporary-extension",
+ "version": "1.0",
+ "browser_specific_settings": {
+ "gecko": {
+ "id": "test-temporary-extension@mozilla.org"
+ }
+ },
+ "background": {
+ "scripts": ["script.js"]
+ }
+}
diff --git a/devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/script.js b/devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/script.js
new file mode 100644
index 0000000000..02d5604c3a
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/resources/test-temporary-extension/script.js
@@ -0,0 +1,8 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* eslint-env browser */
+
+"use strict";
+
+document.body.innerText = "Background Page Body Test Content";
diff --git a/devtools/client/aboutdebugging/test/browser/test-tab-favicons.html b/devtools/client/aboutdebugging/test/browser/test-tab-favicons.html
new file mode 100644
index 0000000000..35954f67a1
--- /dev/null
+++ b/devtools/client/aboutdebugging/test/browser/test-tab-favicons.html
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Favicon tab</title>
+ <link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAATklEQVRYhe3SIQ4AIBADwf7/04elBAtrVlSduGnSTDJ7cuT1PQJwwO+Hl7sAGAA07gjAAfgIBeAAoHFHAA7ARygABwCNOwJwAD5CATRgAYXh+kypw86nAAAAAElFTkSuQmCC">
+ <head>
+ <body>Some page with a favicon</body>
+</html>