public void ReturnFalse_WhenElementArgumentIsNull() { // Act var actualResult = new ImageSanitizer().CanSanitize(null); // Assert Assert.IsFalse(actualResult); }
public void ReturnTrue_WhenElementIsImageElement() { // Arrange var htmlElement = ElementFactory.CreateImage(); // Act var actualResult = new ImageSanitizer().CanSanitize(htmlElement); // Assert Assert.IsTrue(actualResult); }
public void ReturnFalse_WhenElementArgumentIsNotImageElement() { // Arrange var htmlElement = ElementFactory.Create("div"); // Act var actualResult = new ImageSanitizer().CanSanitize(htmlElement); // Assert Assert.IsFalse(actualResult); }
public void ReturnAmpImageElementWithLayoutAttributeSetToFill_IfTheOriginalImageElementHasNoWidthAndHeightAttributesAndShouldDownloadImagesIsNotSpecified() { // Arrange const string ExpectedResult = "fill"; var imageElement = ElementFactory.CreateImage(); imageElement.Source = "http://www.mywebsite.com/img1.jpg"; ElementFactory.Document.Body.Append(imageElement); // Act var actualResult = new ImageSanitizer().Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, actualResult.GetAttribute("layout")); }
public void ReturnAmpImageElementWithLayoutEqualToNoDisplay_WhenTheImageHasAttributeStyleVisibilityHidden() { // Arrange const string ExpectedResult = "nodisplay"; var imageElement = ElementFactory.CreateImage(); imageElement.SetAttribute("style", "visibility:hidden"); // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = new ImageSanitizer().Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, ampElement.GetAttribute("layout")); }
public void ReturnAmpImageElementWithLayoutAttributeSetToResponsive_IfTheOriginalImageElementHasBothWidthAndHeightAttributes() { // Arrange const string ExpectedResult = "responsive"; var imageElement = ElementFactory.CreateImage(); imageElement.Source = "http://www.mywebsite.com/img1.jpg"; imageElement.DisplayWidth = 100; imageElement.DisplayHeight = 100; ElementFactory.Document.Body.Append(imageElement); // Act var actualResult = new ImageSanitizer().Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, actualResult.GetAttribute("layout")); }
public void ReturnAmpImageElement() { // Arrange const int ImageSize = 100; const string ExpectedResult = "AMP-IMG"; var imageElement = ElementFactory.CreateImage(); imageElement.DisplayWidth = ImageSize; imageElement.DisplayHeight = ImageSize; // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = new ImageSanitizer().Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, ampElement.TagName); }
public void ReturnAmpImageElementWithLayoutEqualToResponsive_WhenWidthAndHeightAreSpecified() { // Arrange const string ExpectedResult = "responsive"; const int ImageSize = 100; var imageElement = ElementFactory.CreateImage(); imageElement.DisplayWidth = ImageSize; imageElement.DisplayHeight = ImageSize; // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = new ImageSanitizer().Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, ampElement.GetAttribute("layout")); }
public void ReturnAmpImageElementWithPredefinedHeight_WhenWidthAndHeightAreSpecified() { // Arrange const int ImageSize = 100; var imageElement = ElementFactory.CreateImage(); imageElement.DisplayWidth = ImageSize; imageElement.DisplayHeight = ImageSize; // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = new ImageSanitizer().Sanitize(ElementFactory.Document, imageElement); // Assert int actualHeight = int.Parse(ampElement.GetAttribute("height")); Assert.AreEqual(ImageSize, actualHeight); }
public void ReturnAmpAnimElement_WhenSourceExtensionIsGIF() { // Arrange const string ExpectedResult = "AMP-ANIM"; const int ImageSize = 100; var imageElement = ElementFactory.CreateImage(); imageElement.DisplayWidth = ImageSize; imageElement.DisplayHeight = ImageSize; imageElement.Source = "http://mysite.com/my-animation.gif"; // Adding image element to the document in order to simulate real herarchy ElementFactory.Document.Body.Append(imageElement); // Act var ampElement = new ImageSanitizer().Sanitize(ElementFactory.Document, imageElement); // Assert Assert.AreEqual(ExpectedResult, ampElement.TagName); }
public void CopyAllAttributesFromTheOriginalImageElementToTheAmpElement_Always() { // Arrange var htmlElement = ElementFactory.CreateImage(); htmlElement.Source = "https://www.example.com/img1.png"; htmlElement.Id = "imgId"; htmlElement.ClassName = "someClassName"; htmlElement.DisplayWidth = 100; htmlElement.DisplayHeight = 200; ElementFactory.Document.Body.Append(htmlElement); // Act var actualResult = new ImageSanitizer().Sanitize(ElementFactory.Document, htmlElement); // Assert Assert.AreEqual("https://www.example.com/img1.png", actualResult.GetAttribute("src")); Assert.AreEqual("imgId", actualResult.Id); Assert.AreEqual("someClassName", actualResult.ClassName); Assert.AreEqual(100, int.Parse(actualResult.GetAttribute("width"))); Assert.AreEqual(200, int.Parse(actualResult.GetAttribute("height"))); }