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

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

Issue 1844233004: Moving pixel-capturing code from web_test_proxy_base.* into pixel_dump.* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@replicate-accept-languages
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/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
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/test_interfaces.h" 24 #include "components/test_runner/test_interfaces.h"
24 #include "components/test_runner/test_preferences.h" 25 #include "components/test_runner/test_preferences.h"
25 #include "components/test_runner/web_content_settings.h" 26 #include "components/test_runner/web_content_settings.h"
26 #include "components/test_runner/web_test_delegate.h" 27 #include "components/test_runner/web_test_delegate.h"
27 #include "components/test_runner/web_test_proxy.h" 28 #include "components/test_runner/web_test_proxy.h"
28 #include "gin/arguments.h" 29 #include "gin/arguments.h"
29 #include "gin/array_buffer.h" 30 #include "gin/array_buffer.h"
30 #include "gin/handle.h" 31 #include "gin/handle.h"
31 #include "gin/object_template_builder.h" 32 #include "gin/object_template_builder.h"
32 #include "gin/wrappable.h" 33 #include "gin/wrappable.h"
(...skipping 1667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 #endif 1701 #endif
1701 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true); 1702 web_view_->setVisibilityState(WebPageVisibilityStateVisible, true);
1702 web_view_->mainFrame()->enableViewSourceMode(false); 1703 web_view_->mainFrame()->enableViewSourceMode(false);
1703 1704
1704 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT); 1705 web_view_->setPageOverlayColor(SK_ColorTRANSPARENT);
1705 } 1706 }
1706 1707
1707 top_loading_frame_ = nullptr; 1708 top_loading_frame_ = nullptr;
1708 layout_test_runtime_flags_.Reset(); 1709 layout_test_runtime_flags_.Reset();
1709 mock_screen_orientation_client_->ResetData(); 1710 mock_screen_orientation_client_->ResetData();
1711 drag_image_.reset();
1710 wait_until_external_url_load_ = false; 1712 wait_until_external_url_load_ = false;
1711 1713
1712 WebSecurityPolicy::resetOriginAccessWhitelists(); 1714 WebSecurityPolicy::resetOriginAccessWhitelists();
1713 #if defined(__linux__) || defined(ANDROID) 1715 #if defined(__linux__) || defined(ANDROID)
1714 WebFontRendering::setSubpixelPositioning(false); 1716 WebFontRendering::setSubpixelPositioning(false);
1715 #endif 1717 #endif
1716 1718
1717 if (delegate_) { 1719 if (delegate_) {
1718 // Reset the default quota for each origin to 5MB 1720 // Reset the default quota for each origin to 5MB
1719 delegate_->SetDatabaseQuota(5 * 1024 * 1024); 1721 delegate_->SetDatabaseQuota(5 * 1024 * 1024);
(...skipping 18 matching lines...) Expand all
1738 dump_user_gesture_in_frame_load_callbacks_ = false; 1740 dump_user_gesture_in_frame_load_callbacks_ = false;
1739 dump_title_changes_ = false; 1741 dump_title_changes_ = false;
1740 dump_create_view_ = false; 1742 dump_create_view_ = false;
1741 can_open_windows_ = false; 1743 can_open_windows_ = false;
1742 dump_resource_load_callbacks_ = false; 1744 dump_resource_load_callbacks_ = false;
1743 dump_resource_request_callbacks_ = false; 1745 dump_resource_request_callbacks_ = false;
1744 dump_resource_response_mime_types_ = false; 1746 dump_resource_response_mime_types_ = false;
1745 dump_window_status_changes_ = false; 1747 dump_window_status_changes_ = false;
1746 dump_spell_check_callbacks_ = false; 1748 dump_spell_check_callbacks_ = false;
1747 dump_back_forward_list_ = false; 1749 dump_back_forward_list_ = false;
1748 dump_selection_rect_ = false;
1749 dump_drag_image_ = false;
1750 dump_navigation_policy_ = false; 1750 dump_navigation_policy_ = false;
1751 test_repaint_ = false; 1751 test_repaint_ = false;
1752 sweep_horizontally_ = false; 1752 sweep_horizontally_ = false;
1753 midi_accessor_result_ = true; 1753 midi_accessor_result_ = true;
1754 should_stay_on_page_after_handling_before_unload_ = false; 1754 should_stay_on_page_after_handling_before_unload_ = false;
1755 should_dump_resource_priorities_ = false; 1755 should_dump_resource_priorities_ = false;
1756 has_custom_text_output_ = false; 1756 has_custom_text_output_ = false;
1757 custom_text_output_.clear(); 1757 custom_text_output_.clear();
1758 1758
1759 http_headers_to_clear_.clear(); 1759 http_headers_to_clear_.clear();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 bool TestRunner::IsRecursiveLayoutDumpRequested() { 1840 bool TestRunner::IsRecursiveLayoutDumpRequested() {
1841 CheckResponseMimeType(); 1841 CheckResponseMimeType();
1842 return layout_test_runtime_flags_.dump_child_frames(); 1842 return layout_test_runtime_flags_.dump_child_frames();
1843 } 1843 }
1844 1844
1845 std::string TestRunner::DumpLayout(blink::WebLocalFrame* frame) { 1845 std::string TestRunner::DumpLayout(blink::WebLocalFrame* frame) {
1846 CheckResponseMimeType(); 1846 CheckResponseMimeType();
1847 return ::test_runner::DumpLayout(frame, layout_test_runtime_flags_); 1847 return ::test_runner::DumpLayout(frame, layout_test_runtime_flags_);
1848 } 1848 }
1849 1849
1850 void TestRunner::DumpPixelsAsync(
1851 blink::WebView* web_view,
1852 const base::Callback<void(const SkBitmap&)>& callback) {
1853 if (layout_test_runtime_flags_.dump_drag_image()) {
1854 if (drag_image_.isNull()) {
1855 // This means the test called dumpDragImage but did not initiate a drag.
1856 // Return a blank image so that the test fails.
1857 SkBitmap bitmap;
1858 bitmap.allocN32Pixels(1, 1);
1859 {
1860 SkAutoLockPixels lock(bitmap);
1861 bitmap.eraseColor(0);
1862 }
1863 callback.Run(bitmap);
1864 return;
1865 }
1866
1867 callback.Run(drag_image_.getSkBitmap());
1868 return;
1869 }
1870
1871 test_runner::DumpPixelsAsync(proxy_->GetWebView(), layout_test_runtime_flags_,
1872 delegate_->GetDeviceScaleFactorForTest(),
1873 callback);
1874 }
1875
1850 void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges( 1876 void TestRunner::ReplicateLayoutTestRuntimeFlagsChanges(
1851 const base::DictionaryValue& changed_values) { 1877 const base::DictionaryValue& changed_values) {
1852 layout_test_runtime_flags_.tracked_dictionary().ApplyUntrackedChanges( 1878 layout_test_runtime_flags_.tracked_dictionary().ApplyUntrackedChanges(
1853 changed_values); 1879 changed_values);
1854 } 1880 }
1855 1881
1856 bool TestRunner::HasCustomTextDump(std::string* custom_text_dump) const { 1882 bool TestRunner::HasCustomTextDump(std::string* custom_text_dump) const {
1857 if (shouldDumpAsCustomText()) { 1883 if (shouldDumpAsCustomText()) {
1858 *custom_text_dump = customDumpText(); 1884 *custom_text_dump = customDumpText();
1859 return true; 1885 return true;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 } 1949 }
1924 1950
1925 bool TestRunner::shouldDumpSpellCheckCallbacks() const { 1951 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1926 return dump_spell_check_callbacks_; 1952 return dump_spell_check_callbacks_;
1927 } 1953 }
1928 1954
1929 bool TestRunner::ShouldDumpBackForwardList() const { 1955 bool TestRunner::ShouldDumpBackForwardList() const {
1930 return dump_back_forward_list_; 1956 return dump_back_forward_list_;
1931 } 1957 }
1932 1958
1933 bool TestRunner::shouldDumpSelectionRect() const {
1934 return dump_selection_rect_;
1935 }
1936
1937 bool TestRunner::isPrinting() const { 1959 bool TestRunner::isPrinting() const {
1938 return layout_test_runtime_flags_.is_printing(); 1960 return layout_test_runtime_flags_.is_printing();
1939 } 1961 }
1940 1962
1941 bool TestRunner::shouldWaitUntilExternalURLLoad() const { 1963 bool TestRunner::shouldWaitUntilExternalURLLoad() const {
1942 return wait_until_external_url_load_; 1964 return wait_until_external_url_load_;
1943 } 1965 }
1944 1966
1945 const std::set<std::string>* TestRunner::httpHeadersToClear() const { 1967 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1946 return &http_headers_to_clear_; 1968 return &http_headers_to_clear_;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
2015 } 2037 }
2016 2038
2017 bool TestRunner::isPointerLocked() { 2039 bool TestRunner::isPointerLocked() {
2018 return pointer_locked_; 2040 return pointer_locked_;
2019 } 2041 }
2020 2042
2021 void TestRunner::setToolTipText(const WebString& text) { 2043 void TestRunner::setToolTipText(const WebString& text) {
2022 tooltip_text_ = text.utf8(); 2044 tooltip_text_ = text.utf8();
2023 } 2045 }
2024 2046
2025 bool TestRunner::shouldDumpDragImage() { 2047 void TestRunner::setDragImage(
2026 return dump_drag_image_; 2048 const blink::WebImage& drag_image) {
2049 if (layout_test_runtime_flags_.dump_drag_image()) {
2050 if (drag_image_.isNull())
2051 drag_image_ = drag_image;
2052 }
2027 } 2053 }
2028 2054
2029 bool TestRunner::shouldDumpNavigationPolicy() const { 2055 bool TestRunner::shouldDumpNavigationPolicy() const {
2030 return dump_navigation_policy_; 2056 return dump_navigation_policy_;
2031 } 2057 }
2032 2058
2033 bool TestRunner::midiAccessorResult() { 2059 bool TestRunner::midiAccessorResult() {
2034 return midi_accessor_result_; 2060 return midi_accessor_result_;
2035 } 2061 }
2036 2062
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2800 2826
2801 void TestRunner::DumpSpellCheckCallbacks() { 2827 void TestRunner::DumpSpellCheckCallbacks() {
2802 dump_spell_check_callbacks_ = true; 2828 dump_spell_check_callbacks_ = true;
2803 } 2829 }
2804 2830
2805 void TestRunner::DumpBackForwardList() { 2831 void TestRunner::DumpBackForwardList() {
2806 dump_back_forward_list_ = true; 2832 dump_back_forward_list_ = true;
2807 } 2833 }
2808 2834
2809 void TestRunner::DumpSelectionRect() { 2835 void TestRunner::DumpSelectionRect() {
2810 dump_selection_rect_ = true; 2836 layout_test_runtime_flags_.set_dump_selection_rect(true);
2837 OnLayoutTestRuntimeFlagsChanged();
2811 } 2838 }
2812 2839
2813 void TestRunner::SetPrinting() { 2840 void TestRunner::SetPrinting() {
2814 layout_test_runtime_flags_.set_is_printing(true); 2841 layout_test_runtime_flags_.set_is_printing(true);
2815 OnLayoutTestRuntimeFlagsChanged(); 2842 OnLayoutTestRuntimeFlagsChanged();
2816 } 2843 }
2817 2844
2818 void TestRunner::ClearPrinting() { 2845 void TestRunner::ClearPrinting() {
2819 layout_test_runtime_flags_.set_is_printing(false); 2846 layout_test_runtime_flags_.set_is_printing(false);
2820 OnLayoutTestRuntimeFlagsChanged(); 2847 OnLayoutTestRuntimeFlagsChanged();
(...skipping 20 matching lines...) Expand all
2841 void TestRunner::ShowWebInspector(const std::string& str, 2868 void TestRunner::ShowWebInspector(const std::string& str,
2842 const std::string& frontend_url) { 2869 const std::string& frontend_url) {
2843 ShowDevTools(str, frontend_url); 2870 ShowDevTools(str, frontend_url);
2844 } 2871 }
2845 2872
2846 void TestRunner::WaitUntilExternalURLLoad() { 2873 void TestRunner::WaitUntilExternalURLLoad() {
2847 wait_until_external_url_load_ = true; 2874 wait_until_external_url_load_ = true;
2848 } 2875 }
2849 2876
2850 void TestRunner::DumpDragImage() { 2877 void TestRunner::DumpDragImage() {
2878 layout_test_runtime_flags_.set_dump_drag_image(true);
2851 DumpAsTextWithPixelResults(); 2879 DumpAsTextWithPixelResults();
2852 dump_drag_image_ = true; 2880 OnLayoutTestRuntimeFlagsChanged();
2853 } 2881 }
2854 2882
2855 void TestRunner::DumpNavigationPolicy() { 2883 void TestRunner::DumpNavigationPolicy() {
2856 dump_navigation_policy_ = true; 2884 dump_navigation_policy_ = true;
2857 } 2885 }
2858 2886
2859 void TestRunner::DumpPageImportanceSignals() { 2887 void TestRunner::DumpPageImportanceSignals() {
2860 blink::WebPageImportanceSignals* signals = 2888 blink::WebPageImportanceSignals* signals =
2861 web_view_->pageImportanceSignals(); 2889 web_view_->pageImportanceSignals();
2862 if (!signals) 2890 if (!signals)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
3061 scoped_ptr<InvokeCallbackTask> task( 3089 scoped_ptr<InvokeCallbackTask> task(
3062 new InvokeCallbackTask(this, callback)); 3090 new InvokeCallbackTask(this, callback));
3063 3091
3064 delegate_->FetchManifest( 3092 delegate_->FetchManifest(
3065 web_view_, web_view_->mainFrame()->document().manifestURL(), 3093 web_view_, web_view_->mainFrame()->document().manifestURL(),
3066 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(), 3094 base::Bind(&TestRunner::GetManifestCallback, weak_factory_.GetWeakPtr(),
3067 base::Passed(&task))); 3095 base::Passed(&task)));
3068 } 3096 }
3069 3097
3070 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) { 3098 void TestRunner::CapturePixelsAsyncThen(v8::Local<v8::Function> callback) {
3071 scoped_ptr<InvokeCallbackTask> task( 3099 scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback));
3072 new InvokeCallbackTask(this, callback)); 3100 DumpPixelsAsync(proxy_->GetWebView(),
3073 proxy_->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback, 3101 base::Bind(&TestRunner::CapturePixelsCallback,
3074 weak_factory_.GetWeakPtr(), 3102 weak_factory_.GetWeakPtr(), base::Passed(&task)));
3075 base::Passed(&task)));
3076 } 3103 }
3077 3104
3078 void TestRunner::OnLayoutTestRuntimeFlagsChanged() { 3105 void TestRunner::OnLayoutTestRuntimeFlagsChanged() {
3079 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty()) 3106 if (layout_test_runtime_flags_.tracked_dictionary().changed_values().empty())
3080 return; 3107 return;
3081 3108
3082 delegate_->OnLayoutTestRuntimeFlagsChanged( 3109 delegate_->OnLayoutTestRuntimeFlagsChanged(
3083 layout_test_runtime_flags_.tracked_dictionary().changed_values()); 3110 layout_test_runtime_flags_.tracked_dictionary().changed_values());
3084 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking(); 3111 layout_test_runtime_flags_.tracked_dictionary().ResetChangeTracking();
3085 } 3112 }
3086 3113
3087 void TestRunner::ForceNextWebGLContextCreationToFail() { 3114 void TestRunner::ForceNextWebGLContextCreationToFail() {
3088 if (web_view_) 3115 if (web_view_)
3089 web_view_->forceNextWebGLContextCreationToFail(); 3116 web_view_->forceNextWebGLContextCreationToFail();
3090 } 3117 }
3091 3118
3092 void TestRunner::ForceNextDrawingBufferCreationToFail() { 3119 void TestRunner::ForceNextDrawingBufferCreationToFail() {
3093 if (web_view_) 3120 if (web_view_)
3094 web_view_->forceNextDrawingBufferCreationToFail(); 3121 web_view_->forceNextDrawingBufferCreationToFail();
3095 } 3122 }
3096 3123
3097 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen( 3124 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
3098 int x, int y, v8::Local<v8::Function> callback) { 3125 int x, int y, v8::Local<v8::Function> callback) {
3099 scoped_ptr<InvokeCallbackTask> task( 3126 scoped_ptr<InvokeCallbackTask> task(
3100 new InvokeCallbackTask(this, callback)); 3127 new InvokeCallbackTask(this, callback));
3101 proxy_->CopyImageAtAndCapturePixels( 3128 CopyImageAtAndCapturePixels(
3102 x, y, base::Bind(&TestRunner::CapturePixelsCallback, 3129 proxy_->GetWebView(), x, y,
3103 weak_factory_.GetWeakPtr(), 3130 base::Bind(&TestRunner::CapturePixelsCallback, weak_factory_.GetWeakPtr(),
3104 base::Passed(&task))); 3131 base::Passed(&task)));
3105 } 3132 }
3106 3133
3107 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task, 3134 void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task,
3108 const blink::WebURLResponse& response, 3135 const blink::WebURLResponse& response,
3109 const std::string& data) { 3136 const std::string& data) {
3110 InvokeCallback(std::move(task)); 3137 InvokeCallback(std::move(task));
3111 } 3138 }
3112 3139
3113 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, 3140 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
3114 const SkBitmap& snapshot) { 3141 const SkBitmap& snapshot) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3251 } 3278 }
3252 3279
3253 void TestRunner::DidLosePointerLockInternal() { 3280 void TestRunner::DidLosePointerLockInternal() {
3254 bool was_locked = pointer_locked_; 3281 bool was_locked = pointer_locked_;
3255 pointer_locked_ = false; 3282 pointer_locked_ = false;
3256 if (was_locked) 3283 if (was_locked)
3257 web_view_->didLosePointerLock(); 3284 web_view_->didLosePointerLock();
3258 } 3285 }
3259 3286
3260 } // namespace test_runner 3287 } // 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