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

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: review comments 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..49cccd66a0565b746fcf8b2a7d9428f37ae99e20 100644
--- a/Source/modules/serviceworkers/WaitUntilObserver.cpp
+++ b/Source/modules/serviceworkers/WaitUntilObserver.cpp
@@ -12,6 +12,7 @@
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
#include "modules/serviceworkers/ServiceWorkerGlobalScope.h"
+#include "platform/LayoutTestSupport.h"
#include "platform/NotImplemented.h"
#include "public/platform/WebServiceWorkerEventResult.h"
#include "wtf/Assertions.h"
@@ -21,6 +22,17 @@
namespace blink {
+namespace {
+
+unsigned windowInteractionTimeout()
+{
+ return LayoutTestSupport::isRunningLayoutTest()
+ ? ServiceWorkerGlobalScope::kWindowInteractionTimeoutForTest
+ : ServiceWorkerGlobalScope::kWindowInteractionTimeout;
+}
+
+} // anonymous namespace
+
class WaitUntilObserver::ThenFunction final : public ScriptFunction {
public:
enum ResolveType {
@@ -70,6 +82,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();
+
incrementPendingActivity();
}
@@ -92,13 +112,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(

Powered by Google App Engine
This is Rietveld 408576698