public void SvgPreviewControlShouldAddTextBoxIfBlockedElementsArePresent()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                var svgBuilder = new StringBuilder();
                svgBuilder.AppendLine("<svg width =\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
                svgBuilder.AppendLine("\t<script>alert(\"hello\")</script>");
                svgBuilder.AppendLine("</svg>");

                // Act
                svgPreviewControl.DoPreview(GetMockStream(svgBuilder.ToString()));

                int beforeTick = Environment.TickCount;

                while (svgPreviewControl.Controls.Count < 2 && Environment.TickCount < beforeTick + ThreeSecondsInMilliseconds)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepTimeInMilliseconds);
                }

                // Assert
                Assert.IsInstanceOfType(svgPreviewControl.Controls[0], typeof(RichTextBox));
                Assert.IsInstanceOfType(svgPreviewControl.Controls[1], typeof(WebView2));
                Assert.AreEqual(2, svgPreviewControl.Controls.Count);
            }
        }
        public void SvgPreviewControlInfoBarWidthShouldAdjustWithParentControlWidthChangesIfBlockedElementsArePresent()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                var svgBuilder = new StringBuilder();
                svgBuilder.AppendLine("<svg width =\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
                svgBuilder.AppendLine("\t<script>alert(\"hello\")</script>");
                svgBuilder.AppendLine("</svg>");
                svgPreviewControl.DoPreview(GetMockStream(svgBuilder.ToString()));

                int beforeTick = Environment.TickCount;

                while (svgPreviewControl.Controls.Count == 0 && Environment.TickCount < beforeTick + ThreeSecondsInMilliseconds)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepTimeInMilliseconds);
                }

                var textBox = svgPreviewControl.Controls[0] as RichTextBox;
                var incrementParentControlWidth = 5;
                var initialParentWidth          = svgPreviewControl.Width;
                var initialTextBoxWidth         = textBox.Width;
                var finalParentWidth            = initialParentWidth + incrementParentControlWidth;

                // Act
                svgPreviewControl.Width += incrementParentControlWidth;

                // Assert
                Assert.AreEqual(initialTextBoxWidth, initialParentWidth);
                Assert.AreEqual(textBox.Width, finalParentWidth);
            }
        }
        public void SvgPreviewControlInfoBarWidthShouldAdjustWithParentControlWidthChangesIfSvgPreviewThrows()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                var mockStream = new Mock <IStream>();
                mockStream
                .Setup(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <IntPtr>()))
                .Throws(new Exception());
                svgPreviewControl.DoPreview(mockStream.Object);

                int beforeTick = Environment.TickCount;

                while (svgPreviewControl.Controls.Count == 0 && Environment.TickCount < beforeTick + ThreeSecondsInMilliseconds)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepTimeInMilliseconds);
                }

                var textBox = svgPreviewControl.Controls[0] as RichTextBox;
                var incrementParentControlWidth = 5;
                var initialParentWidth          = svgPreviewControl.Width;
                var initialTextBoxWidth         = textBox.Width;
                var finalParentWidth            = initialParentWidth + incrementParentControlWidth;

                // Act
                svgPreviewControl.Width += incrementParentControlWidth;

                // Assert
                Assert.AreEqual(initialTextBoxWidth, initialParentWidth);
                Assert.AreEqual(textBox.Width, finalParentWidth);
            }
        }
        public void SvgPreviewControlShouldAddValidInfoBarIfSvgPreviewThrows()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                var mockStream = new Mock <IStream>();
                mockStream
                .Setup(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <IntPtr>()))
                .Throws(new Exception());

                // Act
                svgPreviewControl.DoPreview(mockStream.Object);

                int beforeTick = Environment.TickCount;

                while (svgPreviewControl.Controls.Count == 0 && Environment.TickCount < beforeTick + ThreeSecondsInMilliseconds)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepTimeInMilliseconds);
                }

                var textBox = svgPreviewControl.Controls[0] as RichTextBox;

                // Assert
                Assert.IsFalse(string.IsNullOrWhiteSpace(textBox.Text));
                Assert.AreEqual(1, svgPreviewControl.Controls.Count);
                Assert.AreEqual(DockStyle.Top, textBox.Dock);
                Assert.AreEqual(Color.LightYellow, textBox.BackColor);
                Assert.IsTrue(textBox.Multiline);
                Assert.IsTrue(textBox.ReadOnly);
                Assert.AreEqual(RichTextBoxScrollBars.None, textBox.ScrollBars);
                Assert.AreEqual(BorderStyle.None, textBox.BorderStyle);
            }
        }
        public void SvgPreviewControlShouldAddValidInfoBarIfSvgPreviewThrows()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                var mockStream = new Mock <IStream>();
                mockStream
                .Setup(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <IntPtr>()))
                .Throws(new Exception());

                // Act
                svgPreviewControl.DoPreview(mockStream.Object);
                var textBox = svgPreviewControl.Controls[0] as RichTextBox;

                // Assert
                Assert.IsFalse(string.IsNullOrWhiteSpace(textBox.Text));
                Assert.AreEqual(1, svgPreviewControl.Controls.Count);
                Assert.AreEqual(DockStyle.Top, textBox.Dock);
                Assert.AreEqual(Color.LightYellow, textBox.BackColor);
                Assert.IsTrue(textBox.Multiline);
                Assert.IsTrue(textBox.ReadOnly);
                Assert.AreEqual(RichTextBoxScrollBars.None, textBox.ScrollBars);
                Assert.AreEqual(BorderStyle.None, textBox.BorderStyle);
            }
        }
        public void SvgPreviewControlShouldNotAddTextBoxIfNoBlockedElementsArePresent()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                var svgBuilder = new StringBuilder();
                svgBuilder.AppendLine("<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">");
                svgBuilder.AppendLine("\t<circle cx=\"50\" cy=\"50\" r=\"50\">");
                svgBuilder.AppendLine("\t</circle>");
                svgBuilder.AppendLine("</svg>");

                // Act
                svgPreviewControl.DoPreview(GetMockStream(svgBuilder.ToString()));

                int beforeTick = Environment.TickCount;

                while (svgPreviewControl.Controls.Count == 0 && Environment.TickCount < beforeTick + ThreeSecondsInMilliseconds)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepTimeInMilliseconds);
                }

                // Assert
                Assert.IsInstanceOfType(svgPreviewControl.Controls[0], typeof(WebView2));
                Assert.AreEqual(1, svgPreviewControl.Controls.Count);
            }
        }
        public void SvgPreviewControl_ShouldSetScrollBarsEnabledProperty_WhenDoPreviewCalled()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();

            // Act
            svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

            // Assert
            Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).ScrollBarsEnabled, true);
        }
        public void SvgPreviewControl_ShouldFillDockForWebBrowser_WhenDoPreviewCalled()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();

            // Act
            svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

            // Assert
            Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).Dock, DockStyle.Fill);
        }
        public void SvgPreviewControl_ShouldDisableWebBrowserContextMenu_WhenDoPreviewCalled()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();

            // Act
            svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

            // Assert
            Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).IsWebBrowserContextMenuEnabled, false);
        }
        public void SvgPreviewControl_ShouldSetDocumentStream_WhenDoPreviewCalled()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();

            // Act
            svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

            // Assert
            Assert.IsNotNull(((WebBrowser)svgPreviewControl.Controls[0]).DocumentStream);
        }
        public void SvgPreviewControl_ShouldDisableAllowNavigation_WhenDoPreviewCalled()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();

            // Act
            svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

            // Assert
            Assert.AreEqual(((WebBrowser)svgPreviewControl.Controls[0]).AllowNavigation, false);
        }
        public void SvgPreviewControl_ShouldAddExtendedBrowserControl_WhenDoPreviewCalled()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();

            // Act
            svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

            // Assert
            Assert.AreEqual(svgPreviewControl.Controls.Count, 1);
            Assert.IsInstanceOfType(svgPreviewControl.Controls[0], typeof(WebBrowserExt));
        }
        public void SvgPreviewControlShouldSetScriptErrorsSuppressedPropertyWhenDoPreviewCalled()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                // Act
                svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

                // Assert
                Assert.AreEqual(true, ((WebBrowser)svgPreviewControl.Controls[0]).ScriptErrorsSuppressed);
            }
        }
Beispiel #14
0
        public void SvgPreviewControl_ShouldAddTextBox_IfBlockedElementsArePresent()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();
            var svgBuilder        = new StringBuilder();

            svgBuilder.AppendLine("<svg width =\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
            svgBuilder.AppendLine("\t<script>alert(\"hello\")</script>");
            svgBuilder.AppendLine("</svg>");

            // Act
            svgPreviewControl.DoPreview(GetMockStream(svgBuilder.ToString()));

            // Assert
            Assert.IsInstanceOfType(svgPreviewControl.Controls[0], typeof(RichTextBox));
            Assert.IsInstanceOfType(svgPreviewControl.Controls[1], typeof(WebBrowserExt));
            Assert.AreEqual(svgPreviewControl.Controls.Count, 2);
        }
Beispiel #15
0
        public void SvgPreviewControl_ShouldNotAddTextBox_IfNoBlockedElementsArePresent()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();
            var svgBuilder        = new StringBuilder();

            svgBuilder.AppendLine("<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">");
            svgBuilder.AppendLine("\t<circle cx=\"50\" cy=\"50\" r=\"50\">");
            svgBuilder.AppendLine("\t</circle>");
            svgBuilder.AppendLine("</svg>");

            // Act
            svgPreviewControl.DoPreview(GetMockStream(svgBuilder.ToString()));

            // Assert
            Assert.IsInstanceOfType(svgPreviewControl.Controls[0], typeof(WebBrowserExt));
            Assert.AreEqual(svgPreviewControl.Controls.Count, 1);
        }
        public void SvgPreviewControlShouldFillDockForWebView2WhenDoPreviewCalled()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                // Act
                svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

                int beforeTick = Environment.TickCount;

                while (svgPreviewControl.Controls.Count == 0 && Environment.TickCount < beforeTick + ThreeSecondsInMilliseconds)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepTimeInMilliseconds);
                }

                // Assert
                Assert.AreEqual(DockStyle.Fill, ((WebView2)svgPreviewControl.Controls[0]).Dock);
            }
        }
        public void SvgPreviewControlShouldAddExtendedBrowserControlWhenDoPreviewCalled()
        {
            // Arrange
            using (var svgPreviewControl = new SvgPreviewControl())
            {
                // Act
                svgPreviewControl.DoPreview(GetMockStream("<svg></svg>"));

                int beforeTick = Environment.TickCount;

                while (svgPreviewControl.Controls.Count == 0 && Environment.TickCount < beforeTick + ThreeSecondsInMilliseconds)
                {
                    Application.DoEvents();
                    Thread.Sleep(SleepTimeInMilliseconds);
                }

                // Assert
                Assert.AreEqual(1, svgPreviewControl.Controls.Count);
                Assert.IsInstanceOfType(svgPreviewControl.Controls[0], typeof(WebView2));
            }
        }
Beispiel #18
0
        public void SvgPreviewControl_InfoBarWidthShouldAdjustWithParentControlWidthChanges_IfBlockedElementsArePresent()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();
            var svgBuilder        = new StringBuilder();

            svgBuilder.AppendLine("<svg width =\"200\" height=\"200\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
            svgBuilder.AppendLine("\t<script>alert(\"hello\")</script>");
            svgBuilder.AppendLine("</svg>");
            svgPreviewControl.DoPreview(GetMockStream(svgBuilder.ToString()));
            var textBox = svgPreviewControl.Controls[0] as RichTextBox;
            var incrementParentControlWidth = 5;
            var intialParentWidth           = svgPreviewControl.Width;
            var intitialTextBoxWidth        = textBox.Width;
            var finalParentWidth            = intialParentWidth + incrementParentControlWidth;

            // Act
            svgPreviewControl.Width += incrementParentControlWidth;

            // Assert
            Assert.AreEqual(intialParentWidth, intitialTextBoxWidth);
            Assert.AreEqual(finalParentWidth, textBox.Width);
        }
        public void SvgPreviewControl_InfoBarWidthShouldAdjustWithParentControlWidthChanges_IfSvgPreviewThrows()
        {
            // Arrange
            var svgPreviewControl = new SvgPreviewControl();
            var mockStream        = new Mock <IStream>();

            mockStream
            .Setup(x => x.Read(It.IsAny <byte[]>(), It.IsAny <int>(), It.IsAny <IntPtr>()))
            .Throws(new Exception());
            svgPreviewControl.DoPreview(mockStream.Object);
            var textBox = svgPreviewControl.Controls[0] as RichTextBox;
            var incrementParentControlWidth = 5;
            var intialParentWidth           = svgPreviewControl.Width;
            var intitialTextBoxWidth        = textBox.Width;
            var finalParentWidth            = intialParentWidth + incrementParentControlWidth;

            // Act
            svgPreviewControl.Width += incrementParentControlWidth;

            // Assert
            Assert.AreEqual(intialParentWidth, intitialTextBoxWidth);
            Assert.AreEqual(finalParentWidth, textBox.Width);
        }