| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // A single item in the work queue. | 145 // A single item in the work queue. |
| 152 class WorkItem { | 146 class WorkItem { |
| 153 public: | 147 public: |
| 154 virtual ~WorkItem() {} | 148 virtual ~WorkItem() {} |
| 155 | 149 |
| 156 // Returns true if this started a load. | 150 // Returns true if this started a load. |
| 157 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0; | 151 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0; |
| 158 }; | 152 }; |
| 159 | 153 |
| 160 private: | 154 private: |
| 161 friend class InvokeCallbackTask; | |
| 162 friend class TestRunnerBindings; | 155 friend class TestRunnerBindings; |
| 163 friend class WorkQueue; | 156 friend class WorkQueue; |
| 164 | 157 |
| 158 // Helpers for working with base and V8 callbacks. |
| 159 void PostTask(const base::Closure& callback); |
| 160 void PostDelayedTask(long long delay, const base::Closure& callback); |
| 161 void PostV8Callback(const v8::Local<v8::Function>& callback); |
| 162 void PostV8CallbackWithArgs(v8::UniquePersistent<v8::Function> callback, |
| 163 int argc, |
| 164 v8::Local<v8::Value> argv[]); |
| 165 void InvokeV8Callback(const v8::UniquePersistent<v8::Function>& callback); |
| 166 void InvokeV8CallbackWithArgs( |
| 167 const v8::UniquePersistent<v8::Function>& callback, |
| 168 const std::vector<v8::UniquePersistent<v8::Value>>& args); |
| 169 base::Closure CreateClosureThatPostsV8Callback( |
| 170 const v8::Local<v8::Function>& callback); |
| 171 |
| 165 // Helper class for managing events queued by methods like queueLoad or | 172 // Helper class for managing events queued by methods like queueLoad or |
| 166 // queueScript. | 173 // queueScript. |
| 167 class WorkQueue { | 174 class WorkQueue { |
| 168 public: | 175 public: |
| 169 explicit WorkQueue(TestRunner* controller); | 176 explicit WorkQueue(TestRunner* controller); |
| 170 virtual ~WorkQueue(); | 177 virtual ~WorkQueue(); |
| 171 void ProcessWorkSoon(); | 178 void ProcessWorkSoon(); |
| 172 | 179 |
| 173 // Reset the state of the class between tests. | 180 // Reset the state of the class between tests. |
| 174 void Reset(); | 181 void Reset(); |
| 175 | 182 |
| 176 void AddWork(WorkItem*); | 183 void AddWork(WorkItem*); |
| 177 | 184 |
| 178 void set_frozen(bool frozen) { frozen_ = frozen; } | 185 void set_frozen(bool frozen) { frozen_ = frozen; } |
| 179 bool is_empty() { return queue_.empty(); } | 186 bool is_empty() { return queue_.empty(); } |
| 180 WebTaskList* mutable_task_list() { return &task_list_; } | |
| 181 | 187 |
| 182 private: | 188 private: |
| 183 void ProcessWork(); | 189 void ProcessWork(); |
| 184 | 190 |
| 185 class WorkQueueTask : public WebMethodTask<WorkQueue> { | |
| 186 public: | |
| 187 WorkQueueTask(WorkQueue* object) : WebMethodTask<WorkQueue>(object) {} | |
| 188 | |
| 189 void RunIfValid() override; | |
| 190 }; | |
| 191 | |
| 192 WebTaskList task_list_; | |
| 193 std::deque<WorkItem*> queue_; | 191 std::deque<WorkItem*> queue_; |
| 194 bool frozen_; | 192 bool frozen_; |
| 195 TestRunner* controller_; | 193 TestRunner* controller_; |
| 194 |
| 195 base::WeakPtrFactory<WorkQueue> weak_factory_; |
| 196 }; | 196 }; |
| 197 | 197 |
| 198 /////////////////////////////////////////////////////////////////////////// | 198 /////////////////////////////////////////////////////////////////////////// |
| 199 // Methods dealing with the test logic | 199 // Methods dealing with the test logic |
| 200 | 200 |
| 201 // By default, tests end when page load is complete. These methods are used | 201 // By default, tests end when page load is complete. These methods are used |
| 202 // to delay the completion of the test until notifyDone is called. | 202 // to delay the completion of the test until notifyDone is called. |
| 203 void NotifyDone(); | 203 void NotifyDone(); |
| 204 void WaitUntilDone(); | 204 void WaitUntilDone(); |
| 205 | 205 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 | 646 |
| 647 void GetManifestThen(v8::Local<v8::Function> callback); | 647 void GetManifestThen(v8::Local<v8::Function> callback); |
| 648 | 648 |
| 649 // Takes care of notifying the delegate after a change to layout test runtime | 649 // Takes care of notifying the delegate after a change to layout test runtime |
| 650 // flags. | 650 // flags. |
| 651 void OnLayoutTestRuntimeFlagsChanged(); | 651 void OnLayoutTestRuntimeFlagsChanged(); |
| 652 | 652 |
| 653 /////////////////////////////////////////////////////////////////////////// | 653 /////////////////////////////////////////////////////////////////////////// |
| 654 // Internal helpers | 654 // Internal helpers |
| 655 | 655 |
| 656 void GetManifestCallback(scoped_ptr<InvokeCallbackTask> task, | 656 void GetManifestCallback(v8::UniquePersistent<v8::Function> callback, |
| 657 const blink::WebURLResponse& response, | 657 const blink::WebURLResponse& response, |
| 658 const std::string& data); | 658 const std::string& data); |
| 659 void CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, | 659 void CapturePixelsCallback(v8::UniquePersistent<v8::Function> callback, |
| 660 const SkBitmap& snapshot); | 660 const SkBitmap& snapshot); |
| 661 void DispatchBeforeInstallPromptCallback(scoped_ptr<InvokeCallbackTask> task, | 661 void DispatchBeforeInstallPromptCallback( |
| 662 bool canceled); | 662 v8::UniquePersistent<v8::Function> callback, |
| 663 bool canceled); |
| 663 void GetBluetoothManualChooserEventsCallback( | 664 void GetBluetoothManualChooserEventsCallback( |
| 664 scoped_ptr<InvokeCallbackTask> task, | 665 v8::UniquePersistent<v8::Function> callback, |
| 665 const std::vector<std::string>& events); | 666 const std::vector<std::string>& events); |
| 666 | 667 |
| 667 void CheckResponseMimeType(); | 668 void CheckResponseMimeType(); |
| 668 void CompleteNotifyDone(); | 669 void CompleteNotifyDone(); |
| 669 | 670 |
| 670 void DidAcquirePointerLockInternal(); | 671 void DidAcquirePointerLockInternal(); |
| 671 void DidNotAcquirePointerLockInternal(); | 672 void DidNotAcquirePointerLockInternal(); |
| 672 void DidLosePointerLockInternal(); | 673 void DidLosePointerLockInternal(); |
| 673 | 674 |
| 674 // In the Mac code, this is called to trigger the end of a test after the | 675 // 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... |
| 787 bool should_dump_resource_priorities_; | 788 bool should_dump_resource_priorities_; |
| 788 | 789 |
| 789 bool has_custom_text_output_; | 790 bool has_custom_text_output_; |
| 790 std::string custom_text_output_; | 791 std::string custom_text_output_; |
| 791 | 792 |
| 792 std::set<std::string> http_headers_to_clear_; | 793 std::set<std::string> http_headers_to_clear_; |
| 793 | 794 |
| 794 // WAV audio data is stored here. | 795 // WAV audio data is stored here. |
| 795 std::vector<unsigned char> audio_data_; | 796 std::vector<unsigned char> audio_data_; |
| 796 | 797 |
| 797 // Used for test timeouts. | |
| 798 WebTaskList task_list_; | |
| 799 | |
| 800 TestInterfaces* test_interfaces_; | 798 TestInterfaces* test_interfaces_; |
| 801 WebTestDelegate* delegate_; | 799 WebTestDelegate* delegate_; |
| 802 blink::WebView* web_view_; | 800 blink::WebView* web_view_; |
| 803 WebTestProxyBase* proxy_; | 801 WebTestProxyBase* proxy_; |
| 804 | 802 |
| 805 // This is non-0 IFF a load is in progress. | 803 // This is non-0 IFF a load is in progress. |
| 806 blink::WebFrame* top_loading_frame_; | 804 blink::WebFrame* top_loading_frame_; |
| 807 | 805 |
| 808 // WebContentSettingsClient mock object. | 806 // WebContentSettingsClient mock object. |
| 809 scoped_ptr<WebContentSettings> web_content_settings_; | 807 scoped_ptr<WebContentSettings> web_content_settings_; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 831 std::set<blink::WebView*> views_with_scheduled_animations_; | 829 std::set<blink::WebView*> views_with_scheduled_animations_; |
| 832 | 830 |
| 833 base::WeakPtrFactory<TestRunner> weak_factory_; | 831 base::WeakPtrFactory<TestRunner> weak_factory_; |
| 834 | 832 |
| 835 DISALLOW_COPY_AND_ASSIGN(TestRunner); | 833 DISALLOW_COPY_AND_ASSIGN(TestRunner); |
| 836 }; | 834 }; |
| 837 | 835 |
| 838 } // namespace test_runner | 836 } // namespace test_runner |
| 839 | 837 |
| 840 #endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ | 838 #endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ |
| OLD | NEW |