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 {InspectorFront} = require("devtools/server/actors/inspector"); |
michael@0 | 9 | const { Cc, Ci } = require("chrome"); |
michael@0 | 10 | |
michael@0 | 11 | const CSS_URI = "http://mochi.test:8888/browser/browser/devtools/sourceeditor" + |
michael@0 | 12 | "/test/css_statemachine_testcases.css"; |
michael@0 | 13 | const TESTS_URI = "http://mochi.test:8888/browser/browser/devtools/sourceeditor" + |
michael@0 | 14 | "/test/css_autocompletion_tests.json"; |
michael@0 | 15 | |
michael@0 | 16 | const source = read(CSS_URI); |
michael@0 | 17 | const tests = eval(read(TESTS_URI)); |
michael@0 | 18 | |
michael@0 | 19 | const TEST_URI = "data:text/html;charset=UTF-8," + encodeURIComponent( |
michael@0 | 20 | ["<!DOCTYPE html>", |
michael@0 | 21 | "<html>", |
michael@0 | 22 | " <head>", |
michael@0 | 23 | " <title>CSS State machine tests.</title>", |
michael@0 | 24 | " <style type='text/css'>", |
michael@0 | 25 | "#progress {", |
michael@0 | 26 | " width: 500px; height: 30px;", |
michael@0 | 27 | " border: 1px solid black;", |
michael@0 | 28 | " position: relative", |
michael@0 | 29 | "}", |
michael@0 | 30 | "#progress div {", |
michael@0 | 31 | " width: 0%; height: 100%;", |
michael@0 | 32 | " background: green;", |
michael@0 | 33 | " position: absolute;", |
michael@0 | 34 | " z-index: -1; top: 0", |
michael@0 | 35 | "}", |
michael@0 | 36 | "#progress.failed div {", |
michael@0 | 37 | " background: red !important;", |
michael@0 | 38 | "}", |
michael@0 | 39 | "#progress.failed:after {", |
michael@0 | 40 | " content: 'Some tests failed';", |
michael@0 | 41 | " color: white", |
michael@0 | 42 | "}", |
michael@0 | 43 | "#progress:before {", |
michael@0 | 44 | " content: 'Running test ' attr(data-progress) ' of " + tests.length + "';", |
michael@0 | 45 | " color: white;", |
michael@0 | 46 | " text-shadow: 0 0 2px darkgreen;", |
michael@0 | 47 | "}", |
michael@0 | 48 | " </style>", |
michael@0 | 49 | " </head>", |
michael@0 | 50 | " <body>", |
michael@0 | 51 | " <h2>State machine tests for CSS autocompleter.</h2><br>", |
michael@0 | 52 | " <div id='progress' data-progress='0'>", |
michael@0 | 53 | " <div></div>", |
michael@0 | 54 | " </div>", |
michael@0 | 55 | " <div id='devtools-menu' class='devtools-toolbarbutton'></div>", |
michael@0 | 56 | " <div id='devtools-toolbarbutton' class='devtools-menulist'></div>", |
michael@0 | 57 | " <div id='devtools-anotherone'></div>", |
michael@0 | 58 | " <div id='devtools-yetagain'></div>", |
michael@0 | 59 | " <div id='devtools-itjustgoeson'></div>", |
michael@0 | 60 | " <div id='devtools-okstopitnow'></div>", |
michael@0 | 61 | " <div class='hidden-labels-box devtools-toolbarbutton devtools-menulist'></div>", |
michael@0 | 62 | " <div class='devtools-menulist'></div>", |
michael@0 | 63 | " <div class='devtools-menulist'></div>", |
michael@0 | 64 | " <tabs class='devtools-toolbarbutton'><tab></tab><tab></tab><tab></tab></tabs><tabs></tabs>", |
michael@0 | 65 | " <button class='category-name visible'></button>", |
michael@0 | 66 | " <div class='devtools-toolbarbutton' label='true'>", |
michael@0 | 67 | " <hbox class='toolbarbutton-menubutton-button'></hbox></div>", |
michael@0 | 68 | " </body>", |
michael@0 | 69 | " </html>" |
michael@0 | 70 | ].join("\n")); |
michael@0 | 71 | |
michael@0 | 72 | let doc = null; |
michael@0 | 73 | let index = 0; |
michael@0 | 74 | let completer = null; |
michael@0 | 75 | let progress; |
michael@0 | 76 | let progressDiv; |
michael@0 | 77 | let inspector; |
michael@0 | 78 | |
michael@0 | 79 | function test() { |
michael@0 | 80 | waitForExplicitFinish(); |
michael@0 | 81 | gBrowser.selectedTab = gBrowser.addTab(); |
michael@0 | 82 | gBrowser.selectedBrowser.addEventListener("load", function onload() { |
michael@0 | 83 | gBrowser.selectedBrowser.removeEventListener("load", onload, true); |
michael@0 | 84 | doc = content.document; |
michael@0 | 85 | runTests(); |
michael@0 | 86 | }, true); |
michael@0 | 87 | content.location = TEST_URI; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function runTests() { |
michael@0 | 91 | progress = doc.getElementById("progress"); |
michael@0 | 92 | progressDiv = doc.querySelector("#progress > div"); |
michael@0 | 93 | let target = devtools.TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 94 | target.makeRemote().then(() => { |
michael@0 | 95 | inspector = InspectorFront(target.client, target.form); |
michael@0 | 96 | inspector.getWalker().then(walker => { |
michael@0 | 97 | completer = new cssAutoCompleter({walker: walker}); |
michael@0 | 98 | checkStateAndMoveOn(); |
michael@0 | 99 | }); |
michael@0 | 100 | }); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function checkStateAndMoveOn() { |
michael@0 | 104 | if (index == tests.length) { |
michael@0 | 105 | finishUp(); |
michael@0 | 106 | return; |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | let test = tests[index]; |
michael@0 | 110 | progress.dataset.progress = ++index; |
michael@0 | 111 | progressDiv.style.width = 100*index/tests.length + "%"; |
michael@0 | 112 | completer.complete(limit(source, test[0]), |
michael@0 | 113 | {line: test[0][0], ch: test[0][1]}).then(suggestions => { |
michael@0 | 114 | checkState(test[1], suggestions); |
michael@0 | 115 | }).then(checkStateAndMoveOn); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | function checkState(expected, actual) { |
michael@0 | 119 | if (expected.length != actual.length) { |
michael@0 | 120 | ok(false, "Number of suggestions did not match up for state " + index + |
michael@0 | 121 | ". Expected: " + expected.length + ", Actual: " + actual.length); |
michael@0 | 122 | progress.classList.add("failed"); |
michael@0 | 123 | return; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | for (let i = 0; i < actual.length; i++) { |
michael@0 | 127 | if (expected[i] != actual[i].label) { |
michael@0 | 128 | ok (false, "Suggestion " + i + " of state " + index + " did not match up" + |
michael@0 | 129 | ". Expected: " + expected[i] + ". Actual: " + actual[i].label); |
michael@0 | 130 | return; |
michael@0 | 131 | } |
michael@0 | 132 | } |
michael@0 | 133 | ok(true, "Test " + index + " passed. "); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | function finishUp() { |
michael@0 | 137 | completer.walker.release().then(() => { |
michael@0 | 138 | inspector.destroy(); |
michael@0 | 139 | inspector = null; |
michael@0 | 140 | completer = null; |
michael@0 | 141 | }); |
michael@0 | 142 | progress = null; |
michael@0 | 143 | progressDiv = null; |
michael@0 | 144 | gBrowser.removeCurrentTab(); |
michael@0 | 145 | finish(); |
michael@0 | 146 | } |