mirror of
https://github.com/Hopiu/bowser.git
synced 2026-03-17 03:20:24 +00:00
Feature: Smart protocol handling - If no protocol is provided, assume https:// - URLs like 'example.com' become 'https://example.com' - 'example.com/path' becomes 'https://example.com/path' - Special 'about:' URLs are preserved as-is Implementation: - Added _normalize_url() method to Browser class - Checks for '://' in URL to detect existing protocol - Strips whitespace from URLs - Applied in both new_tab() and navigate_to() methods - Supports all URL formats (subdomains, ports, paths, queries) URL Normalization Logic: 1. Strip leading/trailing whitespace 2. Check if URL already has a protocol ('://') 3. Check for special about: URLs 4. Otherwise prepend 'https://' Examples: - 'example.com' → 'https://example.com' - 'https://example.com' → 'https://example.com' (unchanged) - 'about:startpage' → 'about:startpage' (unchanged) - 'www.example.com:8080' → 'https://www.example.com:8080' - 'localhost:3000' → 'https://localhost:3000' Tests added (10 test cases): - test_normalize_url_with_https - test_normalize_url_with_http - test_normalize_url_without_protocol - test_normalize_url_with_path - test_normalize_url_with_about - test_normalize_url_strips_whitespace - test_normalize_url_with_query_string - test_normalize_url_with_subdomain - test_normalize_url_with_port - test_normalize_url_localhost Existing tests still passing (15/15) |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| conftest.py | ||
| README.md | ||
| test_browser.py | ||
| test_cookies.py | ||
| test_frame.py | ||
| test_html_parsing.py | ||
| test_http.py | ||
| test_layout.py | ||
| test_parser.py | ||
| test_render.py | ||
| test_templates.py | ||
| test_url.py | ||
| test_url_normalization.py | ||
Bowser Test Suite
This directory contains the test suite for the Bowser browser.
Running Tests
Run all tests:
uv run pytest
Run with verbose output:
uv run pytest -v
Run specific test file:
uv run pytest tests/test_browser.py
Run with coverage:
uv run pytest --cov=src --cov-report=html
View coverage report:
open htmlcov/index.html
Test Organization
test_url.py- URL parsing and resolutiontest_parser.py- HTML/CSS parsingtest_browser.py- Browser and tab managementtest_cookies.py- Cookie jar functionalitytest_layout.py- Layout engine componentstest_render.py- Rendering primitivesconftest.py- Shared fixtures and configuration
Writing Tests
Tests use pytest. Example:
def test_feature():
# Arrange
obj = MyClass()
# Act
result = obj.method()
# Assert
assert result == expected
Use mocks for GTK components:
@patch('src.browser.browser.Gtk')
def test_with_gtk(mock_gtk):
browser = Browser()
# test code