5#include <fuchsia/ui/views/cpp/fidl.h>
6#include <gtest/gtest.h>
7#include <lib/async-loop/cpp/loop.h>
8#include <lib/async-loop/default.h>
9#include <lib/fidl/cpp/binding_set.h>
10#include <lib/zx/eventpair.h>
16#include "third_party/rapidjson/include/rapidjson/document.h"
19 rapidjson::Document document;
21 if (document.HasParseError() || !document.IsObject()) {
23 return rapidjson::Value();
25 return document.GetObject();
37 vrf_ = std::make_unique<FakeViewRefFocused>();
38 focuser_ = std::make_unique<FakeFocuser>();
40 vrf_bindings.AddBinding(
vrf_.get()),
41 focuser_bindings.AddBinding(
focuser_.get()));
45 vrf_bindings.CloseAll();
46 focuser_bindings.CloseAll();
51 std::unique_ptr<FakeViewRefFocused>
vrf_;
57 fidl::BindingSet<ViewRefFocused> vrf_bindings;
58 fidl::BindingSet<Focuser> focuser_bindings;
66 std::vector<bool> vrf_states{
false,
true,
true,
false,
67 true,
false,
true,
true};
68 std::size_t vrf_index = 0;
69 std::size_t callback_index = 0;
70 focus_delegate_->WatchLoop([&](
bool focus_state) {
73 EXPECT_EQ(vrf_states[callback_index], focus_state);
81 response->ExpectCompleted(focus_state ?
"[true]" :
"[false]");
85 EXPECT_EQ(vrf_index, callback_index++);
89 focus_delegate_->WatchLoop([](
bool _) {
90 ADD_FAILURE() <<
"Subsequent WatchLoops should not be respected!";
103 EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
106 response2->ExpectCompleted(
"[null]");
110 vrf_->ScheduleCallback(vrf_states[vrf_index]);
114 response1->ExpectCompleted(vrf_states[vrf_index] ?
"[true]" :
"[false]");
119 EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
122 response3->ExpectCompleted(vrf_states[vrf_index++] ?
"[true]" :
"[false]");
126 EXPECT_EQ(vrf_index + 1, vrf_->times_watched);
127 }
while (vrf_index < vrf_states.size());
134 fuchsia::ui::views::ViewRefControl view_ref_control;
135 fuchsia::ui::views::ViewRef view_ref;
137 0u, &view_ref_control.reference, &view_ref.reference);
138 ZX_ASSERT(status == ZX_OK);
139 view_ref_control.reference.replace(
140 ZX_DEFAULT_EVENTPAIR_RIGHTS & (~ZX_RIGHT_DUPLICATE),
141 &view_ref_control.reference);
142 view_ref.reference.replace(ZX_RIGHTS_BASIC, &view_ref.reference);
146 message <<
"{" <<
" \"method\":\"View.focus.request\","
148 <<
" \"viewRef\":" << view_ref.reference.get() <<
" }"
153 EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
157 response->ExpectCompleted(
"[0]");
165 fuchsia::ui::views::ViewRefControl view_ref_control;
166 fuchsia::ui::views::ViewRef view_ref;
168 0u, &view_ref_control.reference, &view_ref.reference);
169 ZX_ASSERT(status == ZX_OK);
170 view_ref_control.reference.replace(
171 ZX_DEFAULT_EVENTPAIR_RIGHTS & (~ZX_RIGHT_DUPLICATE),
172 &view_ref_control.reference);
173 view_ref.reference.replace(ZX_RIGHTS_BASIC, &view_ref.reference);
175 focuser_->fail_request_focus();
178 message <<
"{" <<
" \"method\":\"View.focus.request\","
180 <<
" \"viewRef\":" << view_ref.reference.get() <<
" }"
185 EXPECT_TRUE(focus_delegate_->HandlePlatformMessage(
189 response->ExpectCompleted(
192 static_cast<std::underlying_type_t<fuchsia::ui::views::Error>
>(
193 fuchsia::ui::views::Error::DENIED)) +
std::unique_ptr< FakeFocuser > focuser_
std::unique_ptr< FocusDelegate > focus_delegate_
std::unique_ptr< FakeViewRefFocused > vrf_
#define FML_LOG(severity)
rapidjson::Value ParsePlatformMessage(std::string json)
TEST_F(FocusDelegateTest, WatchCallbackSeries)
static SkString to_string(int n)
#define EXPECT_TRUE(handle)