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

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

Issue 2823163002: Port some AOM tests from LayoutTests to SimTests. (Closed)
Patch Set: Created 3 years, 8 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
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 "core/dom/TaskRunnerHelper.h" 6 #include "core/dom/TaskRunnerHelper.h"
7 #include "platform/testing/UnitTestHelpers.h" 7 #include "platform/testing/UnitTestHelpers.h"
8 #include "public/platform/Platform.h" 8 #include "public/platform/Platform.h"
9 #include "public/platform/WebViewScheduler.h" 9 #include "public/platform/WebViewScheduler.h"
10 #include "public/web/WebLocalFrame.h" 10 #include "public/web/WebLocalFrame.h"
11 #include "public/web/WebScriptExecutionCallback.h"
12 #include "public/web/WebScriptSource.h"
13 #include "public/web/WebView.h" 11 #include "public/web/WebView.h"
14 #include "web/tests/sim/SimRequest.h" 12 #include "web/tests/sim/SimRequest.h"
15 #include "web/tests/sim/SimTest.h" 13 #include "web/tests/sim/SimTest.h"
16 14
17 namespace blink { 15 namespace blink {
18 16
19 namespace {
20 class ScriptExecutionCallbackHelper : public WebScriptExecutionCallback {
21 public:
22 const String Result() const { return result_; }
23
24 private:
25 void Completed(const WebVector<v8::Local<v8::Value>>& values) override {
26 if (!values.IsEmpty() && !values[0].IsEmpty() && values[0]->IsString()) {
27 result_ = ToCoreString(v8::Local<v8::String>::Cast(values[0]));
28 }
29 }
30
31 String result_;
32 };
33 } // namespace
34
35 class VirtualTimeTest : public SimTest { 17 class VirtualTimeTest : public SimTest {
36 protected: 18 protected:
37 String ExecuteJavaScript(String script_source) {
38 ScriptExecutionCallbackHelper callback_helper;
39 WebView()
40 .MainFrame()
41 ->ToWebLocalFrame()
42 ->RequestExecuteScriptAndReturnValue(
43 WebScriptSource(WebString(script_source)), false, &callback_helper);
44 return callback_helper.Result();
45 }
46
47 void TearDown() override { 19 void TearDown() override {
48 // The SimTest destructor calls runPendingTasks. This is a problem because 20 // The SimTest destructor calls runPendingTasks. This is a problem because
49 // if there are any repeating tasks, advancing virtual time will cause the 21 // if there are any repeating tasks, advancing virtual time will cause the
50 // runloop to busy loop. Disabling virtual time here fixes that. 22 // runloop to busy loop. Disabling virtual time here fixes that.
51 WebView().Scheduler()->DisableVirtualTimeForTesting(); 23 WebView().Scheduler()->DisableVirtualTimeForTesting();
52 } 24 }
53 }; 25 };
54 26
55 namespace { 27 namespace {
56 void QuitRunLoop() { 28 void QuitRunLoop() {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // ALso schedule a second timer for the same point in time. 200 // ALso schedule a second timer for the same point in time.
229 ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);"); 201 ExecuteJavaScript("setTimeout(() => { run_order.push(2); }, 1000);");
230 202
231 // The second DOM timer shouldn't have run because pausing virtual time also 203 // The second DOM timer shouldn't have run because pausing virtual time also
232 // atomically pauses DOM timers. 204 // atomically pauses DOM timers.
233 testing::RunPendingTasks(); 205 testing::RunPendingTasks();
234 EXPECT_EQ("1", ExecuteJavaScript("run_order.join(', ')")); 206 EXPECT_EQ("1", ExecuteJavaScript("run_order.join(', ')"));
235 } 207 }
236 208
237 } // namespace blink 209 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698