2010-10-11 09:57:56 -07:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-10-11 09:57:56 -07:00
|
|
|
|
|
|
|
// Tests the property provider, which is part of the code completion
|
|
|
|
// infrastructure.
|
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
const TEST_URI = "data:text/html;charset=utf8,<p>test the JS property provider";
|
2010-10-11 09:57:56 -07:00
|
|
|
|
|
|
|
function test() {
|
|
|
|
addTab(TEST_URI);
|
2012-05-25 03:28:47 -07:00
|
|
|
browser.addEventListener("load", testPropertyProvider, true);
|
2010-10-11 09:57:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function testPropertyProvider() {
|
2012-05-25 03:28:47 -07:00
|
|
|
browser.removeEventListener("load", testPropertyProvider, true);
|
2010-10-11 09:57:56 -07:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
let tmp = {};
|
2012-09-26 10:07:57 -07:00
|
|
|
Cu.import("resource://gre/modules/devtools/WebConsoleUtils.jsm", tmp);
|
2012-05-25 03:28:47 -07:00
|
|
|
let JSPropertyProvider = tmp.JSPropertyProvider;
|
|
|
|
tmp = null;
|
2010-10-11 09:57:56 -07:00
|
|
|
|
2012-05-25 03:28:47 -07:00
|
|
|
let completion = JSPropertyProvider(content, "thisIsNotDefined");
|
2010-10-11 09:57:56 -07:00
|
|
|
is (completion.matches.length, 0, "no match for 'thisIsNotDefined");
|
|
|
|
|
|
|
|
// This is a case the PropertyProvider can't handle. Should return null.
|
2012-05-25 03:28:47 -07:00
|
|
|
completion = JSPropertyProvider(content, "window[1].acb");
|
2010-10-11 09:57:56 -07:00
|
|
|
is (completion, null, "no match for 'window[1].acb");
|
|
|
|
|
|
|
|
// A very advanced completion case.
|
|
|
|
var strComplete =
|
|
|
|
'function a() { }document;document.getElementById(window.locatio';
|
2012-05-25 03:28:47 -07:00
|
|
|
completion = JSPropertyProvider(content, strComplete);
|
2010-10-11 09:57:56 -07:00
|
|
|
ok(completion.matches.length == 2, "two matches found");
|
|
|
|
ok(completion.matchProp == "locatio", "matching part is 'test'");
|
|
|
|
ok(completion.matches[0] == "location", "the first match is 'location'");
|
|
|
|
ok(completion.matches[1] == "locationbar", "the second match is 'locationbar'");
|
2012-05-25 03:28:47 -07:00
|
|
|
|
2010-10-11 09:57:56 -07:00
|
|
|
finishTest();
|
|
|
|
}
|
|
|
|
|