diff --git a/browser/components/urlbar/UrlbarEventBufferer.sys.mjs b/browser/components/urlbar/UrlbarEventBufferer.sys.mjs index 91331c0477959..600593db233bb 100644 --- a/browser/components/urlbar/UrlbarEventBufferer.sys.mjs +++ b/browser/components/urlbar/UrlbarEventBufferer.sys.mjs @@ -217,7 +217,7 @@ UKNOWN RUNNING : 1 -RUNNING_GOT_RESULTS +RUNNING_GOT_ALL_HEURISTIC_RESULTS : 2 COMPLETE @@ -433,7 +433,7 @@ than / UrlbarProvidersManager . -CHUNK_HEURISTIC_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS . static DEFERRING_TIMEOUT_MS @@ -442,7 +442,7 @@ Cu . isInAutomation ? -1000 +1500 : 300 ; @@ -850,6 +850,18 @@ onQueryResults queryContext ) { +if +( +queryContext +. +pendingHeuristicProviders +. +size +) +{ +return +; +} this . _lastQuery @@ -858,7 +870,7 @@ status = QUERY_STATUS . -RUNNING_GOT_RESULTS +RUNNING_GOT_ALL_HEURISTIC_RESULTS ; / / @@ -2279,23 +2291,23 @@ this _lastQuery . status -! += = QUERY_STATUS . -RUNNING -& -& +COMPLETE +| +| this . _lastQuery . status -! += = QUERY_STATUS . -RUNNING_GOT_RESULTS +UKNOWN ) { / @@ -2327,7 +2339,7 @@ true ; } let -waitingFirstResult +waitingHeuristicResults = this . @@ -2398,8 +2410,7 @@ are not waiting for -the -first +heuristic results yet . @@ -2428,13 +2439,13 @@ heuristic | | ! -waitingFirstResult +waitingHeuristicResults ) ; } if ( -waitingFirstResult +waitingHeuristicResults | | ! diff --git a/browser/components/urlbar/UrlbarProvidersManager.sys.mjs b/browser/components/urlbar/UrlbarProvidersManager.sys.mjs index 67396f5423e91..2d2717ad0a793 100644 --- a/browser/components/urlbar/UrlbarProvidersManager.sys.mjs +++ b/browser/components/urlbar/UrlbarProvidersManager.sys.mjs @@ -1087,38 +1087,9 @@ _notifyResultsFromProvider for details . -/ -/ -Note -: -to -avoid -handling -events -too -early -the -heuristic -timer -should -be -/ -/ -smaller -than -UrlbarEventBufferer -. -DEFERRING_TIMEOUT_MS -. this . -CHUNK_HEURISTIC_RESULTS_DELAY_MS -= -200 -; -this -. -CHUNK_OTHER_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS = 16 ; @@ -3483,32 +3454,6 @@ to the user . -We -skip -the -Omnibox -provider -/ -/ -because -being -implemented -in -an -add -- -on -we -have -no -control -over -its -/ -/ -performance -characteristics -. if ( provider @@ -3523,16 +3468,6 @@ UrlbarUtils PROVIDER_TYPE . HEURISTIC -& -& -provider -. -name -! -= -" -Omnibox -" ) { this @@ -4556,174 +4491,6 @@ if this . _chunkTimer -& -& -this -. -context -. -pendingHeuristicProviders -. -size -) -{ -/ -/ -This -is -the -first -time -we -see -a -result -and -some -heuristic -providers -/ -/ -are -still -pending -. -We -start -a -longer -" -heuristic -" -timeout -because -we -/ -/ -don -' -t -want -to -surprise -the -user -with -an -unexpected -default -action -( -e -. -g -. -/ -/ -searching -instead -of -handling -a -bookmark -keyword -) -. -/ -/ -Since -heuristic -providers -return -results -pretty -quickly -this -timer -/ -/ -will -often -be -skipped -early -. -/ -/ -Note -that -if -the -heuristic -timer -elapses -we -may -still -cause -an -/ -/ -imperfect -default -action -but -that -' -s -still -better -than -looking -stale -. -this -. -_chunkTimer -= -new -lazy -. -SkippableTimer -( -{ -name -: -" -heuristic -" -callback -: -( -) -= -> -this -. -_notifyResults -( -) -time -: -UrlbarProvidersManager -. -CHUNK_HEURISTIC_RESULTS_DELAY_MS -logger -: -provider -. -logger -} -) -; -} -else -if -( -! -this -. -_chunkTimer | | this @@ -4802,7 +4569,7 @@ time : UrlbarProvidersManager . -CHUNK_OTHER_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS logger : provider @@ -4815,34 +4582,28 @@ logger else if ( -this -. -_chunkTimer -. -name -= -= -" -heuristic -" -& -& ! this . -_chunkTimer +context . -done +pendingHeuristicProviders +. +size & & -! -this +provider . -context +type += += +lazy . -pendingHeuristicProviders +UrlbarUtils . -size +PROVIDER_TYPE +. +HEURISTIC ) { / diff --git a/browser/components/urlbar/tests/browser/browser.toml b/browser/components/urlbar/tests/browser/browser.toml index ddd065dbd2399..e13d98e89405a 100644 --- a/browser/components/urlbar/tests/browser/browser.toml +++ b/browser/components/urlbar/tests/browser/browser.toml @@ -2902,6 +2902,13 @@ or labeled [ " +browser_slow_heuristic +. +js +" +] +[ +" browser_speculative_connect . js diff --git a/browser/components/urlbar/tests/browser/browser_slow_heuristic.js b/browser/components/urlbar/tests/browser/browser_slow_heuristic.js new file mode 100644 index 0000000000000..9400571d89f2a --- /dev/null +++ b/browser/components/urlbar/tests/browser/browser_slow_heuristic.js @@ -0,0 +1,486 @@ +/ +* +Any +copyright +is +dedicated +to +the +Public +Domain +. +* +http +: +/ +/ +creativecommons +. +org +/ +publicdomain +/ +zero +/ +1 +. +0 +/ +* +/ +/ +/ +Test +that +slow +heuristic +results +are +still +waited +for +on +selection +. +" +use +strict +" +; +add_task +( +async +function +test_slow_heuristic +( +) +{ +/ +/ +Must +be +between +CHUNK_RESULTS_DELAY_MS +and +DEFERRING_TIMEOUT_MS +let +timeout += +150 +; +Assert +. +greater +( +timeout +UrlbarProvidersManager +. +CHUNK_RESULTS_DELAY_MS +) +; +Assert +. +greater +( +UrlbarEventBufferer +. +DEFERRING_TIMEOUT_MS +timeout +) +; +/ +/ +First +add +a +provider +that +adds +a +heuristic +result +on +a +delay +. +let +heuristicResult += +new +UrlbarResult +( +UrlbarUtils +. +RESULT_TYPE +. +URL +UrlbarUtils +. +RESULT_SOURCE +. +OTHER_LOCAL +{ +url +: +" +https +: +/ +/ +example +. +com +/ +" +} +) +; +heuristicResult +. +heuristic += +true +; +let +heuristicProvider += +new +UrlbarTestUtils +. +TestProvider +( +{ +results +: +[ +heuristicResult +] +name +: +" +heuristicProvider +" +priority +: +Infinity +addTimeout +: +timeout +} +) +; +UrlbarProvidersManager +. +registerProvider +( +heuristicProvider +) +; +registerCleanupFunction +( +( +) += +> +{ +UrlbarProvidersManager +. +unregisterProvider +( +heuristicProvider +) +; +} +) +; +/ +/ +Do +a +search +without +waiting +for +a +result +. +const +win += +await +BrowserTestUtils +. +openNewBrowserWindow +( +) +; +let +promiseLoaded += +BrowserTestUtils +. +browserLoaded +( +win +. +gBrowser +. +selectedBrowser +) +; +win +. +gURLBar +. +focus +( +) +; +EventUtils +. +sendString +( +" +test +" +win +) +; +EventUtils +. +synthesizeKey +( +" +KEY_Enter +" +{ +} +win +) +; +await +promiseLoaded +; +await +UrlbarTestUtils +. +promisePopupClose +( +win +) +; +await +BrowserTestUtils +. +closeWindow +( +win +) +; +} +) +; +add_task +( +async +function +test_fast_heuristic +( +) +{ +let +longTimeoutMs += +1000000 +; +let +originalHeuristicTimeout += +UrlbarProvidersManager +. +CHUNK_RESULTS_DELAY_MS +; +UrlbarProvidersManager +. +CHUNK_RESULTS_DELAY_MS += +longTimeoutMs +; +registerCleanupFunction +( +( +) += +> +{ +UrlbarProvidersManager +. +CHUNK_RESULTS_DELAY_MS += +originalHeuristicTimeout +; +} +) +; +/ +/ +Add +a +fast +heuristic +provider +. +let +heuristicResult += +new +UrlbarResult +( +UrlbarUtils +. +RESULT_TYPE +. +URL +UrlbarUtils +. +RESULT_SOURCE +. +OTHER_LOCAL +{ +url +: +" +https +: +/ +/ +example +. +com +/ +" +} +) +; +heuristicResult +. +heuristic += +true +; +let +heuristicProvider += +new +UrlbarTestUtils +. +TestProvider +( +{ +results +: +[ +heuristicResult +] +name +: +" +heuristicProvider +" +priority +: +Infinity +} +) +; +UrlbarProvidersManager +. +registerProvider +( +heuristicProvider +) +; +registerCleanupFunction +( +( +) += +> +{ +UrlbarProvidersManager +. +unregisterProvider +( +heuristicProvider +) +; +} +) +; +/ +/ +Do +a +search +. +const +win += +await +BrowserTestUtils +. +openNewBrowserWindow +( +) +; +let +startTime += +Cu +. +now +( +) +; +Assert +. +greater +( +longTimeoutMs +Cu +. +now +( +) +- +startTime +" +Heuristic +result +is +returned +faster +than +CHUNK_RESULTS_DELAY_MS +" +) +; +await +UrlbarTestUtils +. +promisePopupClose +( +win +) +; +await +BrowserTestUtils +. +closeWindow +( +win +) +; +} +) +; diff --git a/browser/components/urlbar/tests/browser/head.js b/browser/components/urlbar/tests/browser/head.js index 8cc1e010e8eda..82c01a953725f 100644 --- a/browser/components/urlbar/tests/browser/head.js +++ b/browser/components/urlbar/tests/browser/head.js @@ -204,6 +204,22 @@ sys . mjs " +UrlbarEventBufferer +: +" +resource +: +/ +/ +/ +modules +/ +UrlbarEventBufferer +. +sys +. +mjs +" UrlbarQueryContext : " diff --git a/browser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_engagement_edge_cases.js b/browser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_engagement_edge_cases.js index 9f42fcab1f254..e5429f8d40b11 100644 --- a/browser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_engagement_edge_cases.js +++ b/browser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_engagement_edge_cases.js @@ -428,28 +428,15 @@ to notifyResults . let -originalHeuristicTimeout +originalChunkTimeout = UrlbarProvidersManager . -CHUNK_HEURISTIC_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS ; UrlbarProvidersManager . -CHUNK_HEURISTIC_RESULTS_DELAY_MS -= -1000000 -; -let -originalOtherTimeout -= -UrlbarProvidersManager -. -CHUNK_OTHER_RESULTS_DELAY_MS -; -UrlbarProvidersManager -. -CHUNK_OTHER_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS = 1000000 ; @@ -523,15 +510,9 @@ anotherHeuristicProvider ; UrlbarProvidersManager . -CHUNK_HEURISTIC_RESULTS_DELAY_MS -= -originalHeuristicTimeout -; -UrlbarProvidersManager -. -CHUNK_OTHER_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS = -originalOtherTimeout +originalChunkTimeout ; } ; diff --git a/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js b/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js index 058320cc3e43a..aa5970d8f4da0 100644 --- a/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js +++ b/browser/components/urlbar/tests/quicksuggest/browser/browser_telemetry_impressionEdgeCases.js @@ -2506,28 +2506,15 @@ avoid here . let -originalHeuristicTimeout +originalChunkTimeout = UrlbarProvidersManager . -CHUNK_HEURISTIC_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS ; UrlbarProvidersManager . -CHUNK_HEURISTIC_RESULTS_DELAY_MS -= -30000 -; -let -originalOtherTimeout -= -UrlbarProvidersManager -. -CHUNK_OTHER_RESULTS_DELAY_MS -; -UrlbarProvidersManager -. -CHUNK_OTHER_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS = 30000 ; @@ -2541,15 +2528,9 @@ cleanup { UrlbarProvidersManager . -CHUNK_HEURISTIC_RESULTS_DELAY_MS -= -originalHeuristicTimeout -; -UrlbarProvidersManager -. -CHUNK_OTHER_RESULTS_DELAY_MS +CHUNK_RESULTS_DELAY_MS = -originalOtherTimeout +originalChunkTimeout ; } ; diff --git a/browser/components/urlbar/tests/unit/test_slow_heuristic.js b/browser/components/urlbar/tests/unit/test_slow_heuristic.js deleted file mode 100644 index 0add1f5fe9c4f..0000000000000 --- a/browser/components/urlbar/tests/unit/test_slow_heuristic.js +++ /dev/null @@ -1,1048 +0,0 @@ -/ -* -Any -copyright -is -dedicated -to -the -Public -Domain -. -http -: -/ -/ -creativecommons -. -org -/ -publicdomain -/ -zero -/ -1 -. -0 -/ -* -/ -/ -* -* -* -Tests -that -a -slow -heuristic -provider -returns -results -normally -if -it -reacts -* -before -the -longer -heuristic -chunk -timer -elapses -. -* -/ -add_task -( -async -function -test_chunking_delays -( -) -{ -let -{ -UrlbarEventBufferer -} -= -ChromeUtils -. -importESModule -( -" -resource -: -/ -/ -/ -modules -/ -UrlbarEventBufferer -. -sys -. -mjs -" -) -; -Assert -. -greater -( -UrlbarEventBufferer -. -DEFERRING_TIMEOUT_MS -UrlbarProvidersManager -. -CHUNK_HEURISTIC_RESULTS_DELAY_MS -" -The -deferring -timeout -must -be -larger -than -the -heuristic -chunk -timer -" -) -; -} -) -; -add_task -( -async -function -test_normal -( -) -{ -/ -/ -In -a -normal -situation -we -fire -the -chunking -timer -early -as -soon -as -all -the -/ -/ -heuristic -providers -reported -back -. -let -origTimer -= -UrlbarProvidersManager -. -CHUNK_HEURISTIC_RESULTS_DELAY_MS -; -/ -/ -Set -to -a -large -value -results -should -be -returned -earlier -. -let -longTimeoutMs -= -10000 -; -UrlbarProvidersManager -. -CHUNK_HEURISTIC_RESULTS_DELAY_MS -= -longTimeoutMs -; -/ -/ -Add -a -heuristic -provider -returning -no -results -and -check -we -don -' -t -wait -/ -/ -for -the -whole -heuristic -timeout -because -of -that -. -let -noResultsHeuristicProvider -= -new -UrlbarTestUtils -. -TestProvider -( -{ -results -: -[ -] -/ -/ -Empty -results -provider -name -: -" -TestHeuristic -" -type -: -UrlbarUtils -. -PROVIDER_TYPE -. -HEURISTIC -} -) -; -UrlbarProvidersManager -. -registerProvider -( -noResultsHeuristicProvider -) -; -let -fastProfileProvider -= -new -UrlbarTestUtils -. -TestProvider -( -{ -results -: -[ -makeVisitResult -( -createContext -( -" -test -" -) -{ -uri -: -" -https -: -/ -/ -www -. -example -. -com -/ -test2 -" -title -: -" -test -visit -for -https -: -/ -/ -www -. -example -. -com -/ -test2 -" -} -) -] -name -: -" -TestNormal -" -type -: -UrlbarUtils -. -PROVIDER_TYPE -. -PROFILE -} -) -; -UrlbarProvidersManager -. -registerProvider -( -fastProfileProvider -) -; -let -slowProfileProvider -= -new -UrlbarTestUtils -. -TestProvider -( -{ -results -: -[ -] -name -: -" -TestNormal -" -type -: -UrlbarUtils -. -PROVIDER_TYPE -. -PROFILE -addTimeout -: -longTimeoutMs -} -) -; -UrlbarProvidersManager -. -registerProvider -( -slowProfileProvider -) -; -function -cleanup -( -) -{ -UrlbarProvidersManager -. -unregisterProvider -( -noResultsHeuristicProvider -) -; -UrlbarProvidersManager -. -unregisterProvider -( -fastProfileProvider -) -; -UrlbarProvidersManager -. -unregisterProvider -( -slowProfileProvider -) -; -UrlbarProvidersManager -. -CHUNK_HEURISTIC_RESULTS_DELAY_MS -= -origTimer -; -} -registerCleanupFunction -( -cleanup -) -; -let -controller -= -UrlbarTestUtils -. -newMockController -( -) -; -let -promiseResultsNotified -= -new -Promise -( -resolve -= -> -{ -let -listener -= -{ -onQueryResults -( -queryContext -) -{ -controller -. -removeQueryListener -( -listener -) -; -resolve -( -queryContext -. -results -) -; -} -} -; -controller -. -addQueryListener -( -listener -) -; -} -) -; -let -context -= -createContext -( -" -test -" -{ -providers -: -[ -noResultsHeuristicProvider -. -name -fastProfileProvider -. -name -slowProfileProvider -. -name -] -} -) -; -/ -/ -Start -the -timer -and -don -' -t -wait -for -the -query -we -want -to -measure -time -to -/ -/ -the -onQueryResults -call -. -let -startTime -= -Cu -. -now -( -) -; -let -promiseQueryComplete -= -controller -. -startQuery -( -context -) -; -await -promiseResultsNotified -; -let -timeDiff -= -Cu -. -now -( -) -- -startTime -; -Assert -. -greater -( -longTimeoutMs -timeDiff -It -took -{ -timeDiff -} -ms -from -start -to -return -results -) -; -/ -/ -Cancelling -the -query -should -return -earlier -and -not -wait -for -the -slow -/ -/ -provider -. -controller -. -cancelQuery -( -) -; -await -promiseQueryComplete -; -timeDiff -= -Cu -. -now -( -) -- -startTime -; -Assert -. -greater -( -longTimeoutMs -timeDiff -It -took -{ -timeDiff -} -ms -from -start -to -cancel -the -query -) -; -cleanup -( -) -; -} -) -; -add_task -( -async -function -test_slow -( -) -{ -/ -/ -Must -be -between -CHUNK_RESULTS_DELAY_MS -and -CHUNK_HEURISTIC_RESULTS_DELAY_MS -. -let -timeout -= -150 -; -Assert -. -greater -( -timeout -UrlbarProvidersManager -. -CHUNK_OTHER_RESULTS_DELAY_MS -) -; -Assert -. -greater -( -UrlbarProvidersManager -. -CHUNK_HEURISTIC_RESULTS_DELAY_MS -timeout -) -; -let -provider1 -= -new -UrlbarTestUtils -. -TestProvider -( -{ -results -: -[ -makeVisitResult -( -createContext -( -" -test -" -) -{ -uri -: -" -https -: -/ -/ -www -. -example -. -com -/ -test -" -title -: -" -test -visit -for -https -: -/ -/ -www -. -example -. -com -/ -test -" -heuristic -: -true -} -) -] -name -: -" -TestHeuristic -" -type -: -UrlbarUtils -. -PROVIDER_TYPE -. -HEURISTIC -addTimeout -: -timeout -} -) -; -UrlbarProvidersManager -. -registerProvider -( -provider1 -) -; -let -provider2 -= -new -UrlbarTestUtils -. -TestProvider -( -{ -results -: -[ -makeVisitResult -( -createContext -( -" -test -" -) -{ -uri -: -" -https -: -/ -/ -www -. -example -. -com -/ -test2 -" -title -: -" -test -visit -for -https -: -/ -/ -www -. -example -. -com -/ -test2 -" -} -) -] -name -: -" -TestNormal -" -type -: -UrlbarUtils -. -PROVIDER_TYPE -. -PROFILE -} -) -; -UrlbarProvidersManager -. -registerProvider -( -provider2 -) -; -registerCleanupFunction -( -( -) -= -> -{ -UrlbarProvidersManager -. -unregisterProvider -( -provider1 -) -; -UrlbarProvidersManager -. -unregisterProvider -( -provider2 -) -; -} -) -; -let -controller -= -UrlbarTestUtils -. -newMockController -( -) -; -let -promiseResultsNotified -= -new -Promise -( -resolve -= -> -{ -let -listener -= -{ -onQueryResults -( -queryContext -) -{ -controller -. -removeQueryListener -( -listener -) -; -resolve -( -queryContext -. -results -) -; -} -} -; -controller -. -addQueryListener -( -listener -) -; -} -) -; -let -context -= -createContext -( -" -test -" -{ -providers -: -[ -provider1 -. -name -provider2 -. -name -] -} -) -; -await -controller -. -startQuery -( -context -) -; -let -results -= -await -promiseResultsNotified -; -info -( -" -Results -: -\ -n -" -+ -results -. -map -( -m -= -> -{ -m -. -title -} -- -{ -m -. -payload -. -url -} -) -. -join -( -" -\ -n -" -) -) -; -Assert -. -equal -( -results -. -length -2 -" -Found -the -expected -number -of -results -" -) -; -Assert -. -ok -( -context -. -results -[ -0 -] -. -heuristic -) -; -Assert -. -equal -( -context -. -results -[ -0 -] -. -payload -. -url -" -https -: -/ -/ -www -. -example -. -com -/ -test -" -) -; -} -) -; diff --git a/browser/components/urlbar/tests/unit/xpcshell.ini b/browser/components/urlbar/tests/unit/xpcshell.ini index 40af956a0b337..844200b9c4f35 100644 --- a/browser/components/urlbar/tests/unit/xpcshell.ini +++ b/browser/components/urlbar/tests/unit/xpcshell.ini @@ -440,11 +440,6 @@ test_search_suggestions_tail js ] [ -test_slow_heuristic -. -js -] -[ test_special_search . js