Skip to content

Commit

Permalink
[fuchsia] Provide helper for working with web.Frames in tests.
Browse files Browse the repository at this point in the history
Bug: 1200314
Change-Id: Ia4dc830d33aa70c7868fafb6b30121aa6f39196b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2879992
Auto-Submit: Wez <wez@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#880633}
  • Loading branch information
Wez authored and Chromium LUCI CQ committed May 8, 2021
1 parent c8edc4c commit ba31645
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fuchsia/engine/BUILD.gn
Expand Up @@ -373,6 +373,8 @@ fuchsia_package_runner("web_engine_with_webui_installer") {
source_set("browsertest_core") {
testonly = true
sources = [
"test/frame_test_helper.cc",
"test/frame_test_helper.h",
"test/test_data.cc",
"test/test_data.h",
"test/web_engine_browser_test.cc",
Expand All @@ -385,6 +387,7 @@ source_set("browsertest_core") {
":web_engine_core",
"//content/public/browser",
"//content/test:test_support",
"//fuchsia/base:test_support",
"//net:test_support",
"//testing/gtest",
"//third_party/fuchsia-sdk/sdk/fidl/fuchsia.web",
Expand Down
34 changes: 34 additions & 0 deletions fuchsia/engine/test/frame_test_helper.cc
@@ -0,0 +1,34 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "fuchsia/engine/test/frame_test_helper.h"

namespace cr_fuchsia {

FrameTestHelper::FrameTestHelper(fuchsia::web::Context* context,
fuchsia::web::CreateFrameParams params)
: navigation_listener_binding_(&navigation_listener_) {
context->CreateFrameWithParams(std::move(params), frame_.NewRequest());
frame_->SetNavigationEventListener(navigation_listener_binding_.NewBinding());
}

FrameTestHelper::FrameTestHelper(fuchsia::web::FrameHost* frame_host,
fuchsia::web::CreateFrameParams params)
: navigation_listener_binding_(&navigation_listener_) {
frame_host->CreateFrameWithParams(std::move(params), frame_.NewRequest());
frame_->SetNavigationEventListener(navigation_listener_binding_.NewBinding());
}

FrameTestHelper::FrameTestHelper(const fuchsia::web::ContextPtr& context,
fuchsia::web::CreateFrameParams params)
: FrameTestHelper(context.get(), std::move(params)) {}

fuchsia::web::NavigationControllerPtr
FrameTestHelper::GetNavigationController() {
fuchsia::web::NavigationControllerPtr controller;
frame_->GetNavigationController(controller.NewRequest());
return controller;
}

} // namespace cr_fuchsia
47 changes: 47 additions & 0 deletions fuchsia/engine/test/frame_test_helper.h
@@ -0,0 +1,47 @@
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FUCHSIA_ENGINE_TEST_FRAME_TEST_HELPER_H_
#define FUCHSIA_ENGINE_TEST_FRAME_TEST_HELPER_H_

#include <fuchsia/web/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>
#include <memory>

#include "fuchsia/base/test_navigation_listener.h"

namespace cr_fuchsia {

// Helper for tests which need to create fuchsia.web.Frames.
class FrameTestHelper {
public:
FrameTestHelper(fuchsia::web::Context* context,
fuchsia::web::CreateFrameParams params);
FrameTestHelper(fuchsia::web::FrameHost* frame_host,
fuchsia::web::CreateFrameParams params);
FrameTestHelper(const fuchsia::web::ContextPtr& context,
fuchsia::web::CreateFrameParams params);
~FrameTestHelper();

FrameTestHelper(const FrameTestHelper&) = delete;
FrameTestHelper& operator=(const FrameTestHelper&) = delete;

// Returns a new NavigationController for each call, which ensures that any
// calls made to |frame()| will have been processed before navigation
// controller requests.
fuchsia::web::NavigationControllerPtr GetNavigationController();

fuchsia::web::FramePtr& frame() { return frame_; }
TestNavigationListener& navigation_listener() { return navigation_listener_; }

private:
fuchsia::web::FramePtr frame_;
TestNavigationListener navigation_listener_;
fidl::Binding<fuchsia::web::NavigationEventListener>
navigation_listener_binding_;
};

} // namespace cr_fuchsia

#endif // FUCHSIA_ENGINE_TEST_FRAME_TEST_HELPER_H_

0 comments on commit ba31645

Please sign in to comment.