OLD | NEW |
1 This directory contains extensions which are unit tests for the extension API. | 1 This directory contains extensions which are unit tests for the extension API. |
2 These tests are written using the extension API test framework, which allows | 2 These tests are written using the extension API test framework, which allows |
3 us to do end-to-end testing of extension API in a browser_test. The general way | 3 us to do end-to-end testing of extension API in a browser_test. The general way |
4 these tests work is to run code in an extension when they're loaded and to post | 4 these tests work is to run code in an extension when they're loaded and to post |
5 a pass or fail notification back up to the C++ unit test which then reports the | 5 a pass or fail notification back up to the C++ unit test which then reports the |
6 success or failure. In the common case, the extension runs many subtests and | 6 success or failure. In the common case, the extension runs many subtests and |
7 then reports up a single pass or fail. This case is made easy by the test | 7 then reports up a single pass or fail. This case is made easy by the test |
8 framework. | 8 framework. |
9 | 9 |
10 To write a new test: | 10 To write a new test: |
11 | 11 |
12 (1) Add a new browser_test which is a subclass of ExtensionApiTest. This test | 12 (1) Add a new browser_test which is a subclass of ExtensionApiTest. This test |
13 should call RunExtensionTest("extension_name") to kick off the test. See | 13 should call RunExtensionTest("extension_name") to kick off the test. See |
14 bookmark_extension_apitest.cc for an example. | 14 bookmark_extension_apitest.cc for an example. |
15 | 15 |
16 (2) Create an extension of in this directory of the same name as the extension | 16 (2) Create an extension of in this directory of the same name as the extension |
17 that your test referred to ("extension_name" above). This test should load | 17 that your test referred to ("extension_name" above). This test should load |
18 either a background page which immediately starts its test. | 18 a background page which immediately starts its test. |
19 | 19 |
20 (3) In your extension page, call chrome.test.runTests with an array of | 20 (3) In your extension page, call chrome.test.runTests with an array of |
21 functions which represent your subtests. Each of these functions will most | 21 functions which represent your subtests. Each of these functions will most |
22 likely call one or more async extension APIs. Wrap the callback for each of | 22 likely call one or more async extension APIs. Wrap the callback for each of |
23 these API calls with chrome.test.callbackPass or chrome.test.callbackFail | 23 these API calls with chrome.test.callbackPass or chrome.test.callbackFail |
24 depending on whether or not you're expecting the callback to generate an error | 24 depending on whether or not you're expecting the callback to generate an error |
25 or not. That's it. The test framework notices when each of these callbacks | 25 or not. That's it. The test framework notices when each of these callbacks |
26 is registered and keeps a count of what's expected. When the right number of | 26 is registered and keeps a count of what's expected. When the right number of |
27 callbacks has fired, that test function will be marked as passed or failed and | 27 callbacks has fired, that test function will be marked as passed or failed and |
28 the next one will be called. Some other useful helper functions you'll use are | 28 the next one will be called. Some other useful helper functions you'll use are |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 [----------] Global test environment tear-down | 81 [----------] Global test environment tear-down |
82 [==========] 1 test from 1 test case ran. (2482 ms total) | 82 [==========] 1 test from 1 test case ran. (2482 ms total) |
83 [ PASSED ] 1 test. | 83 [ PASSED ] 1 test. |
84 1 test run | 84 1 test run |
85 0 test failed | 85 0 test failed |
86 | 86 |
87 Note the RUN/SUCCESS messages in () - these are the subtests that are run in | 87 Note the RUN/SUCCESS messages in () - these are the subtests that are run in |
88 the extension itself. Anything printed with chrome.test.log() will also display | 88 the extension itself. Anything printed with chrome.test.log() will also display |
89 in stdout of the browser test (and hence in the buildbot output for that test). | 89 in stdout of the browser test (and hence in the buildbot output for that test). |
OLD | NEW |