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

Unified Diff: third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp

Issue 2725633002: scheduler: Suspend timers while virtual time is paused (Closed)
Patch Set: Rebased Created 3 years, 9 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: third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp
diff --git a/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp b/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp
index 06c2754d9773111448a7156ad82f0af191856214..fa5445b7b161ca5fbb337fd4edd3a36bbd15c7d6 100644
--- a/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp
+++ b/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/message_loop/message_loop.h"
+#include "core/dom/TaskRunnerHelper.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/Platform.h"
#include "public/platform/WebViewScheduler.h"
@@ -46,9 +47,8 @@ class VirtualTimeTest : public SimTest {
void TearDown() override {
// The SimTest destructor calls runPendingTasks. This is a problem because
// if there are any repeating tasks, advancing virtual time will cause the
- // runloop to busy loop. Pausing virtual time here fixes that.
- webView().scheduler()->setVirtualTimePolicy(
- WebViewScheduler::VirtualTimePolicy::PAUSE);
+ // runloop to busy loop. Disabling virtual time here fixes that.
+ webView().scheduler()->disableVirtualTimeForTesting();
}
};
@@ -198,4 +198,40 @@ TEST_F(VirtualTimeTest,
EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance());
}
+// http://crbug.com/633321
+#if OS(ANDROID)
+#define MAYBE_DOMTimersSuspended DISABLED_DOMTimersSuspended
+#else
+#define MAYBE_DOMTimersSuspended DOMTimersSuspended
+#endif
+TEST_F(VirtualTimeTest, MAYBE_DOMTimersSuspended) {
+ webView().scheduler()->enableVirtualTime();
+
+ // Schedule a normal DOM timer to run at 1s in the future.
+ ExecuteJavaScript(
+ "var run_order = [];"
+ "setTimeout(() => { run_order.push(1); }, 1000);");
+
+ RefPtr<WebTaskRunner> runner =
+ TaskRunnerHelper::get(TaskType::Timer, window().getExecutionContext());
+
+ // Schedule a task to suspend virtual time at the same point in time.
+ runner->postDelayedTask(BLINK_FROM_HERE,
+ WTF::bind(
+ [](WebViewScheduler* scheduler) {
+ scheduler->setVirtualTimePolicy(
+ WebViewScheduler::VirtualTimePolicy::PAUSE);
+ },
+ WTF::unretained(webView().scheduler())),
+ 1000);
+
+ // ALso schedule a second timer for the same point in time.
+ ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);");
+
+ // The second DOM timer shouldn't have run because pausing virtual time also
+ // atomically pauses DOM timers.
+ testing::runPendingTasks();
+ EXPECT_EQ("1", ExecuteJavaScript("run_order.join(', ')"));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698