blob: e7d018c872725be69a177bd3515dbc527ab2bcd7 [file] [log] [blame]
This directory contains tests for chrome extension activity logging.
The tests use two chrome extensions:
-test : sends messages to the friend extension and listens for activity
logged by the friend extension. Checks the activity has been logged
correctly.
-friend: receives messages from the extension and runs a function based on
the contents of the message.
Adding a new test:
In friend/reply.js:
(1) Add a function to call the chrome api calls you want to test. If you
need to use window.open please consider adding your code to
executeApiCallsOnTabUpdated or executeDOMChangesOnTabUpdated. Every
extra window.open call will slow down the tests by 3s and may cause
timeouts.
(2) Add the name of the new function to the function map (fnMap).
IMPORTANT NOTES for adding tests:
- The function should clean up any changes it made (e.g. listeners
it added) before finishing. If they are not cleaned up then unexpected
behavior can happen in test cases that run after this function.
- Every window.open call can add 3 secs to the test run for debug builds.
Making lots of window.open calls will therefore cause the tests to
timeout. If your test needs to use window.open please consider adding
it to one of the following existing functions:
- executeApiCallsOnTabUpdated
- executeDOMChangesOnTabUpdated
In friend/options.html:
(1) Add a button to allow the new function to be called in manual mode.
You may need also to modify the manifest.json and other files in the
friend extension directory.
In test/test.js:
(1) Add the test to the testcase array.
You will need to define the function that sends a message to the
friend extension and define the expected activity logging. Example:
testCases.push({
func: function triggerMyFunctionCall() {
chrome.runtime.sendMessage(FRIEND_EXTENSION_ID,
'my_function_call_id',
function response() { });
},
expected_activity: ['api.call1', 'api.call2', 'api.call3']
});
where 'my_function_call_id' is the key you added to the fn_map in
reply.js.
Running a testcase in Incognito mode:
To check logging when run in incognito mode, add the following to the
testcase:
is_incognito: true
This will automatically cause all new tabs to be opened in incognito mode and
check the url information has been correctly cleaned.
Configuring a testcase for a particular OS:
If you need to disable a test for a particular OS then you can do this by
adding the disabled field to the test case. For example:
disabled: {win: true, mac: true}
If you need to configure different expected activity for a particular OS, you
can override the logging. E.g.:
expected_activity_win: ['api.call1', 'api.call2', 'api.call3']
expected_activity_mac: ['api.call1', 'api.call2', 'api.call3']
See the chrome.runtime.getPlatformInfo documentation for details of which OS
names to use.
Running the tests:
> out/Debug/browser_tests --gtest_filter=ActivityLogApiTest.TriggerEvent
Running in manual mode:
(1) Start chrome with out/Debug/chrome
(2) Navigate to chrome://extensions
(3) Install the friend and test extensions from your chrome src folder
(4) Click on the "options" link under the friend extension
(5) You should see the options page the buttons to run the functions manually