Skip to content

Commit

Permalink
engine: Make Engine::load(Uri) public
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Nov 14, 2023
1 parent 78aebd7 commit 828b29f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
12 changes: 6 additions & 6 deletions engine/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class Engine {
css::StyleSheet const &stylesheet() const { return stylesheet_; }
layout::LayoutBox const *layout() const { return layout_.has_value() ? &*layout_ : nullptr; }

struct [[nodiscard]] LoadResult {
protocol::Response response;
uri::Uri uri_after_redirects;
};
LoadResult load(uri::Uri);

private:
std::function<void(protocol::Error)> on_navigation_failure_{[](protocol::Error) {
}};
Expand All @@ -61,12 +67,6 @@ class Engine {
std::optional<layout::LayoutBox> layout_{};

void on_navigation_success();

struct [[nodiscard]] LoadResult {
protocol::Response response;
uri::Uri uri_after_redirects;
};
LoadResult load(uri::Uri);
};

} // namespace engine
Expand Down
18 changes: 18 additions & 0 deletions engine/engine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,23 @@ int main() {
expect(contains(e.stylesheet().rules, {.selectors{"p"}, .declarations{{css::PropertyId::Color, "green"}}}));
});

etest::test("load", [] {
std::map<std::string, Response> responses;
responses["hax://example.com"s] = Response{
.err = Error::Ok,
.status_line = {.status_code = 301},
.headers = {{"Location", "hax://example.com/redirected"}},
};
responses["hax://example.com/redirected"s] = Response{
.err = Error::Ok,
.status_line = {.status_code = 200},
.body{"<html><body>hello!</body></html>"},
};
engine::Engine e{std::make_unique<FakeProtocolHandler>(responses)};
auto res = e.load(uri::Uri::parse("hax://example.com"));
expect_eq(res.uri_after_redirects, uri::Uri::parse("hax://example.com/redirected"));
expect_eq(res.response, responses.at("hax://example.com/redirected"));
});

return etest::run_all_tests();
}

0 comments on commit 828b29f

Please sign in to comment.