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 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const cssAutoCompleter = require("devtools/sourceeditor/css-autocompleter"); |
michael@0 | 8 | const { Cc, Ci } = require("chrome"); |
michael@0 | 9 | |
michael@0 | 10 | const CSS_URI = "http://mochi.test:8888/browser/browser/devtools/sourceeditor" + |
michael@0 | 11 | "/test/css_statemachine_testcases.css"; |
michael@0 | 12 | const TESTS_URI = "http://mochi.test:8888/browser/browser/devtools/sourceeditor" + |
michael@0 | 13 | "/test/css_statemachine_tests.json"; |
michael@0 | 14 | |
michael@0 | 15 | const source = read(CSS_URI); |
michael@0 | 16 | const tests = eval(read(TESTS_URI)); |
michael@0 | 17 | |
michael@0 | 18 | const TEST_URI = "data:text/html;charset=UTF-8," + encodeURIComponent( |
michael@0 | 19 | ["<!DOCTYPE html>", |
michael@0 | 20 | "<html>", |
michael@0 | 21 | " <head>", |
michael@0 | 22 | " <title>CSS State machine tests.</title>", |
michael@0 | 23 | " <style type='text/css'>", |
michael@0 | 24 | "#progress {", |
michael@0 | 25 | " width: 500px; height: 30px;", |
michael@0 | 26 | " border: 1px solid black;", |
michael@0 | 27 | " position: relative", |
michael@0 | 28 | "}", |
michael@0 | 29 | "#progress div {", |
michael@0 | 30 | " width: 0%; height: 100%;", |
michael@0 | 31 | " background: green;", |
michael@0 | 32 | " position: absolute;", |
michael@0 | 33 | " z-index: -1; top: 0", |
michael@0 | 34 | "}", |
michael@0 | 35 | "#progress.failed div {", |
michael@0 | 36 | " background: red !important;", |
michael@0 | 37 | "}", |
michael@0 | 38 | "#progress.failed:after {", |
michael@0 | 39 | " content: 'Some tests failed';", |
michael@0 | 40 | " color: white", |
michael@0 | 41 | "}", |
michael@0 | 42 | "#progress:before {", |
michael@0 | 43 | " content: 'Running test ' attr(data-progress) ' of " + tests.length + "';", |
michael@0 | 44 | " color: white;", |
michael@0 | 45 | " text-shadow: 0 0 2px darkgreen;", |
michael@0 | 46 | "}", |
michael@0 | 47 | " </style>", |
michael@0 | 48 | " </head>", |
michael@0 | 49 | " <body>", |
michael@0 | 50 | " <h2>State machine tests for CSS autocompleter.</h2><br>", |
michael@0 | 51 | " <div id='progress' data-progress='0'>", |
michael@0 | 52 | " <div></div>", |
michael@0 | 53 | " </div>", |
michael@0 | 54 | " </body>", |
michael@0 | 55 | " </html>" |
michael@0 | 56 | ].join("\n")); |
michael@0 | 57 | |
michael@0 | 58 | let doc = null; |
michael@0 | 59 | function test() { |
michael@0 | 60 | waitForExplicitFinish(); |
michael@0 | 61 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 62 | gBrowser.selectedBrowser.addEventListener("load", function onload() { |
michael@0 | 63 | gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
michael@0 | 64 | doc = content.document; |
michael@0 | 65 | runTests(); |
michael@0 | 66 | }, true); |
michael@0 | 67 | content.location = TEST_URI; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function runTests() { |
michael@0 | 71 | let completer = new cssAutoCompleter(); |
michael@0 | 72 | let checkState = state => { |
michael@0 | 73 | if (state[0] == 'null' && (!completer.state || completer.state == 'null')) { |
michael@0 | 74 | return true; |
michael@0 | 75 | } else if (state[0] == completer.state && state[0] == 'selector' && |
michael@0 | 76 | state[1] == completer.selectorState && |
michael@0 | 77 | state[2] == completer.completing && |
michael@0 | 78 | state[3] == completer.selector) { |
michael@0 | 79 | return true; |
michael@0 | 80 | } else if (state[0] == completer.state && state[0] == 'value' && |
michael@0 | 81 | state[2] == completer.completing && |
michael@0 | 82 | state[3] == completer.propertyName) { |
michael@0 | 83 | return true; |
michael@0 | 84 | } else if (state[0] == completer.state && |
michael@0 | 85 | state[2] == completer.completing && |
michael@0 | 86 | state[0] != 'selector' && state[0] != 'value') { |
michael@0 | 87 | return true; |
michael@0 | 88 | } |
michael@0 | 89 | return false; |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | let progress = doc.getElementById("progress"); |
michael@0 | 93 | let progressDiv = doc.querySelector("#progress > div"); |
michael@0 | 94 | let i = 0; |
michael@0 | 95 | for (let test of tests) { |
michael@0 | 96 | progress.dataset.progress = ++i; |
michael@0 | 97 | progressDiv.style.width = 100*i/tests.length + "%"; |
michael@0 | 98 | completer.resolveState(limit(source, test[0]), |
michael@0 | 99 | {line: test[0][0], ch: test[0][1]}); |
michael@0 | 100 | if (checkState(test[1])) { |
michael@0 | 101 | ok(true, "Test " + i + " passed. "); |
michael@0 | 102 | } |
michael@0 | 103 | else { |
michael@0 | 104 | ok(false, "Test " + i + " failed. Expected state : [" + test[1] + "] but" + |
michael@0 | 105 | " found [" + completer.state + ", " + completer.selectorState + ", " + |
michael@0 | 106 | completer.completing + ", " + |
michael@0 | 107 | (completer.propertyName || completer.selector) + "]."); |
michael@0 | 108 | progress.classList.add("failed"); |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | gBrowser.removeCurrentTab(); |
michael@0 | 112 | finish(); |
michael@0 | 113 | } |