| OLD | NEW |
| 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 26 matching lines...) Expand all Loading... |
| 37 ScriptExecutionCallbackHelper callbackHelper; | 37 ScriptExecutionCallbackHelper callbackHelper; |
| 38 webView() | 38 webView() |
| 39 .mainFrame() | 39 .mainFrame() |
| 40 ->toWebLocalFrame() | 40 ->toWebLocalFrame() |
| 41 ->requestExecuteScriptAndReturnValue( | 41 ->requestExecuteScriptAndReturnValue( |
| 42 WebScriptSource(WebString(scriptSource)), false, &callbackHelper); | 42 WebScriptSource(WebString(scriptSource)), false, &callbackHelper); |
| 43 return callbackHelper.result(); | 43 return callbackHelper.result(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void TearDown() override { | 46 void TearDown() override { |
| 47 // The SimTest destructor calls runPendingTasks. This is a problem because i
f there are | 47 // The SimTest destructor calls runPendingTasks. This is a problem because |
| 48 // any repeating tasks, advancing virtual time will cause the runloop to bus
y loop. Pausing | 48 // if there are any repeating tasks, advancing virtual time will cause the |
| 49 // virtual time here fixes that. | 49 // runloop to busy loop. Pausing virtual time here fixes that. |
| 50 webView().scheduler()->setVirtualTimePolicy( | 50 webView().scheduler()->setVirtualTimePolicy( |
| 51 WebViewScheduler::VirtualTimePolicy::PAUSE); | 51 WebViewScheduler::VirtualTimePolicy::PAUSE); |
| 52 } | 52 } |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 void quitRunLoop() { | 56 void quitRunLoop() { |
| 57 base::MessageLoop::current()->QuitNow(); | 57 base::MessageLoop::current()->QuitNow(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 // Some task queues may have repeating v8 tasks that run forever so we impose a
hard time limit. | 60 // Some task queues may have repeating v8 tasks that run forever so we impose a |
| 61 // hard time limit. |
| 61 void runTasksForPeriod(double delayMs) { | 62 void runTasksForPeriod(double delayMs) { |
| 62 Platform::current()->currentThread()->getWebTaskRunner()->postDelayedTask( | 63 Platform::current()->currentThread()->getWebTaskRunner()->postDelayedTask( |
| 63 BLINK_FROM_HERE, WTF::bind(&quitRunLoop), delayMs); | 64 BLINK_FROM_HERE, WTF::bind(&quitRunLoop), delayMs); |
| 64 testing::enterRunLoop(); | 65 testing::enterRunLoop(); |
| 65 } | 66 } |
| 66 } | 67 } |
| 67 | 68 |
| 68 // http://crbug.com/633321 | 69 // http://crbug.com/633321 |
| 69 #if OS(ANDROID) | 70 #if OS(ANDROID) |
| 70 #define MAYBE_DOMTimersFireInExpectedOrder DISABLED_DOMTimersFireInExpectedOrder | 71 #define MAYBE_DOMTimersFireInExpectedOrder DISABLED_DOMTimersFireInExpectedOrder |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 #else | 156 #else |
| 156 #define MAYBE_VirtualTimeNotAllowedToAdvanceWhileResourcesLoading \ | 157 #define MAYBE_VirtualTimeNotAllowedToAdvanceWhileResourcesLoading \ |
| 157 VirtualTimeNotAllowedToAdvanceWhileResourcesLoading | 158 VirtualTimeNotAllowedToAdvanceWhileResourcesLoading |
| 158 #endif | 159 #endif |
| 159 TEST_F(VirtualTimeTest, | 160 TEST_F(VirtualTimeTest, |
| 160 MAYBE_VirtualTimeNotAllowedToAdvanceWhileResourcesLoading) { | 161 MAYBE_VirtualTimeNotAllowedToAdvanceWhileResourcesLoading) { |
| 161 webView().scheduler()->enableVirtualTime(); | 162 webView().scheduler()->enableVirtualTime(); |
| 162 webView().scheduler()->setVirtualTimePolicy( | 163 webView().scheduler()->setVirtualTimePolicy( |
| 163 WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); | 164 WebViewScheduler::VirtualTimePolicy::DETERMINISTIC_LOADING); |
| 164 | 165 |
| 165 // To ensure determinism virtual time is not allowed to advance until we have
seen at least one load. | 166 // To ensure determinism virtual time is not allowed to advance until we have |
| 167 // seen at least one load. |
| 166 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); | 168 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
| 167 | 169 |
| 168 SimRequest mainResource("https://example.com/test.html", "text/html"); | 170 SimRequest mainResource("https://example.com/test.html", "text/html"); |
| 169 SimRequest cssResource("https://example.com/test.css", "text/css"); | 171 SimRequest cssResource("https://example.com/test.css", "text/css"); |
| 170 | 172 |
| 171 // Loading, virtual time should not advance. | 173 // Loading, virtual time should not advance. |
| 172 loadURL("https://example.com/test.html"); | 174 loadURL("https://example.com/test.html"); |
| 173 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); | 175 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
| 174 | 176 |
| 175 mainResource.start(); | 177 mainResource.start(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 190 // Still Loading, virtual time should not advance. | 192 // Still Loading, virtual time should not advance. |
| 191 mainResource.write("<body>"); | 193 mainResource.write("<body>"); |
| 192 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); | 194 EXPECT_FALSE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
| 193 | 195 |
| 194 // Finished loading, virtual time should be able to advance. | 196 // Finished loading, virtual time should be able to advance. |
| 195 mainResource.finish(); | 197 mainResource.finish(); |
| 196 EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); | 198 EXPECT_TRUE(webView().scheduler()->virtualTimeAllowedToAdvance()); |
| 197 } | 199 } |
| 198 | 200 |
| 199 } // namespace blink | 201 } // namespace blink |
| OLD | NEW |