Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fuchsia] Provide helper for working with web.Frames in tests.
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
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ |