132static constexpr Seconds actionAbsenceTimeout = 300_ms;
133static constexpr Seconds actionDoneTimeout = 1000_ms;
134
135namespace {
136
137class ScopedNotificationCenterObserveOnce {
138public:
139 ScopedNotificationCenterObserveOnce() = default;
140 ScopedNotificationCenterObserveOnce(NSNotificationName name, NSObject* object)
141 {
142 m_observer = [m_center addObserverForName:name object:object queue:nil usingBlock:[this] (NSNotification *) {
143 [m_center removeObserver:m_observer.get()];
144 m_observer = nullptr;
145 m_didObserve = true;
146 m_center = nullptr;
147 }];
148 }
149 ~ScopedNotificationCenterObserveOnce()
150 {
151 if (!m_observer)
152 return;
153 [m_center removeObserver: m_observer.get()];
154 }
155 ScopedNotificationCenterObserveOnce(ScopedNotificationCenterObserveOnce&&) = default;
156 ScopedNotificationCenterObserveOnce& operator=(ScopedNotificationCenterObserveOnce&&) = default;
157
158 bool waitFor(Seconds timeout)
159 {
160 return TestWebKitAPI::Util::runFor(&m_didObserve, timeout);
161 }
162
163 operator bool() const { return m_didObserve; }
164private:
165 NSNotificationCenter * __weak m_center = [NSNotificationCenter defaultCenter];
166 RetainPtr<NSObject> m_observer;
167 bool m_didObserve { false };
168};
169
170}
171