Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "web/tests/sim/SimTest.h" | 5 #include "web/tests/sim/SimTest.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/LocalDOMWindow.h" | 8 #include "core/frame/LocalDOMWindow.h" |
| 9 #include "platform/LayoutTestSupport.h" | 9 #include "platform/LayoutTestSupport.h" |
| 10 #include "platform/scroll/ScrollbarTheme.h" | 10 #include "platform/scroll/ScrollbarTheme.h" |
| 11 #include "platform/testing/UnitTestHelpers.h" | 11 #include "platform/testing/UnitTestHelpers.h" |
| 12 #include "public/platform/WebCache.h" | 12 #include "public/platform/WebCache.h" |
| 13 #include "public/web/WebScriptExecutionCallback.h" | |
| 14 #include "public/web/WebScriptSource.h" | |
| 13 #include "web/WebLocalFrameImpl.h" | 15 #include "web/WebLocalFrameImpl.h" |
| 14 #include "web/WebViewImpl.h" | 16 #include "web/WebViewImpl.h" |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 | 19 |
| 20 namespace { | |
| 21 class ScriptExecutionCallbackHelper : public WebScriptExecutionCallback { | |
| 22 public: | |
| 23 const String Result() const { return result_; } | |
| 24 | |
| 25 private: | |
| 26 void Completed(const WebVector<v8::Local<v8::Value>>& values) override { | |
| 27 if (!values.IsEmpty() && !values[0].IsEmpty() && values[0]->IsString()) { | |
| 28 result_ = ToCoreString(v8::Local<v8::String>::Cast(values[0])); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 String result_; | |
| 33 }; | |
| 34 } // namespace | |
| 35 | |
| 18 SimTest::SimTest() : web_view_client_(compositor_), web_frame_client_(*this) { | 36 SimTest::SimTest() : web_view_client_(compositor_), web_frame_client_(*this) { |
| 19 Document::SetThreadedParsingEnabledForTesting(false); | 37 Document::SetThreadedParsingEnabledForTesting(false); |
| 20 // Use the mock theme to get more predictable code paths, this also avoids | 38 // Use the mock theme to get more predictable code paths, this also avoids |
| 21 // the OS callbacks in ScrollAnimatorMac which can schedule frames | 39 // the OS callbacks in ScrollAnimatorMac which can schedule frames |
| 22 // unpredictably since the OS will randomly call into blink for | 40 // unpredictably since the OS will randomly call into blink for |
| 23 // updateScrollerStyleForNewRecommendedScrollerStyle which then does | 41 // updateScrollerStyleForNewRecommendedScrollerStyle which then does |
| 24 // FrameView::scrollbarStyleChanged and will adjust the scrollbar existence | 42 // FrameView::scrollbarStyleChanged and will adjust the scrollbar existence |
| 25 // in the middle of a test. | 43 // in the middle of a test. |
| 26 LayoutTestSupport::SetMockThemeEnabledForTest(true); | 44 LayoutTestSupport::SetMockThemeEnabledForTest(true); |
| 27 ScrollbarTheme::SetMockScrollbarsEnabled(true); | 45 ScrollbarTheme::SetMockScrollbarsEnabled(true); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 } | 88 } |
| 71 | 89 |
| 72 SimCompositor& SimTest::Compositor() { | 90 SimCompositor& SimTest::Compositor() { |
| 73 return compositor_; | 91 return compositor_; |
| 74 } | 92 } |
| 75 | 93 |
| 76 void SimTest::AddConsoleMessage(const String& message) { | 94 void SimTest::AddConsoleMessage(const String& message) { |
| 77 console_messages_.push_back(message); | 95 console_messages_.push_back(message); |
| 78 } | 96 } |
| 79 | 97 |
| 98 String SimTest::ExecuteJavaScript(String script_source) { | |
| 99 ScriptExecutionCallbackHelper callback_helper; | |
| 100 WebView().MainFrame()->ToWebLocalFrame()->RequestExecuteScriptAndReturnValue( | |
|
esprehn
2017/04/20 19:54:07
Since you can access the core types directly this
| |
| 101 WebScriptSource(WebString(script_source)), false, &callback_helper); | |
| 102 return callback_helper.Result(); | |
| 103 } | |
| 104 | |
| 80 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |