WebCore:
authorantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Nov 2007 18:11:06 +0000 (18:11 +0000)
committerantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Nov 2007 18:11:06 +0000 (18:11 +0000)
        Reviewed by Darin.

        Trigger media load on on src attribute changes as specified in new HTML5 draft.

        Tests: media/video-src-change.html
               media/video-src-remove.html
               media/video-src-set.html

        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::attributeChanged):
        * html/HTMLMediaElement.h:

LayoutTests:

        Reviewed by Darin.

        Tests for media src attribute changes.

        * media/video-src-change-expected.txt: Added.
        * media/video-src-change.html: Added.
        * media/video-src-remove-expected.txt: Added.
        * media/video-src-remove.html: Added.
        * media/video-src-set-expected.txt: Added.
        * media/video-src-set.html: Added.
        * media/video-test.js:

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

LayoutTests/ChangeLog
LayoutTests/media/video-src-change-expected.txt [new file with mode: 0644]
LayoutTests/media/video-src-change.html [new file with mode: 0644]
LayoutTests/media/video-src-remove-expected.txt [new file with mode: 0644]
LayoutTests/media/video-src-remove.html [new file with mode: 0644]
LayoutTests/media/video-src-set-expected.txt [new file with mode: 0644]
LayoutTests/media/video-src-set.html [new file with mode: 0644]
LayoutTests/media/video-test.js
WebCore/ChangeLog
WebCore/html/HTMLMediaElement.cpp
WebCore/html/HTMLMediaElement.h

index 9a436ccdb43834914eeea05f956644f8304675fb..b0250a4464f87f8713a34cac979af0de3086e318 100644 (file)
@@ -1,3 +1,17 @@
+2007-11-06  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Darin.
+        
+        Tests for media src attribute changes.
+
+        * media/video-src-change-expected.txt: Added.
+        * media/video-src-change.html: Added.
+        * media/video-src-remove-expected.txt: Added.
+        * media/video-src-remove.html: Added.
+        * media/video-src-set-expected.txt: Added.
+        * media/video-src-set.html: Added.
+        * media/video-test.js:
+
 2007-11-06  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Darin Adler.
diff --git a/LayoutTests/media/video-src-change-expected.txt b/LayoutTests/media/video-src-change-expected.txt
new file mode 100644 (file)
index 0000000..714de68
--- /dev/null
@@ -0,0 +1,9 @@
+Test that changing src attribute triggers load when network state is empty.
+Test that it does not trigger load when network state is non-empty.
+EVENT(emptied)
+TEST(video.networkState == HTMLMediaElement.EMPTY) OK
+EVENT(begin) TEST(relativeURL(video.currentSrc) == 'content/test.mp4') OK
+EVENT(load)
+TEST(video.networkState != HTMLMediaElement.EMPTY) OK
+END OF TEST
+
diff --git a/LayoutTests/media/video-src-change.html b/LayoutTests/media/video-src-change.html
new file mode 100644 (file)
index 0000000..479a8c0
--- /dev/null
@@ -0,0 +1,19 @@
+<video src=bogus></video>
+<div>
+Test that changing src attribute triggers load when network state is empty.<br>
+Test that it does not trigger load when network state is non-empty.
+</div>
+<script src=video-test.js></script>
+<script>
+waitForEvent('emptied', function () {
+    test('video.networkState == HTMLMediaElement.EMPTY');
+    video.setAttribute('src', 'content/test.mp4')
+    waitForEventAndTest('begin', "relativeURL(video.currentSrc) == 'content/test.mp4'");
+    waitForEvent('load', function () {
+        test('video.networkState != HTMLMediaElement.EMPTY');
+        video.setAttribute('src', 'content/test.wav');
+        waitForEventAndFail('begin');
+        setTimeout(endTest, 500);
+    });
+});
+</script>
diff --git a/LayoutTests/media/video-src-remove-expected.txt b/LayoutTests/media/video-src-remove-expected.txt
new file mode 100644 (file)
index 0000000..dce00fa
--- /dev/null
@@ -0,0 +1,5 @@
+Test that removing src attribute triggers load
+EVENT(emptied)
+EVENT(begin) TEST(relativeURL(video.currentSrc) == 'content/test.mp4') OK
+END OF TEST
+
diff --git a/LayoutTests/media/video-src-remove.html b/LayoutTests/media/video-src-remove.html
new file mode 100644 (file)
index 0000000..a9cd55d
--- /dev/null
@@ -0,0 +1,13 @@
+<video src=bogus>
+    <source src=content/test.mp4></source>
+</video>
+<div>
+Test that removing src attribute triggers load
+</div>
+<script src=video-test.js></script>
+<script>
+waitForEvent('emptied', function () {
+    video.removeAttribute('src')
+    waitForEventTestAndEnd('begin', "relativeURL(video.currentSrc) == 'content/test.mp4'");
+});
+</script>
diff --git a/LayoutTests/media/video-src-set-expected.txt b/LayoutTests/media/video-src-set-expected.txt
new file mode 100644 (file)
index 0000000..4438f2e
--- /dev/null
@@ -0,0 +1,4 @@
+Test that setting src attribute triggers load
+EVENT(begin) TEST(relativeURL(video.currentSrc) == 'content/test.mp4') OK
+END OF TEST
+
diff --git a/LayoutTests/media/video-src-set.html b/LayoutTests/media/video-src-set.html
new file mode 100644 (file)
index 0000000..4ce5828
--- /dev/null
@@ -0,0 +1,9 @@
+<video></video>
+<div>
+Test that setting src attribute triggers load
+</div>
+<script src=video-test.js></script>
+<script>
+video.setAttribute('src', 'content/test.mp4')
+waitForEventTestAndEnd('begin', "relativeURL(video.currentSrc) == 'content/test.mp4'");
+</script>
index a5928238865d9082a62ac31895f17bf8e7400b7b..247bafbed97576c14b3f1d0450bed37715d5c3c1 100644 (file)
@@ -60,6 +60,11 @@ function waitForEventTestAndEnd(eventName, testFuncString)
     waitForEventAndTest(eventName, testFuncString, true);
 }
 
+function waitForEventAndFail(eventName)
+{
+    waitForEventAndTest(eventName, "false", true);
+}
+
 function waitForEventAndTest(eventName, testFuncString, endit)
 {
     function _eventCallback(event)
index d5023b9e6f7de8689ca70c2c74b1653036de6167..070ce7a06aae16fd148b80d9680bc77771a26c0e 100644 (file)
@@ -1,3 +1,17 @@
+2007-11-06  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Darin.
+        
+        Trigger media load on on src attribute changes as specified in new HTML5 draft.
+
+        Tests: media/video-src-change.html
+               media/video-src-remove.html
+               media/video-src-set.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::attributeChanged):
+        * html/HTMLMediaElement.h:
+
 2007-11-06  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Darin Adler.
index e691740f1484bb3418097b51349b6fc0d810215b..8b179990c3721f07d081881a8e7deeb50721d322 100644 (file)
@@ -94,6 +94,19 @@ bool HTMLMediaElement::checkDTD(const Node* newChild)
     return newChild->hasTagName(sourceTag) || HTMLElement::checkDTD(newChild);
 }
 
+void HTMLMediaElement::attributeChanged(Attribute* attr, bool preserveDecls)
+{
+    HTMLElement::attributeChanged(attr, preserveDecls);
+
+    const QualifiedName& attrName = attr->name();
+    if (attrName == srcAttr) {
+        // 3.14.9.2.
+        // change to src attribute triggers load()
+        if (inDocument() && m_networkState == EMPTY)
+            scheduleLoad();
+    }
+}
+    
 void HTMLMediaElement::insertedIntoDocument()
 {
     HTMLElement::insertedIntoDocument();
index 53db7d9a65f99a382d8ef3bfa0cd17a1e5b34d9b..bac4c9f995a939afaf9fe73ba2baea5f2dea3eca 100644 (file)
@@ -49,6 +49,8 @@ public:
     virtual ~HTMLMediaElement();
 
     bool checkDTD(const Node* newChild);
+    
+    void attributeChanged(Attribute*, bool preserveDecls);
 
     virtual bool rendererIsNeeded(RenderStyle*) { return false; }
     virtual void insertedIntoDocument();