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

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: Fixing a test. 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
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 return intercept_post_message_; 2027 return intercept_post_message_;
2023 } 2028 }
2024 2029
2025 bool TestRunner::shouldDumpResourcePriorities() const { 2030 bool TestRunner::shouldDumpResourcePriorities() const {
2026 return should_dump_resource_priorities_; 2031 return should_dump_resource_priorities_;
2027 } 2032 }
2028 2033
2029 bool TestRunner::RequestPointerLock() { 2034 bool TestRunner::RequestPointerLock() {
2030 switch (pointer_lock_planned_result_) { 2035 switch (pointer_lock_planned_result_) {
2031 case PointerLockWillSucceed: 2036 case PointerLockWillSucceed:
2032 delegate_->PostDelayedTask( 2037 PostDelayedTask(0, base::Bind(&TestRunner::DidAcquirePointerLockInternal,
2033 new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal), 2038 weak_factory_.GetWeakPtr()));
2034 0);
2035 return true; 2039 return true;
2036 case PointerLockWillRespondAsync: 2040 case PointerLockWillRespondAsync:
2037 DCHECK(!pointer_locked_); 2041 DCHECK(!pointer_locked_);
2038 return true; 2042 return true;
2039 case PointerLockWillFailSync: 2043 case PointerLockWillFailSync:
2040 DCHECK(!pointer_locked_); 2044 DCHECK(!pointer_locked_);
2041 return false; 2045 return false;
2042 default: 2046 default:
2043 NOTREACHED(); 2047 NOTREACHED();
2044 return false; 2048 return false;
2045 } 2049 }
2046 } 2050 }
2047 2051
2048 void TestRunner::RequestPointerUnlock() { 2052 void TestRunner::RequestPointerUnlock() {
2049 delegate_->PostDelayedTask( 2053 PostDelayedTask(0, base::Bind(&TestRunner::DidLosePointerLockInternal,
2050 new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0); 2054 weak_factory_.GetWeakPtr()));
2051 } 2055 }
2052 2056
2053 bool TestRunner::isPointerLocked() { 2057 bool TestRunner::isPointerLocked() {
2054 return pointer_locked_; 2058 return pointer_locked_;
2055 } 2059 }
2056 2060
2057 void TestRunner::setToolTipText(const WebString& text) { 2061 void TestRunner::setToolTipText(const WebString& text) {
2058 tooltip_text_ = text.utf8(); 2062 tooltip_text_ = text.utf8();
2059 } 2063 }
2060 2064
(...skipping 29 matching lines...) Expand all
2090 bool Run(WebTestDelegate* delegate, WebView*) override { 2094 bool Run(WebTestDelegate* delegate, WebView*) override {
2091 delegate->GoToOffset(distance_); 2095 delegate->GoToOffset(distance_);
2092 return true; // FIXME: Did it really start a navigation? 2096 return true; // FIXME: Did it really start a navigation?
2093 } 2097 }
2094 2098
2095 private: 2099 private:
2096 int distance_; 2100 int distance_;
2097 }; 2101 };
2098 2102
2099 void TestRunner::NotifyDone() { 2103 void TestRunner::NotifyDone() {
2100 // Test didn't timeout. Kill the timeout timer. 2104 // Test didn't timeout. Kill the pending callbacks.
2101 task_list_.RevokeAll(); 2105 weak_factory_.InvalidateWeakPtrs();
2102 2106
2103 CompleteNotifyDone(); 2107 CompleteNotifyDone();
2104 } 2108 }
2105 2109
2106 void TestRunner::WaitUntilDone() { 2110 void TestRunner::WaitUntilDone() {
2107 layout_test_runtime_flags_.set_wait_until_done(true); 2111 layout_test_runtime_flags_.set_wait_until_done(true);
2108 OnLayoutTestRuntimeFlagsChanged(); 2112 OnLayoutTestRuntimeFlagsChanged();
2109 } 2113 }
2110 2114
2111 void TestRunner::QueueBackNavigation(int how_far_back) { 2115 void TestRunner::QueueBackNavigation(int how_far_back) {
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 delegate_->SetFocus(proxy_->web_view(), value); 2969 delegate_->SetFocus(proxy_->web_view(), value);
2966 } 2970 }
2967 2971
2968 std::string TestRunner::PathToLocalResource(const std::string& path) { 2972 std::string TestRunner::PathToLocalResource(const std::string& path) {
2969 return delegate_->PathToLocalResource(path); 2973 return delegate_->PathToLocalResource(path);
2970 } 2974 }
2971 2975
2972 void TestRunner::SetBackingScaleFactor(double value, 2976 void TestRunner::SetBackingScaleFactor(double value,
2973 v8::Local<v8::Function> callback) { 2977 v8::Local<v8::Function> callback) {
2974 delegate_->SetDeviceScaleFactor(value); 2978 delegate_->SetDeviceScaleFactor(value);
2975 delegate_->PostTask(new InvokeCallbackTask(this, callback)); 2979 PostV8Callback(callback);
2976 } 2980 }
2977 2981
2978 void TestRunner::EnableUseZoomForDSF(v8::Local<v8::Function> callback) { 2982 void TestRunner::EnableUseZoomForDSF(v8::Local<v8::Function> callback) {
2979 delegate_->EnableUseZoomForDSF(); 2983 delegate_->EnableUseZoomForDSF();
2980 delegate_->PostTask(new InvokeCallbackTask(this, callback)); 2984 PostV8Callback(callback);
2981 } 2985 }
2982 2986
2983 void TestRunner::SetColorProfile(const std::string& name, 2987 void TestRunner::SetColorProfile(const std::string& name,
2984 v8::Local<v8::Function> callback) { 2988 v8::Local<v8::Function> callback) {
2985 delegate_->SetDeviceColorProfile(name); 2989 delegate_->SetDeviceColorProfile(name);
2986 delegate_->PostTask(new InvokeCallbackTask(this, callback)); 2990 PostV8Callback(callback);
2987 } 2991 }
2988 2992
2989 void TestRunner::SetBluetoothFakeAdapter(const std::string& adapter_name, 2993 void TestRunner::SetBluetoothFakeAdapter(const std::string& adapter_name,
2990 v8::Local<v8::Function> callback) { 2994 v8::Local<v8::Function> callback) {
2991 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback));
2992 delegate_->SetBluetoothFakeAdapter( 2995 delegate_->SetBluetoothFakeAdapter(
2993 adapter_name, 2996 adapter_name, CreateClosureThatPostsV8Callback(callback));
2994 base::Bind(&TestRunner::InvokeCallback, weak_factory_.GetWeakPtr(),
2995 base::Passed(&task)));
2996 } 2997 }
2997 2998
2998 void TestRunner::SetBluetoothManualChooser(bool enable) { 2999 void TestRunner::SetBluetoothManualChooser(bool enable) {
2999 delegate_->SetBluetoothManualChooser(enable); 3000 delegate_->SetBluetoothManualChooser(enable);
3000 } 3001 }
3001 3002
3002 void TestRunner::GetBluetoothManualChooserEvents( 3003 void TestRunner::GetBluetoothManualChooserEvents(
3003 v8::Local<v8::Function> callback) { 3004 v8::Local<v8::Function> callback) {
3004 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback));
3005 return delegate_->GetBluetoothManualChooserEvents( 3005 return delegate_->GetBluetoothManualChooserEvents(
3006 base::Bind(&TestRunner::GetBluetoothManualChooserEventsCallback, 3006 base::Bind(&TestRunner::GetBluetoothManualChooserEventsCallback,
3007 weak_factory_.GetWeakPtr(), base::Passed(&task))); 3007 weak_factory_.GetWeakPtr(),
3008 base::Passed(v8::UniquePersistent<v8::Function>(
3009 blink::mainThreadIsolate(), callback))));
3008 } 3010 }
3009 3011
3010 void TestRunner::SendBluetoothManualChooserEvent(const std::string& event, 3012 void TestRunner::SendBluetoothManualChooserEvent(const std::string& event,
3011 const std::string& argument) { 3013 const std::string& argument) {
3012 delegate_->SendBluetoothManualChooserEvent(event, argument); 3014 delegate_->SendBluetoothManualChooserEvent(event, argument);
3013 } 3015 }
3014 3016
3015 void TestRunner::SetGeofencingMockProvider(bool service_available) { 3017 void TestRunner::SetGeofencingMockProvider(bool service_available) {
3016 delegate_->SetGeofencingMockProvider(service_available); 3018 delegate_->SetGeofencingMockProvider(service_available);
3017 } 3019 }
(...skipping 10 matching lines...) Expand all
3028 const std::string& value, 3030 const std::string& value,
3029 const GURL& origin, 3031 const GURL& origin,
3030 const GURL& embedding_origin) { 3032 const GURL& embedding_origin) {
3031 delegate_->SetPermission(name, value, origin, embedding_origin); 3033 delegate_->SetPermission(name, value, origin, embedding_origin);
3032 } 3034 }
3033 3035
3034 void TestRunner::DispatchBeforeInstallPromptEvent( 3036 void TestRunner::DispatchBeforeInstallPromptEvent(
3035 int request_id, 3037 int request_id,
3036 const std::vector<std::string>& event_platforms, 3038 const std::vector<std::string>& event_platforms,
3037 v8::Local<v8::Function> callback) { 3039 v8::Local<v8::Function> callback) {
3038 scoped_ptr<InvokeCallbackTask> task(
3039 new InvokeCallbackTask(this, callback));
3040
3041 delegate_->DispatchBeforeInstallPromptEvent( 3040 delegate_->DispatchBeforeInstallPromptEvent(
3042 request_id, event_platforms, 3041 request_id, event_platforms,
3043 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback, 3042 base::Bind(&TestRunner::DispatchBeforeInstallPromptCallback,
3044 weak_factory_.GetWeakPtr(), base::Passed(&task))); 3043 weak_factory_.GetWeakPtr(),
3044 base::Passed(v8::UniquePersistent<v8::Function>(
3045 blink::mainThreadIsolate(), callback))));
3045 } 3046 }
3046 3047
3047 void TestRunner::ResolveBeforeInstallPromptPromise( 3048 void TestRunner::ResolveBeforeInstallPromptPromise(
3048 int request_id, 3049 int request_id,
3049 const std::string& platform) { 3050 const std::string& platform) {
3050 test_interfaces_->GetAppBannerClient()->ResolvePromise(request_id, platform); 3051 test_interfaces_->GetAppBannerClient()->ResolvePromise(request_id, platform);
3051 } 3052 }
3052 3053
3053 void TestRunner::SetPOSIXLocale(const std::string& locale) { 3054 void TestRunner::SetPOSIXLocale(const std::string& locale) {
3054 delegate_->SetLocale(locale); 3055 delegate_->SetLocale(locale);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3105 void TestRunner::RemoveWebPageOverlay() { 3106 void TestRunner::RemoveWebPageOverlay() {
3106 if (web_view_) 3107 if (web_view_)
3107 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT); 3108 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
3108 } 3109 }
3109 3110
3110 void TestRunner::LayoutAndPaintAsync() { 3111 void TestRunner::LayoutAndPaintAsync() {
3111 proxy_->LayoutAndPaintAsyncThen(base::Closure()); 3112 proxy_->LayoutAndPaintAsyncThen(base::Closure());
3112 } 3113 }
3113 3114
3114 void TestRunner::LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback) { 3115 void TestRunner::LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback) {
3115 scoped_ptr<InvokeCallbackTask> task( 3116 proxy_->LayoutAndPaintAsyncThen(CreateClosureThatPostsV8Callback(callback));
3116 new InvokeCallbackTask(this, callback));
3117 proxy_->LayoutAndPaintAsyncThen(base::Bind(&TestRunner::InvokeCallback,
3118 weak_factory_.GetWeakPtr(),
3119 base::Passed(&task)));
3120 } 3117 }
3121 3118
3122 void TestRunner::GetManifestThen(v8::Local<v8::Function> callback) { 3119 void TestRunner::GetManifestThen(v8::Local<v8::Function> callback) {
3123 scoped_ptr<InvokeCallbackTask> task( 3120 v8::UniquePersistent<v8::Function> persistent_callback(
3124 new InvokeCallbackTask(this, callback)); 3121 blink::mainThreadIsolate(), callback);
3122
3123 if (!web_view_) {
3124 WebURLResponse response;
3125 response.setHTTPStatusCode(404);
3126 GetManifestCallback(std::move(persistent_callback), response, "");
3127 return;
3128 }
3125 3129
3126 delegate_->FetchManifest( 3130 delegate_->FetchManifest(
3127 web_view_, web_view_->mainFrame()->document().manifestURL(), 3131 web_view_, web_view_->mainFrame()->document().manifestURL(),
3128 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(), 3132 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(),
3129 base::Passed(&task))); 3133 base::Passed(std::move(persistent_callback))));
3130 } 3134 }
3131 3135
3132 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) { 3136 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) {
3133 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback)); 3137 v8::UniquePersistent<v8::Function> persistent_callback(
3134 DumpPixelsAsync(proxy_->web_view(), 3138 blink::mainThreadIsolate(), callback);
3135 base::Bind(&TestRunner::CapturePixelsCallback, 3139
3136 weak_factory_.GetWeakPtr(), base::Passed(&task))); 3140 if (!web_view_) {
3141 CapturePixelsCallback(std::move(persistent_callback), SkBitmap());
3142 return;
3143 }
3144
3145 DumpPixelsAsync(
3146 proxy_->web_view(),
3147 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(),
3148 base::Passed(std::move(persistent_callback))));
3137 } 3149 }
3138 3150
3139 void TestRunner::OnLayoutTestRuntimeFlagsChanged() { 3151 void TestRunner::OnLayoutTestRuntimeFlagsChanged() {
3140 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty()) 3152 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty())
3141 return; 3153 return;
3142 3154
3143 delegate_->OnLayoutTestRuntimeFlagsChanged( 3155 delegate_->OnLayoutTestRuntimeFlagsChanged(
3144 layout_test_runtime_flags_.tracked_dictionary().changed_values()); 3156 layout_test_runtime_flags_.tracked_dictionary().changed_values());
3145 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking(); 3157 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking();
3146 } 3158 }
3147 3159
3148 void TestRunner::ForceNextWebGLContextCreationToFail() { 3160 void TestRunner::ForceNextWebGLContextCreationToFail() {
3149 if (web_view_) 3161 if (web_view_)
3150 web_view_->forceNextWebGLContextCreationToFail(); 3162 web_view_->forceNextWebGLContextCreationToFail();
3151 } 3163 }
3152 3164
3153 void TestRunner::ForceNextDrawingBufferCreationToFail() { 3165 void TestRunner::ForceNextDrawingBufferCreationToFail() {
3154 if (web_view_) 3166 if (web_view_)
3155 web_view_->forceNextDrawingBufferCreationToFail(); 3167 web_view_->forceNextDrawingBufferCreationToFail();
3156 } 3168 }
3157 3169
3158 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen( 3170 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
3159 int x, int y, v8::Local<v8::Function> callback) { 3171 int x, int y, v8::Local<v8::Function> callback) {
3160 scoped_ptr<InvokeCallbackTask> task( 3172 v8::UniquePersistent<v8::Function> persistent_callback(
3161 new InvokeCallbackTask(this, callback)); 3173 blink::mainThreadIsolate(), callback);
3174
3175 if (!web_view_) {
3176 CapturePixelsCallback(std::move(persistent_callback), SkBitmap());
3177 return;
3178 }
3179
3162 CopyImageAtAndCapturePixels( 3180 CopyImageAtAndCapturePixels(
3163 proxy_->web_view(), x, y, 3181 proxy_->web_view(), x, y,
3164 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(), 3182 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(),
3165 base::Passed(&task))); 3183 base::Passed(std::move(persistent_callback))));
3166 } 3184 }
3167 3185
3168 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task, 3186 void TestRunner::GetManifestCallback(
3169 const blink::WebURLResponse& response, 3187 v8::UniquePersistent<v8::Function> callback,
3170 const std::string& data) { 3188 const blink::WebURLResponse& response,
3171 InvokeCallback(std::move(task)); 3189 const std::string& data) {
3190 PostV8CallbackWithArgs(std::move(callback), 0, nullptr);
3172 } 3191 }
3173 3192
3174 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, 3193 void TestRunner::CapturePixelsCallback(
3175 const SkBitmap& snapshot) { 3194 v8::UniquePersistent<v8::Function> callback,
3195 const SkBitmap& snapshot) {
3196 if (!web_view_)
3197 return;
3198
3176 v8::Isolate* isolate = blink::mainThreadIsolate(); 3199 v8::Isolate* isolate = blink::mainThreadIsolate();
3177 v8::HandleScope handle_scope(isolate); 3200 v8::HandleScope handle_scope(isolate);
3178 3201
3179 v8::Local<v8::Context> context = 3202 v8::Local<v8::Context> context =
3180 web_view_->mainFrame()->mainWorldScriptContext(); 3203 web_view_->mainFrame()->mainWorldScriptContext();
3181 if (context.IsEmpty()) 3204 if (context.IsEmpty())
3182 return; 3205 return;
3183 3206
3184 v8::Context::Scope context_scope(context); 3207 v8::Context::Scope context_scope(context);
3185 v8::Local<v8::Value> argv[3]; 3208 v8::Local<v8::Value> argv[3];
(...skipping 18 matching lines...) Expand all
3204 buffer.data(), 3227 buffer.data(),
3205 bufferRowBytes, 3228 bufferRowBytes,
3206 0, 0)) { 3229 0, 0)) {
3207 // We only expect readPixels to fail for null bitmaps. 3230 // We only expect readPixels to fail for null bitmaps.
3208 DCHECK(snapshot.isNull()); 3231 DCHECK(snapshot.isNull());
3209 } 3232 }
3210 3233
3211 argv[2] = blink::WebArrayBufferConverter::toV8Value( 3234 argv[2] = blink::WebArrayBufferConverter::toV8Value(
3212 &buffer, context->Global(), isolate); 3235 &buffer, context->Global(), isolate);
3213 3236
3214 task->SetArguments(3, argv); 3237 PostV8CallbackWithArgs(std::move(callback), arraysize(argv), argv);
3215 InvokeCallback(std::move(task));
3216 } 3238 }
3217 3239
3218 void TestRunner::DispatchBeforeInstallPromptCallback( 3240 void TestRunner::DispatchBeforeInstallPromptCallback(
3219 scoped_ptr<InvokeCallbackTask> task, 3241 v8::UniquePersistent<v8::Function> callback,
3220 bool canceled) { 3242 bool canceled) {
3243 if (!web_view_)
3244 return;
3245
3221 v8::Isolate* isolate = blink::mainThreadIsolate(); 3246 v8::Isolate* isolate = blink::mainThreadIsolate();
3222 v8::HandleScope handle_scope(isolate); 3247 v8::HandleScope handle_scope(isolate);
3223 3248
3224 v8::Local<v8::Context> context = 3249 v8::Local<v8::Context> context =
3225 web_view_->mainFrame()->mainWorldScriptContext(); 3250 web_view_->mainFrame()->mainWorldScriptContext();
3226 if (context.IsEmpty()) 3251 if (context.IsEmpty())
3227 return; 3252 return;
3228 3253
3229 v8::Context::Scope context_scope(context); 3254 v8::Context::Scope context_scope(context);
3230 v8::Local<v8::Value> argv[1]; 3255 v8::Local<v8::Value> arg;
3231 argv[0] = v8::Boolean::New(isolate, canceled); 3256 arg = v8::Boolean::New(isolate, canceled);
3232 3257
3233 task->SetArguments(1, argv); 3258 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
3234 InvokeCallback(std::move(task));
3235 } 3259 }
3236 3260
3237 void TestRunner::GetBluetoothManualChooserEventsCallback( 3261 void TestRunner::GetBluetoothManualChooserEventsCallback(
3238 scoped_ptr<InvokeCallbackTask> task, 3262 v8::UniquePersistent<v8::Function> callback,
3239 const std::vector<std::string>& events) { 3263 const std::vector<std::string>& events) {
3264 if (!web_view_)
3265 return;
3266
3240 // Build the V8 context. 3267 // Build the V8 context.
3241 v8::Isolate* isolate = blink::mainThreadIsolate(); 3268 v8::Isolate* isolate = blink::mainThreadIsolate();
3242 v8::HandleScope handle_scope(isolate); 3269 v8::HandleScope handle_scope(isolate);
3243 v8::Local<v8::Context> context = 3270 v8::Local<v8::Context> context =
3244 web_view_->mainFrame()->mainWorldScriptContext(); 3271 web_view_->mainFrame()->mainWorldScriptContext();
3245 if (context.IsEmpty()) 3272 if (context.IsEmpty())
3246 return; 3273 return;
3247 v8::Context::Scope context_scope(context); 3274 v8::Context::Scope context_scope(context);
3248 3275
3249 // Convert the argument. 3276 // Convert the argument.
3250 v8::Local<v8::Value> arg[1]; 3277 v8::Local<v8::Value> arg;
3251 if (!gin::TryConvertToV8(isolate, events, &arg[0])) 3278 if (!gin::TryConvertToV8(isolate, events, &arg))
3252 return; 3279 return;
3253 3280
3254 // Call the callback. 3281 // Call the callback.
3255 task->SetArguments(1, arg); 3282 PostV8CallbackWithArgs(std::move(callback), 1, &arg);
3256 InvokeCallback(std::move(task));
3257 } 3283 }
3258 3284
3259 void TestRunner::LocationChangeDone() { 3285 void TestRunner::LocationChangeDone() {
3260 web_history_item_count_ = delegate_->NavigationEntryCount(); 3286 web_history_item_count_ = delegate_->NavigationEntryCount();
3261 3287
3262 // No more new work after the first complete load. 3288 // No more new work after the first complete load.
3263 work_queue_.set_frozen(true); 3289 work_queue_.set_frozen(true);
3264 3290
3265 if (!layout_test_runtime_flags_.wait_until_done()) 3291 if (!layout_test_runtime_flags_.wait_until_done())
3266 work_queue_.ProcessWorkSoon(); 3292 work_queue_.ProcessWorkSoon();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3312 } 3338 }
3313 3339
3314 void TestRunner::DidLosePointerLockInternal() { 3340 void TestRunner::DidLosePointerLockInternal() {
3315 bool was_locked = pointer_locked_; 3341 bool was_locked = pointer_locked_;
3316 pointer_locked_ = false; 3342 pointer_locked_ = false;
3317 if (was_locked) 3343 if (was_locked)
3318 web_view_->didLosePointerLock(); 3344 web_view_->didLosePointerLock();
3319 } 3345 }
3320 3346
3321 } // namespace test_runner 3347 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698