Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Unified Diff: Source/modules/serviceworkers/WaitUntilObserver.cpp

Issue 896043004: Tests for WaitUntilObserver and focus/openining windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sw_client_focus_cleanup
Patch Set: cleanup up Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/serviceworkers/WaitUntilObserver.cpp
diff --git a/Source/modules/serviceworkers/WaitUntilObserver.cpp b/Source/modules/serviceworkers/WaitUntilObserver.cpp
index bf4ed4e459ed914644c38adc2f24df6041e8e076..740512d7b9e6b25473d9ac9447a1e92923a3eb86 100644
--- a/Source/modules/serviceworkers/WaitUntilObserver.cpp
+++ b/Source/modules/serviceworkers/WaitUntilObserver.cpp
@@ -21,6 +21,16 @@
namespace blink {
+namespace {
+
+unsigned& windowInteractionTimeout()
+{
+ DEFINE_STATIC_LOCAL(unsigned, windowInteractionTimeout, (ServiceWorkerGlobalScope::kWindowInteractionTimeout));
+ return windowInteractionTimeout;
+}
+
+} // anonymous namespace
+
class WaitUntilObserver::ThenFunction final : public ScriptFunction {
public:
enum ResolveType {
@@ -70,6 +80,14 @@ WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context, EventTyp
void WaitUntilObserver::willDispatchEvent()
{
+ // When handling a notificationclick event, we want to allow one window to
+ // be focused or opened. These calls are allowed between the call to
+ // willDispatchEvent() and the last call to decrementPendingActivity(). If
+ // waitUntil() isn't called, that means between willDispatchEvent() and
+ // didDispatchEvent().
+ if (m_type == NotificationClick)
+ executionContext()->allowWindowInteraction();
dominicc (has gone to gerrit) 2015/02/05 18:58:13 Does it make sense to assert that this has been re
mlamouri (slow - plz ping) 2015/02/05 20:23:12 Not really. The callers are not aware of the numbe
+
incrementPendingActivity();
}
@@ -92,13 +110,12 @@ void WaitUntilObserver::waitUntil(ScriptState* scriptState, const ScriptValue& v
return;
// When handling a notificationclick event, we want to allow one window to
- // be focused or opened. Regardless of whether such action happened,
- // |consumeWindowInteraction| will be called when all the pending activities
- // will be resolved or after a
- if (m_type == NotificationClick) {
- executionContext()->allowWindowInteraction();
- m_consumeWindowInteractionTimer.startOneShot(ServiceWorkerGlobalScope::kWindowInteractionTimeout, FROM_HERE);
- }
+ // be focused or opened. See comments in ::willDispatchEvent(). When
+ // waitUntil() is being used, opening or closing a window must happen in a
+ // timeframe specified by windowInteractionTimeout(), otherwise the calls
+ // will fail.
+ if (m_type == NotificationClick)
+ m_consumeWindowInteractionTimer.startOneShot(windowInteractionTimeout(), FROM_HERE);
incrementPendingActivity();
ScriptPromise::cast(scriptState, value).then(
@@ -164,6 +181,12 @@ void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*)
executionContext()->consumeWindowInteraction();
}
+// static
+void WaitUntilObserver::overrideWindowInteractionTimeoutForTest(unsigned timeout)
+{
+ windowInteractionTimeout() = timeout;
+}
+
void WaitUntilObserver::trace(Visitor* visitor)
{
ContextLifecycleObserver::trace(visitor);
« no previous file with comments | « Source/modules/serviceworkers/WaitUntilObserver.h ('k') | Source/modules/serviceworkers/testing/InternalsServiceWorker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698