@Test public void testCopyStylesFromWindow() { final HTMLDocument document = mock(HTMLDocument.class); final HTMLDocument topDocument = mock(HTMLDocument.class); final Window window = mock(Window.class); final Window topWindow = mock(Window.class); final Element element = mock(Element.class); final Element head = mock(Element.class); final NodeList<Element> parentStyles = spy(new NodeList<>()); parentStyles.length = 1; window.top = topWindow; element.innerHTML = ".page { background: red }"; doReturn(element).when(parentStyles).item(0); doReturn(topDocument).when(helper).getWindowDocument(topWindow); doReturn(element).when(helper).asElement(element); doReturn(head).when(helper).asElement(head); doReturn(mock(Element.class)).when(helper).createElement("style"); when(document.querySelector("head")).thenReturn(head); when(topDocument.querySelectorAll("style")).thenReturn(parentStyles); helper.copyStylesFromWindow(document, window); verify(head).appendChild(elementArgumentCaptor.capture()); final Element copiedStyle = elementArgumentCaptor.getValue(); assertEquals(".page { background: red }", copiedStyle.innerHTML); }
void copyStylesFromWindow(final HTMLDocument printDocument, final Window window) { final HTMLDocument topDocument = getWindowDocument(window.top); final NodeList<Element> parentStyles = topDocument.querySelectorAll("style"); final Element documentHead = asElement(printDocument.querySelector("head")); for (int i = 0; i < parentStyles.length; i++) { final Element copiedStyle = createElement("style"); copiedStyle.innerHTML = asElement(parentStyles.item(i)).innerHTML; documentHead.appendChild(copiedStyle); } }
PrintHelper { void copyStylesFromWindow(final HTMLDocument printDocument, final Window window) { final HTMLDocument topDocument = getWindowDocument(window.top); final NodeList<Element> parentStyles = topDocument.querySelectorAll("style"); final Element documentHead = asElement(printDocument.querySelector("head")); for (int i = 0; i < parentStyles.length; i++) { final Element copiedStyle = createElement("style"); copiedStyle.innerHTML = asElement(parentStyles.item(i)).innerHTML; documentHead.appendChild(copiedStyle); } } }
PrintHelper { void copyStylesFromWindow(final HTMLDocument printDocument, final Window window) { final HTMLDocument topDocument = getWindowDocument(window.top); final NodeList<Element> parentStyles = topDocument.querySelectorAll("style"); final Element documentHead = asElement(printDocument.querySelector("head")); for (int i = 0; i < parentStyles.length; i++) { final Element copiedStyle = createElement("style"); copiedStyle.innerHTML = asElement(parentStyles.item(i)).innerHTML; documentHead.appendChild(copiedStyle); } }  }
PrintHelper { void copyStylesFromWindow(final HTMLDocument printDocument, final Window window) { final HTMLDocument topDocument = getWindowDocument(window.top); final NodeList<Element> parentStyles = topDocument.querySelectorAll("style"); final Element documentHead = asElement(printDocument.querySelector("head")); for (int i = 0; i < parentStyles.length; i++) { final Element copiedStyle = createElement("style"); copiedStyle.innerHTML = asElement(parentStyles.item(i)).innerHTML; documentHead.appendChild(copiedStyle); } }  void print(final HTMLElement element); }
PrintHelper { void copyStylesFromWindow(final HTMLDocument printDocument, final Window window) { final HTMLDocument topDocument = getWindowDocument(window.top); final NodeList<Element> parentStyles = topDocument.querySelectorAll("style"); final Element documentHead = asElement(printDocument.querySelector("head")); for (int i = 0; i < parentStyles.length; i++) { final Element copiedStyle = createElement("style"); copiedStyle.innerHTML = asElement(parentStyles.item(i)).innerHTML; documentHead.appendChild(copiedStyle); } }  void print(final HTMLElement element);  }