During the API review process (bug 246133) the reviewers decided that in order to include html4j to NetBeans Platform, we need to stop using org.apidesign namespace and switch to NetBeans one. Repackaging all SPI packages into org.netbeans.html.smthng.spi.
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
6 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7 * Other names may be trademarks of their respective owners.
9 * The contents of this file are subject to the terms of either the GNU
10 * General Public License Version 2 only ("GPL") or the Common
11 * Development and Distribution License("CDDL") (collectively, the
12 * "License"). You may not use this file except in compliance with the
13 * License. You can obtain a copy of the License at
14 * http://www.netbeans.org/cddl-gplv2.html
15 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16 * specific language governing permissions and limitations under the
17 * License. When distributing the software, include this License Header
18 * Notice in each file and include the License file at
19 * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20 * particular file as subject to the "Classpath" exception as provided
21 * by Oracle in the GPL Version 2 section of the License file that
22 * accompanied this code. If applicable, add the following below the
23 * License Header, with the fields enclosed by brackets [] replaced by
24 * your own identifying information:
25 * "Portions Copyrighted [year] [name of copyright owner]"
29 * The Original Software is NetBeans. The Initial Developer of the Original
30 * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
32 * If you wish your version of this file to be governed by only the CDDL
33 * or only the GPL Version 2, indicate your decision by adding
34 * "[Contributor] elects to include this software in this distribution
35 * under the [CDDL or GPL Version 2] license." If you do not indicate a
36 * single choice of license, a recipient has the option to distribute
37 * your version of this file under either the CDDL, the GPL Version 2 or
38 * to extend the choice of license to its licensees as provided above.
39 * However, if you add GPL Version 2 code and therefore, elected the GPL
40 * Version 2 license, then the option applies only if the new code is
41 * made subject to such option by the copyright holder.
43 package net.java.html.json.tests;
45 import java.util.Arrays;
46 import java.util.List;
47 import java.util.Timer;
48 import java.util.TimerTask;
49 import net.java.html.BrwsrCtx;
50 import net.java.html.json.ComputedProperty;
51 import net.java.html.json.Function;
52 import net.java.html.json.Model;
53 import net.java.html.json.Models;
54 import net.java.html.json.Property;
55 import org.netbeans.html.json.tck.KOTest;
59 * @author Jaroslav Tulach
61 @Model(className="KnockoutModel", properties={
62 @Property(name="name", type=String.class),
63 @Property(name="results", type=String.class, array = true),
64 @Property(name="numbers", type=int.class, array = true),
65 @Property(name="callbackCount", type=int.class),
66 @Property(name="people", type=PersonImpl.class, array = true),
67 @Property(name="enabled", type=boolean.class),
68 @Property(name="latitude", type=double.class),
69 @Property(name="choice", type=KnockoutTest.Choice.class),
70 @Property(name="archetype", type=ArchetypeData.class),
71 @Property(name="archetypes", type=ArchetypeData.class, array = true),
73 public final class KnockoutTest {
74 private KnockoutModel js;
80 @ComputedProperty static List<Integer> resultLengths(List<String> results) {
81 Integer[] arr = new Integer[results.size()];
82 for (int i = 0; i < arr.length; i++) {
83 arr[i] = results.get(i).length();
85 return Arrays.asList(arr);
88 @KOTest public void modifyValueAssertChangeInModelOnEnum() throws Throwable {
89 Object exp = Utils.exposeHTML(KnockoutTest.class,
90 "Latitude: <input id='input' data-bind=\"value: choice\"></input>\n"
94 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
95 m.setChoice(Choice.A);
98 String v = getSetInput(null);
99 assert "A".equals(v) : "Value is really A: " + v;
102 triggerEvent("input", "change");
104 assert Choice.B == m.getChoice(): "Enum property updated: " + m.getChoice();
105 } catch (Throwable t) {
108 Utils.exposeHTML(KnockoutTest.class, "");
112 @KOTest public void modifyValueAssertChangeInModelOnDouble() throws Throwable {
113 Object exp = Utils.exposeHTML(KnockoutTest.class,
114 "Latitude: <input id='input' data-bind=\"value: latitude\"></input>\n"
118 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
122 String v = getSetInput(null);
123 assert "50.5".equals(v) : "Value is really 50.5: " + v;
126 triggerEvent("input", "change");
128 assert 49.5 == m.getLatitude() : "Double property updated: " + m.getLatitude();
129 } catch (Throwable t) {
132 Utils.exposeHTML(KnockoutTest.class, "");
136 @KOTest public void modifyValueAssertChangeInModelOnBoolean() throws Throwable {
137 Object exp = Utils.exposeHTML(KnockoutTest.class,
138 "Latitude: <input id='input' data-bind=\"value: enabled\"></input>\n"
142 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
146 String v = getSetInput(null);
147 assert "true".equals(v) : "Value is really true: " + v;
149 getSetInput("false");
150 triggerEvent("input", "change");
152 assert false == m.isEnabled(): "Boolean property updated: " + m.isEnabled();
153 } catch (Throwable t) {
156 Utils.exposeHTML(KnockoutTest.class, "");
160 @KOTest public void modifyValueAssertChangeInModel() throws Exception {
161 Object exp = Utils.exposeHTML(KnockoutTest.class,
162 "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
163 "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
164 "<button id=\"hello\">Say Hello!</button>\n"
168 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
172 String v = getSetInput(null);
173 assert "Kukuc".equals(v) : "Value is really kukuc: " + v;
175 getSetInput("Jardo");
176 triggerEvent("input", "change");
178 assert "Jardo".equals(m.getName()) : "Name property updated: " + m.getName();
180 Utils.exposeHTML(KnockoutTest.class, "");
184 private static String getSetSelected(int index, Object value) throws Exception {
185 String s = "var index = arguments[0];\n"
186 + "var value = arguments[1];\n"
187 + "var n = window.document.getElementById('input'); \n "
188 + "if (value != null) {\n"
189 + " n.options[index].value = 'me'; \n"
190 + " n.value = 'me'; \n"
191 + " ko.dataFor(n.options[index]).archetype(value); // haven't found better way to trigger ko change yet \n"
193 + "var op = n.options[n.selectedIndex]; \n"
194 + "return op ? op.text : n.selectedIndex;\n";
195 Object ret = Utils.executeScript(
199 return ret == null ? null : ret.toString();
202 @Model(className = "ArchetypeData", properties = {
203 @Property(name = "artifactId", type = String.class),
204 @Property(name = "groupId", type = String.class),
205 @Property(name = "version", type = String.class),
206 @Property(name = "name", type = String.class),
207 @Property(name = "description", type = String.class),
208 @Property(name = "url", type = String.class),
210 static class ArchModel {
213 @KOTest public void selectWorksOnModels() throws Exception {
215 Utils.exposeHTML(KnockoutTest.class,
216 "<select id='input' data-bind=\"options: archetypes,\n" +
217 " optionsText: 'name',\n" +
218 " value: archetype\">\n" +
223 js = Models.bind(new KnockoutModel(), newContext());
224 js.getArchetypes().add(new ArchetypeData("ko4j", "org.netbeans.html", "0.8.3", "ko4j", "ko4j", null));
225 js.getArchetypes().add(new ArchetypeData("crud", "org.netbeans.html", "0.8.3", "crud", "crud", null));
226 js.getArchetypes().add(new ArchetypeData("3rd", "org.netbeans.html", "0.8.3", "3rd", "3rd", null));
227 js.setArchetype(js.getArchetypes().get(1));
230 String v = getSetSelected(0, null);
231 assert "crud".equals(v) : "Second index (e.g. crud) is selected: " + v;
233 String sel = getSetSelected(2, Models.toRaw(js.getArchetypes().get(2)));
234 assert "3rd".equals(sel) : "3rd is selected now: " + sel;
237 if (js.getArchetype() != js.getArchetypes().get(2)) {
238 throw new InterruptedException();
241 Utils.exposeHTML(KnockoutTest.class, "");
244 @KOTest public void modifyValueAssertAsyncChangeInModel() throws Exception {
246 Utils.exposeHTML(KnockoutTest.class,
247 "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
248 "Your name: <input id='input' data-bind=\"value: name\"></input>\n" +
249 "<button id=\"hello\">Say Hello!</button>\n"
252 js = Models.bind(new KnockoutModel(), newContext());
256 String v = getSetInput(null);
257 assert "Kukuc".equals(v) : "Value is really kukuc: " + v;
259 Timer t = new Timer("Set to Jardo");
260 t.schedule(new TimerTask() {
268 String v = getSetInput(null);
269 if (!"Jardo".equals(v)) {
270 throw new InterruptedException();
273 Utils.exposeHTML(KnockoutTest.class, "");
276 private static String getSetInput(String value) throws Exception {
277 String s = "var value = arguments[0];\n"
278 + "var n = window.document.getElementById('input'); \n "
279 + "if (value != null) n['value'] = value; \n "
280 + "return n['value'];";
281 Object ret = Utils.executeScript(
285 return ret == null ? null : ret.toString();
288 public static void triggerEvent(String id, String ev) throws Exception {
291 "ko.utils.triggerEvent(window.document.getElementById(arguments[0]), arguments[1]);",
296 @KOTest public void displayContentOfArray() throws Exception {
297 Object exp = Utils.exposeHTML(KnockoutTest.class,
298 "<ul id='ul' data-bind='foreach: results'>\n"
299 + " <li data-bind='text: $data, click: $root.call'/>\n"
303 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
304 m.getResults().add("Ahoj");
307 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
308 assert cnt == 1 : "One child, but was " + cnt;
310 m.getResults().add("Hi");
312 cnt = Utils.countChildren(KnockoutTest.class, "ul");
313 assert cnt == 2 : "Two children now, but was " + cnt;
315 triggerChildClick("ul", 1);
317 assert 1 == m.getCallbackCount() : "One callback " + m.getCallbackCount();
318 assert "Hi".equals(m.getName()) : "We got callback from 2nd child " + m.getName();
320 Utils.exposeHTML(KnockoutTest.class, "");
324 @KOTest public void displayContentOfAsyncArray() throws Exception {
326 Utils.exposeHTML(KnockoutTest.class,
327 "<ul id='ul' data-bind='foreach: results'>\n"
328 + " <li data-bind='text: $data, click: $root.call'/>\n"
331 js = Models.bind(new KnockoutModel(), newContext());
332 js.getResults().add("Ahoj");
335 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
336 assert cnt == 1 : "One child, but was " + cnt;
338 Timer t = new Timer("add to array");
339 t.schedule(new TimerTask() {
342 js.getResults().add("Hi");
348 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
350 throw new InterruptedException();
354 triggerChildClick("ul", 1);
356 assert 1 == js.getCallbackCount() : "One callback " + js.getCallbackCount();
357 assert "Hi".equals(js.getName()) : "We got callback from 2nd child " + js.getName();
359 Utils.exposeHTML(KnockoutTest.class, "");
363 @KOTest public void displayContentOfComputedArray() throws Exception {
364 Object exp = Utils.exposeHTML(KnockoutTest.class,
365 "<ul id='ul' data-bind='foreach: bothNames'>\n"
366 + " <li data-bind='text: $data, click: $root.assignFirstName'/>\n"
370 Pair m = Models.bind(new Pair("First", "Last", null), newContext());
373 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
374 assert cnt == 2 : "Two children now, but was " + cnt;
376 triggerChildClick("ul", 1);
378 assert "Last".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
380 m.setLastName("Verylast");
382 cnt = Utils.countChildren(KnockoutTest.class, "ul");
383 assert cnt == 2 : "Two children now, but was " + cnt;
385 triggerChildClick("ul", 1);
387 assert "Verylast".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
390 Utils.exposeHTML(KnockoutTest.class, "");
394 @KOTest public void displayContentOfComputedArrayOnASubpair() throws Exception {
395 Object exp = Utils.exposeHTML(KnockoutTest.class,
396 "<div data-bind='with: next'>\n"
397 + "<ul id='ul' data-bind='foreach: bothNames'>\n"
398 + " <li data-bind='text: $data, click: $root.assignFirstName'/>\n"
403 final BrwsrCtx ctx = newContext();
404 Pair m = Models.bind(new Pair(null, null, new Pair("First", "Last", null)), ctx);
407 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
408 assert cnt == 2 : "Two children now, but was " + cnt;
410 triggerChildClick("ul", 1);
412 assert PairModel.ctx == ctx : "Context remains the same";
414 assert "Last".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
416 Utils.exposeHTML(KnockoutTest.class, "");
420 @KOTest public void displayContentOfComputedArrayOnComputedASubpair() throws Exception {
421 Object exp = Utils.exposeHTML(KnockoutTest.class,
422 "<div data-bind='with: nextOne'>\n"
423 + "<ul id='ul' data-bind='foreach: bothNames'>\n"
424 + " <li data-bind='text: $data, click: $root.assignFirstName'/>\n"
429 Pair m = Models.bind(new Pair(null, null, new Pair("First", "Last", null)), newContext());
432 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
433 assert cnt == 2 : "Two children now, but was " + cnt;
435 triggerChildClick("ul", 1);
437 assert "Last".equals(m.getFirstName()) : "We got callback from 2nd child " + m.getFirstName();
439 Utils.exposeHTML(KnockoutTest.class, "");
443 @KOTest public void checkBoxToBooleanBinding() throws Exception {
444 Object exp = Utils.exposeHTML(KnockoutTest.class,
445 "<input type='checkbox' id='b' data-bind='checked: enabled'></input>\n"
448 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
451 assert !m.isEnabled() : "Is disabled";
455 assert m.isEnabled() : "Now the model is enabled";
457 Utils.exposeHTML(KnockoutTest.class, "");
463 @KOTest public void displayContentOfDerivedArray() throws Exception {
464 Object exp = Utils.exposeHTML(KnockoutTest.class,
465 "<ul id='ul' data-bind='foreach: cmpResults'>\n"
466 + " <li><b data-bind='text: $data'></b></li>\n"
470 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
471 m.getResults().add("Ahoj");
474 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
475 assert cnt == 1 : "One child, but was " + cnt;
477 m.getResults().add("hello");
479 cnt = Utils.countChildren(KnockoutTest.class, "ul");
480 assert cnt == 2 : "Two children now, but was " + cnt;
482 Utils.exposeHTML(KnockoutTest.class, "");
486 @KOTest public void displayContentOfArrayOfPeople() throws Exception {
487 Object exp = Utils.exposeHTML(KnockoutTest.class,
488 "<ul id='ul' data-bind='foreach: people'>\n"
489 + " <li data-bind='text: $data.firstName, click: $root.removePerson'></li>\n"
493 final BrwsrCtx c = newContext();
494 KnockoutModel m = Models.bind(new KnockoutModel(), c);
496 final Person first = Models.bind(new Person(), c);
497 first.setFirstName("first");
498 m.getPeople().add(first);
502 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
503 assert cnt == 1 : "One child, but was " + cnt;
505 final Person second = Models.bind(new Person(), c);
506 second.setFirstName("second");
507 m.getPeople().add(second);
509 cnt = Utils.countChildren(KnockoutTest.class, "ul");
510 assert cnt == 2 : "Two children now, but was " + cnt;
512 triggerChildClick("ul", 1);
514 assert 1 == m.getCallbackCount() : "One callback " + m.getCallbackCount();
516 cnt = Utils.countChildren(KnockoutTest.class, "ul");
517 assert cnt == 1 : "Again one child, but was " + cnt;
519 String txt = childText("ul", 0);
520 assert "first".equals(txt) : "Expecting 'first': " + txt;
522 first.setFirstName("changed");
524 txt = childText("ul", 0);
525 assert "changed".equals(txt) : "Expecting 'changed': " + txt;
527 Utils.exposeHTML(KnockoutTest.class, "");
532 static Person firstPerson(List<Person> people) {
533 return people.isEmpty() ? null : people.get(0);
536 @KOTest public void accessFirstPersonWithOnFunction() throws Exception {
537 Object exp = Utils.exposeHTML(KnockoutTest.class,
538 "<p id='ul' data-bind='with: firstPerson'>\n"
539 + " <span data-bind='text: firstName, click: changeSex'></span>\n"
545 Utils.exposeHTML(KnockoutTest.class, "");
549 @KOTest public void onPersonFunction() throws Exception {
550 Object exp = Utils.exposeHTML(KnockoutTest.class,
551 "<ul id='ul' data-bind='foreach: people'>\n"
552 + " <li data-bind='text: $data.firstName, click: changeSex'></li>\n"
558 Utils.exposeHTML(KnockoutTest.class, "");
562 private void trasfertToFemale() throws Exception {
563 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
565 final Person first = Models.bind(new Person(), newContext());
566 first.setFirstName("first");
567 first.setSex(Sex.MALE);
568 m.getPeople().add(first);
573 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
574 assert cnt == 1 : "One child, but was " + cnt;
577 triggerChildClick("ul", 0);
579 assert first.getSex() == Sex.FEMALE : "Transverted to female: " + first.getSex();
582 @KOTest public void stringArrayModificationVisible() throws Exception {
583 Object exp = Utils.exposeHTML(KnockoutTest.class,
585 + "<ul id='ul' data-bind='foreach: results'>\n"
586 + " <li data-bind='text: $data'></li>\n"
591 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
592 m.getResults().add("Ahoj");
593 m.getResults().add("Hello");
596 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
597 assert cnt == 2 : "Two children " + cnt;
599 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "results", "Hi");
600 assert arr instanceof Object[] : "Got back an array: " + arr;
601 final int len = ((Object[])arr).length;
603 assert len == 3 : "Three elements in the array " + len;
605 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
606 assert newCnt == 3 : "Three children in the DOM: " + newCnt;
608 assert m.getResults().size() == 3 : "Three java strings: " + m.getResults();
610 Utils.exposeHTML(KnockoutTest.class, "");
614 @KOTest public void intArrayModificationVisible() throws Exception {
615 Object exp = Utils.exposeHTML(KnockoutTest.class,
617 + "<ul id='ul' data-bind='foreach: numbers'>\n"
618 + " <li data-bind='text: $data'></li>\n"
623 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
624 m.getNumbers().add(1);
625 m.getNumbers().add(31);
628 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
629 assert cnt == 2 : "Two children " + cnt;
631 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "numbers", 42);
632 assert arr instanceof Object[] : "Got back an array: " + arr;
633 final int len = ((Object[])arr).length;
635 assert len == 3 : "Three elements in the array " + len;
637 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
638 assert newCnt == 3 : "Three children in the DOM: " + newCnt;
640 assert m.getNumbers().size() == 3 : "Three java ints: " + m.getNumbers();
641 assert m.getNumbers().get(2) == 42 : "Meaning of world: " + m.getNumbers();
643 Utils.exposeHTML(KnockoutTest.class, "");
647 @KOTest public void derivedIntArrayModificationVisible() throws Exception {
648 Object exp = Utils.exposeHTML(KnockoutTest.class,
650 + "<ul id='ul' data-bind='foreach: resultLengths'>\n"
651 + " <li data-bind='text: $data'></li>\n"
656 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
657 m.getResults().add("Ahoj");
658 m.getResults().add("Hello");
661 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
662 assert cnt == 2 : "Two children " + cnt;
664 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "results", "Hi");
665 assert arr instanceof Object[] : "Got back an array: " + arr;
666 final int len = ((Object[])arr).length;
668 assert len == 3 : "Three elements in the array " + len;
670 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
671 assert newCnt == 3 : "Three children in the DOM: " + newCnt;
673 assert m.getResultLengths().size() == 3 : "Three java ints: " + m.getResultLengths();
674 assert m.getResultLengths().get(2) == 2 : "Size is two: " + m.getResultLengths();
676 Utils.exposeHTML(KnockoutTest.class, "");
680 @KOTest public void archetypeArrayModificationVisible() throws Exception {
681 Object exp = Utils.exposeHTML(KnockoutTest.class,
683 + "<ul id='ul' data-bind='foreach: archetypes'>\n"
684 + " <li data-bind='text: artifactId'></li>\n"
689 KnockoutModel m = Models.bind(new KnockoutModel(), newContext());
692 int cnt = Utils.countChildren(KnockoutTest.class, "ul");
693 assert cnt == 0 : "No children " + cnt;
695 Object arr = Utils.addChildren(KnockoutTest.class, "ul", "archetypes", new ArchetypeData("aid", "gid", "v", "n", "d", "u"));
696 assert arr instanceof Object[] : "Got back an array: " + arr;
697 final int len = ((Object[])arr).length;
699 assert len == 1 : "One element in the array " + len;
701 int newCnt = Utils.countChildren(KnockoutTest.class, "ul");
702 assert newCnt == 1 : "One child in the DOM: " + newCnt;
704 assert m.getArchetypes().size() == 1 : "One archetype: " + m.getArchetypes();
705 assert m.getArchetypes().get(0) != null : "Not null: " + m.getArchetypes();
706 assert m.getArchetypes().get(0).getArtifactId().equals("aid") : "'aid' == " + m.getArchetypes();
708 Utils.exposeHTML(KnockoutTest.class, "");
713 static void call(KnockoutModel m, String data) {
715 m.setCallbackCount(m.getCallbackCount() + 1);
719 static void removePerson(KnockoutModel model, Person data) {
720 model.setCallbackCount(model.getCallbackCount() + 1);
721 model.getPeople().remove(data);
726 static String helloMessage(String name) {
727 return "Hello " + name + "!";
731 static List<String> cmpResults(List<String> results) {
735 private static void triggerClick(String id) throws Exception {
736 String s = "var id = arguments[0];"
737 + "var e = window.document.getElementById(id);\n "
738 + "if (e.checked) throw 'It should not be checked yet: ' + e;\n "
739 + "var ev = window.document.createEvent('MouseEvents');\n "
740 + "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n "
741 + "e.dispatchEvent(ev);\n "
742 + "if (!e.checked) {\n"
743 + " e.checked = true;\n "
744 + " e.dispatchEvent(ev);\n "
750 private static void triggerChildClick(String id, int pos) throws Exception {
752 "var id = arguments[0]; var pos = arguments[1];\n" +
753 "var e = window.document.getElementById(id);\n " +
754 "var ev = window.document.createEvent('MouseEvents');\n " +
755 "ev.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);\n " +
756 "var list = e.childNodes;\n" +
758 "for (var i = 0; i < list.length; i++) {\n" +
759 " if (list[i].nodeType == 1) cnt++;\n" +
760 " if (cnt == pos) return list[i].dispatchEvent(ev);\n" +
768 private static String childText(String id, int pos) throws Exception {
770 "var id = arguments[0]; var pos = arguments[1];" +
771 "var e = window.document.getElementById(id);\n" +
772 "var list = e.childNodes;\n" +
774 "for (var i = 0; i < list.length; i++) {\n" +
775 " if (list[i].nodeType == 1) cnt++;\n" +
776 " if (cnt == pos) return list[i].innerHTML;\n" +
779 return (String)Utils.executeScript(
784 private static BrwsrCtx newContext() {
785 return Utils.newContext(KnockoutTest.class);