diff -r 000000000000 -r 6474c204b198 browser/devtools/sourceeditor/test/browser_css_autocompletion.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/browser/devtools/sourceeditor/test/browser_css_autocompletion.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,146 @@ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const cssAutoCompleter = require("devtools/sourceeditor/css-autocompleter"); +const {InspectorFront} = require("devtools/server/actors/inspector"); +const { Cc, Ci } = require("chrome"); + +const CSS_URI = "http://mochi.test:8888/browser/browser/devtools/sourceeditor" + + "/test/css_statemachine_testcases.css"; +const TESTS_URI = "http://mochi.test:8888/browser/browser/devtools/sourceeditor" + + "/test/css_autocompletion_tests.json"; + +const source = read(CSS_URI); +const tests = eval(read(TESTS_URI)); + +const TEST_URI = "data:text/html;charset=UTF-8," + encodeURIComponent( + ["", + "", + " ", + " CSS State machine tests.", + " ", + " ", + " ", + "

State machine tests for CSS autocompleter.


", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + "
", + " ", + " ", + "
", + "
", + " ", + " " + ].join("\n")); + +let doc = null; +let index = 0; +let completer = null; +let progress; +let progressDiv; +let inspector; + +function test() { + waitForExplicitFinish(); + gBrowser.selectedTab = gBrowser.addTab(); + gBrowser.selectedBrowser.addEventListener("load", function onload() { + gBrowser.selectedBrowser.removeEventListener("load", onload, true); + doc = content.document; + runTests(); + }, true); + content.location = TEST_URI; +} + +function runTests() { + progress = doc.getElementById("progress"); + progressDiv = doc.querySelector("#progress > div"); + let target = devtools.TargetFactory.forTab(gBrowser.selectedTab); + target.makeRemote().then(() => { + inspector = InspectorFront(target.client, target.form); + inspector.getWalker().then(walker => { + completer = new cssAutoCompleter({walker: walker}); + checkStateAndMoveOn(); + }); + }); +} + +function checkStateAndMoveOn() { + if (index == tests.length) { + finishUp(); + return; + } + + let test = tests[index]; + progress.dataset.progress = ++index; + progressDiv.style.width = 100*index/tests.length + "%"; + completer.complete(limit(source, test[0]), + {line: test[0][0], ch: test[0][1]}).then(suggestions => { + checkState(test[1], suggestions); + }).then(checkStateAndMoveOn); +} + +function checkState(expected, actual) { + if (expected.length != actual.length) { + ok(false, "Number of suggestions did not match up for state " + index + + ". Expected: " + expected.length + ", Actual: " + actual.length); + progress.classList.add("failed"); + return; + } + + for (let i = 0; i < actual.length; i++) { + if (expected[i] != actual[i].label) { + ok (false, "Suggestion " + i + " of state " + index + " did not match up" + + ". Expected: " + expected[i] + ". Actual: " + actual[i].label); + return; + } + } + ok(true, "Test " + index + " passed. "); +} + +function finishUp() { + completer.walker.release().then(() => { + inspector.destroy(); + inspector = null; + completer = null; + }); + progress = null; + progressDiv = null; + gBrowser.removeCurrentTab(); + finish(); +}