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 be024f2fb523cc413acef8c9122b23f618c4e551..ea259537af5761312c85d174d3102e5e8dae7741 100644 |
--- a/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp |
+++ b/third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp |
@@ -9,6 +9,7 @@ |
#include "public/web/WebScriptExecutionCallback.h" |
#include "public/web/WebScriptSource.h" |
#include "public/web/WebView.h" |
+#include "web/tests/sim/SimRequest.h" |
#include "web/tests/sim/SimTest.h" |
namespace blink { |
@@ -105,4 +106,45 @@ TEST_F(VirtualTimeTest, AllowVirtualTimeToAdvance) |
EXPECT_EQ("c, b, a", ExecuteJavaScript("run_order.join(', ')")); |
} |
+TEST_F(VirtualTimeTest, VirtualTimeNotAllowedToAdvanceWhileResourcesLoading) |
+{ |
+ webView().scheduler()->enableVirtualTime(); |
+ webView().scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTimePolicy::PAUSE_IF_NETWORK_FETCHES_PENDING); |
+ |
+ EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ |
+ SimRequest mainResource("https://example.com/test.html", "text/html"); |
+ SimRequest cssResource("https://example.com/test.css", "text/css"); |
+ |
+ // Not loading, virtual time should be able to advance. |
+ EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ |
+ // Loading, virtual time should not advance. |
+ loadURL("https://example.com/test.html"); |
+ EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ |
+ mainResource.start(); |
+ |
+ // Still Loading, virtual time should not advance. |
+ mainResource.write("<!DOCTYPE html><link rel=stylesheet href=test.css>"); |
+ EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ |
+ // Still Loading, virtual time should not advance. |
+ cssResource.start(); |
+ cssResource.write("a { color: red; }"); |
+ EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ |
+ // Still Loading, virtual time should not advance. |
+ cssResource.finish(); |
+ EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ |
+ // Still Loading, virtual time should not advance. |
+ mainResource.write("<body>"); |
+ EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+ |
+ // Finished loading, virtual time should be able to advance. |
+ mainResource.finish(); |
+ EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
+} |
+ |
} // namespace blink |