| 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 #ifndef COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ | 5 #ifndef COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ |
| 6 #define COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ | 6 #define COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "components/test_runner/layout_test_runtime_flags.h" | 18 #include "components/test_runner/layout_test_runtime_flags.h" |
| 19 #include "components/test_runner/test_runner_export.h" | 19 #include "components/test_runner/test_runner_export.h" |
| 20 #include "components/test_runner/web_task.h" | |
| 21 #include "components/test_runner/web_test_runner.h" | 20 #include "components/test_runner/web_test_runner.h" |
| 22 #include "third_party/WebKit/public/platform/WebImage.h" | 21 #include "third_party/WebKit/public/platform/WebImage.h" |
| 23 #include "v8/include/v8.h" | 22 #include "v8/include/v8.h" |
| 24 | 23 |
| 25 class GURL; | 24 class GURL; |
| 26 class SkBitmap; | 25 class SkBitmap; |
| 27 | 26 |
| 28 namespace blink { | 27 namespace blink { |
| 29 class WebContentSettingsClient; | 28 class WebContentSettingsClient; |
| 30 class WebFrame; | 29 class WebFrame; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 45 class MockCredentialManagerClient; | 44 class MockCredentialManagerClient; |
| 46 class MockScreenOrientationClient; | 45 class MockScreenOrientationClient; |
| 47 class MockWebSpeechRecognizer; | 46 class MockWebSpeechRecognizer; |
| 48 class MockWebUserMediaClient; | 47 class MockWebUserMediaClient; |
| 49 class SpellCheckClient; | 48 class SpellCheckClient; |
| 50 class TestInterfaces; | 49 class TestInterfaces; |
| 51 class WebContentSettings; | 50 class WebContentSettings; |
| 52 class WebTestDelegate; | 51 class WebTestDelegate; |
| 53 class WebTestProxyBase; | 52 class WebTestProxyBase; |
| 54 | 53 |
| 55 class TestRunner : public WebTestRunner, | 54 class TestRunner : public WebTestRunner { |
| 56 public base::SupportsWeakPtr<TestRunner> { | |
| 57 public: | 55 public: |
| 58 explicit TestRunner(TestInterfaces*); | 56 explicit TestRunner(TestInterfaces*); |
| 59 virtual ~TestRunner(); | 57 virtual ~TestRunner(); |
| 60 | 58 |
| 61 void Install(blink::WebFrame* frame); | 59 void Install(blink::WebFrame* frame); |
| 62 | 60 |
| 63 void SetDelegate(WebTestDelegate*); | 61 void SetDelegate(WebTestDelegate*); |
| 64 void SetWebView(blink::WebView*, WebTestProxyBase*); | 62 void SetWebView(blink::WebView*, WebTestProxyBase*); |
| 65 | 63 |
| 66 void Reset(); | 64 void Reset(); |
| 67 | 65 |
| 68 WebTaskList* mutable_task_list() { return &task_list_; } | |
| 69 | |
| 70 void SetTestIsRunning(bool); | 66 void SetTestIsRunning(bool); |
| 71 bool TestIsRunning() const { return test_is_running_; } | 67 bool TestIsRunning() const { return test_is_running_; } |
| 72 | 68 |
| 73 bool UseMockTheme() const { return use_mock_theme_; } | 69 bool UseMockTheme() const { return use_mock_theme_; } |
| 74 | 70 |
| 75 void InvokeCallback(scoped_ptr<InvokeCallbackTask> callback); | |
| 76 | |
| 77 // WebTestRunner implementation. | 71 // WebTestRunner implementation. |
| 78 bool ShouldGeneratePixelResults() override; | 72 bool ShouldGeneratePixelResults() override; |
| 79 bool ShouldDumpAsAudio() const override; | 73 bool ShouldDumpAsAudio() const override; |
| 80 void GetAudioData(std::vector<unsigned char>* buffer_view) const override; | 74 void GetAudioData(std::vector<unsigned char>* buffer_view) const override; |
| 81 bool IsRecursiveLayoutDumpRequested() override; | 75 bool IsRecursiveLayoutDumpRequested() override; |
| 82 std::string DumpLayout(blink::WebLocalFrame* frame) override; | 76 std::string DumpLayout(blink::WebLocalFrame* frame) override; |
| 83 void DumpPixelsAsync( | 77 void DumpPixelsAsync( |
| 84 blink::WebView* web_view, | 78 blink::WebView* web_view, |
| 85 const base::Callback<void(const SkBitmap&)>& callback) override; | 79 const base::Callback<void(const SkBitmap&)>& callback) override; |
| 86 void ReplicateLayoutTestRuntimeFlagsChanges( | 80 void ReplicateLayoutTestRuntimeFlagsChanges( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 // A single item in the work queue. | 142 // A single item in the work queue. |
| 149 class WorkItem { | 143 class WorkItem { |
| 150 public: | 144 public: |
| 151 virtual ~WorkItem() {} | 145 virtual ~WorkItem() {} |
| 152 | 146 |
| 153 // Returns true if this started a load. | 147 // Returns true if this started a load. |
| 154 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0; | 148 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0; |
| 155 }; | 149 }; |
| 156 | 150 |
| 157 private: | 151 private: |
| 158 friend class InvokeCallbackTask; | |
| 159 friend class TestRunnerBindings; | 152 friend class TestRunnerBindings; |
| 160 friend class WorkQueue; | 153 friend class WorkQueue; |
| 161 | 154 |
| 155 // Helpers for working with base and V8 callbacks. |
| 156 void PostTask(const base::Closure& callback); |
| 157 void PostDelayedTask(long long delay, const base::Closure& callback); |
| 158 void PostV8Callback(const v8::Local<v8::Function>& callback); |
| 159 void PostV8CallbackWithArgs(v8::UniquePersistent<v8::Function> callback, |
| 160 int argc, |
| 161 v8::Local<v8::Value> argv[]); |
| 162 void InvokeV8Callback(const v8::UniquePersistent<v8::Function>& callback); |
| 163 void InvokeV8CallbackWithArgs( |
| 164 const v8::UniquePersistent<v8::Function>& callback, |
| 165 const std::vector<v8::UniquePersistent<v8::Value>>& args); |
| 166 base::Closure CreateClosureThatPostsV8Callback( |
| 167 const v8::Local<v8::Function>& callback); |
| 168 |
| 162 // Helper class for managing events queued by methods like queueLoad or | 169 // Helper class for managing events queued by methods like queueLoad or |
| 163 // queueScript. | 170 // queueScript. |
| 164 class WorkQueue { | 171 class WorkQueue { |
| 165 public: | 172 public: |
| 166 explicit WorkQueue(TestRunner* controller); | 173 explicit WorkQueue(TestRunner* controller); |
| 167 virtual ~WorkQueue(); | 174 virtual ~WorkQueue(); |
| 168 void ProcessWorkSoon(); | 175 void ProcessWorkSoon(); |
| 169 | 176 |
| 170 // Reset the state of the class between tests. | 177 // Reset the state of the class between tests. |
| 171 void Reset(); | 178 void Reset(); |
| 172 | 179 |
| 173 void AddWork(WorkItem*); | 180 void AddWork(WorkItem*); |
| 174 | 181 |
| 175 void set_frozen(bool frozen) { frozen_ = frozen; } | 182 void set_frozen(bool frozen) { frozen_ = frozen; } |
| 176 bool is_empty() { return queue_.empty(); } | 183 bool is_empty() { return queue_.empty(); } |
| 177 WebTaskList* mutable_task_list() { return &task_list_; } | |
| 178 | 184 |
| 179 private: | 185 private: |
| 180 void ProcessWork(); | 186 void ProcessWork(); |
| 181 | 187 |
| 182 class WorkQueueTask : public WebMethodTask<WorkQueue> { | |
| 183 public: | |
| 184 WorkQueueTask(WorkQueue* object) : WebMethodTask<WorkQueue>(object) {} | |
| 185 | |
| 186 void RunIfValid() override; | |
| 187 }; | |
| 188 | |
| 189 WebTaskList task_list_; | |
| 190 std::deque<WorkItem*> queue_; | 188 std::deque<WorkItem*> queue_; |
| 191 bool frozen_; | 189 bool frozen_; |
| 192 TestRunner* controller_; | 190 TestRunner* controller_; |
| 191 |
| 192 base::WeakPtrFactory<WorkQueue> weak_factory_; |
| 193 }; | 193 }; |
| 194 | 194 |
| 195 /////////////////////////////////////////////////////////////////////////// | 195 /////////////////////////////////////////////////////////////////////////// |
| 196 // Methods dealing with the test logic | 196 // Methods dealing with the test logic |
| 197 | 197 |
| 198 // By default, tests end when page load is complete. These methods are used | 198 // By default, tests end when page load is complete. These methods are used |
| 199 // to delay the completion of the test until notifyDone is called. | 199 // to delay the completion of the test until notifyDone is called. |
| 200 void NotifyDone(); | 200 void NotifyDone(); |
| 201 void WaitUntilDone(); | 201 void WaitUntilDone(); |
| 202 | 202 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 643 |
| 644 void GetManifestThen(v8::Local<v8::Function> callback); | 644 void GetManifestThen(v8::Local<v8::Function> callback); |
| 645 | 645 |
| 646 // Takes care of notifying the delegate after a change to layout test runtime | 646 // Takes care of notifying the delegate after a change to layout test runtime |
| 647 // flags. | 647 // flags. |
| 648 void OnLayoutTestRuntimeFlagsChanged(); | 648 void OnLayoutTestRuntimeFlagsChanged(); |
| 649 | 649 |
| 650 /////////////////////////////////////////////////////////////////////////// | 650 /////////////////////////////////////////////////////////////////////////// |
| 651 // Internal helpers | 651 // Internal helpers |
| 652 | 652 |
| 653 void GetManifestCallback(scoped_ptr<InvokeCallbackTask> task, | 653 void GetManifestCallback(v8::UniquePersistent<v8::Function> callback, |
| 654 const blink::WebURLResponse& response, | 654 const blink::WebURLResponse& response, |
| 655 const std::string& data); | 655 const std::string& data); |
| 656 void CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, | 656 void CapturePixelsCallback(v8::UniquePersistent<v8::Function> callback, |
| 657 const SkBitmap& snapshot); | 657 const SkBitmap& snapshot); |
| 658 void DispatchBeforeInstallPromptCallback(scoped_ptr<InvokeCallbackTask> task, | 658 void DispatchBeforeInstallPromptCallback( |
| 659 bool canceled); | 659 v8::UniquePersistent<v8::Function> callback, |
| 660 bool canceled); |
| 660 void GetBluetoothManualChooserEventsCallback( | 661 void GetBluetoothManualChooserEventsCallback( |
| 661 scoped_ptr<InvokeCallbackTask> task, | 662 v8::UniquePersistent<v8::Function> callback, |
| 662 const std::vector<std::string>& events); | 663 const std::vector<std::string>& events); |
| 663 | 664 |
| 664 void CheckResponseMimeType(); | 665 void CheckResponseMimeType(); |
| 665 void CompleteNotifyDone(); | 666 void CompleteNotifyDone(); |
| 666 | 667 |
| 667 void DidAcquirePointerLockInternal(); | 668 void DidAcquirePointerLockInternal(); |
| 668 void DidNotAcquirePointerLockInternal(); | 669 void DidNotAcquirePointerLockInternal(); |
| 669 void DidLosePointerLockInternal(); | 670 void DidLosePointerLockInternal(); |
| 670 | 671 |
| 671 // In the Mac code, this is called to trigger the end of a test after the | 672 // In the Mac code, this is called to trigger the end of a test after the |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 bool should_dump_resource_priorities_; | 785 bool should_dump_resource_priorities_; |
| 785 | 786 |
| 786 bool has_custom_text_output_; | 787 bool has_custom_text_output_; |
| 787 std::string custom_text_output_; | 788 std::string custom_text_output_; |
| 788 | 789 |
| 789 std::set<std::string> http_headers_to_clear_; | 790 std::set<std::string> http_headers_to_clear_; |
| 790 | 791 |
| 791 // WAV audio data is stored here. | 792 // WAV audio data is stored here. |
| 792 std::vector<unsigned char> audio_data_; | 793 std::vector<unsigned char> audio_data_; |
| 793 | 794 |
| 794 // Used for test timeouts. | |
| 795 WebTaskList task_list_; | |
| 796 | |
| 797 TestInterfaces* test_interfaces_; | 795 TestInterfaces* test_interfaces_; |
| 798 WebTestDelegate* delegate_; | 796 WebTestDelegate* delegate_; |
| 799 blink::WebView* web_view_; | 797 blink::WebView* web_view_; |
| 800 WebTestProxyBase* proxy_; | 798 WebTestProxyBase* proxy_; |
| 801 | 799 |
| 802 // This is non-0 IFF a load is in progress. | 800 // This is non-0 IFF a load is in progress. |
| 803 blink::WebFrame* top_loading_frame_; | 801 blink::WebFrame* top_loading_frame_; |
| 804 | 802 |
| 805 // WebContentSettingsClient mock object. | 803 // WebContentSettingsClient mock object. |
| 806 scoped_ptr<WebContentSettings> web_content_settings_; | 804 scoped_ptr<WebContentSettings> web_content_settings_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 828 std::set<blink::WebView*> views_with_scheduled_animations_; | 826 std::set<blink::WebView*> views_with_scheduled_animations_; |
| 829 | 827 |
| 830 base::WeakPtrFactory<TestRunner> weak_factory_; | 828 base::WeakPtrFactory<TestRunner> weak_factory_; |
| 831 | 829 |
| 832 DISALLOW_COPY_AND_ASSIGN(TestRunner); | 830 DISALLOW_COPY_AND_ASSIGN(TestRunner); |
| 833 }; | 831 }; |
| 834 | 832 |
| 835 } // namespace test_runner | 833 } // namespace test_runner |
| 836 | 834 |
| 837 #endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ | 835 #endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ |
| OLD | NEW |