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

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
« no previous file with comments | « Source/modules/serviceworkers/WaitUntilObserver.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/WaitUntilObserver.cpp
diff --git a/Source/modules/serviceworkers/WaitUntilObserver.cpp b/Source/modules/serviceworkers/WaitUntilObserver.cpp
index 4fd5e62241179f89c777ca9f1a73c9f3a48043d1..be1f85301aa89aa2504f96189168e8d0d16ce5ab 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,21 @@
namespace blink {
+namespace {
+
+// Timeout before a service worker that was given window interaction
+// permission loses them. The unit is seconds.
+const unsigned kWindowInteractionTimeout = 10;
+const unsigned kWindowInteractionTimeoutForTest = 1;
+
+unsigned windowInteractionTimeout()
+{
+ return LayoutTestSupport::isRunningLayoutTest()
+ ? kWindowInteractionTimeoutForTest : kWindowInteractionTimeout;
+}
+
+} // anonymous namespace
+
class WaitUntilObserver::ThenFunction final : public ScriptFunction {
public:
enum ResolveType {
@@ -70,6 +86,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 +116,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(
« no previous file with comments | « Source/modules/serviceworkers/WaitUntilObserver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698