Project

General

Profile

Building the browser extension » History » Version 3

0gitnick, 02/19/2022 11:45 PM

1 3 0gitnick
## Building
2
There're currently 2 ways to build Haketilo.
3 1 jahoti
4 3 0gitnick
### 1. Simple stupid way - `build.sh` script
5
You only need a POSIX-compliant environment for this (shell, awk, etc.). It is a viable option if you don't need to run the automated test suite. From project's root directory, using a POSIX shell, you type either:
6
``` shell
7
./build.sh mozilla # to build for Firefox-based browsers
8
```
9
or:
10
``` shell
11
./build.sh chromium # to build for Chromium-based browsers
12
```
13
The unpacked extension shall be generated under `./mozilla-unpacked/` or `./chromium-unpacked/`, respectively. You can then load it into your browser as a temporary extension or pack it into an xpi/crx/zip archive manually, e.g.:
14
``` shell
15
7z a -tzip haketilo.xpi -w mozilla-unpacked/.
16
```
17
18
### 2. `configure`-based build
19
This method assumes you have not only a POSIX environment but also a working Make tool and the zip command. From project's root directory, run the shell commands:
20
``` shell
21
./configure --host=mozilla # or analogically with --host=chromium
22
make
23
```
24
This would generate the unpacked extension under `./mozilla-unpacked/` and its zipped version under `./mozilla_build.zip` (which you can rename to .xpi if you want).
25
26
You can also perform an out-of-source build, for example:
27
``` shell
28
mkdir /tmp/haketilo-build && cd /tmp/haketilo-build
29
/path/to/haketilo/sources/configure --host=chromium
30
make all # will generate both ./mozilla-build.zip and ./chromium-build.zip
31
```
32
33
## Testing
34
35
### Requirements
36
37
- all that is needed for `configure`-based build
38
- a Firefox-based browser (testing under Chromium is not yet supported)
39
- geckodriver
40
- Python3
41
- Python3 bindings for Selenium
42
- Python3 Pytest
43
44
### Configuring
45
46
*Note: like building, testing can be performed out-of-source; this can be useful when testing under multiple browsers simultaneously*
47
48
Running tests requires you to pass some additional information to `configure`. Relevant options are:
49
50
| **option name**  | **explanation**                                                                                                                                                                                                                                                                                                                                                                       |
51
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
52
| `BROWSER_BINARY` | Path to the browser's binary executable. Under many scenarios the browser executable in `PATH` is a shell wrapper around the actual binary. Selenium will refuse to work with that and instead requires the binary to be passed (e.g. `/usr/lib/abrowser/abrowser` instead of `/usr/bin/abrowser`                                                                                     |
53
| `CLEAN_PROFILE`  | Path to a directory with browser profile that is *"clean"*, i.e. has all extensions disabled. This is to mitigate the fact that some browsers pick up globally-installed extensions when creating a new profile for testing and these could interfere with our automated tests. This option can currently be skipped because all tests written so far run the browser in safe mode.  |
54
| `DRIVER`         | Selenium driver command (e.g. `geckodriver`).                                                                                                                                                                                                                                                                                                                                         |
55
| `PYTHON`         | Python 3 command. The interpreter spawned with this command is expected to have Pytest and Selenium in its import path.                                                                                                                                                                                                                                                               |
56
57
Options can be specified to `configure` using the following notations (can be mixed):
58
``` shell
59
./configure --host=mozilla --browser-binary=/usr/local/lib/icecat/icecat
60
./configure --host mozilla --browser-binary /usr/local/lib/icecat/icecat
61
./configure HOST=mozilla BROWSER_BINARY=/usr/local/lib/icecat/icecat
62
```
63
64
`configure` will try to guess the proper values for options that were not given. To help with this, you can (in some cases) give your actual browser name to `--host`, for example:
65
```
66
$ ./configure --host=abrowser
67
Guessing SRCDIR: /home/urz/haketilo-development/browser-extension
68
Guessing BROWSER_BINARY: /usr/lib/abrowser/abrowser
69
Guessing DRIVER: /usr/bin/geckodriver
70
Guessing PYTHON: /usr/bin/python3
71
Guessing DESTDIR: /usr/share/mozilla/extensions/
72
$
73
```
74
75
This may or may not work, depending on the underlying operating system and how the tools were installed.
76
77
### Running
78
79
After configuring, the entire test suite can be run with:
80
``` shell
81
make test
82
```
83
84
Alternatively, it is possible to run Pytest directly to have some fine-grained control over which tests are run, e.g.:
85
``` shell
86
# Generate the necessary certificates and pytest.ini. This is done automatically
87
# when running `make test`.
88
make test-prepare
89
90
# Optionally prevent Python from clobbering source directories with .pyc files.
91
# `make test` rule does the same.
92
#export PYTHONPYCACHEPREFIX="$(pwd)/test__pycache__"
93
94
# Optionally stop Firefox from spawning window(s) during test.
95
#export MOZ_HEADLESS=whatever
96
97
# Run all popup tests with high verbosity.
98
python3 -m pytest -vv -k popup
99
```
100
101
As of Haketilo 1.0-beta1 some tests may spuriously fail. This is the result it being notoriously difficult to avoid some weirdnesses when driving Firefox using Selenium. To make sure a failed test is not the result of some more serious bug, you might want to rerun the test suite.
102
103
### Setting up an environment for manual testing
104
105
The automated tests are run with browser's all network requests going through a Python proxy. The proxy allows us to mock websites that are then navigated to in the browser. At times you might want to replicate this test environment while playing manually with the browser. A poor man's approach is to add something like:
106
``` python
107
from time import sleep
108
sleep(100000)
109
```
110
inside one of the test functions and then run that test function from Pytest (with `MOZ_HEADLESS` unset!). This might make sense when debugging some particular test case. For general experiments we have instead provided convenience targets `make test-environment` and `make test-environment-with-haketilo`. Running any of those will spawn a browser window *together* with a Python shell where `driver` variable will hold Selenium driver object controlling that browser. In case of the `test-environment-with-haketilo` target the browser will additionally appear with Haketilo loaded into it.