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

Side by Side Diff: components/test_runner/test_runner.cc

Issue 1852603002: Replacing most of web_task.h with base::Closure + base::WeakPtrFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-mocks-to-test-runner
Patch Set: Rebasing... Created 4 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
« no previous file with comments | « components/test_runner/test_runner.h ('k') | components/test_runner/web_task.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/test_runner/test_runner.h" 5 #include "components/test_runner/test_runner.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "components/test_runner/app_banner_client.h" 17 #include "components/test_runner/app_banner_client.h"
18 #include "components/test_runner/layout_dump.h" 18 #include "components/test_runner/layout_dump.h"
19 #include "components/test_runner/mock_credential_manager_client.h" 19 #include "components/test_runner/mock_credential_manager_client.h"
20 #include "components/test_runner/mock_screen_orientation_client.h" 20 #include "components/test_runner/mock_screen_orientation_client.h"
21 #include "components/test_runner/mock_web_speech_recognizer.h" 21 #include "components/test_runner/mock_web_speech_recognizer.h"
22 #include "components/test_runner/mock_web_user_media_client.h" 22 #include "components/test_runner/mock_web_user_media_client.h"
23 #include "components/test_runner/pixel_dump.h" 23 #include "components/test_runner/pixel_dump.h"
24 #include "components/test_runner/spell_check_client.h" 24 #include "components/test_runner/spell_check_client.h"
25 #include "components/test_runner/test_interfaces.h" 25 #include "components/test_runner/test_interfaces.h"
26 #include "components/test_runner/test_preferences.h" 26 #include "components/test_runner/test_preferences.h"
27 #include "components/test_runner/web_content_settings.h" 27 #include "components/test_runner/web_content_settings.h"
28 #include "components/test_runner/web_task.h"
28 #include "components/test_runner/web_test_delegate.h" 29 #include "components/test_runner/web_test_delegate.h"
29 #include "components/test_runner/web_test_proxy.h" 30 #include "components/test_runner/web_test_proxy.h"
30 #include "gin/arguments.h" 31 #include "gin/arguments.h"
31 #include "gin/array_buffer.h" 32 #include "gin/array_buffer.h"
32 #include "gin/handle.h" 33 #include "gin/handle.h"
33 #include "gin/object_template_builder.h" 34 #include "gin/object_template_builder.h"
34 #include "gin/wrappable.h" 35 #include "gin/wrappable.h"
35 #include "third_party/WebKit/public/platform/WebCanvas.h" 36 #include "third_party/WebKit/public/platform/WebCanvas.h"
36 #include "third_party/WebKit/public/platform/WebData.h" 37 #include "third_party/WebKit/public/platform/WebData.h"
37 #include "third_party/WebKit/public/platform/WebPasswordCredential.h" 38 #include "third_party/WebKit/public/platform/WebPasswordCredential.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) { 87 if (command_line->HasSwitch(switches::kForceDeviceScaleFactor)) {
87 double scale; 88 double scale;
88 std::string value = 89 std::string value =
89 command_line->GetSwitchValueASCII(switches::kForceDeviceScaleFactor); 90 command_line->GetSwitchValueASCII(switches::kForceDeviceScaleFactor);
90 if (base::StringToDouble(value, &scale)) 91 if (base::StringToDouble(value, &scale))
91 return scale; 92 return scale;
92 } 93 }
93 return 1.f; 94 return 1.f;
94 } 95 }
95 96
96 class HostMethodTask : public WebMethodTask<TestRunner> {
97 public:
98 typedef void (TestRunner::*CallbackMethodType)();
99 HostMethodTask(TestRunner* object, CallbackMethodType callback)
100 : WebMethodTask<TestRunner>(object), callback_(callback) {}
101
102 void RunIfValid() override { (object_->*callback_)(); }
103
104 private:
105 CallbackMethodType callback_;
106 };
107
108 } // namespace 97 } // namespace
109 98
110 class InvokeCallbackTask : public WebMethodTask<TestRunner> {
111 public:
112 InvokeCallbackTask(TestRunner* object, v8::Local<v8::Function> callback)
113 : WebMethodTask<TestRunner>(object),
114 callback_(blink::mainThreadIsolate(), callback),
115 argc_(0) {}
116
117 void RunIfValid() override {
118 v8::Isolate* isolate = blink::mainThreadIsolate();
119 v8::HandleScope handle_scope(isolate);
120 WebFrame* frame = object_->web_view_->mainFrame();
121
122 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
123 if (context.IsEmpty())
124 return;
125
126 v8::Context::Scope context_scope(context);
127
128 scoped_ptr<v8::Local<v8::Value>[]> local_argv;
129 if (argc_) {
130 local_argv.reset(new v8::Local<v8::Value>[argc_]);
131 for (int i = 0; i < argc_; ++i)
132 local_argv[i] = v8::Local<v8::Value>::New(isolate, argv_[i]);
133 }
134
135 frame->callFunctionEvenIfScriptDisabled(
136 v8::Local<v8::Function>::New(isolate, callback_),
137 context->Global(),
138 argc_,
139 local_argv.get());
140 }
141
142 void SetArguments(int argc, v8::Local<v8::Value> argv[]) {
143 v8::Isolate* isolate = blink::mainThreadIsolate();
144 argc_ = argc;
145 argv_.reset(new v8::UniquePersistent<v8::Value>[argc]);
146 for (int i = 0; i < argc; ++i)
147 argv_[i] = v8::UniquePersistent<v8::Value>(isolate, argv[i]);
148 }
149
150 private:
151 v8::UniquePersistent<v8::Function> callback_;
152 int argc_;
153 scoped_ptr<v8::UniquePersistent<v8::Value>[]> argv_;
154 };
155
156 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> { 99 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
157 public: 100 public:
158 static gin::WrapperInfo kWrapperInfo; 101 static gin::WrapperInfo kWrapperInfo;
159 102
160 static void Install(base::WeakPtr<TestRunner> controller, 103 static void Install(base::WeakPtr<TestRunner> controller,
161 WebFrame* frame); 104 WebFrame* frame);
162 105
163 private: 106 private:
164 explicit TestRunnerBindings( 107 explicit TestRunnerBindings(
165 base::WeakPtr<TestRunner> controller); 108 base::WeakPtr<TestRunner> controller);
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 runner_->CapturePixelsAsyncThen(callback); 1439 runner_->CapturePixelsAsyncThen(callback);
1497 } 1440 }
1498 1441
1499 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen( 1442 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1500 int x, int y, v8::Local<v8::Function> callback) { 1443 int x, int y, v8::Local<v8::Function> callback) {
1501 if (runner_) 1444 if (runner_)
1502 runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback); 1445 runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
1503 } 1446 }
1504 1447
1505 void TestRunnerBindings::SetCustomTextOutput(const std::string& output) { 1448 void TestRunnerBindings::SetCustomTextOutput(const std::string& output) {
1506 runner_->setCustomTextOutput(output); 1449 if (runner_)
1450 runner_->setCustomTextOutput(output);
1507 } 1451 }
1508 1452
1509 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name, 1453 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name,
1510 bool enabled) { 1454 bool enabled) {
1511 if (runner_ && runner_->web_view_) { 1455 if (runner_ && runner_->web_view_) {
1512 WebFrame* target_frame = 1456 WebFrame* target_frame =
1513 runner_->web_view_->findFrameByName(WebString::fromUTF8(name)); 1457 runner_->web_view_->findFrameByName(WebString::fromUTF8(name));
1514 if (target_frame) 1458 if (target_frame)
1515 target_frame->enableViewSourceMode(enabled); 1459 target_frame->enableViewSourceMode(enabled);
1516 } 1460 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 1543
1600 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() { 1544 void TestRunnerBindings::ForceNextDrawingBufferCreationToFail() {
1601 if (runner_) 1545 if (runner_)
1602 runner_->ForceNextDrawingBufferCreationToFail(); 1546 runner_->ForceNextDrawingBufferCreationToFail();
1603 } 1547 }
1604 1548
1605 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) { 1549 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1606 } 1550 }
1607 1551
1608 TestRunner::WorkQueue::WorkQueue(TestRunner* controller) 1552 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1609 : frozen_(false) 1553 : frozen_(false), controller_(controller), weak_factory_(this) {}
1610 , controller_(controller) {}
1611 1554
1612 TestRunner::WorkQueue::~WorkQueue() { 1555 TestRunner::WorkQueue::~WorkQueue() {
1613 Reset(); 1556 Reset();
1614 } 1557 }
1615 1558
1616 void TestRunner::WorkQueue::ProcessWorkSoon() { 1559 void TestRunner::WorkQueue::ProcessWorkSoon() {
1617 if (controller_->topLoadingFrame()) 1560 if (controller_->topLoadingFrame())
1618 return; 1561 return;
1619 1562
1620 if (!queue_.empty()) { 1563 if (!queue_.empty()) {
1621 // We delay processing queued work to avoid recursion problems. 1564 // We delay processing queued work to avoid recursion problems.
1622 controller_->delegate_->PostTask(new WorkQueueTask(this)); 1565 controller_->PostTask(base::Bind(&TestRunner::WorkQueue::ProcessWork,
1566 weak_factory_.GetWeakPtr()));
1623 } else if (!controller_->layout_test_runtime_flags_.wait_until_done()) { 1567 } else if (!controller_->layout_test_runtime_flags_.wait_until_done()) {
1624 controller_->delegate_->TestFinished(); 1568 controller_->delegate_->TestFinished();
1625 } 1569 }
1626 } 1570 }
1627 1571
1628 void TestRunner::WorkQueue::Reset() { 1572 void TestRunner::WorkQueue::Reset() {
1629 frozen_ = false; 1573 frozen_ = false;
1630 while (!queue_.empty()) { 1574 while (!queue_.empty()) {
1631 delete queue_.front(); 1575 delete queue_.front();
1632 queue_.pop_front(); 1576 queue_.pop_front();
(...skipping 17 matching lines...) Expand all
1650 queue_.pop_front(); 1594 queue_.pop_front();
1651 if (startedLoad) 1595 if (startedLoad)
1652 return; 1596 return;
1653 } 1597 }
1654 1598
1655 if (!controller_->layout_test_runtime_flags_.wait_until_done() && 1599 if (!controller_->layout_test_runtime_flags_.wait_until_done() &&
1656 !controller_->topLoadingFrame()) 1600 !controller_->topLoadingFrame())
1657 controller_->delegate_->TestFinished(); 1601 controller_->delegate_->TestFinished();
1658 } 1602 }
1659 1603
1660 void TestRunner::WorkQueue::WorkQueueTask::RunIfValid() {
1661 object_->ProcessWork();
1662 }
1663
1664 TestRunner::TestRunner(TestInterfaces* interfaces) 1604 TestRunner::TestRunner(TestInterfaces* interfaces)
1665 : test_is_running_(false), 1605 : test_is_running_(false),
1666 close_remaining_windows_(false), 1606 close_remaining_windows_(false),
1667 work_queue_(this), 1607 work_queue_(this),
1668 web_history_item_count_(0), 1608 web_history_item_count_(0),
1669 intercept_post_message_(false), 1609 intercept_post_message_(false),
1670 test_interfaces_(interfaces), 1610 test_interfaces_(interfaces),
1671 delegate_(nullptr), 1611 delegate_(nullptr),
1672 web_view_(nullptr), 1612 web_view_(nullptr),
1673 web_content_settings_(new WebContentSettings()), 1613 web_content_settings_(new WebContentSettings()),
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 web_history_item_count_ = 0; 1712 web_history_item_count_ = 0;
1773 intercept_post_message_ = false; 1713 intercept_post_message_ = false;
1774 1714
1775 web_content_settings_->Reset(); 1715 web_content_settings_->Reset();
1776 1716
1777 SetUseMockTheme(true); 1717 SetUseMockTheme(true);
1778 1718
1779 pointer_locked_ = false; 1719 pointer_locked_ = false;
1780 pointer_lock_planned_result_ = PointerLockWillSucceed; 1720 pointer_lock_planned_result_ = PointerLockWillSucceed;
1781 1721
1782 task_list_.RevokeAll(); 1722 weak_factory_.InvalidateWeakPtrs();
1783 work_queue_.Reset(); 1723 work_queue_.Reset();
1784 1724
1785 if (close_remaining_windows_ && delegate_) 1725 if (close_remaining_windows_ && delegate_)
1786 delegate_->CloseRemainingWindows(); 1726 delegate_->CloseRemainingWindows();
1787 else 1727 else
1788 close_remaining_windows_ = true; 1728 close_remaining_windows_ = true;
1789 } 1729 }
1790 1730
1791 void TestRunner::SetTestIsRunning(bool running) { 1731 void TestRunner::SetTestIsRunning(bool running) {
1792 test_is_running_ = running; 1732 test_is_running_ = running;
1793 } 1733 }
1794 1734
1795 void TestRunner::InvokeCallback(scoped_ptr<InvokeCallbackTask> task) { 1735 void TestRunner::PostTask(const base::Closure& callback) {
1796 delegate_->PostTask(task.release()); 1736 delegate_->PostTask(new WebCallbackTask(callback));
1737 }
1738
1739 void TestRunner::PostDelayedTask(long long delay,
1740 const base::Closure& callback) {
1741 delegate_->PostDelayedTask(new WebCallbackTask(callback), delay);
1742 }
1743
1744 void TestRunner::PostV8Callback(const v8::Local<v8::Function>& callback) {
1745 PostTask(base::Bind(&TestRunner::InvokeV8Callback, weak_factory_.GetWeakPtr(),
1746 v8::UniquePersistent<v8::Function>(
1747 blink::mainThreadIsolate(), callback)));
1748 }
1749
1750 void TestRunner::PostV8CallbackWithArgs(
1751 v8::UniquePersistent<v8::Function> callback,
1752 int argc,
1753 v8::Local<v8::Value> argv[]) {
1754 std::vector<v8::UniquePersistent<v8::Value>> args;
1755 for (int i = 0; i < argc; i++) {
1756 args.push_back(
1757 v8::UniquePersistent<v8::Value>(blink::mainThreadIsolate(), argv[i]));
1758 }
1759
1760 PostTask(base::Bind(&TestRunner::InvokeV8CallbackWithArgs,
1761 weak_factory_.GetWeakPtr(), std::move(callback),
1762 std::move(args)));
1763 }
1764
1765 void TestRunner::InvokeV8Callback(
1766 const v8::UniquePersistent<v8::Function>& callback) {
1767 std::vector<v8::UniquePersistent<v8::Value>> empty_args;
1768 InvokeV8CallbackWithArgs(callback, std::move(empty_args));
1769 }
1770
1771 void TestRunner::InvokeV8CallbackWithArgs(
1772 const v8::UniquePersistent<v8::Function>& callback,
1773 const std::vector<v8::UniquePersistent<v8::Value>>& args) {
1774 v8::Isolate* isolate = blink::mainThreadIsolate();
1775 v8::HandleScope handle_scope(isolate);
1776
1777 if (!web_view_)
1778 return;
1779 WebFrame* frame = web_view_->mainFrame();
1780 v8::Local<v8::Context> context = frame->mainWorldScriptContext();
1781 if (context.IsEmpty())
1782 return;
1783 v8::Context::Scope context_scope(context);
1784
1785 std::vector<v8::Local<v8::Value>> local_args;
1786 for (const auto& arg : args) {
1787 local_args.push_back(v8::Local<v8::Value>::New(isolate, arg));
1788 }
1789
1790 frame->callFunctionEvenIfScriptDisabled(
1791 v8::Local<v8::Function>::New(isolate, callback), context->Global(),
1792 local_args.size(), local_args.data());
1793 }
1794
1795 base::Closure TestRunner::CreateClosureThatPostsV8Callback(
1796 const v8::Local<v8::Function>& callback) {
1797 return base::Bind(
1798 &TestRunner::PostTask, weak_factory_.GetWeakPtr(),
1799 base::Bind(&TestRunner::InvokeV8Callback, weak_factory_.GetWeakPtr(),
1800 v8::UniquePersistent<v8::Function>(blink::mainThreadIsolate(),
1801 callback)));
1797 } 1802 }
1798 1803
1799 bool TestRunner::shouldDumpEditingCallbacks() const { 1804 bool TestRunner::shouldDumpEditingCallbacks() const {
1800 return dump_editting_callbacks_; 1805 return dump_editting_callbacks_;
1801 } 1806 }
1802 1807
1803 void TestRunner::setShouldDumpAsText(bool value) { 1808 void TestRunner::setShouldDumpAsText(bool value) {
1804 layout_test_runtime_flags_.set_dump_as_text(value); 1809 layout_test_runtime_flags_.set_dump_as_text(value);
1805 OnLayoutTestRuntimeFlagsChanged(); 1810 OnLayoutTestRuntimeFlagsChanged();
1806 } 1811 }
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2014 return intercept_post_message_; 2019 return intercept_post_message_;
2015 } 2020 }
2016 2021
2017 bool TestRunner::shouldDumpResourcePriorities() const { 2022 bool TestRunner::shouldDumpResourcePriorities() const {
2018 return should_dump_resource_priorities_; 2023 return should_dump_resource_priorities_;
2019 } 2024 }
2020 2025
2021 bool TestRunner::RequestPointerLock() { 2026 bool TestRunner::RequestPointerLock() {
2022 switch (pointer_lock_planned_result_) { 2027 switch (pointer_lock_planned_result_) {
2023 case PointerLockWillSucceed: 2028 case PointerLockWillSucceed:
2024 delegate_->PostDelayedTask( 2029 PostDelayedTask(0, base::Bind(&TestRunner::DidAcquirePointerLockInternal,
2025 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal), 2030 weak_factory_.GetWeakPtr()));
2026 0);
2027 return true; 2031 return true;
2028 case PointerLockWillRespondAsync: 2032 case PointerLockWillRespondAsync:
2029 DCHECK(!pointer_locked_); 2033 DCHECK(!pointer_locked_);
2030 return true; 2034 return true;
2031 case PointerLockWillFailSync: 2035 case PointerLockWillFailSync:
2032 DCHECK(!pointer_locked_); 2036 DCHECK(!pointer_locked_);
2033 return false; 2037 return false;
2034 default: 2038 default:
2035 NOTREACHED(); 2039 NOTREACHED();
2036 return false; 2040 return false;
2037 } 2041 }
2038 } 2042 }
2039 2043
2040 void TestRunner::RequestPointerUnlock() { 2044 void TestRunner::RequestPointerUnlock() {
2041 delegate_->PostDelayedTask( 2045 PostDelayedTask(0, base::Bind(&TestRunner::DidLosePointerLockInternal,
2042 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0); 2046 weak_factory_.GetWeakPtr()));
2043 } 2047 }
2044 2048
2045 bool TestRunner::isPointerLocked() { 2049 bool TestRunner::isPointerLocked() {
2046 return pointer_locked_; 2050 return pointer_locked_;
2047 } 2051 }
2048 2052
2049 void TestRunner::setToolTipText(const WebString& text) { 2053 void TestRunner::setToolTipText(const WebString& text) {
2050 tooltip_text_ = text.utf8(); 2054 tooltip_text_ = text.utf8();
2051 } 2055 }
2052 2056
(...skipping 29 matching lines...) Expand all
2082 bool Run(WebTestDelegate* delegate, WebView*) override { 2086 bool Run(WebTestDelegate* delegate, WebView*) override {
2083 delegate->GoToOffset(distance_); 2087 delegate->GoToOffset(distance_);
2084 return true; // FIXME: Did it really start a navigation? 2088 return true; // FIXME: Did it really start a navigation?
2085 } 2089 }
2086 2090
2087 private: 2091 private:
2088 int distance_; 2092 int distance_;
2089 }; 2093 };
2090 2094
2091 void TestRunner::NotifyDone() { 2095 void TestRunner::NotifyDone() {
2092 // Test didn't timeout. Kill the timeout timer. 2096 // Test didn't timeout. Kill the pending callbacks.
2093 task_list_.RevokeAll(); 2097 weak_factory_.InvalidateWeakPtrs();
2094 2098
2095 CompleteNotifyDone(); 2099 CompleteNotifyDone();
2096 } 2100 }
2097 2101
2098 void TestRunner::WaitUntilDone() { 2102 void TestRunner::WaitUntilDone() {
2099 layout_test_runtime_flags_.set_wait_until_done(true); 2103 layout_test_runtime_flags_.set_wait_until_done(true);
2100 OnLayoutTestRuntimeFlagsChanged(); 2104 OnLayoutTestRuntimeFlagsChanged();
2101 } 2105 }
2102 2106
2103 void TestRunner::QueueBackNavigation(int how_far_back) { 2107 void TestRunner::QueueBackNavigation(int how_far_back) {
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 delegate_->SetFocus(proxy_->web_view(), value); 2961 delegate_->SetFocus(proxy_->web_view(), value);
2958 } 2962 }
2959 2963
2960 std::string TestRunner::PathToLocalResource(const std::string& path) { 2964 std::string TestRunner::PathToLocalResource(const std::string& path) {
2961 return delegate_->PathToLocalResource(path); 2965 return delegate_->PathToLocalResource(path);
2962 } 2966 }
2963 2967
2964 void TestRunner::SetBackingScaleFactor(double value, 2968 void TestRunner::SetBackingScaleFactor(double value,
2965 v8::Local<v8::Function> callback) { 2969 v8::Local<v8::Function> callback) {
2966 delegate_->SetDeviceScaleFactor(value); 2970 delegate_->SetDeviceScaleFactor(value);
2967 delegate_->PostTask(new InvokeCallbackTask(this, callback)); 2971 PostV8Callback(callback);
2968 } 2972 }
2969 2973
2970 void TestRunner::EnableUseZoomForDSF(v8::Local<v8::Function> callback) { 2974 void TestRunner::EnableUseZoomForDSF(v8::Local<v8::Function> callback) {
2971 delegate_->EnableUseZoomForDSF(); 2975 delegate_->EnableUseZoomForDSF();
2972 delegate_->PostTask(new InvokeCallbackTask(this, callback)); 2976 PostV8Callback(callback);
2973 } 2977 }
2974 2978
2975 void TestRunner::SetColorProfile(const std::string& name, 2979 void TestRunner::SetColorProfile(const std::string& name,
2976 v8::Local<v8::Function> callback) { 2980 v8::Local<v8::Function> callback) {
2977 delegate_->SetDeviceColorProfile(name); 2981 delegate_->SetDeviceColorProfile(name);
2978 delegate_->PostTask(new InvokeCallbackTask(this, callback)); 2982 PostV8Callback(callback);
2979 } 2983 }
2980 2984
2981 void TestRunner::SetBluetoothFakeAdapter(const std::string& adapter_name, 2985 void TestRunner::SetBluetoothFakeAdapter(const std::string& adapter_name,
2982 v8::Local<v8::Function> callback) { 2986 v8::Local<v8::Function> callback) {
2983 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback));
2984 delegate_->SetBluetoothFakeAdapter( 2987 delegate_->SetBluetoothFakeAdapter(
2985 adapter_name, 2988 adapter_name, CreateClosureThatPostsV8Callback(callback));
2986 base::Bind(&TestRunner::InvokeCallback, weak_factory_.GetWeakPtr(),
2987 base::Passed(&task)));
2988 } 2989 }
2989 2990
2990 void TestRunner::SetBluetoothManualChooser(bool enable) { 2991 void TestRunner::SetBluetoothManualChooser(bool enable) {
2991 delegate_->SetBluetoothManualChooser(enable); 2992 delegate_->SetBluetoothManualChooser(enable);
2992 } 2993 }
2993 2994
2994 void TestRunner::GetBluetoothManualChooserEvents( 2995 void TestRunner::GetBluetoothManualChooserEvents(
2995 v8::Local<v8::Function> callback) { 2996 v8::Local<v8::Function> callback) {
2996 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback));
2997 return delegate_->GetBluetoothManualChooserEvents( 2997 return delegate_->GetBluetoothManualChooserEvents(
2998 base::Bind(&TestRunner::GetBluetoothManualChooserEventsCallback, 2998 base::Bind(&TestRunner::GetBluetoothManualChooserEventsCallback,
2999 weak_factory_.GetWeakPtr(), base::Passed(&task))); 2999 weak_factory_.GetWeakPtr(),
3000 base::Passed(v8::UniquePersistent<v8::Function>(
3001 blink::mainThreadIsolate(), callback))));
3000 } 3002 }
3001 3003
3002 void TestRunner::SendBluetoothManualChooserEvent(const std::string& event, 3004 void TestRunner::SendBluetoothManualChooserEvent(const std::string& event,
3003 const std::string& argument) { 3005 const std::string& argument) {
3004 delegate_->SendBluetoothManualChooserEvent(event, argument); 3006 delegate_->SendBluetoothManualChooserEvent(event, argument);
3005 } 3007 }
3006 3008
3007 void TestRunner::SetGeofencingMockProvider(bool service_available) { 3009 void TestRunner::SetGeofencingMockProvider(bool service_available) {
3008 delegate_->SetGeofencingMockProvider(service_available); 3010 delegate_->SetGeofencingMockProvider(service_available);
3009 } 3011 }
(...skipping 10 matching lines...) Expand all
3020 const std::string& value, 3022 const std::string& value,
3021 const GURL& origin, 3023 const GURL& origin,
3022 const GURL& embedding_origin) { 3024 const GURL& embedding_origin) {
3023 delegate_->SetPermission(name, value, origin, embedding_origin); 3025 delegate_->SetPermission(name, value, origin, embedding_origin);
3024 } 3026 }
3025 3027
3026 void TestRunner::DispatchBeforeInstallPromptEvent( 3028 void TestRunner::DispatchBeforeInstallPromptEvent(
3027 int request_id, 3029 int request_id,
3028 const std::vector<std::string>& event_platforms, 3030 const std::vector<std::string>& event_platforms,
3029 v8::Local<v8::Function> callback) { 3031 v8::Local<v8::Function> callback) {
3030 scoped_ptr<InvokeCallbackTask> task(
3031 new InvokeCallbackTask(this, callback));
3032
3033 delegate_->DispatchBeforeInstallPromptEvent( 3032 delegate_->DispatchBeforeInstallPromptEvent(
3034 request_id, event_platforms, 3033 request_id, event_platforms,
3035 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback, 3034 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback,
3036 weak_factory_.GetWeakPtr(), base::Passed(&task))); 3035 weak_factory_.GetWeakPtr(),
3036 base::Passed(v8::UniquePersistent<v8::Function>(
3037 blink::mainThreadIsolate(), callback))));
3037 } 3038 }
3038 3039
3039 void TestRunner::ResolveBeforeInstallPromptPromise( 3040 void TestRunner::ResolveBeforeInstallPromptPromise(
3040 int request_id, 3041 int request_id,
3041 const std::string& platform) { 3042 const std::string& platform) {
3042 test_interfaces_->GetAppBannerClient()->ResolvePromise(request_id, platform); 3043 test_interfaces_->GetAppBannerClient()->ResolvePromise(request_id, platform);
3043 } 3044 }
3044 3045
3045 void TestRunner::SetPOSIXLocale(const std::string& locale) { 3046 void TestRunner::SetPOSIXLocale(const std::string& locale) {
3046 delegate_->SetLocale(locale); 3047 delegate_->SetLocale(locale);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3097 void TestRunner::RemoveWebPageOverlay() { 3098 void TestRunner::RemoveWebPageOverlay() {
3098 if (web_view_) 3099 if (web_view_)
3099 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT); 3100 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
3100 } 3101 }
3101 3102
3102 void TestRunner::LayoutAndPaintAsync() { 3103 void TestRunner::LayoutAndPaintAsync() {
3103 proxy_->LayoutAndPaintAsyncThen(base::Closure()); 3104 proxy_->LayoutAndPaintAsyncThen(base::Closure());
3104 } 3105 }
3105 3106
3106 void TestRunner::LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback) { 3107 void TestRunner::LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback) {
3107 scoped_ptr<InvokeCallbackTask> task( 3108 proxy_->LayoutAndPaintAsyncThen(CreateClosureThatPostsV8Callback(callback));
3108 new InvokeCallbackTask(this, callback));
3109 proxy_->LayoutAndPaintAsyncThen(base::Bind(&TestRunner::InvokeCallback,
3110 weak_factory_.GetWeakPtr(),
3111 base::Passed(&task)));
3112 } 3109 }
3113 3110
3114 void TestRunner::GetManifestThen(v8::Local<v8::Function> callback) { 3111 void TestRunner::GetManifestThen(v8::Local<v8::Function> callback) {
3115 scoped_ptr<InvokeCallbackTask> task( 3112 v8::UniquePersistent<v8::Function> persistent_callback(
3116 new InvokeCallbackTask(this, callback)); 3113 blink::mainThreadIsolate(), callback);
3114
3115 if (!web_view_) {
3116 WebURLResponse response;
3117 response.setHTTPStatusCode(404);
3118 GetManifestCallback(std::move(persistent_callback), response, "");
3119 return;
3120 }
3117 3121
3118 delegate_->FetchManifest( 3122 delegate_->FetchManifest(
3119 web_view_, web_view_->mainFrame()->document().manifestURL(), 3123 web_view_, web_view_->mainFrame()->document().manifestURL(),
3120 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(), 3124 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(),
3121 base::Passed(&task))); 3125 base::Passed(std::move(persistent_callback))));
3122 } 3126 }
3123 3127
3124 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) { 3128 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) {
3125 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback)); 3129 v8::UniquePersistent<v8::Function> persistent_callback(
3126 DumpPixelsAsync(proxy_->web_view(), 3130 blink::mainThreadIsolate(), callback);
3127 base::Bind(&TestRunner::CapturePixelsCallback, 3131
3128 weak_factory_.GetWeakPtr(), base::Passed(&task))); 3132 if (!web_view_) {
3133 CapturePixelsCallback(std::move(persistent_callback), SkBitmap());
3134 return;
3135 }
3136
3137 DumpPixelsAsync(
3138 proxy_->web_view(),
3139 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(),
3140 base::Passed(std::move(persistent_callback))));
3129 } 3141 }
3130 3142
3131 void TestRunner::OnLayoutTestRuntimeFlagsChanged() { 3143 void TestRunner::OnLayoutTestRuntimeFlagsChanged() {
3132 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty()) 3144 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty())
3133 return; 3145 return;
3134 3146
3135 delegate_->OnLayoutTestRuntimeFlagsChanged( 3147 delegate_->OnLayoutTestRuntimeFlagsChanged(
3136 layout_test_runtime_flags_.tracked_dictionary().changed_values()); 3148 layout_test_runtime_flags_.tracked_dictionary().changed_values());
3137 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking(); 3149 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking();
3138 } 3150 }
3139 3151
3140 void TestRunner::ForceNextWebGLContextCreationToFail() { 3152 void TestRunner::ForceNextWebGLContextCreationToFail() {
3141 if (web_view_) 3153 if (web_view_)
3142 web_view_->forceNextWebGLContextCreationToFail(); 3154 web_view_->forceNextWebGLContextCreationToFail();
3143 } 3155 }
3144 3156
3145 void TestRunner::ForceNextDrawingBufferCreationToFail() { 3157 void TestRunner::ForceNextDrawingBufferCreationToFail() {
3146 if (web_view_) 3158 if (web_view_)
3147 web_view_->forceNextDrawingBufferCreationToFail(); 3159 web_view_->forceNextDrawingBufferCreationToFail();
3148 } 3160 }
3149 3161
3150 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen( 3162 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
3151 int x, int y, v8::Local<v8::Function> callback) { 3163 int x, int y, v8::Local<v8::Function> callback) {
3152 scoped_ptr<InvokeCallbackTask> task( 3164 v8::UniquePersistent<v8::Function> persistent_callback(
3153 new InvokeCallbackTask(this, callback)); 3165 blink::mainThreadIsolate(), callback);
3166
3167 if (!web_view_) {
3168 CapturePixelsCallback(std::move(persistent_callback), SkBitmap());
3169 return;
3170 }
3171
3154 CopyImageAtAndCapturePixels( 3172 CopyImageAtAndCapturePixels(
3155 proxy_->web_view(), x, y, 3173 proxy_->web_view(), x, y,
3156 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(), 3174 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(),
3157 base::Passed(&task))); 3175 base::Passed(std::move(persistent_callback))));
3158 } 3176 }
3159 3177
3160 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task, 3178 void TestRunner::GetManifestCallback(
3161 const blink::WebURLResponse& response, 3179 v8::UniquePersistent<v8::Function> callback,
3162 const std::string& data) { 3180 const blink::WebURLResponse& response,
3163 InvokeCallback(std::move(task)); 3181 const std::string& data) {
3182 PostV8CallbackWithArgs(std::move(callback), 0, nullptr);
3164 } 3183 }
3165 3184
3166 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, 3185 void TestRunner::CapturePixelsCallback(
3167 const SkBitmap& snapshot) { 3186 v8::UniquePersistent<v8::Function> callback,
3187 const SkBitmap& snapshot) {
3188 if (!web_view_)
3189 return;
3190
3168 v8::Isolate* isolate = blink::mainThreadIsolate(); 3191 v8::Isolate* isolate = blink::mainThreadIsolate();
3169 v8::HandleScope handle_scope(isolate); 3192 v8::HandleScope handle_scope(isolate);
3170 3193
3171 v8::Local<v8::Context> context = 3194 v8::Local<v8::Context> context =
3172 web_view_->mainFrame()->mainWorldScriptContext(); 3195 web_view_->mainFrame()->mainWorldScriptContext();
3173 if (context.IsEmpty()) 3196 if (context.IsEmpty())
3174 return; 3197 return;
3175 3198
3176 v8::Context::Scope context_scope(context); 3199 v8::Context::Scope context_scope(context);
3177 v8::Local<v8::Value> argv[3]; 3200 v8::Local<v8::Value> argv[3];
(...skipping 18 matching lines...) Expand all
3196 buffer.data(), 3219 buffer.data(),
3197 bufferRowBytes, 3220 bufferRowBytes,
3198 0, 0)) { 3221 0, 0)) {
3199 // We only expect readPixels to fail for null bitmaps. 3222 // We only expect readPixels to fail for null bitmaps.
3200 DCHECK(snapshot.isNull()); 3223 DCHECK(snapshot.isNull());
3201 } 3224 }
3202 3225
3203 argv[2] = blink::WebArrayBufferConverter::toV8Value( 3226 argv[2] = blink::WebArrayBufferConverter::toV8Value(
3204 &buffer, context->Global(), isolate); 3227 &buffer, context->Global(), isolate);
3205 3228
3206 task->SetArguments(3, argv); 3229 PostV8CallbackWithArgs(std::move(callback), arraysize(argv), argv);
3207 InvokeCallback(std::move(task));
3208 } 3230 }
3209 3231
3210 void TestRunner::DispatchBeforeInstallPromptCallback( 3232 void TestRunner::DispatchBeforeInstallPromptCallback(
3211 scoped_ptr<InvokeCallbackTask> task, 3233 v8::UniquePersistent<v8::Function> callback,
3212 bool canceled) { 3234 bool canceled) {
3235 if (!web_view_)
3236 return;
3237
3213 v8::Isolate* isolate = blink::mainThreadIsolate(); 3238 v8::Isolate* isolate = blink::mainThreadIsolate();
3214 v8::HandleScope handle_scope(isolate); 3239 v8::HandleScope handle_scope(isolate);
3215 3240
3216 v8::Local<v8::Context> context = 3241 v8::Local<v8::Context> context =
3217 web_view_->mainFrame()->mainWorldScriptContext(); 3242 web_view_->mainFrame()->mainWorldScriptContext();
3218 if (context.IsEmpty()) 3243 if (context.IsEmpty())
3219 return; 3244 return;
3220 3245
3221 v8::Context::Scope context_scope(context); 3246 v8::Context::Scope context_scope(context);
3222 v8::Local<v8::Value> argv[1]; 3247 v8::Local<v8::Value> arg;
3223 argv[0] = v8::Boolean::New(isolate, canceled); 3248 arg = v8::Boolean::New(isolate, canceled);
3224 3249
3225 task->SetArguments(1, argv); 3250 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
3226 InvokeCallback(std::move(task));
3227 } 3251 }
3228 3252
3229 void TestRunner::GetBluetoothManualChooserEventsCallback( 3253 void TestRunner::GetBluetoothManualChooserEventsCallback(
3230 scoped_ptr<InvokeCallbackTask> task, 3254 v8::UniquePersistent<v8::Function> callback,
3231 const std::vector<std::string>& events) { 3255 const std::vector<std::string>& events) {
3256 if (!web_view_)
3257 return;
3258
3232 // Build the V8 context. 3259 // Build the V8 context.
3233 v8::Isolate* isolate = blink::mainThreadIsolate(); 3260 v8::Isolate* isolate = blink::mainThreadIsolate();
3234 v8::HandleScope handle_scope(isolate); 3261 v8::HandleScope handle_scope(isolate);
3235 v8::Local<v8::Context> context = 3262 v8::Local<v8::Context> context =
3236 web_view_->mainFrame()->mainWorldScriptContext(); 3263 web_view_->mainFrame()->mainWorldScriptContext();
3237 if (context.IsEmpty()) 3264 if (context.IsEmpty())
3238 return; 3265 return;
3239 v8::Context::Scope context_scope(context); 3266 v8::Context::Scope context_scope(context);
3240 3267
3241 // Convert the argument. 3268 // Convert the argument.
3242 v8::Local<v8::Value> arg[1]; 3269 v8::Local<v8::Value> arg;
3243 if (!gin::TryConvertToV8(isolate, events, &arg[0])) 3270 if (!gin::TryConvertToV8(isolate, events, &arg))
3244 return; 3271 return;
3245 3272
3246 // Call the callback. 3273 // Call the callback.
3247 task->SetArguments(1, arg); 3274 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
3248 InvokeCallback(std::move(task));
3249 } 3275 }
3250 3276
3251 void TestRunner::LocationChangeDone() { 3277 void TestRunner::LocationChangeDone() {
3252 web_history_item_count_ = delegate_->NavigationEntryCount(); 3278 web_history_item_count_ = delegate_->NavigationEntryCount();
3253 3279
3254 // No more new work after the first complete load. 3280 // No more new work after the first complete load.
3255 work_queue_.set_frozen(true); 3281 work_queue_.set_frozen(true);
3256 3282
3257 if (!layout_test_runtime_flags_.wait_until_done()) 3283 if (!layout_test_runtime_flags_.wait_until_done())
3258 work_queue_.ProcessWorkSoon(); 3284 work_queue_.ProcessWorkSoon();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3304 } 3330 }
3305 3331
3306 void TestRunner::DidLosePointerLockInternal() { 3332 void TestRunner::DidLosePointerLockInternal() {
3307 bool was_locked = pointer_locked_; 3333 bool was_locked = pointer_locked_;
3308 pointer_locked_ = false; 3334 pointer_locked_ = false;
3309 if (was_locked) 3335 if (was_locked)
3310 web_view_->didLosePointerLock(); 3336 web_view_->didLosePointerLock();
3311 } 3337 }
3312 3338
3313 } // namespace test_runner 3339 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/test_runner.h ('k') | components/test_runner/web_task.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698