| OLD | NEW | 
|    1 <html> |    1 <html> | 
|    2 <head> |    2 <head> | 
|    3  |    3  | 
|    4 <style type="text/css" media="screen"> |    4 <style type="text/css" media="screen"> | 
|    5 @media (max-device-width: 478px) and (max-device-height: 959px) { |    5 @media (max-device-width: 478px) and (max-device-height: 799px) { | 
|    6     #main { background: red; } |    6     #main { background: red; } | 
|    7 } |    7 } | 
|    8  |    8  | 
|    9 @media (max-device-width: 480px) and (max-device-height: 960px) { |    9 @media (max-device-width: 480px) and (max-device-height: 800px) { | 
|   10     #main { background: green; } |   10     #main { background: green; } | 
|   11 } |   11 } | 
|   12  |   12  | 
|   13 @media (min-device-width: 481px) and (min-device-height: 961px) { |   13 @media (min-device-width: 481px) and (min-device-height: 801px) { | 
|   14     #main { background: yellow; } |   14     #main { background: yellow; } | 
|   15 } |   15 } | 
|   16  |   16  | 
|   17 body { |   17 body { | 
|   18     position: absolute; |   18     position: absolute; | 
|   19     top: 0; |   19     top: 0; | 
|   20     right: 0; |   20     right: 0; | 
|   21     bottom: 0; |   21     bottom: 0; | 
|   22     left: 0; |   22     left: 0; | 
|   23     margin: 0; |   23     margin: 0; | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|   34 { |   34 { | 
|   35     return JSON.stringify({ |   35     return JSON.stringify({ | 
|   36         screen: window.screen.width + "x" + window.screen.height, |   36         screen: window.screen.width + "x" + window.screen.height, | 
|   37         inner: window.innerWidth + "x" + window.innerHeight, |   37         inner: window.innerWidth + "x" + window.innerHeight, | 
|   38         body: document.body.offsetWidth + "x" + document.body.offsetHeight |   38         body: document.body.offsetWidth + "x" + document.body.offsetHeight | 
|   39     }); |   39     }); | 
|   40 } |   40 } | 
|   41  |   41  | 
|   42 function test() |   42 function test() | 
|   43 { |   43 { | 
|   44     var exceededDimension = 10000001; |   44     var overridesEnabled = false; | 
|   45     var originalScreenSize; |   45     var originalScreenSize; | 
|   46  |   46  | 
|   47     function saveSizeCallback(jsonResult) |   47     function saveSizeCallback(jsonResult) | 
|   48     { |   48     { | 
|   49         var value = JSON.parse(jsonResult.value); |   49         var value = JSON.parse(jsonResult.value); | 
|   50         originalScreenSize = value.screen; |   50         originalScreenSize = value.screen; | 
|   51         if (!originalScreenSize || originalScreenSize.indexOf("x") === -1) |   51         if (!originalScreenSize || originalScreenSize.indexOf("x") === -1) | 
|   52             InspectorTest.addResult("Invalid original screen size: " + originalS
     creenSize + ". Expect runtime failures later on."); |   52             InspectorTest.addResult("Invalid original screen size: " + originalS
     creenSize + ". Expect runtime failures later on."); | 
|   53  |   53  | 
|   54         InspectorTest.selectNodeAndWaitForStyles("main", step0); |   54         InspectorTest.selectNodeAndWaitForStyles("main", step0); | 
|   55     } |   55     } | 
|   56  |   56  | 
|   57     InspectorTest.evaluateInPage("getSizes()", saveSizeCallback); |   57     InspectorTest.evaluateInPage("getSizes()", saveSizeCallback); | 
|   58  |   58  | 
|   59  |   59  | 
|   60     function step0() |   60     function step0() | 
|   61     { |   61     { | 
|   62         overrideAndDumpData(480, 800, step1); |   62         overrideAndDumpData(480, 800, step1); | 
|   63     } |   63     } | 
|   64  |   64  | 
|   65     function step1() |   65     function step1() | 
|   66     { |   66     { | 
|   67         function compareSizeCallback(jsonResult) |  | 
|   68         { |  | 
|   69             // Check that the screen size reported is the same as the original o
     ne. |  | 
|   70             var result = JSON.parse(jsonResult.value); |  | 
|   71             if (result.screen !== originalScreenSize) |  | 
|   72                 InspectorTest.addResult("Original size " + originalScreenSize + 
     " not restored, found: " + result.screen); |  | 
|   73             step2(); |  | 
|   74         } |  | 
|   75  |  | 
|   76         function overrideCallback() |  | 
|   77         { |  | 
|   78             InspectorTest.evaluateInPage("getSizes()", compareSizeCallback); |  | 
|   79         } |  | 
|   80  |  | 
|   81         // Disable overrides. |  | 
|   82         PageAgent.setDeviceMetricsOverride(0, 0, 1, true, overrideCallback); |  | 
|   83     } |  | 
|   84  |  | 
|   85     function step2() |  | 
|   86     { |  | 
|   87         overrideAndDumpData(800, 480, step3); |  | 
|   88     } |  | 
|   89  |  | 
|   90     function step3() |  | 
|   91     { |  | 
|   92         applyOverride(exceededDimension, 800, step4); |  | 
|   93     } |  | 
|   94  |  | 
|   95     function step4() |  | 
|   96     { |  | 
|   97         applyOverride(-1, 800, step5); |  | 
|   98     } |  | 
|   99  |  | 
|  100     function step5() |  | 
|  101     { |  | 
|  102         applyOverride(480, exceededDimension, step6); |  | 
|  103     } |  | 
|  104  |  | 
|  105     function step6() |  | 
|  106     { |  | 
|  107         function callback() |  | 
|  108         { |  | 
|  109             InspectorTest.addResult("Current dimensions:"); |  | 
|  110             getAndDumpSizes(step7); |  | 
|  111         } |  | 
|  112         applyOverride(480, -1, callback); |  | 
|  113     } |  | 
|  114  |  | 
|  115     function step7() |  | 
|  116     { |  | 
|  117         function callback(jsonResult) |   67         function callback(jsonResult) | 
|  118         { |   68         { | 
|  119             var value = JSON.parse(jsonResult.value); |   69             var value = JSON.parse(jsonResult.value); | 
|  120             if (value.screen !== originalScreenSize) |   70             if (value.screen !== originalScreenSize) | 
|  121                 InspectorTest.addResult("Screen size not restored, actual: " + v
     alue.screen + ", expected: " + originalScreenSize); |   71                 InspectorTest.addResult("Screen size not restored, actual: " + v
     alue.screen + ", expected: " + originalScreenSize); | 
|  122             else |   72             else | 
|  123                 InspectorTest.addResult("Screen size same as original - OK"); |   73                 InspectorTest.addResult("Screen size same as original - OK"); | 
|  124             step8(); |   74             step2(); | 
|  125         } |   75         } | 
|  126  |   76  | 
|  127         InspectorTest.addResult("Disable PageAgent:"); |   77         InspectorTest.addResult("Disable PageAgent:"); | 
|  128         PageAgent.disable(); |   78         PageAgent.disable(); | 
|  129         InspectorTest.evaluateInPage("getSizes()", callback); |   79         InspectorTest.evaluateInPage("getSizes()", callback); | 
|  130     } |   80     } | 
|  131  |   81  | 
|  132     function step8() |   82     function step2() | 
|  133     { |   83     { | 
|  134         function callback(jsonResult) |   84         function callback(jsonResult) | 
|  135         { |   85         { | 
|  136             var value = JSON.parse(jsonResult.value); |   86             var value = JSON.parse(jsonResult.value); | 
|  137             if (value.screen !== originalScreenSize) |   87             if (value.screen !== originalScreenSize) | 
|  138                 InspectorTest.addResult("Screen size not restored, actual: " + v
     alue.screen + ", expected: " + originalScreenSize); |   88                 InspectorTest.addResult("Screen size not restored, actual: " + v
     alue.screen + ", expected: " + originalScreenSize); | 
|  139             else |   89             else | 
|  140                 InspectorTest.addResult("Screen size same as original - OK"); |   90                 InspectorTest.addResult("Screen size same as original - OK"); | 
|  141             InspectorTest.completeTest(); |   91             InspectorTest.completeTest(); | 
|  142         } |   92         } | 
|  143  |   93  | 
|  144         InspectorTest.addResult("Enable PageAgent:"); |   94         InspectorTest.addResult("Enable PageAgent:"); | 
|  145         PageAgent.enable(); |   95         PageAgent.enable(); | 
|  146         InspectorTest.evaluateInPage("getSizes()", callback); |   96         InspectorTest.evaluateInPage("getSizes()", callback); | 
|  147     } |   97     } | 
|  148  |   98  | 
|  149     function applyOverride(width, height, userCallback) |   99     function applyOverride(width, height, userCallback) | 
|  150     { |  100     { | 
|  151         function callback(error) |  101         function callback(reload, error) | 
|  152         { |  102         { | 
|  153             if (error) |  103             if (error) | 
|  154                 InspectorTest.addResult("Override: " + width + "x" + height + " 
     => ERROR"); |  104                 InspectorTest.addResult("Override: " + width + "x" + height + " 
     => ERROR"); | 
|  155             userCallback(); |  105             if (reload && !error) { | 
 |  106                 InspectorTest.reloadPage(userCallback); | 
 |  107             } else { | 
 |  108                 userCallback(); | 
 |  109             } | 
|  156         } |  110         } | 
|  157         PageAgent.setDeviceMetricsOverride(width, height, 1, true, callback); |  111          | 
 |  112         var enabled = width > 0 && height > 0; | 
 |  113         PageAgent.setDeviceMetricsOverride(width, height, 1, true, callback.bind
     (null, enabled != overridesEnabled)); | 
 |  114         overridesEnabled = enabled; | 
|  158     } |  115     } | 
|  159  |  116  | 
|  160     function overrideAndDumpData(width, height, callback) |  117     function overrideAndDumpData(width, height, callback) | 
|  161     { |  118     { | 
|  162         function finalCallback() |  119         function finalCallback() | 
|  163         { |  120         { | 
|  164             InspectorTest.addResult("Main style:"); |  121             InspectorTest.addResult("Main style:"); | 
|  165             InspectorTest.dumpSelectedElementStyles(true, false, true); |  122             InspectorTest.dumpSelectedElementStyles(true, false, true); | 
|  166             callback(); |  123             callback(); | 
|  167         } |  124         } | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  205         } |  162         } | 
|  206  |  163  | 
|  207         InspectorTest.evaluateInPage("getSizes()", getSizesCallback); |  164         InspectorTest.evaluateInPage("getSizes()", getSizesCallback); | 
|  208     } |  165     } | 
|  209 } |  166 } | 
|  210 </script> |  167 </script> | 
|  211 </head> |  168 </head> | 
|  212  |  169  | 
|  213 <body onload="runTest()"> |  170 <body onload="runTest()"> | 
|  214 <p> |  171 <p> | 
|  215 Tests that screen dimension overrides affect media rules, body dimensions, and w
     indow.screen. |  172 Tests that disabling page agent cancels device metrics override. | 
|  216 </p> |  173 </p> | 
|  217  |  174  | 
|  218 <div id="main"></div> |  175 <div id="main"></div> | 
|  219 </body> |  176 </body> | 
|  220 </html> |  177 </html> | 
| OLD | NEW |