diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/components/urlbar/tests/unit/test_UrlbarController_integration.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/urlbar/tests/unit/test_UrlbarController_integration.js')
-rw-r--r-- | browser/components/urlbar/tests/unit/test_UrlbarController_integration.js | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/browser/components/urlbar/tests/unit/test_UrlbarController_integration.js b/browser/components/urlbar/tests/unit/test_UrlbarController_integration.js new file mode 100644 index 0000000000..220af80e06 --- /dev/null +++ b/browser/components/urlbar/tests/unit/test_UrlbarController_integration.js @@ -0,0 +1,106 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * These tests test the UrlbarController in association with the model. + */ + +"use strict"; + +const TEST_URL = "http://example.com"; +const match = new UrlbarResult( + UrlbarUtils.RESULT_TYPE.TAB_SWITCH, + UrlbarUtils.RESULT_SOURCE.TABS, + { url: TEST_URL } +); +let controller; + +add_setup(async function () { + controller = UrlbarTestUtils.newMockController(); +}); + +add_task(async function test_basic_search() { + let provider = registerBasicTestProvider([match]); + const context = createContext(TEST_URL, { providers: [provider.name] }); + + let startedPromise = promiseControllerNotification( + controller, + "onQueryStarted" + ); + let resultsPromise = promiseControllerNotification( + controller, + "onQueryResults" + ); + + controller.startQuery(context); + + let params = await startedPromise; + + Assert.equal(params[0], context); + + params = await resultsPromise; + + Assert.deepEqual( + params[0].results, + [match], + "Should have the expected match" + ); +}); + +add_task(async function test_cancel_search() { + let providerCanceledDeferred = Promise.withResolvers(); + let provider = registerBasicTestProvider( + [match], + providerCanceledDeferred.resolve + ); + const context = createContext(TEST_URL, { providers: [provider.name] }); + + let startedPromise = promiseControllerNotification( + controller, + "onQueryStarted" + ); + let cancelPromise = promiseControllerNotification( + controller, + "onQueryCancelled" + ); + + let delayResultsPromise = new Promise(resolve => { + controller.addQueryListener({ + async onQueryResults(queryContext) { + controller.removeQueryListener(this); + controller.cancelQuery(queryContext); + resolve(); + }, + }); + }); + + let result = new UrlbarResult( + UrlbarUtils.RESULT_TYPE.URL, + UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, + { url: "https://example.com/1", title: "example" } + ); + + // We are awaiting for asynchronous work on initialization. + // For this test, we need the query objects to be created. We ensure this by + // using a delayed Provider. We wait for onQueryResults, then cancel the + // query. By that time the query objects are created. Then we unblock the + // delayed provider. + let delayedProvider = new UrlbarTestUtils.TestProvider({ + delayResultsPromise, + results: [result], + type: UrlbarUtils.PROVIDER_TYPE.PROFILE, + }); + + UrlbarProvidersManager.registerProvider(delayedProvider); + + controller.startQuery(context); + + let params = await startedPromise; + Assert.equal(params[0], context); + + info("Should have notified the provider the query is canceled"); + await providerCanceledDeferred.promise; + + params = await cancelPromise; + UrlbarProvidersManager.unregisterProvider(delayedProvider); +}); |