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