667
edits
Changes
→Tests
## Switching focus to another window - '''jsiu3'''
# <s>Tests for mouselocklost event</s> - '''stsang'''
=====Reviewing Tests===== There are a series of common mistakes in the tests that need to get fixed. Here are some of them: # Need to clean-up tabs vs. spaces and indentation issues (2-spaces per tab) in many test files. Use https://github.com/einars/js-beautify. [https://github.com/rhung/mozilla-central/blob/mouselock-tests/dom/tests/mochitest/mouselock/test_userPref.html This is a test that is formatted correctly], in terms of indentation and spaces vs. tabs.# No line of code should be 80 characters or longer--break them so they are under 80# No Windows end-of-lines, use Unix end-of-lines# No whitespace at the end of a line# Run your test code through http://www.jshint.com/. Note, it will complain about unknown globals like SimpleTest. Make sure the rest of the JavaScript is good.# Remove unnecessary comments. Only things that explain the test.# If you need constants, use const instead of var# Don't use variables if they aren't needed. For example, don't introduce a variable to store a value, only to pass it into ok() or is(). Just test the expression in ok() or is().# Make sure your JavaScript follows proper naming: goodVariableName, bad_variable_name, badvariablename;# Tests should follow the template as closely as makes sense: http://pastebin.com/vxmsepVh# Tests should include a simple comment block describing what is being tested# Only use <code>SimpleTest.waitForFocus()</code> if you really need it.# Be consistent with "..." vs. '...' for strings. Pick one and use it throughout the file.# Remove <code>console.log()</code># Prefer <code>document.body</code> to <code>document.getElementsByTagName('body')[0]</code># Braces on the same line: <code>if (...) {\n</code> and <code>} else {\n</code># An error message for is() or ok() of "Error message" is not acceptable. Make sure you understand the failure.# If you need to actually lock the mouse, you'll need <code>SpecialPowers.setBoolPref("full-screen-api.allow-trusted-requests-only", false);</code> to allow non-user initiated fullscreen mode (i.e., normally it requires a user to click a button or trigger some other event).# If you're testing that variable foo or expression fooFunction() are true, use ok(), not is(): <code>ok(foo, "Error message if not true.");</code> or <code>ok(fooFunction(), "Error message if function returns false");</code>. Don't do <code>is(foo, true, "Error message if false.");# Make sure code that relies on things happening in asynchronous code gets called in a callback or event handler, not on the next line. For example, if you call navigator.pointer.lock(), you can't check navigator.pointer.islocked() on the next line, you need to use the successCallback/errorCallback. Same for focus or blur calls and events. Actions that trigger something happening in the future often need a callback or event handler.# Prefer <code>i++;</code> to <code>i+=1;</code>
====Demos, Docs, Other====