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

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

Issue 1840823002: Extract WebViewClient implementation out of WebTestProxyBase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@separate-pixel-dump-code
Patch Set: Expanding a comment + an IWYU fix. 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/test_runner.gyp » ('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
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 runner_->SetAcceptLanguages(accept_languages); 1088 runner_->SetAcceptLanguages(accept_languages);
1089 } 1089 }
1090 1090
1091 void TestRunnerBindings::SetPluginsEnabled(bool enabled) { 1091 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
1092 if (runner_) 1092 if (runner_)
1093 runner_->SetPluginsEnabled(enabled); 1093 runner_->SetPluginsEnabled(enabled);
1094 } 1094 }
1095 1095
1096 bool TestRunnerBindings::AnimationScheduled() { 1096 bool TestRunnerBindings::AnimationScheduled() {
1097 if (runner_) 1097 if (runner_)
1098 return runner_->AnimationScheduled(); 1098 return runner_->GetAnimationScheduled();
1099 else 1099 else
1100 return false; 1100 return false;
1101 } 1101 }
1102 1102
1103 void TestRunnerBindings::DumpEditingCallbacks() { 1103 void TestRunnerBindings::DumpEditingCallbacks() {
1104 if (runner_) 1104 if (runner_)
1105 runner_->DumpEditingCallbacks(); 1105 runner_->DumpEditingCallbacks();
1106 } 1106 }
1107 1107
1108 void TestRunnerBindings::DumpAsMarkup() { 1108 void TestRunnerBindings::DumpAsMarkup() {
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 1676
1677 TestRunner::~TestRunner() {} 1677 TestRunner::~TestRunner() {}
1678 1678
1679 void TestRunner::Install(WebFrame* frame) { 1679 void TestRunner::Install(WebFrame* frame) {
1680 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), frame); 1680 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), frame);
1681 } 1681 }
1682 1682
1683 void TestRunner::SetDelegate(WebTestDelegate* delegate) { 1683 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1684 delegate_ = delegate; 1684 delegate_ = delegate;
1685 web_content_settings_->SetDelegate(delegate); 1685 web_content_settings_->SetDelegate(delegate);
1686 if (speech_recognizer_)
1687 speech_recognizer_->SetDelegate(delegate);
1686 } 1688 }
1687 1689
1688 void TestRunner::SetWebView(WebView* webView, WebTestProxyBase* proxy) { 1690 void TestRunner::SetWebView(WebView* webView, WebTestProxyBase* proxy) {
1689 web_view_ = webView; 1691 web_view_ = webView;
1690 proxy_ = proxy; 1692 proxy_ = proxy;
1691 } 1693 }
1692 1694
1693 void TestRunner::Reset() { 1695 void TestRunner::Reset() {
1694 if (web_view_) { 1696 if (web_view_) {
1695 web_view_->setZoomLevel(0); 1697 web_view_->setZoomLevel(0);
1696 web_view_->setTextZoomFactor(1); 1698 web_view_->setTextZoomFactor(1);
1697 web_view_->setTabKeyCyclesThroughElements(true); 1699 web_view_->setTabKeyCyclesThroughElements(true);
1698 #if !defined(OS_MACOSX) && !defined(OS_WIN) 1700 #if !defined(OS_MACOSX) && !defined(OS_WIN)
1699 // (Constants copied because we can't depend on the header that defined 1701 // (Constants copied because we can't depend on the header that defined
1700 // them from this file.) 1702 // them from this file.)
1701 web_view_->setSelectionColors( 1703 web_view_->setSelectionColors(
1702 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232); 1704 0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1703 #endif 1705 #endif
1704 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true); 1706 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true);
1705 web_view_->mainFrame()->enableViewSourceMode(false); 1707 web_view_->mainFrame()->enableViewSourceMode(false);
1706 1708
1707 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT); 1709 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
1708 } 1710 }
1709 1711
1710 top_loading_frame_ = nullptr; 1712 top_loading_frame_ = nullptr;
1711 layout_test_runtime_flags_.Reset(); 1713 layout_test_runtime_flags_.Reset();
1712 mock_screen_orientation_client_->ResetData(); 1714 mock_screen_orientation_client_->ResetData();
1713 drag_image_.reset(); 1715 drag_image_.reset();
1716 views_with_scheduled_animations_.clear();
1714 wait_until_external_url_load_ = false; 1717 wait_until_external_url_load_ = false;
1715 1718
1716 WebSecurityPolicy::resetOriginAccessWhitelists(); 1719 WebSecurityPolicy::resetOriginAccessWhitelists();
1717 #if defined(__linux__) || defined(ANDROID) 1720 #if defined(__linux__) || defined(ANDROID)
1718 WebFontRendering::setSubpixelPositioning(false); 1721 WebFontRendering::setSubpixelPositioning(false);
1719 #endif 1722 #endif
1720 1723
1721 if (delegate_) { 1724 if (delegate_) {
1722 // Reset the default quota for each origin to 5MB 1725 // Reset the default quota for each origin to 5MB
1723 delegate_->SetDatabaseQuota(5 * 1024 * 1024); 1726 delegate_->SetDatabaseQuota(5 * 1024 * 1024);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1863 bitmap.eraseColor(0); 1866 bitmap.eraseColor(0);
1864 } 1867 }
1865 callback.Run(bitmap); 1868 callback.Run(bitmap);
1866 return; 1869 return;
1867 } 1870 }
1868 1871
1869 callback.Run(drag_image_.getSkBitmap()); 1872 callback.Run(drag_image_.getSkBitmap());
1870 return; 1873 return;
1871 } 1874 }
1872 1875
1873 test_runner::DumpPixelsAsync(proxy_->GetWebView(), layout_test_runtime_flags_, 1876 test_runner::DumpPixelsAsync(proxy_->web_view(), layout_test_runtime_flags_,
1874 delegate_->GetDeviceScaleFactorForTest(), 1877 delegate_->GetDeviceScaleFactorForTest(),
1875 callback); 1878 callback);
1876 } 1879 }
1877 1880
1878 void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges( 1881 void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges(
1879 const base::DictionaryValue& changed_values) { 1882 const base::DictionaryValue& changed_values) {
1880 layout_test_runtime_flags_.tracked_dictionary().ApplyUntrackedChanges( 1883 layout_test_runtime_flags_.tracked_dictionary().ApplyUntrackedChanges(
1881 changed_values); 1884 changed_values);
1882 } 1885 }
1883 1886
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
2547 MockScreenOrientationClient* TestRunner::getMockScreenOrientationClient() { 2550 MockScreenOrientationClient* TestRunner::getMockScreenOrientationClient() {
2548 return mock_screen_orientation_client_.get(); 2551 return mock_screen_orientation_client_.get();
2549 } 2552 }
2550 2553
2551 MockWebUserMediaClient* TestRunner::getMockWebUserMediaClient() { 2554 MockWebUserMediaClient* TestRunner::getMockWebUserMediaClient() {
2552 if (!user_media_client_.get()) 2555 if (!user_media_client_.get())
2553 user_media_client_.reset(new MockWebUserMediaClient(delegate_)); 2556 user_media_client_.reset(new MockWebUserMediaClient(delegate_));
2554 return user_media_client_.get(); 2557 return user_media_client_.get();
2555 } 2558 }
2556 2559
2560 MockWebSpeechRecognizer* TestRunner::getMockWebSpeechRecognizer() {
2561 if (!speech_recognizer_.get()) {
2562 speech_recognizer_.reset(new MockWebSpeechRecognizer());
2563 speech_recognizer_->SetDelegate(delegate_);
2564 }
2565 return speech_recognizer_.get();
2566 }
2567
2557 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) { 2568 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2558 blink::WebScreenOrientationType orientation; 2569 blink::WebScreenOrientationType orientation;
2559 2570
2560 if (orientation_str == "portrait-primary") { 2571 if (orientation_str == "portrait-primary") {
2561 orientation = WebScreenOrientationPortraitPrimary; 2572 orientation = WebScreenOrientationPortraitPrimary;
2562 } else if (orientation_str == "portrait-secondary") { 2573 } else if (orientation_str == "portrait-secondary") {
2563 orientation = WebScreenOrientationPortraitSecondary; 2574 orientation = WebScreenOrientationPortraitSecondary;
2564 } else if (orientation_str == "landscape-primary") { 2575 } else if (orientation_str == "landscape-primary") {
2565 orientation = WebScreenOrientationLandscapePrimary; 2576 orientation = WebScreenOrientationLandscapePrimary;
2566 } else { 2577 } else {
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 std::string TestRunner::GetAcceptLanguages() const { 2698 std::string TestRunner::GetAcceptLanguages() const {
2688 return layout_test_runtime_flags_.accept_languages(); 2699 return layout_test_runtime_flags_.accept_languages();
2689 } 2700 }
2690 2701
2691 void TestRunner::SetAcceptLanguages(const std::string& accept_languages) { 2702 void TestRunner::SetAcceptLanguages(const std::string& accept_languages) {
2692 if (accept_languages == GetAcceptLanguages()) 2703 if (accept_languages == GetAcceptLanguages())
2693 return; 2704 return;
2694 2705
2695 layout_test_runtime_flags_.set_accept_languages(accept_languages); 2706 layout_test_runtime_flags_.set_accept_languages(accept_languages);
2696 OnLayoutTestRuntimeFlagsChanged(); 2707 OnLayoutTestRuntimeFlagsChanged();
2697 proxy_->GetWebView()->acceptLanguagesChanged(); 2708 proxy_->web_view()->acceptLanguagesChanged();
2698 } 2709 }
2699 2710
2700 void TestRunner::SetPluginsEnabled(bool enabled) { 2711 void TestRunner::SetPluginsEnabled(bool enabled) {
2701 delegate_->Preferences()->plugins_enabled = enabled; 2712 delegate_->Preferences()->plugins_enabled = enabled;
2702 delegate_->ApplyPreferences(); 2713 delegate_->ApplyPreferences();
2703 } 2714 }
2704 2715
2705 bool TestRunner::AnimationScheduled() { 2716 bool TestRunner::GetAnimationScheduled() const {
2706 return proxy_->AnimationScheduled(); 2717 bool is_animation_scheduled = !views_with_scheduled_animations_.empty();
2718 return is_animation_scheduled;
2719 }
2720
2721 void TestRunner::OnAnimationScheduled(blink::WebView* view) {
2722 views_with_scheduled_animations_.insert(view);
2723 }
2724
2725 void TestRunner::OnAnimationBegun(blink::WebView* view) {
2726 views_with_scheduled_animations_.erase(view);
2707 } 2727 }
2708 2728
2709 void TestRunner::DumpEditingCallbacks() { 2729 void TestRunner::DumpEditingCallbacks() {
2710 dump_editting_callbacks_ = true; 2730 dump_editting_callbacks_ = true;
2711 } 2731 }
2712 2732
2713 void TestRunner::DumpAsMarkup() { 2733 void TestRunner::DumpAsMarkup() {
2714 layout_test_runtime_flags_.set_dump_as_markup(true); 2734 layout_test_runtime_flags_.set_dump_as_markup(true);
2715 layout_test_runtime_flags_.set_generate_pixel_results(false); 2735 layout_test_runtime_flags_.set_generate_pixel_results(false);
2716 OnLayoutTestRuntimeFlagsChanged(); 2736 OnLayoutTestRuntimeFlagsChanged();
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2926 2946
2927 void TestRunner::SetDatabaseQuota(int quota) { 2947 void TestRunner::SetDatabaseQuota(int quota) {
2928 delegate_->SetDatabaseQuota(quota); 2948 delegate_->SetDatabaseQuota(quota);
2929 } 2949 }
2930 2950
2931 void TestRunner::SetAlwaysAcceptCookies(bool accept) { 2951 void TestRunner::SetAlwaysAcceptCookies(bool accept) {
2932 delegate_->SetAcceptAllCookies(accept); 2952 delegate_->SetAcceptAllCookies(accept);
2933 } 2953 }
2934 2954
2935 void TestRunner::SetWindowIsKey(bool value) { 2955 void TestRunner::SetWindowIsKey(bool value) {
2936 delegate_->SetFocus(proxy_, value); 2956 delegate_->SetFocus(proxy_->web_view(), value);
2937 } 2957 }
2938 2958
2939 std::string TestRunner::PathToLocalResource(const std::string& path) { 2959 std::string TestRunner::PathToLocalResource(const std::string& path) {
2940 return delegate_->PathToLocalResource(path); 2960 return delegate_->PathToLocalResource(path);
2941 } 2961 }
2942 2962
2943 void TestRunner::SetBackingScaleFactor(double value, 2963 void TestRunner::SetBackingScaleFactor(double value,
2944 v8::Local<v8::Function> callback) { 2964 v8::Local<v8::Function> callback) {
2945 delegate_->SetDeviceScaleFactor(value); 2965 delegate_->SetDeviceScaleFactor(value);
2946 delegate_->PostTask(new InvokeCallbackTask(this, callback)); 2966 delegate_->PostTask(new InvokeCallbackTask(this, callback));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 delegate_->SimulateWebNotificationClick(title, action_index); 3054 delegate_->SimulateWebNotificationClick(title, action_index);
3035 } 3055 }
3036 3056
3037 void TestRunner::SimulateWebNotificationClose(const std::string& title, 3057 void TestRunner::SimulateWebNotificationClose(const std::string& title,
3038 bool by_user) { 3058 bool by_user) {
3039 delegate_->SimulateWebNotificationClose(title, by_user); 3059 delegate_->SimulateWebNotificationClose(title, by_user);
3040 } 3060 }
3041 3061
3042 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript, 3062 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
3043 double confidence) { 3063 double confidence) {
3044 proxy_->GetSpeechRecognizerMock()->AddMockResult( 3064 getMockWebSpeechRecognizer()->AddMockResult(WebString::fromUTF8(transcript),
3045 WebString::fromUTF8(transcript), confidence); 3065 confidence);
3046 } 3066 }
3047 3067
3048 void TestRunner::SetMockSpeechRecognitionError(const std::string& error, 3068 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
3049 const std::string& message) { 3069 const std::string& message) {
3050 proxy_->GetSpeechRecognizerMock()->SetError(WebString::fromUTF8(error), 3070 getMockWebSpeechRecognizer()->SetError(WebString::fromUTF8(error),
3051 WebString::fromUTF8(message)); 3071 WebString::fromUTF8(message));
3052 } 3072 }
3053 3073
3054 bool TestRunner::WasMockSpeechRecognitionAborted() { 3074 bool TestRunner::WasMockSpeechRecognitionAborted() {
3055 return proxy_->GetSpeechRecognizerMock()->WasAborted(); 3075 return getMockWebSpeechRecognizer()->WasAborted();
3056 } 3076 }
3057 3077
3058 void TestRunner::AddMockCredentialManagerResponse(const std::string& id, 3078 void TestRunner::AddMockCredentialManagerResponse(const std::string& id,
3059 const std::string& name, 3079 const std::string& name,
3060 const std::string& avatar, 3080 const std::string& avatar,
3061 const std::string& password) { 3081 const std::string& password) {
3062 proxy_->GetCredentialManagerClientMock()->SetResponse( 3082 proxy_->GetCredentialManagerClientMock()->SetResponse(
3063 new WebPasswordCredential(WebString::fromUTF8(id), 3083 new WebPasswordCredential(WebString::fromUTF8(id),
3064 WebString::fromUTF8(password), 3084 WebString::fromUTF8(password),
3065 WebString::fromUTF8(name), 3085 WebString::fromUTF8(name),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3097 new InvokeCallbackTask(this, callback)); 3117 new InvokeCallbackTask(this, callback));
3098 3118
3099 delegate_->FetchManifest( 3119 delegate_->FetchManifest(
3100 web_view_, web_view_->mainFrame()->document().manifestURL(), 3120 web_view_, web_view_->mainFrame()->document().manifestURL(),
3101 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(), 3121 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(),
3102 base::Passed(&task))); 3122 base::Passed(&task)));
3103 } 3123 }
3104 3124
3105 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) { 3125 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) {
3106 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback)); 3126 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback));
3107 DumpPixelsAsync(proxy_->GetWebView(), 3127 DumpPixelsAsync(proxy_->web_view(),
3108 base::Bind(&TestRunner::CapturePixelsCallback, 3128 base::Bind(&TestRunner::CapturePixelsCallback,
3109 weak_factory_.GetWeakPtr(), base::Passed(&task))); 3129 weak_factory_.GetWeakPtr(), base::Passed(&task)));
3110 } 3130 }
3111 3131
3112 void TestRunner::OnLayoutTestRuntimeFlagsChanged() { 3132 void TestRunner::OnLayoutTestRuntimeFlagsChanged() {
3113 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty()) 3133 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty())
3114 return; 3134 return;
3115 3135
3116 delegate_->OnLayoutTestRuntimeFlagsChanged( 3136 delegate_->OnLayoutTestRuntimeFlagsChanged(
3117 layout_test_runtime_flags_.tracked_dictionary().changed_values()); 3137 layout_test_runtime_flags_.tracked_dictionary().changed_values());
3118 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking(); 3138 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking();
3119 } 3139 }
3120 3140
3121 void TestRunner::ForceNextWebGLContextCreationToFail() { 3141 void TestRunner::ForceNextWebGLContextCreationToFail() {
3122 if (web_view_) 3142 if (web_view_)
3123 web_view_->forceNextWebGLContextCreationToFail(); 3143 web_view_->forceNextWebGLContextCreationToFail();
3124 } 3144 }
3125 3145
3126 void TestRunner::ForceNextDrawingBufferCreationToFail() { 3146 void TestRunner::ForceNextDrawingBufferCreationToFail() {
3127 if (web_view_) 3147 if (web_view_)
3128 web_view_->forceNextDrawingBufferCreationToFail(); 3148 web_view_->forceNextDrawingBufferCreationToFail();
3129 } 3149 }
3130 3150
3131 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen( 3151 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
3132 int x, int y, v8::Local<v8::Function> callback) { 3152 int x, int y, v8::Local<v8::Function> callback) {
3133 scoped_ptr<InvokeCallbackTask> task( 3153 scoped_ptr<InvokeCallbackTask> task(
3134 new InvokeCallbackTask(this, callback)); 3154 new InvokeCallbackTask(this, callback));
3135 CopyImageAtAndCapturePixels( 3155 CopyImageAtAndCapturePixels(
3136 proxy_->GetWebView(), x, y, 3156 proxy_->web_view(), x, y,
3137 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(), 3157 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(),
3138 base::Passed(&task))); 3158 base::Passed(&task)));
3139 } 3159 }
3140 3160
3141 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task, 3161 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task,
3142 const blink::WebURLResponse& response, 3162 const blink::WebURLResponse& response,
3143 const std::string& data) { 3163 const std::string& data) {
3144 InvokeCallback(std::move(task)); 3164 InvokeCallback(std::move(task));
3145 } 3165 }
3146 3166
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 } 3305 }
3286 3306
3287 void TestRunner::DidLosePointerLockInternal() { 3307 void TestRunner::DidLosePointerLockInternal() {
3288 bool was_locked = pointer_locked_; 3308 bool was_locked = pointer_locked_;
3289 pointer_locked_ = false; 3309 pointer_locked_ = false;
3290 if (was_locked) 3310 if (was_locked)
3291 web_view_->didLosePointerLock(); 3311 web_view_->didLosePointerLock();
3292 } 3312 }
3293 3313
3294 } // namespace test_runner 3314 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/test_runner.h ('k') | components/test_runner/test_runner.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698