| 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 "content/shell/test_runner/test_runner.h" | 5 #include "content/shell/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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace | 94 } // namespace |
| 95 | 95 |
| 96 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> { | 96 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> { |
| 97 public: | 97 public: |
| 98 static gin::WrapperInfo kWrapperInfo; | 98 static gin::WrapperInfo kWrapperInfo; |
| 99 | 99 |
| 100 static void Install(base::WeakPtr<TestRunner> test_runner, | 100 static void Install(base::WeakPtr<TestRunner> test_runner, |
| 101 base::WeakPtr<TestRunnerForSpecificView> view_test_runner, | 101 base::WeakPtr<TestRunnerForSpecificView> view_test_runner, |
| 102 WebLocalFrame* frame); | 102 WebLocalFrame* frame, |
| 103 bool is_web_platform_tests_mode); |
| 103 | 104 |
| 104 private: | 105 private: |
| 105 explicit TestRunnerBindings( | 106 explicit TestRunnerBindings( |
| 106 base::WeakPtr<TestRunner> test_runner, | 107 base::WeakPtr<TestRunner> test_runner, |
| 107 base::WeakPtr<TestRunnerForSpecificView> view_test_runner); | 108 base::WeakPtr<TestRunnerForSpecificView> view_test_runner); |
| 108 ~TestRunnerBindings() override; | 109 ~TestRunnerBindings() override; |
| 109 | 110 |
| 110 // gin::Wrappable: | 111 // gin::Wrappable: |
| 111 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 112 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 112 v8::Isolate* isolate) override; | 113 v8::Isolate* isolate) override; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 298 |
| 298 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings); | 299 DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings); |
| 299 }; | 300 }; |
| 300 | 301 |
| 301 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {gin::kEmbedderNativeGin}; | 302 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {gin::kEmbedderNativeGin}; |
| 302 | 303 |
| 303 // static | 304 // static |
| 304 void TestRunnerBindings::Install( | 305 void TestRunnerBindings::Install( |
| 305 base::WeakPtr<TestRunner> test_runner, | 306 base::WeakPtr<TestRunner> test_runner, |
| 306 base::WeakPtr<TestRunnerForSpecificView> view_test_runner, | 307 base::WeakPtr<TestRunnerForSpecificView> view_test_runner, |
| 307 WebLocalFrame* frame) { | 308 WebLocalFrame* frame, |
| 309 bool is_web_platform_tests_mode) { |
| 308 v8::Isolate* isolate = blink::mainThreadIsolate(); | 310 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 309 v8::HandleScope handle_scope(isolate); | 311 v8::HandleScope handle_scope(isolate); |
| 310 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); | 312 v8::Local<v8::Context> context = frame->mainWorldScriptContext(); |
| 311 if (context.IsEmpty()) | 313 if (context.IsEmpty()) |
| 312 return; | 314 return; |
| 313 | 315 |
| 314 v8::Context::Scope context_scope(context); | 316 v8::Context::Scope context_scope(context); |
| 315 | 317 |
| 316 TestRunnerBindings* wrapped = | 318 TestRunnerBindings* wrapped = |
| 317 new TestRunnerBindings(test_runner, view_test_runner); | 319 new TestRunnerBindings(test_runner, view_test_runner); |
| 318 gin::Handle<TestRunnerBindings> bindings = | 320 gin::Handle<TestRunnerBindings> bindings = |
| 319 gin::CreateHandle(isolate, wrapped); | 321 gin::CreateHandle(isolate, wrapped); |
| 320 if (bindings.IsEmpty()) | 322 if (bindings.IsEmpty()) |
| 321 return; | 323 return; |
| 322 v8::Local<v8::Object> global = context->Global(); | 324 v8::Local<v8::Object> global = context->Global(); |
| 323 v8::Local<v8::Value> v8_bindings = bindings.ToV8(); | 325 v8::Local<v8::Value> v8_bindings = bindings.ToV8(); |
| 324 | 326 |
| 325 std::vector<std::string> names; | 327 std::vector<std::string> names; |
| 326 names.push_back("testRunner"); | 328 names.push_back("testRunner"); |
| 327 names.push_back("layoutTestController"); | 329 names.push_back("layoutTestController"); |
| 328 for (size_t i = 0; i < names.size(); ++i) | 330 for (size_t i = 0; i < names.size(); ++i) |
| 329 global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings); | 331 global->Set(gin::StringToV8(isolate, names[i].c_str()), v8_bindings); |
| 332 |
| 333 // The web-platform-tests suite require that reference comparison is delayed |
| 334 // for any test with a 'reftest-wait' class on the root element, until that |
| 335 // class attribute is removed. To support this approach, we inject some |
| 336 // JavaScript that implements the same behavior using TestRunner. |
| 337 // |
| 338 // See http://web-platform-tests.org/writing-tests/reftests.html for more |
| 339 // details about reference tests in the web-platform-tests suite. |
| 340 if (is_web_platform_tests_mode) { |
| 341 frame->executeScript(blink::WebString( |
| 342 R"(window.addEventListener('load', function() { |
| 343 if (!window.testRunner) { |
| 344 return; |
| 345 } |
| 346 const target = document.documentElement; |
| 347 if (target != null && target.classList.contains('reftest-wait')) { |
| 348 window.testRunner.waitUntilDone(); |
| 349 const observer = new MutationObserver(function(mutations) { |
| 350 mutations.forEach(function(mutation) { |
| 351 if (!target.classList.contains('reftest-wait')) { |
| 352 window.testRunner.notifyDone(); |
| 353 } |
| 354 }); |
| 355 }); |
| 356 const config = {attributes: true}; |
| 357 observer.observe(target, config); |
| 358 } |
| 359 });)")); |
| 360 } |
| 330 } | 361 } |
| 331 | 362 |
| 332 TestRunnerBindings::TestRunnerBindings( | 363 TestRunnerBindings::TestRunnerBindings( |
| 333 base::WeakPtr<TestRunner> runner, | 364 base::WeakPtr<TestRunner> runner, |
| 334 base::WeakPtr<TestRunnerForSpecificView> view_runner) | 365 base::WeakPtr<TestRunnerForSpecificView> view_runner) |
| 335 : runner_(runner), view_runner_(view_runner) {} | 366 : runner_(runner), view_runner_(view_runner) {} |
| 336 | 367 |
| 337 TestRunnerBindings::~TestRunnerBindings() {} | 368 TestRunnerBindings::~TestRunnerBindings() {} |
| 338 | 369 |
| 339 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder( | 370 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder( |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1619 effective_connection_type_( | 1650 effective_connection_type_( |
| 1620 blink::WebEffectiveConnectionType::TypeUnknown), | 1651 blink::WebEffectiveConnectionType::TypeUnknown), |
| 1621 weak_factory_(this) {} | 1652 weak_factory_(this) {} |
| 1622 | 1653 |
| 1623 TestRunner::~TestRunner() {} | 1654 TestRunner::~TestRunner() {} |
| 1624 | 1655 |
| 1625 void TestRunner::Install( | 1656 void TestRunner::Install( |
| 1626 WebLocalFrame* frame, | 1657 WebLocalFrame* frame, |
| 1627 base::WeakPtr<TestRunnerForSpecificView> view_test_runner) { | 1658 base::WeakPtr<TestRunnerForSpecificView> view_test_runner) { |
| 1628 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), view_test_runner, | 1659 TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), view_test_runner, |
| 1629 frame); | 1660 frame, is_web_platform_tests_mode()); |
| 1630 } | 1661 } |
| 1631 | 1662 |
| 1632 void TestRunner::SetDelegate(WebTestDelegate* delegate) { | 1663 void TestRunner::SetDelegate(WebTestDelegate* delegate) { |
| 1633 delegate_ = delegate; | 1664 delegate_ = delegate; |
| 1634 mock_content_settings_client_->SetDelegate(delegate); | 1665 mock_content_settings_client_->SetDelegate(delegate); |
| 1635 spellcheck_->SetDelegate(delegate); | 1666 spellcheck_->SetDelegate(delegate); |
| 1636 if (speech_recognizer_) | 1667 if (speech_recognizer_) |
| 1637 speech_recognizer_->SetDelegate(delegate); | 1668 speech_recognizer_->SetDelegate(delegate); |
| 1638 } | 1669 } |
| 1639 | 1670 |
| (...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2808 | 2839 |
| 2809 void TestRunner::NotifyDone() { | 2840 void TestRunner::NotifyDone() { |
| 2810 if (layout_test_runtime_flags_.wait_until_done() && !topLoadingFrame() && | 2841 if (layout_test_runtime_flags_.wait_until_done() && !topLoadingFrame() && |
| 2811 !will_navigate_ && work_queue_.is_empty()) | 2842 !will_navigate_ && work_queue_.is_empty()) |
| 2812 delegate_->TestFinished(); | 2843 delegate_->TestFinished(); |
| 2813 layout_test_runtime_flags_.set_wait_until_done(false); | 2844 layout_test_runtime_flags_.set_wait_until_done(false); |
| 2814 OnLayoutTestRuntimeFlagsChanged(); | 2845 OnLayoutTestRuntimeFlagsChanged(); |
| 2815 } | 2846 } |
| 2816 | 2847 |
| 2817 } // namespace test_runner | 2848 } // namespace test_runner |
| OLD | NEW |