AW: add test for multiple FlagOverrideHelpers
No change to logic, only tests. There is a new use case in https://crrev.com/c/5833784 which involves multiple FlagOverrideHelper instances. This class wasn't really designed for this, but it technically does work. This adds test coverage to explicitly cover this use case and prevent regressions. Bug: 380498990 Test: out/Default/bin/run_android_webview_junit_tests -f *FlagOverrideHelperTest#* Change-Id: Ia2e122e1e927b6e2a2e27254469e3d8d276364dd Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6044551 Auto-Submit: Nate Fischer <ntfschr@chromium.org> Reviewed-by: Adam Walls <avvall@chromium.org> Commit-Queue: Nate Fischer <ntfschr@chromium.org> Cr-Commit-Position: refs/heads/main@{#1387174}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
baa9566efa
commit
df23e40ff8
@ -282,4 +282,50 @@ public class FlagOverrideHelperTest {
|
||||
assertEnabledFeatures(arrayToSet("feature-1"));
|
||||
assertDisabledFeatures(arrayToSet("feature-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testMultipleOverrides() {
|
||||
Map<String, Boolean> map1 = new HashMap<>();
|
||||
map1.put("flag-1", true);
|
||||
map1.put("flag-2", false);
|
||||
map1.put("feature-1", true);
|
||||
map1.put("feature-2", false);
|
||||
FlagOverrideHelper helper1 = new FlagOverrideHelper(sMockFlagList);
|
||||
helper1.applyFlagOverrides(map1);
|
||||
|
||||
Assert.assertTrue(
|
||||
"The 'flag-1' commandline flag should be applied",
|
||||
CommandLine.getInstance().hasSwitch("flag-1"));
|
||||
Assert.assertFalse(
|
||||
"The 'flag-2' commandline flag should not be applied",
|
||||
CommandLine.getInstance().hasSwitch("flag-2"));
|
||||
Assert.assertFalse(
|
||||
"The 'flag-3' commandline flag should be off by default",
|
||||
CommandLine.getInstance().hasSwitch("flag-3"));
|
||||
assertEnabledFeatures(arrayToSet("feature-1"));
|
||||
assertDisabledFeatures(arrayToSet("feature-2"));
|
||||
|
||||
Map<String, Boolean> map2 = new HashMap<>();
|
||||
// Try a variety of ways to override.
|
||||
map2.put("flag-1", !map1.get("flag-1")); // invert the switch value
|
||||
map2.put("flag-2", map1.get("flag-2")); // keep the same switch value
|
||||
// Don't do anything with feature-1
|
||||
map2.put("feature-2", !map1.get("feature-2")); // invert the feature value
|
||||
map2.put("flag-3", true); // add a new flag
|
||||
FlagOverrideHelper helper2 = new FlagOverrideHelper(sMockFlagList);
|
||||
helper2.applyFlagOverrides(map2);
|
||||
|
||||
Assert.assertFalse(
|
||||
"The 'flag-1' commandline flag should be removed by the second FlagOverrideHelper",
|
||||
CommandLine.getInstance().hasSwitch("flag-1"));
|
||||
Assert.assertFalse(
|
||||
"The 'flag-2' commandline flag should not be applied by the second"
|
||||
+ " FlagOverrideHelper",
|
||||
CommandLine.getInstance().hasSwitch("flag-2"));
|
||||
Assert.assertTrue(
|
||||
"The 'flag-3' commandline flag should be added by the second FlagOverrideHelper",
|
||||
CommandLine.getInstance().hasSwitch("flag-3"));
|
||||
assertEnabledFeatures(arrayToSet("feature-1", "feature-2"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user