public void ReturnFalse_WhenTheHtmlElementHasNoAttributeStartingWithOnPrefix() { // Act var actualResult = new JavaScriptRelatedAttributeSanitizer().CanSanitize(ElementFactory.CreateAnchor()); // Assert Assert.IsFalse(actualResult); }
public void ReturnFalse_WhenElementHasNotTargetAttribute() { // Act var actualResult = new TargetAttributeSanitizer().CanSanitize(ElementFactory.CreateAnchor()); // Assert Assert.IsFalse(actualResult); }
public void ReturnFalse_WhenHtmlElementHasNotHrefAttribute() { // Act var actualResult = new HrefJavaScriptSanitizer().CanSanitize(ElementFactory.CreateAnchor()); // Assert Assert.IsFalse(actualResult); }
public void ReturnFalse_WhenHtmlElementIsNotIFrame() { // Arrange var htmlElement = ElementFactory.CreateAnchor(); // Act var actualResult = new YouTubeVideoSanitizer().CanSanitize(htmlElement); // Assert Assert.IsFalse(actualResult); }
public void SetTargetAttributeToBlank() { // Arrange var htmlElement = ElementFactory.CreateAnchor(); // Act var actualResult = new TargetAttributeSanitizer().Sanitize(ElementFactory.Document, htmlElement); // Assert Assert.IsTrue(htmlElement.HasAttribute("target")); Assert.AreEqual("_blank", htmlElement.GetAttribute("target")); }
private IHtmlInlineFrameElement CreateIFrame() { var iframe = ElementFactory.CreateIFrame(); iframe.Source = string.Format("http://youtube.com/embed/{0}", VideoId); var parent = ElementFactory.CreateAnchor(); parent.AppendChild(iframe); return(iframe); }
public void ReturnTrue_WhenElementHasTargetAttributeEqualEmptyString() { // Arrange var linkElement = ElementFactory.CreateAnchor(); linkElement.SetAttribute("target", string.Empty); // Act var actualResult = new TargetAttributeSanitizer().CanSanitize(linkElement); // Assert Assert.IsTrue(actualResult); }
public void ReturnTrue_WhenElementHasTargetAttributeNotEqualToBlank() { // Arrange var linkElement = ElementFactory.CreateAnchor(); linkElement.SetAttribute("target", "_parent"); // Act var actualResult = new TargetAttributeSanitizer().CanSanitize(linkElement); // Assert Assert.IsTrue(actualResult); }
public void ReturnTrue_WhenHrefAttributeIsStartingWithJavaScript() { // Arrange var anchorElement = ElementFactory.CreateAnchor(); anchorElement.Href = "javascript:void(0);"; // Act var actualResult = new HrefJavaScriptSanitizer().CanSanitize(anchorElement); // Assert Assert.IsTrue(actualResult); }
public void ReturnFalse_WhenHrefAttributeIsNotStartingWithJavaScript() { // Arrange var anchorElement = ElementFactory.CreateAnchor(); anchorElement.Href = "/random-url"; // Act var actualResult = new HrefJavaScriptSanitizer().CanSanitize(anchorElement); // Assert Assert.IsFalse(actualResult); }
public void RemoveScriptElement() { // Arrange var parentElement = ElementFactory.CreateAnchor(); var scriptElement = ElementFactory.CreateScript(); parentElement.AppendChild(scriptElement); // Act new ScriptElementSanitizer().Sanitize(null, scriptElement); // Assert Assert.AreEqual(0, parentElement.Children.Length); }
public void ReturnNull_WhenScriptElementIsRemoved() { // Arrange var parentElement = ElementFactory.CreateAnchor(); var scriptElement = ElementFactory.CreateScript(); parentElement.AppendChild(scriptElement); // Act var actualResult = new ScriptElementSanitizer().Sanitize(null, scriptElement); // Assert Assert.IsNull(actualResult); }
public void ReplaceHrefAttributeWithHash() { // Arrange var anchorElement = ElementFactory.CreateAnchor(); anchorElement.Href = "javascript:void(0);"; // Act var actualResult = new HrefJavaScriptSanitizer().Sanitize(null, anchorElement); // Assert // Using .GetAttribute("href") because AngleSharp tries to resolve absolute url and that leads to // about:blank/# . Explantion: https://github.com/AngleSharp/AngleSharp/issues/53 Assert.AreEqual("#", anchorElement.GetAttribute("href")); }