Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=819930 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 819930</title> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 12 | <style> |
michael@0 | 13 | @media braille { |
michael@0 | 14 | body { |
michael@0 | 15 | background-color: rgb(255, 255, 0); |
michael@0 | 16 | } |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | @media embossed { |
michael@0 | 20 | body { |
michael@0 | 21 | background-color: rgb(210, 180, 140); |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | @media handheld { |
michael@0 | 26 | body { |
michael@0 | 27 | background-color: rgb(0, 255, 0); |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | @media print { |
michael@0 | 32 | body { |
michael@0 | 33 | background-color: rgb(0, 255, 255); |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | @media projection { |
michael@0 | 38 | body { |
michael@0 | 39 | background-color: rgb(30, 144, 255); |
michael@0 | 40 | } |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | @media screen { |
michael@0 | 44 | body { |
michael@0 | 45 | background-color: green; |
michael@0 | 46 | } |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | @media speech { |
michael@0 | 50 | body { |
michael@0 | 51 | background-color: rgb(192, 192, 192); |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | @media tty { |
michael@0 | 56 | body { |
michael@0 | 57 | background-color: rgb(255, 192, 203); |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | @media tv { |
michael@0 | 62 | body { |
michael@0 | 63 | background-color: rgb(75, 0, 130); |
michael@0 | 64 | } |
michael@0 | 65 | } |
michael@0 | 66 | </style> |
michael@0 | 67 | </head> |
michael@0 | 68 | <body> |
michael@0 | 69 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=819930">Mozilla Bug 819930</a> |
michael@0 | 70 | <p id="display"></p> |
michael@0 | 71 | |
michael@0 | 72 | <div id="content" style="display: none"></div> |
michael@0 | 73 | <pre id="test"> |
michael@0 | 74 | <script type="application/javascript;version=1.7"> |
michael@0 | 75 | let tests = [{name: 'braille', value: 'rgb(255, 255, 0)'}, |
michael@0 | 76 | {name: 'embossed', value: 'rgb(210, 180, 140)'}, |
michael@0 | 77 | {name: 'handheld', value: 'rgb(0, 255, 0)'}, |
michael@0 | 78 | {name: 'print', value: 'rgb(0, 255, 255)'}, |
michael@0 | 79 | {name: 'projection', value: 'rgb(30, 144, 255)'}, |
michael@0 | 80 | {name: 'speech', value: 'rgb(192, 192, 192)'}, |
michael@0 | 81 | {name: 'tty', value: 'rgb(255, 192, 203)'}, |
michael@0 | 82 | {name: 'tv', value: 'rgb(75, 0, 130)'}]; |
michael@0 | 83 | |
michael@0 | 84 | let originalColor = 'rgb(0, 128, 0)'; |
michael@0 | 85 | let body = document.body; |
michael@0 | 86 | |
michael@0 | 87 | let getColor = function() { |
michael@0 | 88 | return window.getComputedStyle(body) |
michael@0 | 89 | .getPropertyValue('background-color'); |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | tests.forEach(function(test) { |
michael@0 | 93 | // Emulate the given media |
michael@0 | 94 | SpecialPowers.emulateMedium(window, test.name); |
michael@0 | 95 | is(getColor(), test.value, 'emulating ' + test.name + ' produced ' + |
michael@0 | 96 | 'correct rendering'); |
michael@0 | 97 | |
michael@0 | 98 | // Do the @media screen rules get applied after ending the emulation? |
michael@0 | 99 | SpecialPowers.stopEmulatingMedium(window); |
michael@0 | 100 | is(getColor(), originalColor, 'Ending ' + test.name + |
michael@0 | 101 | ' emulation restores style for original medium'); |
michael@0 | 102 | |
michael@0 | 103 | // CSS media types are case-insensitive; we should be too. |
michael@0 | 104 | SpecialPowers.emulateMedium(window, test.name.toUpperCase()); |
michael@0 | 105 | is(getColor(), test.value, |
michael@0 | 106 | test.name + ' emulation is case-insensitive'); |
michael@0 | 107 | SpecialPowers.stopEmulatingMedium(window); |
michael@0 | 108 | }); |
michael@0 | 109 | |
michael@0 | 110 | // Emulating screen should produce the same rendering as when there is |
michael@0 | 111 | // no emulation in effect |
michael@0 | 112 | SpecialPowers.emulateMedium(window, 'screen'); |
michael@0 | 113 | is(getColor(), originalColor, |
michael@0 | 114 | 'Emulating screen produces original rendering'); |
michael@0 | 115 | SpecialPowers.stopEmulatingMedium(window); |
michael@0 | 116 | |
michael@0 | 117 | // Screen should be case-insensitive too |
michael@0 | 118 | SpecialPowers.emulateMedium(window, 'SCREEN'); |
michael@0 | 119 | is(getColor(), originalColor, 'screen emulation is case-insensitive'); |
michael@0 | 120 | SpecialPowers.stopEmulatingMedium(window); |
michael@0 | 121 | |
michael@0 | 122 | // An invalid parameter shouldn't fail. Given the CSS rules above, |
michael@0 | 123 | // an invalid parameter should result in a different rendering from any |
michael@0 | 124 | // produced thus far |
michael@0 | 125 | try { |
michael@0 | 126 | SpecialPowers.emulateMedium(window, 'clay'); |
michael@0 | 127 | let invalid = getColor(); |
michael@0 | 128 | tests.push({name: 'screen', value: 'green'}); |
michael@0 | 129 | tests.forEach(function(test) { |
michael@0 | 130 | isnot(invalid, test.value, 'Emulating invalid type differs from ' + |
michael@0 | 131 | test.name); |
michael@0 | 132 | }); |
michael@0 | 133 | } catch (e) { |
michael@0 | 134 | ok(false, 'Supplying invalid type to emulateMedium shouldn\'t throw'); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | SpecialPowers.stopEmulatingMedium(window); |
michael@0 | 138 | </script> |
michael@0 | 139 | </pre> |
michael@0 | 140 | </body> |
michael@0 | 141 | </html> |