Example #1
0
        public void PermissionsPolicy_Build_WhenNoValues_Returns()
        {
            var builder = new PermissionsPolicyBuilder();

            var result = builder.Build();

            result.Should().BeNullOrEmpty();
        }
Example #2
0
        /// <summary>
        /// Configure a permission policy.
        /// </summary>
        /// <param name="configure">Configure the Permissions-Policy header</param>
        /// <returns>The complete Permissions-Policy header</returns>
        public static PermissionsPolicyHeader Build(Action <PermissionsPolicyBuilder> configure)
        {
            var builder = new PermissionsPolicyBuilder();

            configure(builder);

            return(new PermissionsPolicyHeader(builder.Build()));
        }
Example #3
0
        public void PermissionsPolicy_Build_AddAccelerometer_WhenIncludesAllAndNone_ThrowsInvalidOperationException()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddAccelerometer()
            .None()
            .All();

            Assert.Throws <InvalidOperationException>(() => builder.Build());
        }
Example #4
0
        public void PermissionsPolicy_Build_AddFLoC_Calculation_WhenIncludesNone_OnlyWritesNone()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddFederatedLearningOfCohortsCalculation()
            .None();

            var result = builder.Build();

            result.Should().Be("interest-cohort=()");
        }
Example #5
0
        public void PermissionsPolicy_Build_AddSelfOnly_ReturnsOnlySelf()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddAccelerometer()
            .Self();

            var result = builder.Build();

            result.Should().Be("accelerometer=self");
        }
Example #6
0
        public void PermissionsPolicy_Build_AddingTheSameDirectiveTwice_OverwritesThePreviousCopy()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddAccelerometer().Self();
            builder.AddAccelerometer().None();

            var result = builder.Build();

            result.Should().Be("accelerometer=()");
        }
Example #7
0
        public void PermissionsPolicy_Build_CustomPermissionsPolicyBuilder_AddsValues()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddCustomFeature("push").None();
            builder.AddCustomFeature("vibrate").All();

            var result = builder.Build();

            result.Should().Be("push=(), vibrate=*");
        }
Example #8
0
        public void PermissionsPolicy_Build_AddAccelerometer_WhenAddsMultipleValue_ReturnsAllValues()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddAccelerometer()
            .Self()
            .For("http://testUrl.com").For("https://testUrl2.se");

            var result = builder.Build();

            result.Should().Be("accelerometer=(self \"http://testUrl.com\" \"https://testUrl2.se\")");
        }
Example #9
0
        public void PermissionsPolicy_Build_CustomPermissionsPolicyDirective_AddsValues()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddCustomFeature("push", string.Empty);
            builder.AddCustomFeature("vibrate", "*");
            builder.AddCustomFeature("something-else", string.Empty);

            var result = builder.Build();

            result.Should().Be("push=(), vibrate=*, something-else=()");
        }
Example #10
0
        public void PermissionsBuild_AddAccelerometer_WhenIncludesAll_OnlyWritesAll()
        {
            var builder = new PermissionsPolicyBuilder();

            builder.AddAccelerometer()
            .Self()
            .For("http://testUrl.com")
            .All();

            var result = builder.Build();

            result.Should().Be("accelerometer=*");
        }