| 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 |
| (...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 void TestRunner::WorkQueue::AddWork(WorkItem* work) { | 1552 void TestRunner::WorkQueue::AddWork(WorkItem* work) { |
| 1553 if (frozen_) { | 1553 if (frozen_) { |
| 1554 delete work; | 1554 delete work; |
| 1555 return; | 1555 return; |
| 1556 } | 1556 } |
| 1557 queue_.push_back(work); | 1557 queue_.push_back(work); |
| 1558 } | 1558 } |
| 1559 | 1559 |
| 1560 void TestRunner::WorkQueue::ProcessWork() { | 1560 void TestRunner::WorkQueue::ProcessWork() { |
| 1561 // Quit doing work once a load is in progress. | 1561 // Quit doing work once a load is in progress. |
| 1562 while (!queue_.empty()) { | 1562 if (controller_->main_view_) { |
| 1563 bool startedLoad = queue_.front()->Run(controller_->delegate_, | 1563 while (!queue_.empty()) { |
| 1564 controller_->web_view_); | 1564 bool startedLoad = |
| 1565 delete queue_.front(); | 1565 queue_.front()->Run(controller_->delegate_, controller_->main_view_); |
| 1566 queue_.pop_front(); | 1566 delete queue_.front(); |
| 1567 if (startedLoad) | 1567 queue_.pop_front(); |
| 1568 return; | 1568 if (startedLoad) |
| 1569 return; |
| 1570 } |
| 1569 } | 1571 } |
| 1570 | 1572 |
| 1571 if (!controller_->layout_test_runtime_flags_.wait_until_done() && | 1573 if (!controller_->layout_test_runtime_flags_.wait_until_done() && |
| 1572 !controller_->topLoadingFrame()) | 1574 !controller_->topLoadingFrame()) |
| 1573 controller_->delegate_->TestFinished(); | 1575 controller_->delegate_->TestFinished(); |
| 1574 } | 1576 } |
| 1575 | 1577 |
| 1576 TestRunner::TestRunner(TestInterfaces* interfaces) | 1578 TestRunner::TestRunner(TestInterfaces* interfaces) |
| 1577 : test_is_running_(false), | 1579 : test_is_running_(false), |
| 1578 close_remaining_windows_(false), | 1580 close_remaining_windows_(false), |
| 1579 work_queue_(this), | 1581 work_queue_(this), |
| 1580 web_history_item_count_(0), | 1582 web_history_item_count_(0), |
| 1581 test_interfaces_(interfaces), | 1583 test_interfaces_(interfaces), |
| 1582 delegate_(nullptr), | 1584 delegate_(nullptr), |
| 1583 web_view_(nullptr), | 1585 main_view_(nullptr), |
| 1584 mock_content_settings_client_( | 1586 mock_content_settings_client_( |
| 1585 new MockContentSettingsClient(&layout_test_runtime_flags_)), | 1587 new MockContentSettingsClient(&layout_test_runtime_flags_)), |
| 1586 credential_manager_client_(new MockCredentialManagerClient), | 1588 credential_manager_client_(new MockCredentialManagerClient), |
| 1587 mock_screen_orientation_client_(new MockScreenOrientationClient), | 1589 mock_screen_orientation_client_(new MockScreenOrientationClient), |
| 1588 spellcheck_(new SpellCheckClient(this)), | 1590 spellcheck_(new SpellCheckClient(this)), |
| 1589 chooser_count_(0), | 1591 chooser_count_(0), |
| 1590 previously_focused_view_(nullptr), | 1592 previously_focused_view_(nullptr), |
| 1591 weak_factory_(this) {} | 1593 weak_factory_(this) {} |
| 1592 | 1594 |
| 1593 TestRunner::~TestRunner() {} | 1595 TestRunner::~TestRunner() {} |
| 1594 | 1596 |
| 1595 void TestRunner::Install( | 1597 void TestRunner::Install( |
| 1596 WebLocalFrame* frame, | 1598 WebLocalFrame* frame, |
| 1597 base::WeakPtr<TestRunnerForSpecificView> view_test_runner) { | 1599 base::WeakPtr<TestRunnerForSpecificView> view_test_runner) { |
| 1598 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), view_test_runner, | 1600 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), view_test_runner, |
| 1599 frame); | 1601 frame); |
| 1600 } | 1602 } |
| 1601 | 1603 |
| 1602 void TestRunner::SetDelegate(WebTestDelegate* delegate) { | 1604 void TestRunner::SetDelegate(WebTestDelegate* delegate) { |
| 1603 delegate_ = delegate; | 1605 delegate_ = delegate; |
| 1604 mock_content_settings_client_->SetDelegate(delegate); | 1606 mock_content_settings_client_->SetDelegate(delegate); |
| 1605 spellcheck_->SetDelegate(delegate); | 1607 spellcheck_->SetDelegate(delegate); |
| 1606 if (speech_recognizer_) | 1608 if (speech_recognizer_) |
| 1607 speech_recognizer_->SetDelegate(delegate); | 1609 speech_recognizer_->SetDelegate(delegate); |
| 1608 } | 1610 } |
| 1609 | 1611 |
| 1610 void TestRunner::SetWebView(WebView* webView) { | 1612 void TestRunner::SetMainView(WebView* web_view) { |
| 1611 web_view_ = webView; | 1613 main_view_ = web_view; |
| 1612 } | 1614 } |
| 1613 | 1615 |
| 1614 void TestRunner::Reset() { | 1616 void TestRunner::Reset() { |
| 1615 top_loading_frame_ = nullptr; | 1617 top_loading_frame_ = nullptr; |
| 1616 layout_test_runtime_flags_.Reset(); | 1618 layout_test_runtime_flags_.Reset(); |
| 1617 mock_screen_orientation_client_->ResetData(); | 1619 mock_screen_orientation_client_->ResetData(); |
| 1618 drag_image_.reset(); | 1620 drag_image_.reset(); |
| 1619 views_with_scheduled_animations_.clear(); | 1621 views_with_scheduled_animations_.clear(); |
| 1620 | 1622 |
| 1621 WebSecurityPolicy::resetOriginAccessWhitelists(); | 1623 WebSecurityPolicy::resetOriginAccessWhitelists(); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1855 } | 1857 } |
| 1856 | 1858 |
| 1857 bool TestRunner::shouldDumpPingLoaderCallbacks() const { | 1859 bool TestRunner::shouldDumpPingLoaderCallbacks() const { |
| 1858 return test_is_running_ && | 1860 return test_is_running_ && |
| 1859 layout_test_runtime_flags_.dump_ping_loader_callbacks(); | 1861 layout_test_runtime_flags_.dump_ping_loader_callbacks(); |
| 1860 } | 1862 } |
| 1861 | 1863 |
| 1862 void TestRunner::setShouldEnableViewSource(bool value) { | 1864 void TestRunner::setShouldEnableViewSource(bool value) { |
| 1863 // TODO(lukasza): This flag should be 1) replicated across OOPIFs and | 1865 // TODO(lukasza): This flag should be 1) replicated across OOPIFs and |
| 1864 // 2) applied to all views, not just the main window view. | 1866 // 2) applied to all views, not just the main window view. |
| 1865 web_view_->mainFrame()->enableViewSourceMode(value); | 1867 |
| 1868 // Path-based test config is trigerred by BlinkTestRunner, when |main_view_| |
| 1869 // is guaranteed to exist at this point. |
| 1870 DCHECK(main_view_); |
| 1871 |
| 1872 main_view_->mainFrame()->enableViewSourceMode(value); |
| 1866 } | 1873 } |
| 1867 | 1874 |
| 1868 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const { | 1875 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const { |
| 1869 return test_is_running_ && | 1876 return test_is_running_ && |
| 1870 layout_test_runtime_flags_.dump_user_gesture_in_frame_load_callbacks(); | 1877 layout_test_runtime_flags_.dump_user_gesture_in_frame_load_callbacks(); |
| 1871 } | 1878 } |
| 1872 | 1879 |
| 1873 bool TestRunner::shouldDumpTitleChanges() const { | 1880 bool TestRunner::shouldDumpTitleChanges() const { |
| 1874 return layout_test_runtime_flags_.dump_title_changes(); | 1881 return layout_test_runtime_flags_.dump_title_changes(); |
| 1875 } | 1882 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 | 1930 |
| 1924 bool TestRunner::shouldWaitUntilExternalURLLoad() const { | 1931 bool TestRunner::shouldWaitUntilExternalURLLoad() const { |
| 1925 return layout_test_runtime_flags_.wait_until_external_url_load(); | 1932 return layout_test_runtime_flags_.wait_until_external_url_load(); |
| 1926 } | 1933 } |
| 1927 | 1934 |
| 1928 const std::set<std::string>* TestRunner::httpHeadersToClear() const { | 1935 const std::set<std::string>* TestRunner::httpHeadersToClear() const { |
| 1929 return &http_headers_to_clear_; | 1936 return &http_headers_to_clear_; |
| 1930 } | 1937 } |
| 1931 | 1938 |
| 1932 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear) { | 1939 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear) { |
| 1933 if (frame->top()->view() != web_view_) | 1940 if (frame->top()->view() != main_view_) |
| 1934 return; | 1941 return; |
| 1935 if (!test_is_running_) | 1942 if (!test_is_running_) |
| 1936 return; | 1943 return; |
| 1937 if (clear) { | 1944 if (clear) { |
| 1938 top_loading_frame_ = nullptr; | 1945 top_loading_frame_ = nullptr; |
| 1939 LocationChangeDone(); | 1946 LocationChangeDone(); |
| 1940 } else if (!top_loading_frame_) { | 1947 } else if (!top_loading_frame_) { |
| 1941 top_loading_frame_ = frame; | 1948 top_loading_frame_ = frame; |
| 1942 } | 1949 } |
| 1943 } | 1950 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2124 delegate->LoadURLForFrame(url_, target_); | 2131 delegate->LoadURLForFrame(url_, target_); |
| 2125 return true; // FIXME: Did it really start a navigation? | 2132 return true; // FIXME: Did it really start a navigation? |
| 2126 } | 2133 } |
| 2127 | 2134 |
| 2128 private: | 2135 private: |
| 2129 WebURL url_; | 2136 WebURL url_; |
| 2130 std::string target_; | 2137 std::string target_; |
| 2131 }; | 2138 }; |
| 2132 | 2139 |
| 2133 void TestRunner::QueueLoad(const std::string& url, const std::string& target) { | 2140 void TestRunner::QueueLoad(const std::string& url, const std::string& target) { |
| 2141 if (!main_view_) |
| 2142 return; |
| 2143 |
| 2134 // FIXME: Implement WebURL::resolve() and avoid GURL. | 2144 // FIXME: Implement WebURL::resolve() and avoid GURL. |
| 2135 GURL current_url = web_view_->mainFrame()->document().url(); | 2145 GURL current_url = main_view_->mainFrame()->document().url(); |
| 2136 GURL full_url = current_url.Resolve(url); | 2146 GURL full_url = current_url.Resolve(url); |
| 2137 work_queue_.AddWork(new WorkItemLoad(full_url, target)); | 2147 work_queue_.AddWork(new WorkItemLoad(full_url, target)); |
| 2138 } | 2148 } |
| 2139 | 2149 |
| 2140 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) { | 2150 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) { |
| 2141 bool value; | 2151 bool value; |
| 2142 args->GetNext(&value); | 2152 args->GetNext(&value); |
| 2143 layout_test_runtime_flags_.set_policy_delegate_enabled(value); | 2153 layout_test_runtime_flags_.set_policy_delegate_enabled(value); |
| 2144 | 2154 |
| 2145 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean()) { | 2155 if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean()) { |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3231 work_queue_.ProcessWorkSoon(); | 3241 work_queue_.ProcessWorkSoon(); |
| 3232 } | 3242 } |
| 3233 | 3243 |
| 3234 void TestRunner::CheckResponseMimeType() { | 3244 void TestRunner::CheckResponseMimeType() { |
| 3235 // Text output: the test page can request different types of output which we | 3245 // Text output: the test page can request different types of output which we |
| 3236 // handle here. | 3246 // handle here. |
| 3237 | 3247 |
| 3238 if (layout_test_runtime_flags_.dump_as_text()) | 3248 if (layout_test_runtime_flags_.dump_as_text()) |
| 3239 return; | 3249 return; |
| 3240 | 3250 |
| 3241 WebDataSource* data_source = web_view_->mainFrame()->dataSource(); | 3251 if (!main_view_) |
| 3252 return; |
| 3253 |
| 3254 WebDataSource* data_source = main_view_->mainFrame()->dataSource(); |
| 3242 if (!data_source) | 3255 if (!data_source) |
| 3243 return; | 3256 return; |
| 3244 | 3257 |
| 3245 std::string mimeType = data_source->response().mimeType().utf8(); | 3258 std::string mimeType = data_source->response().mimeType().utf8(); |
| 3246 if (mimeType != "text/plain") | 3259 if (mimeType != "text/plain") |
| 3247 return; | 3260 return; |
| 3248 | 3261 |
| 3249 layout_test_runtime_flags_.set_dump_as_text(true); | 3262 layout_test_runtime_flags_.set_dump_as_text(true); |
| 3250 layout_test_runtime_flags_.set_generate_pixel_results(false); | 3263 layout_test_runtime_flags_.set_generate_pixel_results(false); |
| 3251 OnLayoutTestRuntimeFlagsChanged(); | 3264 OnLayoutTestRuntimeFlagsChanged(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3329 | 3342 |
| 3330 blink::WebView* TestRunnerForSpecificView::web_view() { | 3343 blink::WebView* TestRunnerForSpecificView::web_view() { |
| 3331 return web_test_proxy_base_->web_view(); | 3344 return web_test_proxy_base_->web_view(); |
| 3332 } | 3345 } |
| 3333 | 3346 |
| 3334 WebTestDelegate* TestRunnerForSpecificView::delegate() { | 3347 WebTestDelegate* TestRunnerForSpecificView::delegate() { |
| 3335 return web_test_proxy_base_->delegate(); | 3348 return web_test_proxy_base_->delegate(); |
| 3336 } | 3349 } |
| 3337 | 3350 |
| 3338 } // namespace test_runner | 3351 } // namespace test_runner |
| OLD | NEW |