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