browser_webconsole_property_provider.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Tests the property provider, which is part of the code completion
  5. // infrastructure.
  6. "use strict";
  7. const TEST_URI = "data:text/html;charset=utf8,<p>test the JS property provider";
  8. function test() {
  9. loadTab(TEST_URI).then(testPropertyProvider);
  10. }
  11. function testPropertyProvider({browser}) {
  12. browser.removeEventListener("load", testPropertyProvider, true);
  13. let {JSPropertyProvider} = require("devtools/shared/webconsole/js-property-provider");
  14. let tmp = Cu.import("resource://gre/modules/jsdebugger.jsm", {});
  15. tmp.addDebuggerToGlobal(tmp);
  16. let dbg = new tmp.Debugger();
  17. let dbgWindow = dbg.addDebuggee(content);
  18. let completion = JSPropertyProvider(dbgWindow, null, "thisIsNotDefined");
  19. is(completion.matches.length, 0, "no match for 'thisIsNotDefined");
  20. // This is a case the PropertyProvider can't handle. Should return null.
  21. completion = JSPropertyProvider(dbgWindow, null, "window[1].acb");
  22. is(completion, null, "no match for 'window[1].acb");
  23. // A very advanced completion case.
  24. let strComplete =
  25. "function a() { }document;document.getElementById(window.locatio";
  26. completion = JSPropertyProvider(dbgWindow, null, strComplete);
  27. ok(completion.matches.length == 2, "two matches found");
  28. ok(completion.matchProp == "locatio", "matching part is 'test'");
  29. let matches = completion.matches;
  30. matches.sort();
  31. ok(matches[0] == "location", "the first match is 'location'");
  32. ok(matches[1] == "locationbar", "the second match is 'locationbar'");
  33. dbg.removeDebuggee(content);
  34. finishTest();
  35. }