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

Side by Side Diff: third_party/WebKit/Source/web/tests/VirtualTimeTest.cpp

Issue 2377243003: Make VirtualTimeTest fast (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "platform/testing/UnitTestHelpers.h" 6 #include "platform/testing/UnitTestHelpers.h"
7 #include "public/platform/Platform.h" 7 #include "public/platform/Platform.h"
8 #include "public/platform/WebViewScheduler.h" 8 #include "public/platform/WebViewScheduler.h"
9 #include "public/web/WebLocalFrame.h" 9 #include "public/web/WebLocalFrame.h"
10 #include "public/web/WebScriptExecutionCallback.h" 10 #include "public/web/WebScriptExecutionCallback.h"
(...skipping 23 matching lines...) Expand all
34 34
35 class VirtualTimeTest : public SimTest { 35 class VirtualTimeTest : public SimTest {
36 protected: 36 protected:
37 String ExecuteJavaScript(String scriptSource) 37 String ExecuteJavaScript(String scriptSource)
38 { 38 {
39 ScriptExecutionCallbackHelper callbackHelper; 39 ScriptExecutionCallbackHelper callbackHelper;
40 webView().mainFrame()->toWebLocalFrame()->requestExecuteScriptAndReturnV alue( 40 webView().mainFrame()->toWebLocalFrame()->requestExecuteScriptAndReturnV alue(
41 WebScriptSource(WebString(scriptSource)), false, &callbackHelper); 41 WebScriptSource(WebString(scriptSource)), false, &callbackHelper);
42 return callbackHelper.result(); 42 return callbackHelper.result();
43 } 43 }
44
45 void TearDown() override
46 {
47 // The SimTest destructor calls runPendingTasks. This is a problem becau se if there are
48 // any repeating tasks, advancing virtual time will cause the runloop to busy loop. Pausing
49 // virtual time here fixes that.
50 webView().scheduler()->setVirtualTimePolicy(WebViewScheduler::VirtualTim ePolicy::PAUSE);
51 }
44 }; 52 };
45 53
46 namespace { 54 namespace {
47 void quitRunLoop() 55 void quitRunLoop()
48 { 56 {
49 base::MessageLoop::current()->QuitNow(); 57 base::MessageLoop::current()->QuitNow();
50 } 58 }
51 59
52 // Some task queues may have repeating v8 tasks that run forever so we impos e a hard time limit. 60 // Some task queues may have repeating v8 tasks that run forever so we impos e a hard time limit.
53 void runTasksForPeriod(double delayMs) 61 void runTasksForPeriod(double delayMs)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // Still Loading, virtual time should not advance. 187 // Still Loading, virtual time should not advance.
180 mainResource.write("<body>"); 188 mainResource.write("<body>");
181 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); 189 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance());
182 190
183 // Finished loading, virtual time should be able to advance. 191 // Finished loading, virtual time should be able to advance.
184 mainResource.finish(); 192 mainResource.finish();
185 EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); 193 EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance());
186 } 194 }
187 195
188 } // namespace blink 196 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698