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

Side by Side Diff: components/test_runner/web_view_test_client.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
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 "components/test_runner/web_view_test_client.h" 5 #include "components/test_runner/web_view_test_client.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
8 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
9 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h" 12 #include "base/time/time.h"
11 #include "components/test_runner/event_sender.h" 13 #include "components/test_runner/event_sender.h"
12 #include "components/test_runner/mock_web_speech_recognizer.h" 14 #include "components/test_runner/mock_web_speech_recognizer.h"
13 #include "components/test_runner/test_common.h" 15 #include "components/test_runner/test_common.h"
14 #include "components/test_runner/test_runner.h" 16 #include "components/test_runner/test_runner.h"
15 #include "components/test_runner/web_task.h" 17 #include "components/test_runner/web_task.h"
16 #include "components/test_runner/web_test_delegate.h" 18 #include "components/test_runner/web_test_delegate.h"
17 #include "components/test_runner/web_test_proxy.h" 19 #include "components/test_runner/web_test_proxy.h"
18 #include "third_party/WebKit/public/platform/WebURLRequest.h" 20 #include "third_party/WebKit/public/platform/WebURLRequest.h"
19 #include "third_party/WebKit/public/web/WebFrame.h" 21 #include "third_party/WebKit/public/web/WebFrame.h"
20 #include "third_party/WebKit/public/web/WebLocalFrame.h" 22 #include "third_party/WebKit/public/web/WebLocalFrame.h"
21 #include "third_party/WebKit/public/web/WebPagePopup.h" 23 #include "third_party/WebKit/public/web/WebPagePopup.h"
22 #include "third_party/WebKit/public/web/WebPrintParams.h" 24 #include "third_party/WebKit/public/web/WebPrintParams.h"
23 #include "third_party/WebKit/public/web/WebView.h" 25 #include "third_party/WebKit/public/web/WebView.h"
24 #include "third_party/WebKit/public/web/WebWidget.h" 26 #include "third_party/WebKit/public/web/WebWidget.h"
25 27
26 namespace test_runner { 28 namespace test_runner {
27 29
28 namespace {
29
30 class HostMethodTask : public WebMethodTask<WebViewTestClient> {
31 public:
32 typedef void (WebViewTestClient::*CallbackMethodType)();
33 HostMethodTask(WebViewTestClient* object, CallbackMethodType callback)
34 : WebMethodTask<WebViewTestClient>(object), callback_(callback) {}
35
36 void RunIfValid() override { (object_->*callback_)(); }
37
38 private:
39 CallbackMethodType callback_;
40 };
41
42 } // namespace
43
44 WebViewTestClient::WebViewTestClient(TestRunner* test_runner, 30 WebViewTestClient::WebViewTestClient(TestRunner* test_runner,
45 WebTestDelegate* delegate, 31 WebTestDelegate* delegate,
46 EventSender* event_sender, 32 EventSender* event_sender,
47 WebTestProxyBase* web_test_proxy_base) 33 WebTestProxyBase* web_test_proxy_base)
48 : test_runner_(test_runner), 34 : test_runner_(test_runner),
49 delegate_(delegate), 35 delegate_(delegate),
50 event_sender_(event_sender), 36 event_sender_(event_sender),
51 web_test_proxy_base_(web_test_proxy_base), 37 web_test_proxy_base_(web_test_proxy_base),
52 animation_scheduled_(false) { 38 animation_scheduled_(false),
39 weak_factory_(this) {
53 DCHECK(test_runner); 40 DCHECK(test_runner);
54 DCHECK(delegate); 41 DCHECK(delegate);
55 DCHECK(event_sender); 42 DCHECK(event_sender);
56 DCHECK(web_test_proxy_base); 43 DCHECK(web_test_proxy_base);
57 } 44 }
58 45
59 WebViewTestClient::~WebViewTestClient() {} 46 WebViewTestClient::~WebViewTestClient() {}
60 47
61 void WebViewTestClient::scheduleAnimation() { 48 void WebViewTestClient::scheduleAnimation() {
62 if (!test_runner_->TestIsRunning()) 49 if (!test_runner_->TestIsRunning())
63 return; 50 return;
64 51
65 if (!animation_scheduled_) { 52 if (!animation_scheduled_) {
66 animation_scheduled_ = true; 53 animation_scheduled_ = true;
67 test_runner_->OnAnimationScheduled(web_test_proxy_base_->web_view()); 54 test_runner_->OnAnimationScheduled(web_test_proxy_base_->web_view());
68 55
69 delegate_->PostDelayedTask( 56 delegate_->PostDelayedTask(
70 new HostMethodTask(this, &WebViewTestClient::AnimateNow), 1); 57 new WebCallbackTask(base::Bind(&WebViewTestClient::AnimateNow,
58 weak_factory_.GetWeakPtr())),
59 1);
71 } 60 }
72 } 61 }
73 62
74 void WebViewTestClient::AnimateNow() { 63 void WebViewTestClient::AnimateNow() {
75 if (animation_scheduled_) { 64 if (animation_scheduled_) {
76 blink::WebWidget* web_widget = web_test_proxy_base_->web_widget(); 65 blink::WebWidget* web_widget = web_test_proxy_base_->web_widget();
77 animation_scheduled_ = false; 66 animation_scheduled_ = false;
78 test_runner_->OnAnimationBegun(web_test_proxy_base_->web_view()); 67 test_runner_->OnAnimationBegun(web_test_proxy_base_->web_view());
79 68
80 base::TimeDelta animate_time = base::TimeTicks::Now() - base::TimeTicks(); 69 base::TimeDelta animate_time = base::TimeTicks::Now() - base::TimeTicks();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // to cancel the input method's ongoing composition session. 210 // to cancel the input method's ongoing composition session.
222 if (web_test_proxy_base_) 211 if (web_test_proxy_base_)
223 web_test_proxy_base_->web_widget()->confirmComposition(); 212 web_test_proxy_base_->web_widget()->confirmComposition();
224 } 213 }
225 214
226 blink::WebString WebViewTestClient::acceptLanguages() { 215 blink::WebString WebViewTestClient::acceptLanguages() {
227 return blink::WebString::fromUTF8(test_runner_->GetAcceptLanguages()); 216 return blink::WebString::fromUTF8(test_runner_->GetAcceptLanguages());
228 } 217 }
229 218
230 } // namespace test_runner 219 } // namespace test_runner
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698