2009-07-30 Eric Carlson <eric.carlson@apple.com>
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jul 2009 16:05:02 +0000 (16:05 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jul 2009 16:05:02 +0000 (16:05 +0000)
        Reviewed by Simon Fraser.

        Video elements fires another "load" event when attached to DOM
        https://bugs.webkit.org/show_bug.cgi?id=27623

        Test: media/media-load-event.html

        * html/HTMLMediaElement.cpp:
        (WebCore::HTMLMediaElement::insertedIntoDocument):
            Only schedule load when element's network state is NETWORK_EMPTY.

2009-07-30  Eric Carlson  <eric.carlson@apple.com>

        Reviewed by Simon Fraser.

        Video elements fires another "load" event when attached to DOM
        https://bugs.webkit.org/show_bug.cgi?id=27623

        * media/media-load-event-expected.txt: Added.
        * media/media-load-event.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/media/media-load-event-expected.txt [new file with mode: 0644]
LayoutTests/media/media-load-event.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLMediaElement.cpp

index d9a5cf8..98a01a1 100644 (file)
@@ -1,3 +1,13 @@
+2009-07-30  Eric Carlson  <eric.carlson@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        Video elements fires another "load" event when attached to DOM
+        https://bugs.webkit.org/show_bug.cgi?id=27623
+
+        * media/media-load-event-expected.txt: Added.
+        * media/media-load-event.html: Added.
+
 2009-07-29  Jian Li  <jianli@chromium.org>
 
         Reviewed by Darin Adler.
diff --git a/LayoutTests/media/media-load-event-expected.txt b/LayoutTests/media/media-load-event-expected.txt
new file mode 100644 (file)
index 0000000..3393cb4
--- /dev/null
@@ -0,0 +1,18 @@
+Test that media file is not reloaded when an element is inserted into the DOM.
+
+RUN(media = document.createElement('audio'))
+RUN(media.src = 'content/test.wav')
+RUN(media.load())
+
+EVENT(loadstart)
+EVENT(durationchange)
+EVENT(loadeddata)
+EVENT(load)
+
+RUN(document.getElementById('parent').appendChild(media))
+RUN(media.play())
+
+EVENT(play)
+EVENT(playing)
+END OF TEST
+
diff --git a/LayoutTests/media/media-load-event.html b/LayoutTests/media/media-load-event.html
new file mode 100644 (file)
index 0000000..5afbe80
--- /dev/null
@@ -0,0 +1,48 @@
+<html>
+    <head>
+        <script src=video-test.js></script>
+
+        <script>
+
+            function loaded()
+            {
+                consoleWrite("EVENT(load)");
+                consoleWrite("");
+                run("document.getElementById('parent').appendChild(media)");
+                run("media.play()");
+                window.setTimeout(endTest, 250);
+                consoleWrite("");
+            }
+
+            function start()
+            {
+                run("media = document.createElement('audio')");
+
+                media.onload = loaded;
+
+                waitForEvent("loadstart");
+                waitForEvent("waiting");
+                waitForEvent("ratechange");
+                waitForEvent("durationchange");
+                waitForEvent("pause");
+                waitForEvent("play");
+                waitForEvent("playing");
+                waitForEvent('loadeddata');
+
+                run("media.src = 'content/test.wav'");
+                run("media.load()");
+
+                consoleWrite("");
+            }
+
+        </script>
+    </head>
+
+    <body onload="start()">
+
+    <p>Test that media file is not reloaded when an element is inserted into the DOM.</p>
+
+    <div id="parent"></div>
+    
+    </body>
+</html>
index 1601cf1..e9ea72d 100644 (file)
@@ -1,3 +1,16 @@
+2009-07-30  Eric Carlson  <eric.carlson@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        Video elements fires another "load" event when attached to DOM
+        https://bugs.webkit.org/show_bug.cgi?id=27623
+
+        Test: media/media-load-event.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::insertedIntoDocument):
+            Only schedule load when element's network state is NETWORK_EMPTY.
+
 2009-07-30  Anton Muhin  <antonm@chromium.org>
 
         Reviewed by David Levin.
index 7cda3fb..251e85f 100644 (file)
@@ -234,7 +234,7 @@ RenderObject* HTMLMediaElement::createRenderer(RenderArena* arena, RenderStyle*)
 void HTMLMediaElement::insertedIntoDocument()
 {
     HTMLElement::insertedIntoDocument();
-    if (!src().isEmpty())
+    if (!src().isEmpty() && m_networkState == NETWORK_EMPTY)
         scheduleLoad();
 }