| 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/renderer/test_runner/test_runner.h" | 5 #include "content/shell/renderer/test_runner/test_runner.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/public/test/layouttest_support.h" | 10 #include "content/public/test/layouttest_support.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 v8_str->WriteUtf8(chars.get(), length); | 67 v8_str->WriteUtf8(chars.get(), length); |
| 68 return WebString::fromUTF8(chars.get()); | 68 return WebString::fromUTF8(chars.get()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 class HostMethodTask : public WebMethodTask<TestRunner> { | 71 class HostMethodTask : public WebMethodTask<TestRunner> { |
| 72 public: | 72 public: |
| 73 typedef void (TestRunner::*CallbackMethodType)(); | 73 typedef void (TestRunner::*CallbackMethodType)(); |
| 74 HostMethodTask(TestRunner* object, CallbackMethodType callback) | 74 HostMethodTask(TestRunner* object, CallbackMethodType callback) |
| 75 : WebMethodTask<TestRunner>(object), callback_(callback) {} | 75 : WebMethodTask<TestRunner>(object), callback_(callback) {} |
| 76 | 76 |
| 77 virtual void RunIfValid() OVERRIDE { (object_->*callback_)(); } | 77 virtual void RunIfValid() override { (object_->*callback_)(); } |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 CallbackMethodType callback_; | 80 CallbackMethodType callback_; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 } // namespace | 83 } // namespace |
| 84 | 84 |
| 85 class InvokeCallbackTask : public WebMethodTask<TestRunner> { | 85 class InvokeCallbackTask : public WebMethodTask<TestRunner> { |
| 86 public: | 86 public: |
| 87 InvokeCallbackTask(TestRunner* object, v8::Handle<v8::Function> callback) | 87 InvokeCallbackTask(TestRunner* object, v8::Handle<v8::Function> callback) |
| 88 : WebMethodTask<TestRunner>(object), | 88 : WebMethodTask<TestRunner>(object), |
| 89 callback_(blink::mainThreadIsolate(), callback), | 89 callback_(blink::mainThreadIsolate(), callback), |
| 90 argc_(0) {} | 90 argc_(0) {} |
| 91 | 91 |
| 92 virtual void RunIfValid() OVERRIDE { | 92 virtual void RunIfValid() override { |
| 93 v8::Isolate* isolate = blink::mainThreadIsolate(); | 93 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 94 v8::HandleScope handle_scope(isolate); | 94 v8::HandleScope handle_scope(isolate); |
| 95 WebFrame* frame = object_->web_view_->mainFrame(); | 95 WebFrame* frame = object_->web_view_->mainFrame(); |
| 96 | 96 |
| 97 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); | 97 v8::Handle<v8::Context> context = frame->mainWorldScriptContext(); |
| 98 if (context.IsEmpty()) | 98 if (context.IsEmpty()) |
| 99 return; | 99 return; |
| 100 | 100 |
| 101 v8::Context::Scope context_scope(context); | 101 v8::Context::Scope context_scope(context); |
| 102 | 102 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 static void Install(base::WeakPtr<TestRunner> controller, | 135 static void Install(base::WeakPtr<TestRunner> controller, |
| 136 WebFrame* frame); | 136 WebFrame* frame); |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 explicit TestRunnerBindings( | 139 explicit TestRunnerBindings( |
| 140 base::WeakPtr<TestRunner> controller); | 140 base::WeakPtr<TestRunner> controller); |
| 141 virtual ~TestRunnerBindings(); | 141 virtual ~TestRunnerBindings(); |
| 142 | 142 |
| 143 // gin::Wrappable: | 143 // gin::Wrappable: |
| 144 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 144 virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 145 v8::Isolate* isolate) OVERRIDE; | 145 v8::Isolate* isolate) override; |
| 146 | 146 |
| 147 void LogToStderr(const std::string& output); | 147 void LogToStderr(const std::string& output); |
| 148 void NotifyDone(); | 148 void NotifyDone(); |
| 149 void WaitUntilDone(); | 149 void WaitUntilDone(); |
| 150 void QueueBackNavigation(int how_far_back); | 150 void QueueBackNavigation(int how_far_back); |
| 151 void QueueForwardNavigation(int how_far_forward); | 151 void QueueForwardNavigation(int how_far_forward); |
| 152 void QueueReload(); | 152 void QueueReload(); |
| 153 void QueueLoadingScript(const std::string& script); | 153 void QueueLoadingScript(const std::string& script); |
| 154 void QueueNonLoadingScript(const std::string& script); | 154 void QueueNonLoadingScript(const std::string& script); |
| 155 void QueueLoad(gin::Arguments* args); | 155 void QueueLoad(gin::Arguments* args); |
| (...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) { | 1444 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) { |
| 1445 } | 1445 } |
| 1446 | 1446 |
| 1447 class TestPageOverlay : public WebPageOverlay { | 1447 class TestPageOverlay : public WebPageOverlay { |
| 1448 public: | 1448 public: |
| 1449 explicit TestPageOverlay(WebView* web_view) | 1449 explicit TestPageOverlay(WebView* web_view) |
| 1450 : web_view_(web_view) { | 1450 : web_view_(web_view) { |
| 1451 } | 1451 } |
| 1452 virtual ~TestPageOverlay() {} | 1452 virtual ~TestPageOverlay() {} |
| 1453 | 1453 |
| 1454 virtual void paintPageOverlay(WebCanvas* canvas) OVERRIDE { | 1454 virtual void paintPageOverlay(WebCanvas* canvas) override { |
| 1455 SkRect rect = SkRect::MakeWH(web_view_->size().width, | 1455 SkRect rect = SkRect::MakeWH(web_view_->size().width, |
| 1456 web_view_->size().height); | 1456 web_view_->size().height); |
| 1457 SkPaint paint; | 1457 SkPaint paint; |
| 1458 paint.setColor(SK_ColorCYAN); | 1458 paint.setColor(SK_ColorCYAN); |
| 1459 paint.setStyle(SkPaint::kFill_Style); | 1459 paint.setStyle(SkPaint::kFill_Style); |
| 1460 canvas->drawRect(rect, paint); | 1460 canvas->drawRect(rect, paint); |
| 1461 } | 1461 } |
| 1462 | 1462 |
| 1463 private: | 1463 private: |
| 1464 WebView* web_view_; | 1464 WebView* web_view_; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1908 | 1908 |
| 1909 void TestRunner::ShowDevTools(const std::string& settings, | 1909 void TestRunner::ShowDevTools(const std::string& settings, |
| 1910 const std::string& frontend_url) { | 1910 const std::string& frontend_url) { |
| 1911 delegate_->ShowDevTools(settings, frontend_url); | 1911 delegate_->ShowDevTools(settings, frontend_url); |
| 1912 } | 1912 } |
| 1913 | 1913 |
| 1914 class WorkItemBackForward : public TestRunner::WorkItem { | 1914 class WorkItemBackForward : public TestRunner::WorkItem { |
| 1915 public: | 1915 public: |
| 1916 WorkItemBackForward(int distance) : distance_(distance) {} | 1916 WorkItemBackForward(int distance) : distance_(distance) {} |
| 1917 | 1917 |
| 1918 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE { | 1918 virtual bool Run(WebTestDelegate* delegate, WebView*) override { |
| 1919 delegate->GoToOffset(distance_); | 1919 delegate->GoToOffset(distance_); |
| 1920 return true; // FIXME: Did it really start a navigation? | 1920 return true; // FIXME: Did it really start a navigation? |
| 1921 } | 1921 } |
| 1922 | 1922 |
| 1923 private: | 1923 private: |
| 1924 int distance_; | 1924 int distance_; |
| 1925 }; | 1925 }; |
| 1926 | 1926 |
| 1927 void TestRunner::NotifyDone() { | 1927 void TestRunner::NotifyDone() { |
| 1928 if (disable_notify_done_) | 1928 if (disable_notify_done_) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1941 void TestRunner::QueueBackNavigation(int how_far_back) { | 1941 void TestRunner::QueueBackNavigation(int how_far_back) { |
| 1942 work_queue_.AddWork(new WorkItemBackForward(-how_far_back)); | 1942 work_queue_.AddWork(new WorkItemBackForward(-how_far_back)); |
| 1943 } | 1943 } |
| 1944 | 1944 |
| 1945 void TestRunner::QueueForwardNavigation(int how_far_forward) { | 1945 void TestRunner::QueueForwardNavigation(int how_far_forward) { |
| 1946 work_queue_.AddWork(new WorkItemBackForward(how_far_forward)); | 1946 work_queue_.AddWork(new WorkItemBackForward(how_far_forward)); |
| 1947 } | 1947 } |
| 1948 | 1948 |
| 1949 class WorkItemReload : public TestRunner::WorkItem { | 1949 class WorkItemReload : public TestRunner::WorkItem { |
| 1950 public: | 1950 public: |
| 1951 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE { | 1951 virtual bool Run(WebTestDelegate* delegate, WebView*) override { |
| 1952 delegate->Reload(); | 1952 delegate->Reload(); |
| 1953 return true; | 1953 return true; |
| 1954 } | 1954 } |
| 1955 }; | 1955 }; |
| 1956 | 1956 |
| 1957 void TestRunner::QueueReload() { | 1957 void TestRunner::QueueReload() { |
| 1958 work_queue_.AddWork(new WorkItemReload()); | 1958 work_queue_.AddWork(new WorkItemReload()); |
| 1959 } | 1959 } |
| 1960 | 1960 |
| 1961 class WorkItemLoadingScript : public TestRunner::WorkItem { | 1961 class WorkItemLoadingScript : public TestRunner::WorkItem { |
| 1962 public: | 1962 public: |
| 1963 WorkItemLoadingScript(const std::string& script) | 1963 WorkItemLoadingScript(const std::string& script) |
| 1964 : script_(script) {} | 1964 : script_(script) {} |
| 1965 | 1965 |
| 1966 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE { | 1966 virtual bool Run(WebTestDelegate*, WebView* web_view) override { |
| 1967 web_view->mainFrame()->executeScript( | 1967 web_view->mainFrame()->executeScript( |
| 1968 WebScriptSource(WebString::fromUTF8(script_))); | 1968 WebScriptSource(WebString::fromUTF8(script_))); |
| 1969 return true; // FIXME: Did it really start a navigation? | 1969 return true; // FIXME: Did it really start a navigation? |
| 1970 } | 1970 } |
| 1971 | 1971 |
| 1972 private: | 1972 private: |
| 1973 std::string script_; | 1973 std::string script_; |
| 1974 }; | 1974 }; |
| 1975 | 1975 |
| 1976 void TestRunner::QueueLoadingScript(const std::string& script) { | 1976 void TestRunner::QueueLoadingScript(const std::string& script) { |
| 1977 work_queue_.AddWork(new WorkItemLoadingScript(script)); | 1977 work_queue_.AddWork(new WorkItemLoadingScript(script)); |
| 1978 } | 1978 } |
| 1979 | 1979 |
| 1980 class WorkItemNonLoadingScript : public TestRunner::WorkItem { | 1980 class WorkItemNonLoadingScript : public TestRunner::WorkItem { |
| 1981 public: | 1981 public: |
| 1982 WorkItemNonLoadingScript(const std::string& script) | 1982 WorkItemNonLoadingScript(const std::string& script) |
| 1983 : script_(script) {} | 1983 : script_(script) {} |
| 1984 | 1984 |
| 1985 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE { | 1985 virtual bool Run(WebTestDelegate*, WebView* web_view) override { |
| 1986 web_view->mainFrame()->executeScript( | 1986 web_view->mainFrame()->executeScript( |
| 1987 WebScriptSource(WebString::fromUTF8(script_))); | 1987 WebScriptSource(WebString::fromUTF8(script_))); |
| 1988 return false; | 1988 return false; |
| 1989 } | 1989 } |
| 1990 | 1990 |
| 1991 private: | 1991 private: |
| 1992 std::string script_; | 1992 std::string script_; |
| 1993 }; | 1993 }; |
| 1994 | 1994 |
| 1995 void TestRunner::QueueNonLoadingScript(const std::string& script) { | 1995 void TestRunner::QueueNonLoadingScript(const std::string& script) { |
| 1996 work_queue_.AddWork(new WorkItemNonLoadingScript(script)); | 1996 work_queue_.AddWork(new WorkItemNonLoadingScript(script)); |
| 1997 } | 1997 } |
| 1998 | 1998 |
| 1999 class WorkItemLoad : public TestRunner::WorkItem { | 1999 class WorkItemLoad : public TestRunner::WorkItem { |
| 2000 public: | 2000 public: |
| 2001 WorkItemLoad(const WebURL& url, const std::string& target) | 2001 WorkItemLoad(const WebURL& url, const std::string& target) |
| 2002 : url_(url), target_(target) {} | 2002 : url_(url), target_(target) {} |
| 2003 | 2003 |
| 2004 virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE { | 2004 virtual bool Run(WebTestDelegate* delegate, WebView*) override { |
| 2005 delegate->LoadURLForFrame(url_, target_); | 2005 delegate->LoadURLForFrame(url_, target_); |
| 2006 return true; // FIXME: Did it really start a navigation? | 2006 return true; // FIXME: Did it really start a navigation? |
| 2007 } | 2007 } |
| 2008 | 2008 |
| 2009 private: | 2009 private: |
| 2010 WebURL url_; | 2010 WebURL url_; |
| 2011 std::string target_; | 2011 std::string target_; |
| 2012 }; | 2012 }; |
| 2013 | 2013 |
| 2014 void TestRunner::QueueLoad(const std::string& url, const std::string& target) { | 2014 void TestRunner::QueueLoad(const std::string& url, const std::string& target) { |
| 2015 // FIXME: Implement WebURL::resolve() and avoid GURL. | 2015 // FIXME: Implement WebURL::resolve() and avoid GURL. |
| 2016 GURL current_url = web_view_->mainFrame()->document().url(); | 2016 GURL current_url = web_view_->mainFrame()->document().url(); |
| 2017 GURL full_url = current_url.Resolve(url); | 2017 GURL full_url = current_url.Resolve(url); |
| 2018 work_queue_.AddWork(new WorkItemLoad(full_url, target)); | 2018 work_queue_.AddWork(new WorkItemLoad(full_url, target)); |
| 2019 } | 2019 } |
| 2020 | 2020 |
| 2021 class WorkItemLoadHTMLString : public TestRunner::WorkItem { | 2021 class WorkItemLoadHTMLString : public TestRunner::WorkItem { |
| 2022 public: | 2022 public: |
| 2023 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url) | 2023 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url) |
| 2024 : html_(html), base_url_(base_url) {} | 2024 : html_(html), base_url_(base_url) {} |
| 2025 | 2025 |
| 2026 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url, | 2026 WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url, |
| 2027 const WebURL& unreachable_url) | 2027 const WebURL& unreachable_url) |
| 2028 : html_(html), base_url_(base_url), unreachable_url_(unreachable_url) {} | 2028 : html_(html), base_url_(base_url), unreachable_url_(unreachable_url) {} |
| 2029 | 2029 |
| 2030 virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE { | 2030 virtual bool Run(WebTestDelegate*, WebView* web_view) override { |
| 2031 web_view->mainFrame()->loadHTMLString( | 2031 web_view->mainFrame()->loadHTMLString( |
| 2032 WebData(html_.data(), html_.length()), | 2032 WebData(html_.data(), html_.length()), |
| 2033 base_url_, unreachable_url_); | 2033 base_url_, unreachable_url_); |
| 2034 return true; | 2034 return true; |
| 2035 } | 2035 } |
| 2036 | 2036 |
| 2037 private: | 2037 private: |
| 2038 std::string html_; | 2038 std::string html_; |
| 2039 WebURL base_url_; | 2039 WebURL base_url_; |
| 2040 WebURL unreachable_url_; | 2040 WebURL unreachable_url_; |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2948 } | 2948 } |
| 2949 | 2949 |
| 2950 void TestRunner::DidLosePointerLockInternal() { | 2950 void TestRunner::DidLosePointerLockInternal() { |
| 2951 bool was_locked = pointer_locked_; | 2951 bool was_locked = pointer_locked_; |
| 2952 pointer_locked_ = false; | 2952 pointer_locked_ = false; |
| 2953 if (was_locked) | 2953 if (was_locked) |
| 2954 web_view_->didLosePointerLock(); | 2954 web_view_->didLosePointerLock(); |
| 2955 } | 2955 } |
| 2956 | 2956 |
| 2957 } // namespace content | 2957 } // namespace content |
| OLD | NEW |