File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\lib\layout\RenderOnDemandTest.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2011, CloudBees, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package lib.layout;
25
26 import com.gargoylesoftware.htmlunit.ScriptResult;
27 import com.gargoylesoftware.htmlunit.html.HtmlPage;
28 import org.jvnet.hudson.test.HudsonTestCase;
29
30 /**
31 * Tests &lt;renderOnDemand> tag.
32 *
33 * @author Kohsuke Kawaguchi
34 */
35 public class RenderOnDemandTest extends HudsonTestCase {
36 /**
37 * Makes sure that the behavior rules are applied to newly inserted nodes,
38 * even when multiple nodes are added.
39 */
40 public void testBehaviour() throws Exception {
41 HtmlPage p = createWebClient().goTo("self/testBehaviour");
42
43 p.executeJavaScript("renderOnDemand(document.getElementsBySelector('.lazy')[0])");
44 // all AJAX calls complete before the above method returns
45
46 ScriptResult r = p.executeJavaScript("var r=document.getElementsBySelector('DIV.a'); r[0].innerHTML+r[1].innerHTML+r[2].innerHTML");
47 assertEquals("AlphaBravoCharlie",r.getJavaScriptResult().toString());
48 }
49
50 /*
51 public void testMemoryConsumption() throws Exception {
52 createWebClient().goTo("self/testBehaviour"); // prime caches
53 int total = 0;
54 for (MemoryAssert.HistogramElement element : MemoryAssert.increasedMemory(new Callable<Void>() {
55 @Override public Void call() throws Exception {
56 createWebClient().goTo("self/testBehaviour");
57 return null;
58 }
59 }, new Filter() {
60 @Override public boolean accept(Object obj, Object referredFrom, Field reference) {
61 return !obj.getClass().getName().contains("htmlunit");
62 }
63 })) {
64 total += element.byteSize;
65 System.out.println(element.className + " ×" + element.instanceCount + ": " + element.byteSize);
66 }
67 System.out.println("total: " + total);
68 }
69 */
70
71 /**
72 * Makes sure that scripts get evaluated.
73 */
74 public void testScript() throws Exception {
75 HtmlPage p = createWebClient().goTo("self/testScript");
76 assertNull(p.getElementById("loaded"));
77
78 p.getElementById("button").click();
79 // all AJAX calls complete before the above method returns
80
81 assertNotNull(p.getElementById("loaded"));
82 ScriptResult r = p.executeJavaScript("x");
83 assertEquals("xxx",r.getJavaScriptResult().toString());
84
85 r = p.executeJavaScript("y");
86 assertEquals("yyy",r.getJavaScriptResult().toString());
87
88 // if you want to test this in the browser
89 /*
90 System.out.println("Try http://localhost:"+localPort+"/self/testScript");
91 interactiveBreak();
92 */
93 }
94 }
95