Search in sources :

Example 6 with HtmlLink

use of com.gargoylesoftware.htmlunit.html.HtmlLink in project faces by jakartaee.

the class URLClient method outputStyleEncodeTest.

/*
   * @class.setup_props: webServerHost; webServerPort; ts_home;
   */
/**
 * @testName: outputStyleEncodeTest
 * @assertion_ids: PENDING
 * @test_Strategy: Validate the following test cases.
 *
 *                 case 1: Make sure that there is a given number of 'link'
 *                 elements (2) tags rendered in the head of the response.
 *
 *                 case 2: Make sure that the correct attributes are rendered
 *                 when we call for a style sheet with no Library.
 *
 *                 case 3: Make sure that the correct attributes are rendered
 *                 when we call for a style sheet with library specified.
 *
 *                 case 4: Make sure that the correct value is set when we
 *                 have a media attribute.
 *
 * @since 2.0
 */
public void outputStyleEncodeTest() throws Fault {
    StringBuilder messages = new StringBuilder(128);
    Formatter formatter = new Formatter(messages);
    // ------------------------------------------------------------ case 1
    HtmlPage pageOne = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet.xhtml");
    List<HtmlLink> links = pageOne.getDocumentElement().getHtmlElementsByTagName("link");
    if (2 != links.size()) {
        formatter.format("Wrong number of '%s' elements rendered. %n" + "Expected: %s %n" + "Received: " + links.size(), "link", "2");
    }
    // ------------------------------------------------------------ case 2
    HtmlPage pageTwo = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet_1.xhtml");
    List<HtmlLink> linkTwo = pageTwo.getDocumentElement().getHtmlElementsByTagName("link");
    String expected1 = "/jsf_render_outputstyle_web/faces/" + "jakarta.faces.resource/night.css";
    this.testLink(linkTwo.get(0), expected1, formatter);
    // ------------------------------------------------------------ case 3
    HtmlPage pageThree = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet_2.xhtml");
    List<HtmlLink> linkThree = pageThree.getDocumentElement().getHtmlElementsByTagName("link");
    String expected2 = "/jsf_render_outputstyle_web/faces/" + "jakarta.faces.resource/morning.css";
    String expectedLib = "ln=cssLibrary";
    this.testLink(linkThree.get(0), expected2, formatter);
    this.testLink(linkThree.get(0), expectedLib, formatter);
    // ------------------------------------------------------------ case 4
    HtmlPage pageOneA = getPage(CONTEXT_ROOT + "/faces/encodetest_facelet.xhtml");
    List<HtmlLink> link = pageOne.getDocumentElement().getHtmlElementsByTagName("link");
    String mediaOne = link.get(0).getAttribute("media");
    this.testAtts("screen", mediaOne, "media", formatter);
    String mediaTwo = link.get(1).getAttribute("media");
    this.testAtts("all", mediaTwo, "media", formatter);
    handleTestStatus(messages);
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) Formatter(java.util.Formatter) HtmlLink(com.gargoylesoftware.htmlunit.html.HtmlLink)

Example 7 with HtmlLink

use of com.gargoylesoftware.htmlunit.html.HtmlLink in project maven-doxia-sitetools by apache.

the class HeadVerifier method verify.

/**
 * {@inheritDoc}
 */
public void verify(String file) throws Exception {
    HtmlPage page = htmlPage(file);
    assertNotNull(page);
    HtmlElement html = page.getDocumentElement();
    assertNotNull(html);
    assertEquals("en", html.getAttribute("lang"));
    List<HtmlElement> heads = html.getElementsByTagName("head");
    assertEquals(1, heads.size());
    HtmlElement head = heads.get(0);
    assertNotNull(head);
    Iterator<HtmlElement> elementIterator = head.getHtmlElementDescendants().iterator();
    // ----------------------------------------------------------------------
    // 
    // ----------------------------------------------------------------------
    HtmlMeta meta = (HtmlMeta) elementIterator.next();
    assertEquals("UTF-8", meta.getAttribute("charset"));
    // Skip viewport
    elementIterator.next();
    meta = (HtmlMeta) elementIterator.next();
    assertEquals("generator", meta.getAttribute("name"), "Unexpected meta entry found generated resource " + file);
    String generator = meta.getAttribute("content");
    assertEquals("Apache Maven Doxia Site Renderer", generator, "Unexpected value found for generator meta entry in generated resource " + file);
    meta = (HtmlMeta) elementIterator.next();
    assertEquals("author", meta.getAttribute("name"));
    assertEquals("John Doe", meta.getAttribute("content").trim());
    HtmlTitle title = (HtmlTitle) elementIterator.next();
    assertNotNull(title);
    HtmlLink link = (HtmlLink) elementIterator.next();
    assertNotNull(link);
    link = (HtmlLink) elementIterator.next();
    assertNotNull(link);
    link = (HtmlLink) elementIterator.next();
    assertNotNull(link);
    link = (HtmlLink) elementIterator.next();
    assertNotNull(link);
    meta = (HtmlMeta) elementIterator.next();
    assertEquals("description", meta.getAttribute("name"));
    assertEquals("Free Web tutorials", meta.getAttribute("content"));
    meta = (HtmlMeta) elementIterator.next();
    assertEquals("keywords", meta.getAttribute("name"));
    assertEquals("HTML,CSS,XML,JavaScript", meta.getAttribute("content"));
    HtmlBase base = (HtmlBase) elementIterator.next();
    assertEquals("http://maven.apache.org/", base.getAttribute("href"));
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlBase(com.gargoylesoftware.htmlunit.html.HtmlBase) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) HtmlTitle(com.gargoylesoftware.htmlunit.html.HtmlTitle) HtmlLink(com.gargoylesoftware.htmlunit.html.HtmlLink) HtmlMeta(com.gargoylesoftware.htmlunit.html.HtmlMeta)

Example 8 with HtmlLink

use of com.gargoylesoftware.htmlunit.html.HtmlLink in project jenkins by jenkinsci.

the class AjaxTest method rejectedLinks.

@Issue("JENKINS-21254")
@PresetData(PresetData.DataSet.NO_ANONYMOUS_READACCESS)
@Test
public void rejectedLinks() throws Exception {
    JenkinsRule.WebClient wc = r.createWebClient();
    String prefix = r.contextPath + '/';
    for (DomElement e : wc.goTo("login").getElementsByTagName("link")) {
        String href = ((HtmlLink) e).getHrefAttribute();
        if (!href.startsWith(prefix)) {
            System.err.println("ignoring " + href);
            continue;
        }
        System.err.println("checking " + href);
        wc.goTo(href.substring(prefix.length()), null);
    }
}
Also used : DomElement(com.gargoylesoftware.htmlunit.html.DomElement) HtmlLink(com.gargoylesoftware.htmlunit.html.HtmlLink) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Issue(org.jvnet.hudson.test.Issue) PresetData(org.jvnet.hudson.test.recipes.PresetData) Test(org.junit.Test)

Aggregations

HtmlLink (com.gargoylesoftware.htmlunit.html.HtmlLink)8 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)3 MediaListImpl (com.gargoylesoftware.css.dom.MediaListImpl)2 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)2 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)2 HtmlStyle (com.gargoylesoftware.htmlunit.html.HtmlStyle)2 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)2 MalformedURLException (java.net.MalformedURLException)2 Test (org.junit.Test)2 Issue (org.jvnet.hudson.test.Issue)2 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)2 PresetData (org.jvnet.hudson.test.recipes.PresetData)2 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1 HtmlBase (com.gargoylesoftware.htmlunit.html.HtmlBase)1 HtmlMeta (com.gargoylesoftware.htmlunit.html.HtmlMeta)1 HtmlTitle (com.gargoylesoftware.htmlunit.html.HtmlTitle)1 URL (java.net.URL)1 Formatter (java.util.Formatter)1