matchMedia addListener event can not be triggered every time by width be change over the condition .

UNCONFIRMED
Unassigned

Status

()

Core
Document Navigation
UNCONFIRMED
5 years ago
5 years ago

People

(Reporter: zhanglin, Unassigned)

Tracking

15 Branch
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: DUPEME)

Attachments

(1 attachment)

(Reporter)

Description

5 years ago
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4

Steps to reproduce:

see code:
        <iframe width="200" height="100" id="iframe1" ></iframe>
        <script>
            function reflow(doc) {
                doc.body.offsetWidth;
            }

            var iframe = document.querySelector("iframe");
            var iframe_window = window.frames[0];
            var iframe1 = document.getElementById("iframe1");
            reflow(iframe_window.document);

            var i = 0;
            var totalCount = 10;
            var count = 0;
            var divineCount = 10;
            var width_list = [201,199];
            var mq1 = iframe_window.matchMedia("(max-width:200px)");
            mq1.addListener(function(mql){ 
                
                count = count + 1; 

            });

            var equalAssert = async_test("Check for the correct number of event triggers");

            var changeFrameWidth = function(iWidth) {
                iframe1.style.width = iWidth + "px";
                i = (i === 0) ? 1 : 0;
                totalCount = totalCount - 1;
                if(totalCount > 0)
                {
                    setTimeout(function(){
                        changeFrameWidth(width_list[i]);
                    }, 100);
                }
                else
                {
                    setTimeout(function(){
                           alert(divineCount === count)
                    }, 100);
                    
                }
            };



Actual results:

alert false


Expected results:

alert true in chrome
(Reporter)

Comment 1

5 years ago
Created attachment 673673 [details]
Check for the correct number of event triggers

Updated

5 years ago
Component: Untriaged → DOM: CSS Object Model
Product: Firefox → Core
(Reporter)

Comment 2

5 years ago
Comment on attachment 673673 [details]
Check for the correct number of event triggers

><!DOCTYPE html>
>     <html>
>        <head>
>        <title>CSS Test: CSSOM View matchMedia's addListener</title>
>        <link rel="author" title="zhanglin" href="mailto:xiaoxiaozhanglin@gmail.com" />
>        <link rel="help" href="http://dev.w3.org/csswg/cssom-view/#the-mediaquerylist-interface" />
>        <meta name="flags" content="dom" />
>        <script src='http://w3c-test.org/resources/testharness.js'></script>
>        <script src='http://w3c-test.org/resources/testharnessreport.js'></script>
>          <style type="text/css">
>            iframe { border: none; }
>        </style>
>    </head>
>    <body>
>        <div id="log"></div>
>        <iframe width="200" height="100" id="iframe1" ></iframe>
>        <script>
>            function reflow(doc) {
>                doc.body.offsetWidth;
>            }
>
>            var iframe = document.querySelector("iframe");
>            var iframe_window = window.frames[0];
>            var iframe1 = document.getElementById("iframe1");
>            reflow(iframe_window.document);
>
>            var i = 0;
>            var totalCount = 10;
>            var count = 0;
>            var divineCount = 10;
>            var width_list = [201,199];
>            var mq1 = iframe_window.matchMedia("(max-width:200px)");
>            mq1.addListener(function(mql){ 
>                
>                count = count + 1; 
>
>            });
>
>
>            var changeFrameWidth = function(iWidth) {
>                iframe1.style.width = iWidth + "px";
>                i = (i === 0) ? 1 : 0;
>                totalCount = totalCount - 1;
>                if(totalCount > 0)
>                {
>                    setTimeout(function(){
>                        changeFrameWidth(width_list[i]);
>                    }, 100);
>                }
>                else
>                {
>                    setTimeout(function(){
>                        equalAssert.step(function(){
>                            assert_equals(divineCount, count, "this will be 10 times of event triggers by change width");
>                        });
>                        equalAssert.done();
>                    }, 100);
>                    // console.log("**" + count + "**");
>                }
>            };
>
>            changeFrameWidth(width_list[0]);
>
>
>        </script>
>    </body>
></html>

Updated

5 years ago
Attachment #673673 - Attachment mime type: text/plain → text/html
Component: DOM: CSS Object Model → Style System (CSS)
The testcase is adding a media query listener to the temporary about:blank, but then the real about:blank loads, and wipes out the listener (since it's a new document and such).

The right fix on our end is to not have the temporary about:blank.  The right fix for the page is to use a load listener on the iframe to attach stuff to the window inside (which would be absolutely needed if the iframe had an src other than about:blank).
Whiteboard: DUPEME
Component: Style System (CSS) → Document Navigation
You need to log in before you can comment on or make changes to this bug.