browser/devtools/debugger/test/browser_dbg_variables-view-accessibility.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_variables-view-accessibility.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,557 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Make sure that the variables view is keyboard accessible.
     1.9 + */
    1.10 +
    1.11 +let gTab, gDebuggee, gPanel, gDebugger;
    1.12 +let gVariablesView;
    1.13 +
    1.14 +function test() {
    1.15 +  initDebugger("about:blank").then(([aTab, aDebuggee, aPanel]) => {
    1.16 +    gTab = aTab;
    1.17 +    gDebuggee = aDebuggee;
    1.18 +    gPanel = aPanel;
    1.19 +    gDebugger = gPanel.panelWin;
    1.20 +    gVariablesView = gDebugger.DebuggerView.Variables;
    1.21 +
    1.22 +    performTest().then(null, aError => {
    1.23 +      ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.24 +    });
    1.25 +  });
    1.26 +}
    1.27 +
    1.28 +function performTest() {
    1.29 +  let arr = [
    1.30 +    42,
    1.31 +    true,
    1.32 +    "nasu",
    1.33 +    undefined,
    1.34 +    null,
    1.35 +    [0, 1, 2],
    1.36 +    { prop1: 9, prop2: 8 }
    1.37 +  ];
    1.38 +
    1.39 +  let obj = {
    1.40 +    p0: 42,
    1.41 +    p1: true,
    1.42 +    p2: "nasu",
    1.43 +    p3: undefined,
    1.44 +    p4: null,
    1.45 +    p5: [3, 4, 5],
    1.46 +    p6: { prop1: 7, prop2: 6 },
    1.47 +    get p7() { return arr; },
    1.48 +    set p8(value) { arr[0] = value }
    1.49 +  };
    1.50 +
    1.51 +  let test = {
    1.52 +    someProp0: 42,
    1.53 +    someProp1: true,
    1.54 +    someProp2: "nasu",
    1.55 +    someProp3: undefined,
    1.56 +    someProp4: null,
    1.57 +    someProp5: arr,
    1.58 +    someProp6: obj,
    1.59 +    get someProp7() { return arr; },
    1.60 +    set someProp7(value) { arr[0] = value }
    1.61 +  };
    1.62 +
    1.63 +  gVariablesView.eval = function() {};
    1.64 +  gVariablesView.switch = function() {};
    1.65 +  gVariablesView.delete = function() {};
    1.66 +  gVariablesView.rawObject = test;
    1.67 +  gVariablesView.scrollPageSize = 5;
    1.68 +
    1.69 +  return Task.spawn(function() {
    1.70 +    yield waitForTick();
    1.71 +
    1.72 +    // Part 0: Test generic focus methods on the variables view.
    1.73 +
    1.74 +    gVariablesView.focusFirstVisibleItem();
    1.75 +    is(gVariablesView.getFocusedItem().name, "someProp0",
    1.76 +      "The 'someProp0' item should be focused.");
    1.77 +
    1.78 +    gVariablesView.focusNextItem();
    1.79 +    is(gVariablesView.getFocusedItem().name, "someProp1",
    1.80 +      "The 'someProp1' item should be focused.");
    1.81 +
    1.82 +    gVariablesView.focusPrevItem();
    1.83 +    is(gVariablesView.getFocusedItem().name, "someProp0",
    1.84 +      "The 'someProp0' item should be focused.");
    1.85 +
    1.86 +    // Part 1: Make sure that UP/DOWN keys don't scroll the variables view.
    1.87 +
    1.88 +    yield synthesizeKeyAndWaitForTick("VK_DOWN", {});
    1.89 +    is(gVariablesView._parent.scrollTop, 0,
    1.90 +      "The 'variables' view shouldn't scroll when pressing the DOWN key.");
    1.91 +
    1.92 +    yield synthesizeKeyAndWaitForTick("VK_UP", {});
    1.93 +    is(gVariablesView._parent.scrollTop, 0,
    1.94 +      "The 'variables' view shouldn't scroll when pressing the UP key.");
    1.95 +
    1.96 +    // Part 2: Make sure that RETURN/ESCAPE toggle input elements.
    1.97 +
    1.98 +    yield synthesizeKeyAndWaitForElement("VK_RETURN", {}, ".element-value-input", true);
    1.99 +    yield synthesizeKeyAndWaitForElement("VK_ESCAPE", {}, ".element-value-input", false);
   1.100 +    yield synthesizeKeyAndWaitForElement("VK_RETURN", { shiftKey: true }, ".element-name-input", true);
   1.101 +    yield synthesizeKeyAndWaitForElement("VK_ESCAPE", {}, ".element-name-input", false);
   1.102 +
   1.103 +    // Part 3: Test simple navigation.
   1.104 +
   1.105 +    EventUtils.sendKey("DOWN", gDebugger);
   1.106 +    is(gVariablesView.getFocusedItem().name, "someProp1",
   1.107 +      "The 'someProp1' item should be focused.");
   1.108 +
   1.109 +    EventUtils.sendKey("UP", gDebugger);
   1.110 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.111 +      "The 'someProp0' item should be focused.");
   1.112 +
   1.113 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.114 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.115 +      "The 'someProp5' item should be focused.");
   1.116 +
   1.117 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.118 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.119 +      "The 'someProp0' item should be focused.");
   1.120 +
   1.121 +    EventUtils.sendKey("END", gDebugger);
   1.122 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.123 +      "The '__proto__' item should be focused.");
   1.124 +
   1.125 +    EventUtils.sendKey("HOME", gDebugger);
   1.126 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.127 +      "The 'someProp0' item should be focused.");
   1.128 +
   1.129 +    // Part 4: Test if pressing the same navigation key twice works as expected.
   1.130 +
   1.131 +    EventUtils.sendKey("DOWN", gDebugger);
   1.132 +    is(gVariablesView.getFocusedItem().name, "someProp1",
   1.133 +      "The 'someProp1' item should be focused.");
   1.134 +
   1.135 +    EventUtils.sendKey("DOWN", gDebugger);
   1.136 +    is(gVariablesView.getFocusedItem().name, "someProp2",
   1.137 +      "The 'someProp2' item should be focused.");
   1.138 +
   1.139 +    EventUtils.sendKey("UP", gDebugger);
   1.140 +    is(gVariablesView.getFocusedItem().name, "someProp1",
   1.141 +      "The 'someProp1' item should be focused.");
   1.142 +
   1.143 +    EventUtils.sendKey("UP", gDebugger);
   1.144 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.145 +      "The 'someProp0' item should be focused.");
   1.146 +
   1.147 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.148 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.149 +      "The 'someProp5' item should be focused.");
   1.150 +
   1.151 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.152 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.153 +      "The '__proto__' item should be focused.");
   1.154 +
   1.155 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.156 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.157 +      "The 'someProp5' item should be focused.");
   1.158 +
   1.159 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.160 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.161 +      "The 'someProp0' item should be focused.");
   1.162 +
   1.163 +    // Part 5: Test that HOME/PAGE_UP/PAGE_DOWN are symmetrical.
   1.164 +
   1.165 +    EventUtils.sendKey("HOME", gDebugger);
   1.166 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.167 +      "The 'someProp0' item should be focused.");
   1.168 +
   1.169 +    EventUtils.sendKey("HOME", gDebugger);
   1.170 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.171 +      "The 'someProp0' item should be focused.");
   1.172 +
   1.173 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.174 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.175 +      "The 'someProp0' item should be focused.");
   1.176 +
   1.177 +    EventUtils.sendKey("HOME", gDebugger);
   1.178 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.179 +      "The 'someProp0' item should be focused.");
   1.180 +
   1.181 +    EventUtils.sendKey("END", gDebugger);
   1.182 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.183 +      "The '__proto__' item should be focused.");
   1.184 +
   1.185 +    EventUtils.sendKey("END", gDebugger);
   1.186 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.187 +      "The '__proto__' item should be focused.");
   1.188 +
   1.189 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.190 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.191 +      "The '__proto__' item should be focused.");
   1.192 +
   1.193 +    EventUtils.sendKey("END", gDebugger);
   1.194 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.195 +      "The '__proto__' item should be focused.");
   1.196 +
   1.197 +    // Part 6: Test that focus doesn't leave the variables view.
   1.198 +
   1.199 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.200 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.201 +      "The 'someProp5' item should be focused.");
   1.202 +
   1.203 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.204 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.205 +      "The 'someProp0' item should be focused.");
   1.206 +
   1.207 +    EventUtils.sendKey("UP", gDebugger);
   1.208 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.209 +      "The 'someProp0' item should be focused.");
   1.210 +
   1.211 +    EventUtils.sendKey("UP", gDebugger);
   1.212 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.213 +      "The 'someProp0' item should be focused.");
   1.214 +
   1.215 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.216 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.217 +      "The 'someProp5' item should be focused.");
   1.218 +
   1.219 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.220 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.221 +      "The '__proto__' item should be focused.");
   1.222 +
   1.223 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.224 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.225 +      "The '__proto__' item should be focused.");
   1.226 +
   1.227 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.228 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.229 +      "The '__proto__' item should be focused.");
   1.230 +
   1.231 +    // Part 7: Test that random offsets don't occur in tandem with HOME/END.
   1.232 +
   1.233 +    EventUtils.sendKey("HOME", gDebugger);
   1.234 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.235 +      "The 'someProp0' item should be focused.");
   1.236 +
   1.237 +    EventUtils.sendKey("DOWN", gDebugger);
   1.238 +    is(gVariablesView.getFocusedItem().name, "someProp1",
   1.239 +      "The 'someProp1' item should be focused.");
   1.240 +
   1.241 +    EventUtils.sendKey("END", gDebugger);
   1.242 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.243 +      "The '__proto__' item should be focused.");
   1.244 +
   1.245 +    EventUtils.sendKey("DOWN", gDebugger);
   1.246 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.247 +      "The '__proto__' item should be focused.");
   1.248 +
   1.249 +    // Part 8: Test that the RIGHT key expands elements as intended.
   1.250 +
   1.251 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.252 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.253 +      "The 'someProp5' item should be focused.");
   1.254 +    is(gVariablesView.getFocusedItem().expanded, false,
   1.255 +      "The 'someProp5' item should not be expanded yet.");
   1.256 +
   1.257 +    yield synthesizeKeyAndWaitForTick("VK_RIGHT", {});
   1.258 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.259 +      "The 'someProp5' item should be focused.");
   1.260 +    is(gVariablesView.getFocusedItem().expanded, true,
   1.261 +      "The 'someProp5' item should now be expanded.");
   1.262 +    is(gVariablesView.getFocusedItem()._store.size, 9,
   1.263 +      "There should be 9 properties in the selected variable.");
   1.264 +    is(gVariablesView.getFocusedItem()._enumItems.length, 7,
   1.265 +      "There should be 7 enumerable properties in the selected variable.");
   1.266 +    is(gVariablesView.getFocusedItem()._nonEnumItems.length, 2,
   1.267 +      "There should be 2 non-enumerable properties in the selected variable.");
   1.268 +
   1.269 +    yield waitForChildNodes(gVariablesView.getFocusedItem()._enum, 7);
   1.270 +    yield waitForChildNodes(gVariablesView.getFocusedItem()._nonenum, 2);
   1.271 +
   1.272 +    EventUtils.sendKey("RIGHT", gDebugger);
   1.273 +    is(gVariablesView.getFocusedItem().name, "0",
   1.274 +      "The '0' item should be focused.");
   1.275 +
   1.276 +    EventUtils.sendKey("RIGHT", gDebugger);
   1.277 +    is(gVariablesView.getFocusedItem().name, "0",
   1.278 +      "The '0' item should still be focused.");
   1.279 +
   1.280 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.281 +    is(gVariablesView.getFocusedItem().name, "5",
   1.282 +      "The '5' item should be focused.");
   1.283 +    is(gVariablesView.getFocusedItem().expanded, false,
   1.284 +      "The '5' item should not be expanded yet.");
   1.285 +
   1.286 +    yield synthesizeKeyAndWaitForTick("VK_RIGHT", {});
   1.287 +    is(gVariablesView.getFocusedItem().name, "5",
   1.288 +      "The '5' item should be focused.");
   1.289 +    is(gVariablesView.getFocusedItem().expanded, true,
   1.290 +      "The '5' item should now be expanded.");
   1.291 +    is(gVariablesView.getFocusedItem()._store.size, 5,
   1.292 +      "There should be 5 properties in the selected variable.");
   1.293 +    is(gVariablesView.getFocusedItem()._enumItems.length, 3,
   1.294 +      "There should be 3 enumerable properties in the selected variable.");
   1.295 +    is(gVariablesView.getFocusedItem()._nonEnumItems.length, 2,
   1.296 +      "There should be 2 non-enumerable properties in the selected variable.");
   1.297 +
   1.298 +    yield waitForChildNodes(gVariablesView.getFocusedItem()._enum, 3);
   1.299 +    yield waitForChildNodes(gVariablesView.getFocusedItem()._nonenum, 2);
   1.300 +
   1.301 +    EventUtils.sendKey("RIGHT", gDebugger);
   1.302 +    is(gVariablesView.getFocusedItem().name, "0",
   1.303 +      "The '0' item should be focused.");
   1.304 +
   1.305 +    EventUtils.sendKey("RIGHT", gDebugger);
   1.306 +    is(gVariablesView.getFocusedItem().name, "0",
   1.307 +      "The '0' item should still be focused.");
   1.308 +
   1.309 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.310 +    is(gVariablesView.getFocusedItem().name, "6",
   1.311 +      "The '6' item should be focused.");
   1.312 +    is(gVariablesView.getFocusedItem().expanded, false,
   1.313 +      "The '6' item should not be expanded yet.");
   1.314 +
   1.315 +    yield synthesizeKeyAndWaitForTick("VK_RIGHT", {});
   1.316 +    is(gVariablesView.getFocusedItem().name, "6",
   1.317 +      "The '6' item should be focused.");
   1.318 +    is(gVariablesView.getFocusedItem().expanded, true,
   1.319 +      "The '6' item should now be expanded.");
   1.320 +    is(gVariablesView.getFocusedItem()._store.size, 3,
   1.321 +      "There should be 3 properties in the selected variable.");
   1.322 +    is(gVariablesView.getFocusedItem()._enumItems.length, 2,
   1.323 +      "There should be 2 enumerable properties in the selected variable.");
   1.324 +    is(gVariablesView.getFocusedItem()._nonEnumItems.length, 1,
   1.325 +      "There should be 1 non-enumerable properties in the selected variable.");
   1.326 +
   1.327 +    yield waitForChildNodes(gVariablesView.getFocusedItem()._enum, 2);
   1.328 +    yield waitForChildNodes(gVariablesView.getFocusedItem()._nonenum, 1);
   1.329 +
   1.330 +    EventUtils.sendKey("RIGHT", gDebugger);
   1.331 +    is(gVariablesView.getFocusedItem().name, "prop1",
   1.332 +      "The 'prop1' item should be focused.");
   1.333 +
   1.334 +    EventUtils.sendKey("RIGHT", gDebugger);
   1.335 +    is(gVariablesView.getFocusedItem().name, "prop1",
   1.336 +      "The 'prop1' item should still be focused.");
   1.337 +
   1.338 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.339 +    is(gVariablesView.getFocusedItem().name, "someProp6",
   1.340 +      "The 'someProp6' item should be focused.");
   1.341 +    is(gVariablesView.getFocusedItem().expanded, false,
   1.342 +      "The 'someProp6' item should not be expanded yet.");
   1.343 +
   1.344 +    // Part 9: Test that the RIGHT key collapses elements as intended.
   1.345 +
   1.346 +    EventUtils.sendKey("LEFT", gDebugger);
   1.347 +    is(gVariablesView.getFocusedItem().name, "someProp6",
   1.348 +      "The 'someProp6' item should be focused.");
   1.349 +
   1.350 +    EventUtils.sendKey("UP", gDebugger);
   1.351 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.352 +      "The '__proto__' item should be focused.");
   1.353 +
   1.354 +    EventUtils.sendKey("LEFT", gDebugger);
   1.355 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.356 +      "The 'someProp5' item should be focused.");
   1.357 +    is(gVariablesView.getFocusedItem().expanded, true,
   1.358 +      "The '6' item should still be expanded.");
   1.359 +
   1.360 +    EventUtils.sendKey("LEFT", gDebugger);
   1.361 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.362 +      "The 'someProp5' item should still be focused.");
   1.363 +    is(gVariablesView.getFocusedItem().expanded, false,
   1.364 +      "The '6' item should still not be expanded anymore.");
   1.365 +
   1.366 +    EventUtils.sendKey("LEFT", gDebugger);
   1.367 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.368 +      "The 'someProp5' item should still be focused.");
   1.369 +
   1.370 +    // Part 9: Test continuous navigation.
   1.371 +
   1.372 +    EventUtils.sendKey("UP", gDebugger);
   1.373 +    is(gVariablesView.getFocusedItem().name, "someProp4",
   1.374 +      "The 'someProp4' item should be focused.");
   1.375 +
   1.376 +    EventUtils.sendKey("UP", gDebugger);
   1.377 +    is(gVariablesView.getFocusedItem().name, "someProp3",
   1.378 +      "The 'someProp3' item should be focused.");
   1.379 +
   1.380 +    EventUtils.sendKey("UP", gDebugger);
   1.381 +    is(gVariablesView.getFocusedItem().name, "someProp2",
   1.382 +      "The 'someProp2' item should be focused.");
   1.383 +
   1.384 +    EventUtils.sendKey("UP", gDebugger);
   1.385 +    is(gVariablesView.getFocusedItem().name, "someProp1",
   1.386 +      "The 'someProp1' item should be focused.");
   1.387 +
   1.388 +    EventUtils.sendKey("UP", gDebugger);
   1.389 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.390 +      "The 'someProp0' item should be focused.");
   1.391 +
   1.392 +    EventUtils.sendKey("PAGE_UP", gDebugger);
   1.393 +    is(gVariablesView.getFocusedItem().name, "someProp0",
   1.394 +      "The 'someProp0' item should be focused.");
   1.395 +
   1.396 +    EventUtils.sendKey("PAGE_DOWN", gDebugger);
   1.397 +    is(gVariablesView.getFocusedItem().name, "someProp5",
   1.398 +      "The 'someProp5' item should be focused.");
   1.399 +
   1.400 +    EventUtils.sendKey("DOWN", gDebugger);
   1.401 +    is(gVariablesView.getFocusedItem().name, "someProp6",
   1.402 +      "The 'someProp6' item should be focused.");
   1.403 +
   1.404 +    EventUtils.sendKey("DOWN", gDebugger);
   1.405 +    is(gVariablesView.getFocusedItem().name, "someProp7",
   1.406 +      "The 'someProp7' item should be focused.");
   1.407 +
   1.408 +    EventUtils.sendKey("DOWN", gDebugger);
   1.409 +    is(gVariablesView.getFocusedItem().name, "get",
   1.410 +      "The 'get' item should be focused.");
   1.411 +
   1.412 +    EventUtils.sendKey("DOWN", gDebugger);
   1.413 +    is(gVariablesView.getFocusedItem().name, "set",
   1.414 +      "The 'set' item should be focused.");
   1.415 +
   1.416 +    EventUtils.sendKey("DOWN", gDebugger);
   1.417 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.418 +      "The '__proto__' item should be focused.");
   1.419 +
   1.420 +    // Part 10: Test that BACKSPACE deletes items in the variables view.
   1.421 +
   1.422 +    EventUtils.sendKey("BACK_SPACE", gDebugger);
   1.423 +    is(gVariablesView.getFocusedItem().name, "__proto__",
   1.424 +      "The '__proto__' variable should still be focused.");
   1.425 +    is(gVariablesView.getFocusedItem().value, "[object Object]",
   1.426 +      "The '__proto__' variable should not have an empty value.");
   1.427 +    is(gVariablesView.getFocusedItem().visible, false,
   1.428 +      "The '__proto__' variable should be hidden.");
   1.429 +
   1.430 +    EventUtils.sendKey("UP", gDebugger);
   1.431 +    is(gVariablesView.getFocusedItem().name, "set",
   1.432 +      "The 'set' item should be focused.");
   1.433 +    is(gVariablesView.getFocusedItem().value, "[object Object]",
   1.434 +      "The 'set' item should not have an empty value.");
   1.435 +    is(gVariablesView.getFocusedItem().visible, true,
   1.436 +      "The 'set' item should be visible.");
   1.437 +
   1.438 +    EventUtils.sendKey("BACK_SPACE", gDebugger);
   1.439 +    is(gVariablesView.getFocusedItem().name, "set",
   1.440 +      "The 'set' item should still be focused.");
   1.441 +    is(gVariablesView.getFocusedItem().value, "[object Object]",
   1.442 +      "The 'set' item should not have an empty value.");
   1.443 +    is(gVariablesView.getFocusedItem().visible, true,
   1.444 +      "The 'set' item should be visible.");
   1.445 +    is(gVariablesView.getFocusedItem().twisty, false,
   1.446 +      "The 'set' item should be disabled and have a hidden twisty.");
   1.447 +
   1.448 +    EventUtils.sendKey("UP", gDebugger);
   1.449 +    is(gVariablesView.getFocusedItem().name, "get",
   1.450 +      "The 'get' item should be focused.");
   1.451 +    is(gVariablesView.getFocusedItem().value, "[object Object]",
   1.452 +      "The 'get' item should not have an empty value.");
   1.453 +    is(gVariablesView.getFocusedItem().visible, true,
   1.454 +      "The 'get' item should be visible.");
   1.455 +
   1.456 +    EventUtils.sendKey("BACK_SPACE", gDebugger);
   1.457 +    is(gVariablesView.getFocusedItem().name, "get",
   1.458 +      "The 'get' item should still be focused.");
   1.459 +    is(gVariablesView.getFocusedItem().value, "[object Object]",
   1.460 +      "The 'get' item should not have an empty value.");
   1.461 +    is(gVariablesView.getFocusedItem().visible, true,
   1.462 +      "The 'get' item should be visible.");
   1.463 +    is(gVariablesView.getFocusedItem().twisty, false,
   1.464 +      "The 'get' item should be disabled and have a hidden twisty.");
   1.465 +
   1.466 +    EventUtils.sendKey("UP", gDebugger);
   1.467 +    is(gVariablesView.getFocusedItem().name, "someProp7",
   1.468 +      "The 'someProp7' item should be focused.");
   1.469 +    is(gVariablesView.getFocusedItem().value, undefined,
   1.470 +      "The 'someProp7' variable should have an empty value.");
   1.471 +    is(gVariablesView.getFocusedItem().visible, true,
   1.472 +      "The 'someProp7' variable should be visible.");
   1.473 +
   1.474 +    EventUtils.sendKey("BACK_SPACE", gDebugger);
   1.475 +    is(gVariablesView.getFocusedItem().name, "someProp7",
   1.476 +      "The 'someProp7' variable should still be focused.");
   1.477 +    is(gVariablesView.getFocusedItem().value, undefined,
   1.478 +      "The 'someProp7' variable should have an empty value.");
   1.479 +    is(gVariablesView.getFocusedItem().visible, false,
   1.480 +      "The 'someProp7' variable should be hidden.");
   1.481 +
   1.482 +    // Part 11: Test that Ctrl-C copies the current item to the system clipboard
   1.483 +
   1.484 +    gVariablesView.focusFirstVisibleItem();
   1.485 +    let copied = promise.defer();
   1.486 +    let expectedValue = gVariablesView.getFocusedItem().name
   1.487 +      + gVariablesView.getFocusedItem().separatorStr
   1.488 +      + gVariablesView.getFocusedItem().value;
   1.489 +
   1.490 +    waitForClipboard(expectedValue, function setup() {
   1.491 +        EventUtils.synthesizeKey("C", { metaKey: true }, gDebugger);
   1.492 +      }, copied.resolve, copied.reject
   1.493 +    );
   1.494 +
   1.495 +    try {
   1.496 +      yield copied.promise;
   1.497 +      ok(true,
   1.498 +        "Ctrl-C copied the selected item to the clipboard.");
   1.499 +    } catch (e) {
   1.500 +      ok(false,
   1.501 +        "Ctrl-C didn't copy the selected item to the clipboard.");
   1.502 +    }
   1.503 +
   1.504 +    yield closeDebuggerAndFinish(gPanel);
   1.505 +  });
   1.506 +}
   1.507 +
   1.508 +registerCleanupFunction(function() {
   1.509 +  gTab = null;
   1.510 +  gDebuggee = null;
   1.511 +  gPanel = null;
   1.512 +  gDebugger = null;
   1.513 +  gVariablesView = null;
   1.514 +});
   1.515 +
   1.516 +function synthesizeKeyAndWaitForElement(aKey, aModifiers, aSelector, aExistence) {
   1.517 +  EventUtils.synthesizeKey(aKey, aModifiers, gDebugger);
   1.518 +  return waitForElement(aSelector, aExistence);
   1.519 +}
   1.520 +
   1.521 +function synthesizeKeyAndWaitForTick(aKey, aModifiers) {
   1.522 +  EventUtils.synthesizeKey(aKey, aModifiers, gDebugger);
   1.523 +  return waitForTick();
   1.524 +}
   1.525 +
   1.526 +function waitForElement(aSelector, aExistence) {
   1.527 +  return waitForPredicate(() => {
   1.528 +    return !!gVariablesView._list.querySelector(aSelector) == aExistence;
   1.529 +  });
   1.530 +}
   1.531 +
   1.532 +function waitForChildNodes(aTarget, aCount) {
   1.533 +  return waitForPredicate(() => {
   1.534 +    return aTarget.childNodes.length == aCount;
   1.535 +  });
   1.536 +}
   1.537 +
   1.538 +function waitForPredicate(aPredicate, aInterval = 10) {
   1.539 +  let deferred = promise.defer();
   1.540 +
   1.541 +  // Poll every few milliseconds until the element is retrieved.
   1.542 +  let count = 0;
   1.543 +  let intervalID = window.setInterval(() => {
   1.544 +    // Make sure we don't wait for too long.
   1.545 +    if (++count > 1000) {
   1.546 +      deferred.reject("Timed out while polling for the element.");
   1.547 +      window.clearInterval(intervalID);
   1.548 +      return;
   1.549 +    }
   1.550 +    // Check if the predicate condition is fulfilled.
   1.551 +    if (!aPredicate()) {
   1.552 +      return;
   1.553 +    }
   1.554 +    // We got the element, it's safe to callback.
   1.555 +    window.clearInterval(intervalID);
   1.556 +    deferred.resolve();
   1.557 +  }, aInterval);
   1.558 +
   1.559 +  return deferred.promise;
   1.560 +}

mercurial