-
Notifications
You must be signed in to change notification settings - Fork 207
fix(tests): Update filter expression script to use ExperimentAPI module. #12855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
18a8a34
fix(tests): Update filter expression script to use ExperimetAPI module.
b4handjr 9eee567
Fix async script.
b4handjr 548425a
More updates.
b4handjr 048714e
Updates based on review.
b4handjr 90dbba3
Merge branch 'main' into fix-12851
b4handjr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 29 additions & 37 deletions
66
experimenter/tests/integration/nimbus/utils/filter_expression.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,47 @@ | ||
async function remoteSettings(arguments) { | ||
|
||
/* | ||
Arguments contains 2 items. | ||
arguments[0] - the JEXL targeting string | ||
arguments[1] - the experiment recipe | ||
*/ | ||
|
||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1868838 - | ||
// ASRouterTargeting was moved from browser/components/newtab into | ||
// browser/components/asrouter and its import path changed. | ||
async function remoteSettings(targetingString, recipe) { | ||
const { TelemetryEnvironment } = ChromeUtils.importESModule("resource://gre/modules/TelemetryEnvironment.sys.mjs"); | ||
await TelemetryEnvironment.onInitialized(); | ||
|
||
let ASRouterTargeting; | ||
|
||
try { | ||
ASRouterTargeting = ChromeUtils.importESModule("resource:///modules/asrouter/ASRouterTargeting.sys.mjs"); | ||
} catch (ex) { | ||
if (ex.result === Cr.NS_ERROR_FILE_NOT_FOUND) { | ||
ASRouterTargeting = ChromeUtils.importESModule("resource://activity-stream/lib/ASRouterTargeting.sys.mjs"); | ||
} else { | ||
throw ex; | ||
} | ||
} | ||
const ExperimentManager = ChromeUtils.importESModule("resource://nimbus/lib/ExperimentManager.sys.mjs"); | ||
const TargetingContext = ChromeUtils.importESModule("resource://messaging-system/targeting/Targeting.sys.mjs"); | ||
const { ASRouterTargeting } = ChromeUtils.importESModule("resource:///modules/asrouter/ASRouterTargeting.sys.mjs"); | ||
const { ExperimentAPI } = ChromeUtils.importESModule("resource://nimbus/ExperimentAPI.sys.mjs"); | ||
const { TargetingContext } = ChromeUtils.importESModule("resource://messaging-system/targeting/Targeting.sys.mjs"); | ||
|
||
const _experiment = JSON.parse(arguments[1]); | ||
const _experiment = JSON.parse(recipe); | ||
await ExperimentAPI.ready(); | ||
|
||
const context = TargetingContext.TargetingContext.combineContexts( | ||
const context = TargetingContext.combineContexts( | ||
_experiment, | ||
{ | ||
defaultProfile: {}, | ||
attributionData: {}, | ||
isMSIX: {}, | ||
isDefaultHandler: {}, | ||
defaultPDFHandler: {} | ||
}, // Workaround for supporting background tasks | ||
ExperimentManager.ExperimentManager.createTargetingContext(), | ||
ASRouterTargeting.ASRouterTargeting.Environment | ||
}, | ||
ExperimentAPI._manager.createTargetingContext(), | ||
ASRouterTargeting.Environment | ||
); | ||
const targetingContext = new TargetingContext.TargetingContext(context); | ||
let result = false; | ||
const targetingContext = new TargetingContext(context); | ||
try { | ||
result = await targetingContext.evalWithDefault(arguments[0]) !== undefined; | ||
const evalResult = await targetingContext.evalWithDefault(targetingString); | ||
return evalResult !== undefined; | ||
} catch (err) { | ||
result = null; | ||
return null; | ||
} | ||
return result; | ||
} | ||
|
||
let results = remoteSettings(arguments); | ||
|
||
return results; | ||
/* | ||
Arguments contains 3 items. | ||
arguments[0] - the JEXL targeting string | ||
arguments[1] - the experiment recipe | ||
arguments[3] - the callback from selenium | ||
*/ | ||
const [targetingString, recipe, callback] = arguments; | ||
|
||
remoteSettings(targetingString, recipe) | ||
.then(result => { | ||
callback(result); | ||
}) | ||
.catch(err => { | ||
callback(null); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.