2010-09-07 Joseph Pecoraro <joepeck@webkit.org>
authorjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Sep 2010 23:34:11 +0000 (23:34 +0000)
committerjoepeck@webkit.org <joepeck@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Sep 2010 23:34:11 +0000 (23:34 +0000)
        Reviewed by Darin Adler.

        Provide a way to trigger a <select multiple> onchange event on changes
        https://bugs.webkit.org/show_bug.cgi?id=45192

        Testing the DOMHTMLSelectElement interface for selecting an
        index in a <select> and triggering a "change" event. This also
        tests for allowing multiple selections.

        * platform/mac/fast/objc/dom-html-select-activate-expected.txt: Added.
        * platform/mac/fast/objc/dom-html-select-activate.html: Added.

2010-09-07  Joseph Pecoraro  <joepeck@webkit.org>

        Reviewed by Darin Adler.

        Provide a way to trigger a <select multiple> onchange event on changes
        https://bugs.webkit.org/show_bug.cgi?id=45192

        Adds a selector on ObjCController for testing
        -[DOMHTMLSelectElement _activateItemAtIndex:allowMultipleSelection:] and
        its different uses.

        * DumpRenderTree/mac/ObjCController.m:
        (+[ObjCController isSelectorExcludedFromWebScript:]):
        (+[ObjCController webScriptNameForSelector:]):
        (-[ObjCController setSelectElement:selectedIndex:allowingMultiple:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@66930 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/mac/fast/objc/dom-html-select-activate-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/fast/objc/dom-html-select-activate.html [new file with mode: 0644]
WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/mac/ObjCController.m

index a7ce9c5..89a5ac3 100644 (file)
@@ -1,3 +1,17 @@
+2010-09-07  Joseph Pecoraro  <joepeck@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Provide a way to trigger a <select multiple> onchange event on changes
+        https://bugs.webkit.org/show_bug.cgi?id=45192
+
+        Testing the DOMHTMLSelectElement interface for selecting an
+        index in a <select> and triggering a "change" event. This also
+        tests for allowing multiple selections.
+
+        * platform/mac/fast/objc/dom-html-select-activate-expected.txt: Added.
+        * platform/mac/fast/objc/dom-html-select-activate.html: Added.
+
 2010-09-07  Tony Chang  <tony@chromium.org>
 
         Reviewed by Dimitri Glazkov.
diff --git a/LayoutTests/platform/mac/fast/objc/dom-html-select-activate-expected.txt b/LayoutTests/platform/mac/fast/objc/dom-html-select-activate-expected.txt
new file mode 100644 (file)
index 0000000..ac27666
--- /dev/null
@@ -0,0 +1,21 @@
+      
+This tests the Private Objective-C DOM HTML Bindings API for selecting indexes of a <select> that also activate the "change" event.
+
+Select a single index in a normal <select>.
+-- change event fired --
+PASS - expected index was selected.
+
+Select a single index in a sized <select>.
+-- change event fired --
+PASS - expected index was selected.
+
+Select multiple indexes, in a <select multiple>.
+-- change event fired --
+-- change event fired --
+PASS - selected options were what we expected.
+
+Select multiple indexes, with multi-select on, in a <select multiple>.
+-- change event fired --
+-- change event fired --
+PASS - selected options were what we expected.
+
diff --git a/LayoutTests/platform/mac/fast/objc/dom-html-select-activate.html b/LayoutTests/platform/mac/fast/objc/dom-html-select-activate.html
new file mode 100644 (file)
index 0000000..05858ae
--- /dev/null
@@ -0,0 +1,120 @@
+<!DOCTYPE html>
+<html>
+<head><title></title></head>
+<body onload="test()">
+
+    <select id="single">
+        <option>0</option>
+        <option>1</option>
+        <option>2</option>
+    </select>
+
+    <select id="sized" size="3">
+        <option>0</option>
+        <option>1</option>
+        <option>2</option>
+    </select>
+
+    <select id="multiple-1" multiple>
+        <option>0</option>
+        <option>1</option>
+        <option>2</option>
+    </select>
+
+    <select id="multiple-2" multiple>
+        <option>0</option>
+        <option>1</option>
+        <option>2</option>
+    </select>
+
+    <pre id="console"></pre>
+
+    <script>
+
+    // -----------
+    //   Helpers
+    // -----------
+
+    function log(msg) {
+        document.getElementById("console").appendChild(document.createTextNode(msg + "\n"));
+    }
+
+    function onChangeEventHandler(event) {
+        log("-- change event fired --");
+    }
+
+    function assertSelectedIndex(elem, index) {
+        if (elem.selectedIndex === index)
+            log("PASS - expected index was selected.");
+        else
+            log("FAIL - expected index was " + elem.selected + " but was expected to be " + index + ".");
+    }
+
+    function assertSelectedIndexes(elem, flags) {
+        var allGood = true;
+        var options = elem.options;
+        for (var i=0; i<options.length; ++i) {
+            if (options[i].selected !== flags[i]) {
+                log("FAIL - option " + i + " was not what we expected.");
+                allGood = false;
+            }
+        }
+
+        if (allGood)
+            log("PASS - selected options were what we expected.")
+    }
+
+    // ------------
+    //   The Test
+    // ------------
+
+    function test() {
+        if (!window.layoutTestController) {
+            log("This test can only be run under DumpRenderTree.");
+            return;
+        }
+
+        layoutTestController.dumpAsText();
+
+        log("This tests the Private Objective-C DOM HTML Bindings API for selecting indexes of a <select> that also activate the \"change\" event.");
+        wrapper("Select a single index in a normal <select>.", "single", testSingle);
+        wrapper("Select a single index in a sized <select>.", "sized", testSized);
+        wrapper("Select multiple indexes, in a <select multiple>.", "multiple-1", testMultiple1);
+        wrapper("Select multiple indexes, with multi-select on, in a <select multiple>.", "multiple-2", testMultiple2);
+    }
+
+    function wrapper(msg, id, func) {
+        log("");
+        log(msg);
+        var elem = document.getElementById(id);
+        elem.addEventListener("change", onChangeEventHandler, false);
+        func(elem);
+    }
+
+    function testSingle(elem) {
+        objCController.setSelectElementSelectedIndexAllowingMultiple(elem, 1, false);
+        assertSelectedIndex(elem, 1);
+    }
+
+    function testSized(elem) {
+        objCController.setSelectElementSelectedIndexAllowingMultiple(elem, 1, false);
+        assertSelectedIndex(elem, 1);
+    }
+
+    function testMultiple1(elem) {
+        // Triggers selecting index 1 then 2, expecting the result to be just index 2 selected.
+        objCController.setSelectElementSelectedIndexAllowingMultiple(elem, 1, false);
+        objCController.setSelectElementSelectedIndexAllowingMultiple(elem, 2, false);
+        assertSelectedIndexes(elem, [false, false, true]);
+    }
+
+    function testMultiple2(elem) {
+        // Triggers selecting index 1 then 2, expecting the result to be both are selected.
+        objCController.setSelectElementSelectedIndexAllowingMultiple(elem, 1, true);
+        objCController.setSelectElementSelectedIndexAllowingMultiple(elem, 2, true);
+        assertSelectedIndexes(elem, [false, true, true]);
+    }
+
+    </script>
+</body>
+</html>
index 1d476ee..6f3cacb 100644 (file)
@@ -1,3 +1,19 @@
+2010-09-07  Joseph Pecoraro  <joepeck@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Provide a way to trigger a <select multiple> onchange event on changes
+        https://bugs.webkit.org/show_bug.cgi?id=45192
+
+        Adds a selector on ObjCController for testing
+        -[DOMHTMLSelectElement _activateItemAtIndex:allowMultipleSelection:] and
+        its different uses.
+
+        * DumpRenderTree/mac/ObjCController.m:
+        (+[ObjCController isSelectorExcludedFromWebScript:]):
+        (+[ObjCController webScriptNameForSelector:]):
+        (-[ObjCController setSelectElement:selectedIndex:allowingMultiple:]):
+
 2010-09-07  James Robinson  <jamesr@chromium.org>
 
         Rubber-stamped by Dimitri Glazkov.
index 641d2cc..f1d1c10 100644 (file)
 #import "config.h"
 #import "ObjCController.h"
 
+// Avoid compile error in DOMPrivate.h.
+@class NSFont;
+
 #import <JavaScriptCore/JavaScriptCore.h>
 #import <WebKit/DOMAbstractView.h>
+#import <WebKit/DOMPrivate.h>
 #import <WebKit/WebScriptObject.h>
 #import <WebKit/WebView.h>
 #import <pthread.h>
@@ -73,6 +77,7 @@ static void* runJavaScriptThread(void* arg)
             || aSelector == @selector(testValueForKey)
             || aSelector == @selector(testHasWebScriptKey:)
             || aSelector == @selector(testArray)
+            || aSelector == @selector(setSelectElement:selectedIndex:allowingMultiple:)
         )
         return NO;
     return YES;
@@ -102,6 +107,8 @@ static void* runJavaScriptThread(void* arg)
         return @"testHasWebScriptKey";
     if (aSelector == @selector(testArray))
         return @"testArray";
+    if (aSelector == @selector(setSelectElement:selectedIndex:allowingMultiple:))
+        return @"setSelectElementSelectedIndexAllowingMultiple";
 
     return nil;
 }
@@ -263,4 +270,16 @@ static void* runJavaScriptThread(void* arg)
     return nil;
 }
 
+#pragma mark -
+#pragma mark Testing Objective-C DOM HTML Bindings
+
+- (void)setSelectElement:(WebScriptObject *)element selectedIndex:(int)index allowingMultiple:(BOOL)allowingMultiple
+{
+    if (![element isKindOfClass:[DOMHTMLSelectElement class]])
+        return;
+
+    DOMHTMLSelectElement *select = (DOMHTMLSelectElement*)element;
+    [select _activateItemAtIndex:index allowMultipleSelection:allowingMultiple];
+}
+
 @end