CINXE.COM
XPCShell tests — Firefox Source Docs documentation
<!doctype html> <html class="writer-html5" lang="en" data-content_root="../../"> <head> <base href="https://firefox-source-docs.mozilla.org/testing/xpcshell/index.html"> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>XPCShell tests — Firefox Source Docs documentation</title> <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=fa44fd50"> <link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094"> <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css?v=fd3f3429"> <link rel="stylesheet" type="text/css" href="../../_static/copybutton.css?v=76b2166b"> <link rel="stylesheet" type="text/css" href="../../_static/custom_theme.css?v=dc5ed815"> <link rel="stylesheet" type="text/css" href="../../_static/design-style.1e8bd061cd6da7fc9cf755528e8ffc24.min.css?v=0a3b3ea7"> <link rel="shortcut icon" href="../../_static/firefox.ico"><!--[if lt IE 9]> <script src="../../_static/js/html5shiv.min.js"></script> <![endif]--> <script src="../../_static/jquery.js?v=5d32c60e"></script> <script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> <script src="../../_static/documentation_options.js?v=5929fcd5"></script> <script src="../../_static/doctools.js?v=9a2dae69"></script> <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script> <script src="../../_static/clipboard.min.js?v=a7894cd8"></script> <script src="../../_static/copybutton.js?v=30646c52"></script> <script src="../../_static/design-tabs.js?v=36754332"></script> <script src="../../_static/js/theme.js"></script> <link rel="index" title="Index" href="../../genindex.html"> <link rel="search" title="Search" href="../../search.html"> <link rel="next" title="TPS" href="../tps/index.html"> <link rel="prev" title="Mochitest" href="../mochitest-plain/index.html"> <meta http-equiv="X-Translated-By" content="Google"> <meta http-equiv="X-Translated-To" content="iw"> <script type="text/javascript" src="https://www.gstatic.com/_/translate_http/_/js/k=translate_http.tr.en_GB.tKc6KWkFf-8.O/am=gAE/d=1/rs=AN8SPfrf36LIV3DkhtRBGWFnLWWzaykPyw/m=corsproxy" data-sourceurl="https://firefox-source-docs.mozilla.org/testing/xpcshell/index.html"></script> <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" rel="stylesheet"> <script type="text/javascript" src="https://www.gstatic.com/_/translate_http/_/js/k=translate_http.tr.en_GB.tKc6KWkFf-8.O/am=gAE/d=1/exm=corsproxy/ed=1/rs=AN8SPfrf36LIV3DkhtRBGWFnLWWzaykPyw/m=phishing_protection" data-phishing-protection-enabled="false" data-forms-warning-enabled="true" data-source-url="https://firefox-source-docs.mozilla.org/testing/xpcshell/index.html"></script> <meta name="robots" content="none"> </head> <body class="wy-body-for-nav"> <script type="text/javascript" src="https://www.gstatic.com/_/translate_http/_/js/k=translate_http.tr.en_GB.tKc6KWkFf-8.O/am=gAE/d=1/exm=corsproxy,phishing_protection/ed=1/rs=AN8SPfrf36LIV3DkhtRBGWFnLWWzaykPyw/m=navigationui" data-environment="prod" data-proxy-url="https://firefox--source--docs-mozilla-org.translate.goog" data-proxy-full-url="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB" data-source-url="https://firefox-source-docs.mozilla.org/testing/xpcshell/index.html" data-source-language="pl" data-target-language="iw" data-display-language="en-GB" data-detected-source-language="" data-is-source-untranslated="false" data-source-untranslated-url="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://firefox-source-docs.mozilla.org/testing/xpcshell/index.html&anno=2" data-client="tr"></script> <div class="wy-grid-for-nav"> <nav data-toggle="wy-nav-shift" class="wy-nav-side"> <div class="wy-side-scroll"> <div class="wy-side-nav-search"><a href="https://firefox--source--docs-mozilla-org.translate.goog/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB" class="icon icon-home"> Firefox Source Docs <img src="../../_static/firefox-wordmark.svg" class="logo" alt="Logo"> </a><!-- -- This code is governed by the BSD license ----> <div> <h3>Quick search</h3> <script> (function () { var cx = "dd12886298f75dbef"; var gcse = document.createElement("script"); gcse.async = true; gcse.src = "https://cse.google.com/cse.js?cx=" + cx; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(gcse, s); })(); </script><gcse:search></gcse:search> </div> </div> <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> <p class="caption" role="heading"><span class="caption-text">Overview</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/glossary/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">A Glossary of Common Terms</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/overview/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">A Quick Guide to Mozilla Applications</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Getting Started</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/setup/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Getting Set Up To Work On The Firefox Codebase</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Working On Firefox</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/contributing/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Working on Firefox</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/bug-mgmt/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Bug Handling</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Firefox User Guide</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/devtools-user/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox DevTools User Docs</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Source Code Documentation</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mots/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Governance</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/browser/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox Front-end</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/dom/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">DOM</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/editor/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Editor</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/layout/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Style system (CSS) & Layout</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/gfx/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Graphics</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/ipc/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Processes, Threads and IPC</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/devtools/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox DevTools Contributor Docs</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/toolkit/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Toolkit</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/js/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">SpiderMonkey</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/jsloader/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">JS Loader</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mobile/android/geckoview/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">GeckoView</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mobile/android/fenix/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Fenix</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mobile/android/focus-android/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Focus for Android</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/dom/bindings/webidl/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">WebIDL</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/modules/libpref/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">libpref</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/networking/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Networking</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/remote/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Remote Protocols</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/services/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Services</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/permissions/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Permissions</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/uriloader/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">File Handling</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/widget/cocoa/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox on macOS</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/widget/windows/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox on Windows</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/toolkit/components/ml/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox AI Runtime</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/accessible/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Accessibility</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/media/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Media Playback</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/code-quality/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Code quality</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/writing-rust-code/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Writing Rust Code</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/rust-components/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Rust Components</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/profiler/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Gecko Profiler</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/performance/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Performance</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/storage/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Database bindings (SQLite, KV, …)</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/xpcom/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">XPCOM</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/nspr/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">NSPR</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/security/nss/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Network Security Services (NSS)</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/content-security/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Web Security Checks in Gecko</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">The Firefox Build System</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mach/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Mach</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/try/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Pushing to Try</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/build/buildsystem/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Build System</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/taskcluster/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox CI and Taskgraph</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/moztreedocs/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Managing Documentation</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mozbuild/vendor/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Vendoring Third Party Components</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Testing & Test Infrastructure</span></p> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/automated-testing/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Automated Testing</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/treeherder-try/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Understanding Treeherder Results</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/sheriffed-intermittents/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Sheriffed intermittent failures</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/tests-for-new-config/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Turning on Firefox tests for a new configuration</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/intermittent/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Avoiding intermittent tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/testing-policy/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Testing Policy</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/ci-configs/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Configuration Changes</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/browser-chrome/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Browser chrome mochitests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/chrome-tests/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Chrome Tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/marionette/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Marionette</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/geckodriver/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">geckodriver</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/test-verification/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Test Verification</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/webrender/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">WebRender Tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Mochitest</a></li> <li class="toctree-l1 current"><a class="current reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#">XPCShell tests</a> <ul> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#introducing-xpcshell-testing">Introducing xpcshell testing</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#creating-a-new-test-directory">Creating a new test directory</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#creating-a-new-test-in-an-existing-directory">Creating a new test in an existing directory</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-tests">Running tests</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#xpcshell-testing-api">xpcshell Testing API</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#assertions">Assertions</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#test-case-registration-and-execution">Test case registration and execution</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#environment">Environment</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#utility">Utility</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#multiprocess-communication">Multiprocess communication</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#xpcshell-toml-manifest">xpcshell.toml manifest</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#creating-a-new-xpcshell-toml-file">Creating a new xpcshell.toml file</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#test-head-and-support-files">Test head and support files</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#additional-testing-considerations">Additional testing considerations</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#async-tests">Async tests</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#task-based-asynchronous-tests">Task-based asynchronous tests</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#callback-based-asynchronous-tests">Callback-based asynchronous tests</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#other-tests">Other tests</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#testing-in-child-processeses">Testing in child processeses</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#platform-specific-tests">Platform-specific tests</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#runtime-detection">Runtime detection</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#conditionally-running-a-test">Conditionally running a test</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-through-the-add-task-or-add-test-function">Adding conditions through the <code class="docutils literal notranslate"><span class="pre">add_task</span></code> or <code class="docutils literal notranslate"><span class="pre">add_test</span></code> function</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-in-the-xpcshell-toml-manifest">Adding conditions in the xpcshell.toml manifest</a> <ul> <li class="toctree-l4"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#skip-if">skip-if</a></li> <li class="toctree-l4"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#fail-if">fail-if</a></li> <li class="toctree-l4"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#run-sequentially">run-sequentially</a></li> </ul></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#manifest-conditional-expressions">Manifest conditional expressions</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-a-specific-test-only">Running a specific test only</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#problems-with-pending-events-and-shutdown">Problems with pending events and shutdown</a></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#debugging-xpcshell-tests">Debugging xpcshell-tests</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-unit-tests-under-the-javascript-debugger">Running unit tests under the javascript debugger</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#via-jsdebugger">Via –jsdebugger</a></li> </ul></li> <li class="toctree-l2"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-unit-tests-under-a-c-debugger">Running unit tests under a C++ debugger</a> <ul> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#via-debugger-and-debugger-interactive">Via <code class="docutils literal notranslate"><span class="pre">--debugger</span> <span class="pre">and</span> <span class="pre">-debugger-interactive</span></code></a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#debugging-xpcshell-tests-in-a-child-process">Debugging xpcshell tests in a child process</a></li> <li class="toctree-l3"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#debug-both-parent-and-child-processes">Debug both parent and child processes</a></li> </ul></li> </ul></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/tps/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">TPS</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/web-platform/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">web-platform-tests</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/gtest/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">GTest</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/fuzzing/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Fuzzing</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/sanitizer/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Sanitizer</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/perfdocs/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Performance Testing</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/code-coverage/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Code coverage</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/testing-rust-code/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Testing & Debugging Rust Code</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Releases & Updates</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/update-infrastructure/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Mozilla Update Infrastructure</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/update-infrastructure/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#watershed-updates">Watershed Updates</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/update-infrastructure/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#desupport-updates">Desupport Updates</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/tools/update-verify/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Update Verify</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Localization & Internationalization</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/intl/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Internationalization</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/l10n/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Localization</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Firefox and Python</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/mozbase/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">mozbase</a></li> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/python/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Using third-party Python packages</a></li> </ul> <p class="caption" role="heading"><span class="caption-text">Metrics Collected in Firefox</span></p> <ul> <li class="toctree-l1"><a class="reference internal" href="https://firefox--source--docs-mozilla-org.translate.goog/metrics/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Metrics</a></li> </ul> </div> </div> </nav> <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> <nav class="wy-nav-top" aria-label="Mobile navigation menu"><i data-toggle="wy-nav-top" class="fa fa-bars"></i> <a href="https://firefox--source--docs-mozilla-org.translate.goog/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">Firefox Source Docs</a> </nav> <div class="wy-nav-content"> <div class="rst-content"><!-- 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/. --> <div role="navigation" aria-label="Page navigation"> <ul class="wy-breadcrumbs"> <li><a href="https://firefox--source--docs-mozilla-org.translate.goog/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB" class="icon icon-home" aria-label="Home"></a></li> <li class="breadcrumb-item active">XPCShell tests</li> <li class="wy-breadcrumbs-aside"><a href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://bugzilla.mozilla.org/enter_bug.cgi?product%3DDeveloper%2BInfrastructure%26component%3DFirefox%2BSource%2BDocs%253A%2BContent%26short_desc%3DDocumentation%2Bissue%2Bon%2Btesting/xpcshell/index%26comment%3DURL%2B%3D%2Bhttps://firefox-source-docs.mozilla.org/testing/xpcshell/index.html%26bug_file_loc%3Dhttps://firefox-source-docs.mozilla.org/testing/xpcshell/index.html" rel="nofollow">Report an issue</a> / <a href="https://firefox--source--docs-mozilla-org.translate.goog/_sources/testing/xpcshell/index.rst.txt?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB" rel="nofollow"> View page source</a></li> </ul> <hr> </div> <div role="main" class="document" itemscope itemtype="http://schema.org/Article"> <div itemprop="articleBody"> <section id="xpcshell-tests"> <h1>XPCShell tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#xpcshell-tests" title="Link to this heading"></a></h1> <p>xpcshell tests are quick-to-run tests, that are generally used to write unit tests. They do not have access to the full browser chrome like <code class="docutils literal notranslate"><span class="pre">browser</span> <span class="pre">chrome</span> <span class="pre">tests</span></code>, and so have much lower overhead. They are typical run by using <code class="docutils literal notranslate"><span class="pre">./mach</span> <span class="pre">xpcshell-test</span></code> which initiates a new <code class="docutils literal notranslate"><span class="pre">xpcshell</span></code> session with the xpcshell testing harness. Anything available to the XPCOM layer (through scriptable interfaces) can be tested with xpcshell. See <code class="docutils literal notranslate"><span class="pre">Mozilla</span> <span class="pre">automated</span> <span class="pre">testing</span></code> and <code class="docutils literal notranslate"><span class="pre">pages</span> <span class="pre">tagged</span> <span class="pre">"automated</span> <span class="pre">testing"</span></code> for more information.</p> <section id="introducing-xpcshell-testing"> <h2>Introducing xpcshell testing<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#introducing-xpcshell-testing" title="Link to this heading"></a></h2> <p>xpcshell test filenames must start with <code class="docutils literal notranslate"><span class="pre">test_</span></code>.</p> <section id="creating-a-new-test-directory"> <h3>Creating a new test directory<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#creating-a-new-test-directory" title="Link to this heading"></a></h3> <p>If you need to create a new test directory, then follow the steps here. The test runner needs to know about the existence of the tests and how to configure them through the use of the <code class="docutils literal notranslate"><span class="pre">xpcshell.toml</span></code> manifest file.</p> <p>First add a <code class="docutils literal notranslate"><span class="pre">XPCSHELL_TESTS_MANIFESTS</span> <span class="pre">+=</span> <span class="pre">['xpcshell.toml']</span></code> declaration (with the correct relative <code class="docutils literal notranslate"><span class="pre">xpcshell.toml</span></code> path) to the <code class="docutils literal notranslate"><span class="pre">moz.build</span></code> file located in or above the directory.</p> <p>Then create an empty <code class="docutils literal notranslate"><span class="pre">xpcshell.toml</span></code> file to tell the build system about the individual tests, and provide any additional configuration options.</p> </section> <section id="creating-a-new-test-in-an-existing-directory"> <h3>Creating a new test in an existing directory<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#creating-a-new-test-in-an-existing-directory" title="Link to this heading"></a></h3> <p>If you’re creating a new test in an existing directory, you can simply run:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>$<span class="w"> </span>./mach<span class="w"> </span>addtest<span class="w"> </span>path/to/test/test_example.js $<span class="w"> </span>hg<span class="w"> </span>add<span class="w"> </span>path/to/test/test_example.js </pre> </div> </div> <p>This will automatically create the test file and add it to <code class="docutils literal notranslate"><span class="pre">xpcshell.toml</span></code>, the second line adds it to your commit.</p> <p>The test file contains an empty test which will give you an idea of how to write a test. There are plenty more examples throughout mozilla-central.</p> </section> </section> <section id="running-tests"> <h2>Running tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-tests" title="Link to this heading"></a></h2> <p>To run the test, execute it by running the <code class="docutils literal notranslate"><span class="pre">mach</span></code> command from the root of the Gecko source code directory.</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span><span class="c1"># Run a single test:</span> $<span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>path/to/tests/test_example.js <span class="c1"># Test an entire test suite in a folder:</span> $<span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>path/to/tests/ <span class="c1"># Or run any type of test, including both xpcshell and browser chrome tests:</span> $<span class="w"> </span>./mach<span class="w"> </span><span class="nb">test</span><span class="w"> </span>path/to/tests/test_example.js </pre> </div> </div> <p>The test is executed by the testing harness. It will call in turn:</p> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">run_test</span></code> (if it exists).</p></li> <li><p>Any functions added with <code class="docutils literal notranslate"><span class="pre">add_task</span></code> or <code class="docutils literal notranslate"><span class="pre">add_test</span></code> in the order they were defined in the file.</p></li> </ul> <p>See also the notes below around <code class="docutils literal notranslate"><span class="pre">add_task</span></code> and <code class="docutils literal notranslate"><span class="pre">add_test</span></code>.</p> </section> <section id="xpcshell-testing-api"> <h2>xpcshell Testing API<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#xpcshell-testing-api" title="Link to this heading"></a></h2> <p>xpcshell tests have access to the following functions. They are defined in <a class="reference external" href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://searchfox.org/mozilla-central/source/testing/xpcshell/head.js">testing/xpcshell/head.js</a> and <a class="reference external" href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://searchfox.org/mozilla-central/source/testing/modules/Assert.sys.mjs">testing/modules/Assert.sys.mjs</a>.</p> <section id="assertions"> <h3>Assertions<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#assertions" title="Link to this heading"></a></h3> <ul class="simple"> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.ok(truthyOrFalsy[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.equal(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.notEqual(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.deepEqual(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.notDeepEqual(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.strictEqual(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.notStrictEqual(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.rejects(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.greater(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.greaterOrEqual(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.less(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> <li><p><code class="docutils literal notranslate"><span class="pre">Assert.lessOrEqual(actual,</span> <span class="pre">expected[,</span> <span class="pre">message])</span></code></p></li> </ul> <p>These assertion methods are provided by <a class="reference external" href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://searchfox.org/mozilla-central/source/testing/modules/Assert.sys.mjs">testing/modules/Assert.sys.mjs</a>. It implements the <a class="reference external" href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=http://wiki.commonjs.org/wiki/Unit_Testing/1.1">CommonJS Unit Testing specification version 1.1</a>, which provides a basic, standardized interface for performing in-code logical assertions with optional, customizable error reporting. It is <em>highly</em> recommended to use these assertion methods, instead of the ones mentioned below. You can on all these methods remove the <code class="docutils literal notranslate"><span class="pre">Assert.</span></code> from the beginning of the name, e.g. <code class="docutils literal notranslate"><span class="pre">ok(true)</span></code> rather than <code class="docutils literal notranslate"><span class="pre">Assert.ok(true)</span></code>, however keeping the <code class="docutils literal notranslate"><span class="pre">Assert.</span></code> prefix may be seen as more descriptive and easier to spot where the tests are. <code class="docutils literal notranslate"><span class="pre">Assert.throws(callback,</span> <span class="pre">expectedException[,</span> <span class="pre">message])</span></code> <code class="docutils literal notranslate"><span class="pre">Assert.throws(callback[,</span> <span class="pre">message])</span></code> Asserts that the provided callback function throws an exception. The <code class="docutils literal notranslate"><span class="pre">expectedException</span></code> argument can be an <code class="docutils literal notranslate"><span class="pre">Error</span></code> instance, or a regular expression matching part of the error message (like in <code class="docutils literal notranslate"><span class="pre">Assert.throws(()</span> <span class="pre">=></span> <span class="pre">a.b,</span> <span class="pre">/is</span> <span class="pre">not</span> <span class="pre">defined/</span></code>). <code class="docutils literal notranslate"><span class="pre">Assert.rejects(promise,</span> <span class="pre">expectedException[,</span> <span class="pre">message])</span></code> Asserts that the provided promise is rejected. Note: that this should be called prefixed with an <code class="docutils literal notranslate"><span class="pre">await</span></code>. The <code class="docutils literal notranslate"><span class="pre">expectedException</span></code> argument can be an <code class="docutils literal notranslate"><span class="pre">Error</span></code> instance, or a regular expression matching part of the error message. Example: <code class="docutils literal notranslate"><span class="pre">await</span> <span class="pre">Assert.rejects(myPromise,</span> <span class="pre">/bad</span> <span class="pre">response/);</span></code></p> </section> <section id="test-case-registration-and-execution"> <h3>Test case registration and execution<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#test-case-registration-and-execution" title="Link to this heading"></a></h3> <dl class="simple"> <dt> <code class="docutils literal notranslate"><span class="pre">add_task([condition,</span> <span class="pre">]testFunc)</span></code> </dt> <dd> <p>Add an asynchronous function or to the list of tests that are to be run asynchronously. Whenever the function <code class="docutils literal notranslate"><span class="pre">await</span></code>s a <a class="reference external" href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a>, the test runner waits until the promise is resolved or rejected before proceeding. Rejected promises are converted into exceptions, and resolved promises are converted into values. You can optionally specify a condition which causes the test function to be skipped; see <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-through-the-add-task-or-add-test-function">Adding conditions through the add_task or add_test function</a> for details. For tests that use <code class="docutils literal notranslate"><span class="pre">add_task()</span></code>, the <code class="docutils literal notranslate"><span class="pre">run_test()</span></code> function is optional, but if present, it should also call <code class="docutils literal notranslate"><span class="pre">run_next_test()</span></code> to start execution of all asynchronous test functions. The test cases must not call <code class="docutils literal notranslate"><span class="pre">run_next_test()</span></code>, it is called automatically when the task finishes. See <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#async-tests">Async tests</a>, below, for more information.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">add_test([condition,</span> <span class="pre">]testFunction)</span></code> </dt> <dd> <p>Add a test function to the list of tests that are to be run asynchronously. You can optionally specify a condition which causes the test function to be skipped; see <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-through-the-add-task-or-add-test-function">Adding conditions through the add_task or add_test function</a> for details. Each test function must call <code class="docutils literal notranslate"><span class="pre">run_next_test()</span></code> when it’s done. For tests that use <code class="docutils literal notranslate"><span class="pre">add_test()</span></code>, <code class="docutils literal notranslate"><span class="pre">the</span> <span class="pre">run_test()</span></code> function is optional, but if present, it should also call <code class="docutils literal notranslate"><span class="pre">run_next_test()</span></code> to start execution of all asynchronous test functions. In most cases, you should rather use the more readable variant <code class="docutils literal notranslate"><span class="pre">add_task()</span></code>. See <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#async-tests">Async tests</a>, below, for more information.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">run_next_test()</span></code> </dt> <dd> <p>Run the next test function from the list of asynchronous tests. Each test function must call <code class="docutils literal notranslate"><span class="pre">run_next_test()</span></code> when it’s done. <code class="docutils literal notranslate"><span class="pre">run_test()</span></code> should also call <code class="docutils literal notranslate"><span class="pre">run_next_test()</span></code> to start execution of all asynchronous test functions. See <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#async-tests">Async tests</a>, below, for more information.</p> </dd> <dt> <strong>``registerCleanupFunction``</strong><code class="docutils literal notranslate"><span class="pre">(callback)</span></code> </dt> <dd> <p>Executes the function <code class="docutils literal notranslate"><span class="pre">callback</span></code> after the current JS test file has finished running, regardless of whether the tests inside it pass or fail. You can use this to clean up anything that might otherwise cause problems between test runs. If <code class="docutils literal notranslate"><span class="pre">callback</span></code> returns a <code class="docutils literal notranslate"><span class="pre">Promise</span></code>, the test will not finish until the promise is fulfilled or rejected (making the termination function asynchronous). Cleanup functions are called in reverse order of registration.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">do_test_pending()</span></code> </dt> <dd> <p>Delay exit of the test until do_test_finished() is called. do_test_pending() may be called multiple times, and do_test_finished() must be paired with each before the unit test will exit.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">do_test_finished()</span></code> </dt> <dd> <p>Call this function to inform the test framework that an asynchronous operation has completed. If all asynchronous operations have completed (i.e., every do_test_pending() has been matched with a do_test_finished() in execution), then the unit test will exit.</p> </dd> </dl> </section> <section id="environment"> <h3>Environment<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#environment" title="Link to this heading"></a></h3> <dl> <dt> <code class="docutils literal notranslate"><span class="pre">do_get_file(testdirRelativePath,</span> <span class="pre">allowNonexistent)</span></code> </dt> <dd> <p>Returns an <code class="docutils literal notranslate"><span class="pre">nsILocalFile</span></code> object representing the given file (or directory) in the test directory. For example, if your test is unit/test_something.js, and you need to access unit/data/somefile, you would call <code class="docutils literal notranslate"><span class="pre">do_get_file('data/somefile')</span></code>. The given path must be delimited with forward slashes. You can use this to access test-specific auxiliary files if your test requires access to external files. Note that you can also use this function to get directories.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p><strong>Note:</strong> If your test needs access to one or more files that aren’t in the test directory, you should install those files to the test directory in the Makefile where you specify <code class="docutils literal notranslate"><span class="pre">XPCSHELL_TESTS</span></code>. For an example, see <code class="docutils literal notranslate"><span class="pre">netwerk/test/Makefile.in#117</span></code>.</p> </div> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">do_get_profile()</span></code> </dt> <dd> <p>Registers a directory with the profile service and returns an <code class="docutils literal notranslate"><span class="pre">nsILocalFile</span></code> object representing that directory. It also makes sure that the <strong>profile-change-net-teardown</strong>, <strong>profile-change-teardown</strong>, and <strong>profile-before-change</strong> <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/en/Observer_Notifications?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#Application_shutdown">observer notifications</a> are sent before the test finishes. This is useful if the components loaded in the test observe them to do cleanup on shutdown (e.g., places).</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p><strong>Note:</strong> <code class="docutils literal notranslate"><span class="pre">do_register_cleanup</span></code> will perform any cleanup operation <em>before</em> the profile and the network is shut down by the observer notifications.</p> </div> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">do_get_idle()</span></code> </dt> <dd> <p>By default xpcshell tests will disable the idle service, so that idle time will always be reported as 0. Calling this function will re-enable the service and return a handle to it; the idle time will then be correctly requested to the underlying OS. The idle-daily notification could be fired when requesting idle service. It is suggested to always get the service through this method if the test has to use idle.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">do_get_cwd()</span></code> </dt> <dd> <p>Returns an <code class="docutils literal notranslate"><span class="pre">nsILocalFile</span></code> object representing the test directory. This is the directory containing the test file when it is currently being run. Your test can write to this directory as well as read any files located alongside your test. Your test should be careful to ensure that it will not fail if a file it intends to write already exists, however.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">load(testdirRelativePath)</span></code> </dt> <dd> <p>Imports the JavaScript file referenced by <code class="docutils literal notranslate"><span class="pre">testdirRelativePath</span></code> into the global script context, executing the code inside it. The file specified is a file within the test directory. For example, if your test is unit/test_something.js and you have another file unit/extra_helpers.js, you can load the second file from the first by calling <code class="docutils literal notranslate"><span class="pre">load('extra_helpers.js')</span></code>.</p> </dd> </dl> </section> <section id="utility"> <h3>Utility<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#utility" title="Link to this heading"></a></h3> <dl class="simple"> <dt> <code class="docutils literal notranslate"><span class="pre">do_parse_document(path,</span> <span class="pre">type)</span></code> </dt> <dd> <p>Parses and returns a DOM document.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">executeSoon(callback)</span></code> </dt> <dd> <p>Executes the function <code class="docutils literal notranslate"><span class="pre">callback</span></code> on a later pass through the event loop. Use this when you want some code to execute after the current function has finished executing, but you don’t care about a specific time delay. This function will automatically insert a <code class="docutils literal notranslate"><span class="pre">do_test_pending</span></code> / <code class="docutils literal notranslate"><span class="pre">do_test_finished</span></code> pair for you.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">do_timeout(delay,</span> <span class="pre">fun)</span></code> </dt> <dd> <p>Call this function to schedule a timeout. The given function will be called with no arguments provided after the specified delay (in milliseconds). Note that you must call <code class="docutils literal notranslate"><span class="pre">do_test_pending</span></code> so that the test isn’t completed before your timer fires, and you must call <code class="docutils literal notranslate"><span class="pre">do_test_finished</span></code> when the actions you perform in the timeout complete, if you have no other functionality to test. (Note: the function argument used to be a string argument to be passed to eval, and some older branches support only a string argument or support both string and function.)</p> </dd> </dl> </section> <section id="multiprocess-communication"> <h3>Multiprocess communication<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#multiprocess-communication" title="Link to this heading"></a></h3> <dl class="simple"> <dt> <code class="docutils literal notranslate"><span class="pre">do_send_remote_message(name,</span> <span class="pre">optionalData)</span></code> </dt> <dd> <p>Asynchronously send a message to all remote processes. Pairs with <code class="docutils literal notranslate"><span class="pre">do_await_remote_message</span></code> or equivalent ProcessMessageManager listeners.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">do_await_remote_message(name,</span> <span class="pre">optionalCallback)</span></code> </dt> <dd> <p>Returns a promise that is resolved when the message is received. Must be paired with<code class="docutils literal notranslate"><span class="pre">do_send_remote_message</span></code> or equivalent ProcessMessageManager calls. If <strong>optionalCallback</strong> is provided, the callback must call <code class="docutils literal notranslate"><span class="pre">do_test_finished</span></code>. If optionalData is passed to <code class="docutils literal notranslate"><span class="pre">do_send_remote_message</span></code> then that data is the first argument to <strong>optionalCallback</strong> or the value to which the promise resolves.</p> </dd> </dl> </section> </section> <section id="xpcshell-toml-manifest"> <h2>xpcshell.toml manifest<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#xpcshell-toml-manifest" title="Link to this heading"></a></h2> <p>The manifest controls what tests are included in a test suite, and the configuration of the tests. It is loaded via the `moz.build` property configuration property.</p> <p>The following are all of the configuration options for a test suite as listed under the <code class="docutils literal notranslate"><span class="pre">[DEFAULT]</span></code> section of the manifest.</p> <dl class="simple"> <dt> <code class="docutils literal notranslate"><span class="pre">tags</span></code> </dt> <dd> <p>Tests can be filtered by tags when running multiple tests. The command for mach is <code class="docutils literal notranslate"><span class="pre">./mach</span> <span class="pre">xpcshell-test</span> <span class="pre">--tag</span> <span class="pre">TAGNAME</span></code></p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">head</span></code> </dt> <dd> <p>The relative path to the head JavaScript file, which is run once before a test suite is run. The variables declared in the root scope are available as globals in the test files. See <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#test-head-and-support-files">Test head and support files</a> for more information and usage.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">firefox-appdir</span></code> </dt> <dd> <p>Set this to “browser” if your tests need access to things in the browser/ directory (e.g. additional XPCOM services that live there)</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">skip-if</span></code> <code class="docutils literal notranslate"><span class="pre">run-if</span></code> <code class="docutils literal notranslate"><span class="pre">fail-if</span></code> </dt> <dd> <p>For this entire test suite, run the tests only if they meet certain conditions. See <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-through-the-add-task-or-add-test-function">Adding conditions in the xpcshell.toml manifest</a> for how to use these properties.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">support-files</span></code> </dt> <dd> <p>Make files available via the <code class="docutils literal notranslate"><span class="pre">resource://test/[filename]</span></code> path to the tests. The path can be relative to other directories, but it will be served only with the filename. See <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#test-head-and-support-files">Test head and support files</a> for more information and usage.</p> </dd> <dt> <code class="docutils literal notranslate"><span class="pre">[test_*]</span></code> </dt> <dd> <p>Test file names must start with <code class="docutils literal notranslate"><span class="pre">test_</span></code> and are listed in square brackets</p> </dd> </dl> <section id="creating-a-new-xpcshell-toml-file"> <h3>Creating a new xpcshell.toml file<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#creating-a-new-xpcshell-toml-file" title="Link to this heading"></a></h3> <p>When creating a new directory and new xpcshell.toml manifest file, the following must be added to a moz.build file near that file in the directory hierarchy:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span><span class="nv">XPCSHELL_TESTS_MANIFESTS</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="o">[</span><span class="s1">'path/to/xpcshell.toml'</span><span class="o">]</span> </pre> </div> </div> <p>Typically, the moz.build containing <em>XPCSHELL_TESTS_MANIFESTS</em> is not in the same directory as <em>xpcshell.toml</em>, but rather in a parent directory. Common directory structures look like:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>feature ├──moz.build └──tests/xpcshell <span class="w"> </span>└──xpcshell.toml <span class="c1"># or</span> feature ├──moz.build └──tests <span class="w"> </span>├──moz.build <span class="w"> </span>└──xpcshell <span class="w"> </span>└──xpcshell.toml </pre> </div> </div> </section> <section id="test-head-and-support-files"> <h3>Test head and support files<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#test-head-and-support-files" title="Link to this heading"></a></h3> <p>Typically in a test suite, similar setup code and dependencies will need to be loaded in across each test. This can be done through the test head, which is the file declared in the <code class="docutils literal notranslate"><span class="pre">xpcshell.toml</span></code> manifest file under the <code class="docutils literal notranslate"><span class="pre">head</span></code> property. The file itself is typically called <code class="docutils literal notranslate"><span class="pre">head.js</span></code>. Any variable declared in the test head will be in the global scope of each test in that test suite.</p> <p>In addition to the test head, other support files can be declared in the <code class="docutils literal notranslate"><span class="pre">xpcshell.toml</span></code> manifest file. This is done through the <code class="docutils literal notranslate"><span class="pre">support-files</span></code> declaration. These files will be made available through the url <code class="docutils literal notranslate"><span class="pre">resource://test</span></code> plus the name of the file. These files can then be loaded in using the <code class="docutils literal notranslate"><span class="pre">ChromeUtils.importESModule</span></code> function or other loaders. The support files can be located in other directory as well, and they will be made available by their filename.</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span><span class="c1"># File structure:</span> path/to/tests ├──head.js ├──module.mjs ├──moz.build ├──test_example.js └──xpcshell.toml </pre> </div> </div> <div class="highlight-toml notranslate"> <div class="highlight"> <pre><span></span><span class="c1"># xpcshell.toml</span> <span class="k">[DEFAULT]</span> <span class="n">head</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="err">head.js</span> <span class="n">support-files</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="err">./module.mjs</span> <span class="w"> </span><span class="p">..</span><span class="err">/</span><span class="p">..</span><span class="err">/</span><span class="n">some</span><span class="err">/</span><span class="n">other</span><span class="err">/</span><span class="n">file</span><span class="p">.</span><span class="n">js</span> <span class="k">[test_component_state.js]</span> </pre> </div> </div> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="c1">// head.js</span> <span class="kd">var</span><span class="w"> </span><span class="nx">globalValue</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"A global value."</span><span class="p">;</span> <span class="c1">// Import support-files.</span> <span class="kd">const</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">foo</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">ChromeUtils</span><span class="p">.</span><span class="nx">importESModule</span><span class="p">(</span><span class="s2">"resource://test/module.mjs"</span><span class="p">);</span> <span class="kd">const</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">bar</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">ChromeUtils</span><span class="p">.</span><span class="nx">importESModule</span><span class="p">(</span><span class="s2">"resource://test/file.mjs"</span><span class="p">);</span> </pre> </div> </div> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="c1">// test_example.js</span> <span class="kd">function</span><span class="w"> </span><span class="nx">run_test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">equal</span><span class="p">(</span><span class="nx">globalValue</span><span class="p">,</span><span class="w"> </span><span class="s2">"A global value."</span><span class="p">,</span><span class="w"> </span><span class="s2">"Declarations in head.js can be accessed"</span><span class="p">);</span> <span class="p">}</span> </pre> </div> </div> </section> </section> <section id="additional-testing-considerations"> <h2>Additional testing considerations<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#additional-testing-considerations" title="Link to this heading"></a></h2> <section id="async-tests"> <h3>Async tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#async-tests" title="Link to this heading"></a></h3> <p>Asynchronous tests (that is, those whose success cannot be determined until after <code class="docutils literal notranslate"><span class="pre">run_test</span></code> finishes) can be written in a variety of ways.</p> </section> </section> <section id="task-based-asynchronous-tests"> <h2>Task-based asynchronous tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#task-based-asynchronous-tests" title="Link to this heading"></a></h2> <p>The easiest is using the <code class="docutils literal notranslate"><span class="pre">add_task</span></code> helper. <code class="docutils literal notranslate"><span class="pre">add_task</span></code> can take an asynchronous function as a parameter. <code class="docutils literal notranslate"><span class="pre">add_task</span></code> tests are run automatically if you don’t have a <code class="docutils literal notranslate"><span class="pre">run_test</span></code> function.</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="nx">add_task</span><span class="p">(</span><span class="k">async</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">test_foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="nx">makeFoo</span><span class="p">();</span><span class="w"> </span><span class="c1">// makeFoo() returns a Promise<foo></span> <span class="w"> </span><span class="nx">equal</span><span class="p">(</span><span class="nx">foo</span><span class="p">,</span><span class="w"> </span><span class="nx">expectedFoo</span><span class="p">,</span><span class="w"> </span><span class="s2">"Should have received the expected object"</span><span class="p">);</span> <span class="p">});</span> <span class="nx">add_task</span><span class="p">(</span><span class="k">async</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">test_bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nx">foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">await</span><span class="w"> </span><span class="nx">makeBar</span><span class="p">();</span><span class="w"> </span><span class="c1">// makeBar() returns a Promise<bar></span> <span class="w"> </span><span class="nx">Assert</span><span class="p">.</span><span class="nx">equal</span><span class="p">(</span><span class="nx">bar</span><span class="p">,</span><span class="w"> </span><span class="nx">expectedBar</span><span class="p">,</span><span class="w"> </span><span class="s2">"Should have received the expected object"</span><span class="p">);</span> <span class="p">});</span> </pre> </div> </div> <section id="callback-based-asynchronous-tests"> <h3>Callback-based asynchronous tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#callback-based-asynchronous-tests" title="Link to this heading"></a></h3> <p>You can also use <code class="docutils literal notranslate"><span class="pre">add_test</span></code>, which takes a function and adds it to the list of asynchronously-run functions. Each function given to <code class="docutils literal notranslate"><span class="pre">add_test</span></code> must also call <code class="docutils literal notranslate"><span class="pre">run_next_test</span></code> at its end. You should normally use <code class="docutils literal notranslate"><span class="pre">add_task</span></code> instead of <code class="docutils literal notranslate"><span class="pre">add_test</span></code>, but you may see <code class="docutils literal notranslate"><span class="pre">add_test</span></code> in existing tests.</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="nx">add_test</span><span class="p">(</span><span class="kd">function</span><span class="w"> </span><span class="nx">test_foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">makeFoo</span><span class="p">(</span><span class="kd">function</span><span class="w"> </span><span class="nx">callback</span><span class="p">(</span><span class="nx">foo</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// makeFoo invokes a callback<foo> once completed</span> <span class="w"> </span><span class="nx">equal</span><span class="p">(</span><span class="nx">foo</span><span class="p">,</span><span class="w"> </span><span class="nx">expectedFoo</span><span class="p">);</span> <span class="w"> </span><span class="nx">run_next_test</span><span class="p">();</span> <span class="w"> </span><span class="p">});</span> <span class="p">});</span> <span class="nx">add_test</span><span class="p">(</span><span class="kd">function</span><span class="w"> </span><span class="nx">test_bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">makeBar</span><span class="p">(</span><span class="kd">function</span><span class="w"> </span><span class="nx">callback</span><span class="p">(</span><span class="nx">bar</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">equal</span><span class="p">(</span><span class="nx">bar</span><span class="p">,</span><span class="w"> </span><span class="nx">expectedBar</span><span class="p">);</span> <span class="w"> </span><span class="nx">run_next_test</span><span class="p">();</span> <span class="w"> </span><span class="p">});</span> <span class="p">});</span> </pre> </div> </div> </section> <section id="other-tests"> <h3>Other tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#other-tests" title="Link to this heading"></a></h3> <p>We can also tell the test harness not to kill the test process once <code class="docutils literal notranslate"><span class="pre">run_test()</span></code> is finished, but to keep spinning the event loop until our callbacks have been called and our test has completed. Newer tests prefer the use of <code class="docutils literal notranslate"><span class="pre">add_task</span></code> rather than this method. This can be achieved with <code class="docutils literal notranslate"><span class="pre">do_test_pending()</span></code> and <code class="docutils literal notranslate"><span class="pre">do_test_finished()</span></code>:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="kd">function</span><span class="w"> </span><span class="nx">run_test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="c1">// Tell the harness to keep spinning the event loop at least</span> <span class="w"> </span><span class="c1">// until the next do_test_finished() call.</span> <span class="w"> </span><span class="nx">do_test_pending</span><span class="p">();</span> <span class="w"> </span><span class="nx">someAsyncProcess</span><span class="p">(</span><span class="kd">function</span><span class="w"> </span><span class="nx">callback</span><span class="p">(</span><span class="nx">result</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="nx">equal</span><span class="p">(</span><span class="nx">result</span><span class="p">,</span><span class="w"> </span><span class="nx">expectedResult</span><span class="p">);</span> <span class="w"> </span><span class="c1">// Close previous do_test_pending() call.</span> <span class="w"> </span><span class="nx">do_test_finished</span><span class="p">();</span> <span class="w"> </span><span class="p">});</span> <span class="p">}</span> </pre> </div> </div> </section> <section id="testing-in-child-processeses"> <h3>Testing in child processeses<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#testing-in-child-processeses" title="Link to this heading"></a></h3> <p>By default xpcshell tests run in the parent process. If you wish to run test logic in the child, you have several ways to do it:</p> <ol class="arabic simple"> <li><p>Create a regular test_foo.js test, and then write a wrapper test_foo_wrap.js file that uses the <code class="docutils literal notranslate"><span class="pre">run_test_in_child()</span></code> function to run an entire script file in the child. This is an easy way to arrange for a test to be run twice, once in chrome and then later (via the _wrap.js file) in content. See /network/test/unit_ipc for examples. The <code class="docutils literal notranslate"><span class="pre">run_test_in_child()</span></code> function takes a callback, so you should be able to call it multiple times with different files, if that’s useful.</p></li> <li><p>For tests that need to run logic in both the parent + child processes during a single test run, you may use the poorly documented <code class="docutils literal notranslate"><span class="pre">sendCommand()</span></code> function, which takes a code string to be executed on the child, and a callback function to be run on the parent when it has completed. You will want to first call do_load_child_test_harness() to set up a reasonable test environment on the child. <code class="docutils literal notranslate"><span class="pre">sendCommand</span></code> returns immediately, so you will generally want to use <code class="docutils literal notranslate"><span class="pre">do_test_pending</span></code>/<code class="docutils literal notranslate"><span class="pre">do_test_finished</span></code> with it. NOTE: this method of test has not been used much, and your level of pain may be significant. Consider option #1 if possible.</p></li> </ol> <p>See the documentation for <code class="docutils literal notranslate"><span class="pre">run_test_in_child()</span></code> and <code class="docutils literal notranslate"><span class="pre">do_load_child_test_harness()</span></code> in testing/xpcshell/head.js for more information.</p> </section> <section id="platform-specific-tests"> <h3>Platform-specific tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#platform-specific-tests" title="Link to this heading"></a></h3> <p>Sometimes you might want a test to know what platform it’s running on (to test platform-specific features, or allow different behaviors). Unit tests are not normally invoked from a Makefile (unlike Mochitests), or preprocessed (so not #ifdefs), so platform detection with those methods isn’t trivial.</p> </section> <section id="runtime-detection"> <h3>Runtime detection<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#runtime-detection" title="Link to this heading"></a></h3> <p>Some tests will want to only execute certain portions on specific platforms. Use <a class="reference external" href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://searchfox.org/mozilla-central/rev/5f0a7ca8968ac5cef8846e1d970ef178b8b76dcc/toolkit/modules/AppConstants.sys.mjs%23158">AppConstants.sys.mjs</a> for determining the platform, for example:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="kd">let</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">AppConstants</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="nx">ChromeUtils</span><span class="p">.</span><span class="nx">importESModule</span><span class="p">(</span><span class="s2">"resource://gre/modules/AppConstants.mjs"</span><span class="p">);</span> <span class="kd">let</span><span class="w"> </span><span class="nx">isMac</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">AppConstants</span><span class="p">.</span><span class="nx">platform</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"macosx"</span><span class="p">;</span> </pre> </div> </div> </section> </section> <section id="conditionally-running-a-test"> <h2>Conditionally running a test<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#conditionally-running-a-test" title="Link to this heading"></a></h2> <p>There are two different ways to conditional skip a test, either through</p> <section id="adding-conditions-through-the-add-task-or-add-test-function"> <h3>Adding conditions through the <code class="docutils literal notranslate"><span class="pre">add_task</span></code> or <code class="docutils literal notranslate"><span class="pre">add_test</span></code> function<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-through-the-add-task-or-add-test-function" title="Link to this heading"></a></h3> <p>You can use conditionals on individual test functions instead of entire files. The condition is provided as an optional first parameter passed into <code class="docutils literal notranslate"><span class="pre">add_task()</span></code> or <code class="docutils literal notranslate"><span class="pre">add_test()</span></code>. The condition is an object which contains a function named <code class="docutils literal notranslate"><span class="pre">skip_if()</span></code>, which is an <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">arrow function</a> returning a boolean value which is <strong>``true``</strong> if the test should be skipped.</p> <p>For example, you can provide a test which only runs on Mac OS X like this:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="kd">let</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">AppConstants</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="o">=</span> <span class="w"> </span><span class="nx">ChromeUtils</span><span class="p">.</span><span class="nx">importESModule</span><span class="p">(</span><span class="s2">"resource://gre/modules/AppConstants.sys.mjs"</span><span class="p">);</span> <span class="nx">add_task</span><span class="p">({</span> <span class="w"> </span><span class="nx">skip_if</span><span class="o">:</span><span class="w"> </span><span class="p">()</span><span class="w"> </span><span class="p">=></span><span class="w"> </span><span class="nx">AppConstants</span><span class="p">.</span><span class="nx">platform</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s2">"mac"</span> <span class="p">},</span><span class="w"> </span><span class="k">async</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">some_test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="c1">// Test code goes here</span> <span class="p">});</span> </pre> </div> </div> <p>Since <code class="docutils literal notranslate"><span class="pre">AppConstants.platform</span> <span class="pre">!=</span> <span class="pre">"mac"</span></code> is <code class="docutils literal notranslate"><span class="pre">true</span></code> only when testing on Mac OS X, the test will be skipped on all other platforms.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p><strong>Note:</strong> Arrow functions are ideal here because if your condition compares constants, it will already have been evaluated before the test is even run, meaning your output will not be able to show the specifics of what the condition is.</p> </div> </section> <section id="adding-conditions-in-the-xpcshell-toml-manifest"> <h3>Adding conditions in the xpcshell.toml manifest<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-in-the-xpcshell-toml-manifest" title="Link to this heading"></a></h3> <p>Sometimes you may want to add conditions to specify that a test should be skipped in certain configurations, or that a test is known to fail on certain platforms. You can do this in xpcshell manifests by adding annotations below the test file entry in the manifest, for example:</p> <div class="highlight-ini notranslate"> <div class="highlight"> <pre><span></span><span class="k">[test_example.js]</span> <span class="na">skip-if</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">os == 'win'</span> </pre> </div> </div> <p>This example would skip running <code class="docutils literal notranslate"><span class="pre">test_example.js</span></code> on Windows.</p> <div class="admonition note"> <p class="admonition-title">Note</p> <p><strong>Note:</strong> Starting with Gecko (Firefox 40 / Thunderbird 40 / SeaMonkey 2.37), you can use conditionals on individual test functions instead of on entire files. See <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#adding-conditions-through-the-add-task-or-add-test-function">Adding conditions through the add_task or add_test function</a> above for details.</p> </div> <p>There are currently four conditionals you can specify:</p> <section id="skip-if"> <h4>skip-if<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#skip-if" title="Link to this heading"></a></h4> <p><code class="docutils literal notranslate"><span class="pre">skip-if</span></code> tells the harness to skip running this test if the condition evaluates to true. You should use this only if the test has no meaning on a certain platform, or causes undue problems like hanging the test suite for a long time.</p> <section id="run-if"> <h5>run-if<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#run-if" title="Link to this heading"></a></h5> <p><code class="docutils literal notranslate"><span class="pre">run-if</span></code> tells the harness to only run this test if the condition evaluates to true. It functions as the inverse of <code class="docutils literal notranslate"><span class="pre">skip-if</span></code>.</p> </section> </section> <section id="fail-if"> <h4>fail-if<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#fail-if" title="Link to this heading"></a></h4> <p><code class="docutils literal notranslate"><span class="pre">fail-if</span></code> tells the harness that this test is expected to fail if the condition is true. If you add this to a test, make sure you file a bug on the failure and include the bug number in a comment in the manifest, like:</p> <div class="highlight-ini notranslate"> <div class="highlight"> <pre><span></span><span class="k">[test_example.js]</span> <span class="c1"># bug xxxxxx</span> <span class="na">fail-if</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">os == 'linux'</span> </pre> </div> </div> </section> <section id="run-sequentially"> <h4>run-sequentially<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#run-sequentially" title="Link to this heading"></a></h4> <p><code class="docutils literal notranslate"><span class="pre">run-sequentially</span></code>basically tells the harness to run the respective test in isolation. This is required for tests that are not “thread-safe”. You should do all you can to avoid using this option, since this will kill performance. However, we understand that there are some cases where this is imperative, so we made this option available. If you add this to a test, make sure you specify a reason and possibly even a bug number, like:</p> <div class="highlight-ini notranslate"> <div class="highlight"> <pre><span></span><span class="k">[test_example.js]</span> <span class="na">run-sequentially</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">Has to launch Firefox binary, bug 123456.</span> </pre> </div> </div> </section> </section> <section id="manifest-conditional-expressions"> <h3>Manifest conditional expressions<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#manifest-conditional-expressions" title="Link to this heading"></a></h3> <p>For a more detailed description of the syntax of the conditional expressions, as well as what variables are available, <cite>see this page </en/XPCshell_Test_Manifest_Expressions</cite>.</p> </section> </section> <section id="running-a-specific-test-only"> <h2>Running a specific test only<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-a-specific-test-only" title="Link to this heading"></a></h2> <p>When working on a specific feature or issue, it is convenient to only run a specific task from a whole test suite. Use <code class="docutils literal notranslate"><span class="pre">.only()</span></code> for that purpose:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="nx">add_task</span><span class="p">(</span><span class="k">async</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">some_test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="c1">// Some test.</span> <span class="p">});</span> <span class="nx">add_task</span><span class="p">(</span><span class="k">async</span><span class="w"> </span><span class="kd">function</span><span class="w"> </span><span class="nx">some_interesting_test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <span class="c1">// Only this test will be executed.</span> <span class="p">}).</span><span class="nx">only</span><span class="p">();</span> </pre> </div> </div> </section> <section id="problems-with-pending-events-and-shutdown"> <h2>Problems with pending events and shutdown<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#problems-with-pending-events-and-shutdown" title="Link to this heading"></a></h2> <p>Events are not processed during test execution if not explicitly triggered. This sometimes causes issues during shutdown, when code is run that expects previously created events to have been already processed. In such cases, this code at the end of a test can help:</p> <div class="highlight-js notranslate"> <div class="highlight"> <pre><span></span><span class="kd">let</span><span class="w"> </span><span class="nx">thread</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">gThreadManager</span><span class="p">.</span><span class="nx">currentThread</span><span class="p">;</span> <span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="nx">thread</span><span class="p">.</span><span class="nx">hasPendingEvents</span><span class="p">())</span> <span class="w"> </span><span class="nx">thread</span><span class="p">.</span><span class="nx">processNextEvent</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span> </pre> </div> </div> </section> <section id="debugging-xpcshell-tests"> <h2>Debugging xpcshell-tests<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#debugging-xpcshell-tests" title="Link to this heading"></a></h2> <section id="running-unit-tests-under-the-javascript-debugger"> <h3>Running unit tests under the javascript debugger<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-unit-tests-under-the-javascript-debugger" title="Link to this heading"></a></h3> </section> <section id="via-jsdebugger"> <h3>Via –jsdebugger<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#via-jsdebugger" title="Link to this heading"></a></h3> <p>You can specify flags when issuing the <code class="docutils literal notranslate"><span class="pre">xpcshell-test</span></code> command that will cause your test to stop right before running so you can attach the <a class="reference external" href="https://firefox--source--docs-mozilla-org.translate.goog/docs/Tools/Tools_Toolbox?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB">javascript debugger</a>.</p> <p>Example:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>$<span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>--jsdebugger<span class="w"> </span>browser/components/tests/unit/test_browserGlue_pingcentre.js <span class="w"> </span><span class="m">0</span>:00.50<span class="w"> </span>INFO<span class="w"> </span>Running<span class="w"> </span>tests<span class="w"> </span>sequentially. ... <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">""</span> <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">"*******************************************************************"</span> <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">"Waiting for the debugger to connect on port 6000"</span> <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">""</span> <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">"To connect the debugger, open a Firefox instance, select 'Connect'"</span> <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">"from the Developer menu and specify the port as 6000"</span> <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">"*******************************************************************"</span> <span class="w"> </span><span class="m">0</span>:00.68<span class="w"> </span>INFO<span class="w"> </span><span class="s2">""</span> <span class="w"> </span><span class="m">0</span>:00.71<span class="w"> </span>INFO<span class="w"> </span><span class="s2">"Still waiting for debugger to connect..."</span> ... </pre> </div> </div> <p>At this stage in a running Firefox instance:</p> <ul class="simple"> <li><p>Go to the three-bar menu, then select <code class="docutils literal notranslate"><span class="pre">More</span> <span class="pre">tools</span></code> -> <code class="docutils literal notranslate"><span class="pre">Remote</span> <span class="pre">Debugging</span></code></p></li> <li><p>A new tab is opened. In the Network Location box, enter <code class="docutils literal notranslate"><span class="pre">localhost:6000</span></code> and select <code class="docutils literal notranslate"><span class="pre">Connect</span></code></p></li> <li><p>You should then get a link to <em>``Main Process``</em>, click it and the Developer Tools debugger window will open.</p></li> <li><p>It will be paused at the start of the test, so you can add breakpoints, or start running as appropriate.</p></li> </ul> <p>If you get a message such as:</p> <div class="highlight-default notranslate"> <div class="highlight"> <pre><span></span> <span class="mi">0</span><span class="p">:</span><span class="mf">00.62</span> <span class="n">ERROR</span> <span class="n">Failed</span> <span class="n">to</span> <span class="n">initialize</span> <span class="n">debugging</span><span class="p">:</span> <span class="n">Error</span><span class="p">:</span> <span class="n">resource</span><span class="p">:</span><span class="o">//</span><span class="n">devtools</span> <span class="n">appears</span> <span class="n">to</span> <span class="n">be</span> <span class="n">inaccessible</span> <span class="kn">from</span> <span class="nn">the</span> <span class="n">xpcshell</span> <span class="n">environment</span><span class="o">.</span> <span class="n">This</span> <span class="n">can</span> <span class="n">usually</span> <span class="n">be</span> <span class="n">resolved</span> <span class="n">by</span> <span class="n">adding</span><span class="p">:</span> <span class="n">firefox</span><span class="o">-</span><span class="n">appdir</span> <span class="o">=</span> <span class="n">browser</span> <span class="n">to</span> <span class="n">the</span> <span class="n">xpcshell</span><span class="o">.</span><span class="n">toml</span> <span class="n">manifest</span><span class="o">.</span> <span class="n">It</span> <span class="ow">is</span> <span class="n">possible</span> <span class="k">for</span> <span class="n">this</span> <span class="n">to</span> <span class="n">alter</span> <span class="n">test</span> <span class="n">behevior</span> <span class="n">by</span> <span class="n">triggering</span> <span class="n">additional</span> <span class="n">browser</span> <span class="n">code</span> <span class="n">to</span> <span class="n">run</span><span class="p">,</span> <span class="n">so</span> <span class="n">check</span> <span class="n">test</span> <span class="n">behavior</span> <span class="n">after</span> <span class="n">making</span> <span class="n">this</span> <span class="n">change</span><span class="o">.</span> </pre> </div> </div> <p>This is typically a test in core code. You can attempt to add that to the xpcshell.toml, however as it says, it might affect how the test runs and cause failures. Generally the firefox-appdir should only be left in xpcshell.toml for tests that are in the browser/ directory, or are Firefox-only.</p> </section> </section> <section id="running-unit-tests-under-a-c-debugger"> <h2>Running unit tests under a C++ debugger<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#running-unit-tests-under-a-c-debugger" title="Link to this heading"></a></h2> <section id="via-debugger-and-debugger-interactive"> <h3>Via <code class="docutils literal notranslate"><span class="pre">--debugger</span> <span class="pre">and</span> <span class="pre">-debugger-interactive</span></code><a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#via-debugger-and-debugger-interactive" title="Link to this heading"></a></h3> <p>You can specify flags when issuing the <code class="docutils literal notranslate"><span class="pre">xpcshell-test</span></code> command that will launch xpcshell in the specified debugger (implemented in <a class="reference external" href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://bugzilla.mozilla.org/show_bug.cgi?id%3D382682">bug 382682</a>). Provide the full path to the debugger, or ensure that the named debugger is in your system PATH.</p> <p>Example:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>$<span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>--debugger<span class="w"> </span>gdb<span class="w"> </span>--debugger-interactive<span class="w"> </span>netwerk/test/unit/test_resumable_channel.js <span class="c1"># js>_execute_test();</span> ...failure<span class="w"> </span>or<span class="w"> </span>success<span class="w"> </span>messages<span class="w"> </span>are<span class="w"> </span>printed<span class="w"> </span>to<span class="w"> </span>the<span class="w"> </span>console... <span class="c1"># js>quit();</span> </pre> </div> </div> <p>On Windows with the VS debugger:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>$<span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>--debugger<span class="w"> </span>devenv<span class="w"> </span>--debugger-interactive<span class="w"> </span>netwerk/test/test_resumable_channel.js </pre> </div> </div> <p>Or with WinDBG:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>$<span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>--debugger<span class="w"> </span>windbg<span class="w"> </span>--debugger-interactive<span class="w"> </span>netwerk/test/test_resumable_channel.js </pre> </div> </div> <p>Or with modern WinDbg (WinDbg Preview as of April 2020):</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>$<span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>--debugger<span class="w"> </span>WinDbgX<span class="w"> </span>--debugger-interactive<span class="w"> </span>netwerk/test/test_resumable_channel.js </pre> </div> </div> </section> <section id="debugging-xpcshell-tests-in-a-child-process"> <h3>Debugging xpcshell tests in a child process<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#debugging-xpcshell-tests-in-a-child-process" title="Link to this heading"></a></h3> <p>To debug the child process, where code is often being run in a project, set MOZ_DEBUG_CHILD_PROCESS=1 in your environment (or on the command line) and run the test. You will see the child process emit a printf with its process ID, then sleep. Attach a debugger to the child’s pid, and when it wakes up you can debug it:</p> <div class="highlight-bash notranslate"> <div class="highlight"> <pre><span></span>$<span class="w"> </span><span class="nv">MOZ_DEBUG_CHILD_PROCESS</span><span class="o">=</span><span class="m">1</span><span class="w"> </span>./mach<span class="w"> </span>xpcshell-test<span class="w"> </span>test_simple_wrap.js CHILDCHILDCHILDCHILD <span class="w"> </span>debug<span class="w"> </span>me<span class="w"> </span>@13476 </pre> </div> </div> </section> <section id="debug-both-parent-and-child-processes"> <h3>Debug both parent and child processes<a class="headerlink" href="https://firefox--source--docs-mozilla-org.translate.goog/testing/xpcshell/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB#debug-both-parent-and-child-processes" title="Link to this heading"></a></h3> <p>Use MOZ_DEBUG_CHILD_PROCESS=1 to attach debuggers to each process. (For gdb at least, this means running separate copies of gdb, one for each process.)</p> </section> </section> </section> </div> </div> <footer> <div class="rst-footer-buttons" role="navigation" aria-label="Footer"><a href="https://firefox--source--docs-mozilla-org.translate.goog/testing/mochitest-plain/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB" class="btn btn-neutral float-left" title="Mochitest" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> <a href="https://firefox--source--docs-mozilla-org.translate.goog/testing/tps/index.html?_x_tr_sl=pl&_x_tr_tl=iw&_x_tr_hl=en-GB" class="btn btn-neutral float-right" title="TPS" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> </div> <hr> <div role="contentinfo"> <p></p> </div> Built with <a href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://www.sphinx-doc.org/">Sphinx</a> using a <a href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://github.com/readthedocs/sphinx_rtd_theme">theme</a> provided by <a href="https://translate.google.com/website?sl=pl&tl=iw&hl=en-GB&u=https://readthedocs.org">Read the Docs</a>. </footer> </div> </div> </section> </div> <script> jQuery(function () { SphinxRtdTheme.Navigation.enable(true); }); </script> <script>function gtElInit() {var lib = new google.translate.TranslateService();lib.translatePage('pl', 'iw', function () {});}</script> <script src="https://translate.google.com/translate_a/element.js?cb=gtElInit&hl=en-GB&client=wt" type="text/javascript"></script> </body> </html>