| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file contains the definition for LayoutTestController. | 5 // This file contains the definition for LayoutTestController. |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "webkit/tools/test_shell/layout_test_controller.h" | 9 #include "webkit/tools/test_shell/layout_test_controller.h" |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" |
| 17 #include "webkit/glue/dom_operations.h" | 18 #include "webkit/glue/dom_operations.h" |
| 18 #include "webkit/glue/webframe.h" | 19 #include "webkit/glue/webframe.h" |
| 19 #include "webkit/glue/webpreferences.h" | 20 #include "webkit/glue/webpreferences.h" |
| 20 #include "webkit/glue/webview.h" | 21 #include "webkit/glue/webview.h" |
| 21 #include "webkit/tools/test_shell/test_navigation_controller.h" | 22 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 22 #include "webkit/tools/test_shell/test_shell.h" | 23 #include "webkit/tools/test_shell/test_shell.h" |
| 23 | 24 |
| 24 using std::string; | 25 using std::string; |
| 25 using std::wstring; | 26 using std::wstring; |
| 26 | 27 |
| 28 using WebKit::WebScriptSource; |
| 29 using WebKit::WebString; |
| 30 |
| 27 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 28 namespace { | 32 namespace { |
| 29 | 33 |
| 30 // Stops the test from running and prints a brief warning to stdout. Called | 34 // Stops the test from running and prints a brief warning to stdout. Called |
| 31 // when the timer for loading a layout test expires. | 35 // when the timer for loading a layout test expires. |
| 32 VOID CALLBACK TestTimeout(HWND hwnd, UINT msg, UINT_PTR timer_id, DWORD ms) { | 36 VOID CALLBACK TestTimeout(HWND hwnd, UINT msg, UINT_PTR timer_id, DWORD ms) { |
| 33 puts("#TEST_TIMED_OUT\n"); | 37 puts("#TEST_TIMED_OUT\n"); |
| 34 reinterpret_cast<TestShell*>(timer_id)->TestFinished(); | 38 reinterpret_cast<TestShell*>(timer_id)->TestFinished(); |
| 35 // Print a warning to be caught by the layout-test script. | 39 // Print a warning to be caught by the layout-test script. |
| 36 } | 40 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 BindMethod("dumpEditingCallbacks", &LayoutTestController::dumpEditingCallbacks
); | 81 BindMethod("dumpEditingCallbacks", &LayoutTestController::dumpEditingCallbacks
); |
| 78 BindMethod("dumpBackForwardList", &LayoutTestController::dumpBackForwardList); | 82 BindMethod("dumpBackForwardList", &LayoutTestController::dumpBackForwardList); |
| 79 BindMethod("dumpFrameLoadCallbacks", &LayoutTestController::dumpFrameLoadCallb
acks); | 83 BindMethod("dumpFrameLoadCallbacks", &LayoutTestController::dumpFrameLoadCallb
acks); |
| 80 BindMethod("dumpResourceLoadCallbacks", &LayoutTestController::dumpResourceLoa
dCallbacks); | 84 BindMethod("dumpResourceLoadCallbacks", &LayoutTestController::dumpResourceLoa
dCallbacks); |
| 81 BindMethod("dumpStatusCallbacks", &LayoutTestController::dumpWindowStatusChang
es); | 85 BindMethod("dumpStatusCallbacks", &LayoutTestController::dumpWindowStatusChang
es); |
| 82 BindMethod("dumpTitleChanges", &LayoutTestController::dumpTitleChanges); | 86 BindMethod("dumpTitleChanges", &LayoutTestController::dumpTitleChanges); |
| 83 BindMethod("setAcceptsEditing", &LayoutTestController::setAcceptsEditing); | 87 BindMethod("setAcceptsEditing", &LayoutTestController::setAcceptsEditing); |
| 84 BindMethod("waitUntilDone", &LayoutTestController::waitUntilDone); | 88 BindMethod("waitUntilDone", &LayoutTestController::waitUntilDone); |
| 85 BindMethod("notifyDone", &LayoutTestController::notifyDone); | 89 BindMethod("notifyDone", &LayoutTestController::notifyDone); |
| 86 BindMethod("queueReload", &LayoutTestController::queueReload); | 90 BindMethod("queueReload", &LayoutTestController::queueReload); |
| 87 BindMethod("queueScript", &LayoutTestController::queueScript); | 91 BindMethod("queueLoadingScript", &LayoutTestController::queueLoadingScript); |
| 92 BindMethod("queueNonLoadingScript", &LayoutTestController::queueNonLoadingScri
pt); |
| 88 BindMethod("queueLoad", &LayoutTestController::queueLoad); | 93 BindMethod("queueLoad", &LayoutTestController::queueLoad); |
| 89 BindMethod("queueBackNavigation", &LayoutTestController::queueBackNavigation); | 94 BindMethod("queueBackNavigation", &LayoutTestController::queueBackNavigation); |
| 90 BindMethod("queueForwardNavigation", &LayoutTestController::queueForwardNaviga
tion); | 95 BindMethod("queueForwardNavigation", &LayoutTestController::queueForwardNaviga
tion); |
| 91 BindMethod("windowCount", &LayoutTestController::windowCount); | 96 BindMethod("windowCount", &LayoutTestController::windowCount); |
| 92 BindMethod("setCanOpenWindows", &LayoutTestController::setCanOpenWindows); | 97 BindMethod("setCanOpenWindows", &LayoutTestController::setCanOpenWindows); |
| 93 BindMethod("setCloseRemainingWindowsWhenComplete", &LayoutTestController::setC
loseRemainingWindowsWhenComplete); | 98 BindMethod("setCloseRemainingWindowsWhenComplete", &LayoutTestController::setC
loseRemainingWindowsWhenComplete); |
| 94 BindMethod("objCIdentityIsEqual", &LayoutTestController::objCIdentityIsEqual); | 99 BindMethod("objCIdentityIsEqual", &LayoutTestController::objCIdentityIsEqual); |
| 95 BindMethod("setWindowIsKey", &LayoutTestController::setWindowIsKey); | 100 BindMethod("setWindowIsKey", &LayoutTestController::setWindowIsKey); |
| 96 BindMethod("setTabKeyCyclesThroughElements", &LayoutTestController::setTabKeyC
yclesThroughElements); | 101 BindMethod("setTabKeyCyclesThroughElements", &LayoutTestController::setTabKeyC
yclesThroughElements); |
| 97 BindMethod("setUserStyleSheetLocation", &LayoutTestController::setUserStyleShe
etLocation); | 102 BindMethod("setUserStyleSheetLocation", &LayoutTestController::setUserStyleShe
etLocation); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 if (!queue_.empty()) { | 159 if (!queue_.empty()) { |
| 155 // We delay processing queued work to avoid recursion problems. | 160 // We delay processing queued work to avoid recursion problems. |
| 156 timer_.Start(base::TimeDelta(), this, &WorkQueue::ProcessWork); | 161 timer_.Start(base::TimeDelta(), this, &WorkQueue::ProcessWork); |
| 157 } else if (!wait_until_done_) { | 162 } else if (!wait_until_done_) { |
| 158 shell_->TestFinished(); | 163 shell_->TestFinished(); |
| 159 } | 164 } |
| 160 } | 165 } |
| 161 | 166 |
| 162 void LayoutTestController::WorkQueue::ProcessWork() { | 167 void LayoutTestController::WorkQueue::ProcessWork() { |
| 163 // Quit doing work once a load is in progress. | 168 // Quit doing work once a load is in progress. |
| 164 while (!queue_.empty() && !shell_->delegate()->top_loading_frame()) { | 169 while (!queue_.empty()) { |
| 165 queue_.front()->Run(shell_); | 170 bool started_load = queue_.front()->Run(shell_); |
| 166 delete queue_.front(); | 171 delete queue_.front(); |
| 167 queue_.pop(); | 172 queue_.pop(); |
| 173 |
| 174 if (started_load) |
| 175 return; |
| 168 } | 176 } |
| 169 | 177 |
| 170 if (!shell_->delegate()->top_loading_frame() && !wait_until_done_) { | 178 if (!wait_until_done_) |
| 171 shell_->TestFinished(); | 179 shell_->TestFinished(); |
| 172 } | |
| 173 } | 180 } |
| 174 | 181 |
| 175 void LayoutTestController::WorkQueue::Reset() { | 182 void LayoutTestController::WorkQueue::Reset() { |
| 176 frozen_ = false; | 183 frozen_ = false; |
| 177 while (!queue_.empty()) { | 184 while (!queue_.empty()) { |
| 178 delete queue_.front(); | 185 delete queue_.front(); |
| 179 queue_.pop(); | 186 queue_.pop(); |
| 180 } | 187 } |
| 181 } | 188 } |
| 182 | 189 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 !shell_->delegate()->top_loading_frame() && work_queue_.empty()) { | 280 !shell_->delegate()->top_loading_frame() && work_queue_.empty()) { |
| 274 shell_->TestFinished(); | 281 shell_->TestFinished(); |
| 275 } | 282 } |
| 276 wait_until_done_ = false; | 283 wait_until_done_ = false; |
| 277 result->SetNull(); | 284 result->SetNull(); |
| 278 } | 285 } |
| 279 | 286 |
| 280 class WorkItemBackForward : public LayoutTestController::WorkItem { | 287 class WorkItemBackForward : public LayoutTestController::WorkItem { |
| 281 public: | 288 public: |
| 282 WorkItemBackForward(int distance) : distance_(distance) {} | 289 WorkItemBackForward(int distance) : distance_(distance) {} |
| 283 void Run(TestShell* shell) { | 290 bool Run(TestShell* shell) { |
| 284 shell->GoBackOrForward(distance_); | 291 shell->GoBackOrForward(distance_); |
| 292 return true; // TODO(darin): Did it really start a navigation? |
| 285 } | 293 } |
| 286 private: | 294 private: |
| 287 int distance_; | 295 int distance_; |
| 288 }; | 296 }; |
| 289 | 297 |
| 290 void LayoutTestController::queueBackNavigation( | 298 void LayoutTestController::queueBackNavigation( |
| 291 const CppArgumentList& args, CppVariant* result) { | 299 const CppArgumentList& args, CppVariant* result) { |
| 292 if (args.size() > 0 && args[0].isNumber()) | 300 if (args.size() > 0 && args[0].isNumber()) |
| 293 work_queue_.AddWork(new WorkItemBackForward(-args[0].ToInt32())); | 301 work_queue_.AddWork(new WorkItemBackForward(-args[0].ToInt32())); |
| 294 result->SetNull(); | 302 result->SetNull(); |
| 295 } | 303 } |
| 296 | 304 |
| 297 void LayoutTestController::queueForwardNavigation( | 305 void LayoutTestController::queueForwardNavigation( |
| 298 const CppArgumentList& args, CppVariant* result) { | 306 const CppArgumentList& args, CppVariant* result) { |
| 299 if (args.size() > 0 && args[0].isNumber()) | 307 if (args.size() > 0 && args[0].isNumber()) |
| 300 work_queue_.AddWork(new WorkItemBackForward(args[0].ToInt32())); | 308 work_queue_.AddWork(new WorkItemBackForward(args[0].ToInt32())); |
| 301 result->SetNull(); | 309 result->SetNull(); |
| 302 } | 310 } |
| 303 | 311 |
| 304 class WorkItemReload : public LayoutTestController::WorkItem { | 312 class WorkItemReload : public LayoutTestController::WorkItem { |
| 305 public: | 313 public: |
| 306 void Run(TestShell* shell) { | 314 bool Run(TestShell* shell) { |
| 307 shell->Reload(); | 315 shell->Reload(); |
| 316 return true; |
| 308 } | 317 } |
| 309 }; | 318 }; |
| 310 | 319 |
| 311 void LayoutTestController::queueReload( | 320 void LayoutTestController::queueReload( |
| 312 const CppArgumentList& args, CppVariant* result) { | 321 const CppArgumentList& args, CppVariant* result) { |
| 313 work_queue_.AddWork(new WorkItemReload); | 322 work_queue_.AddWork(new WorkItemReload); |
| 314 result->SetNull(); | 323 result->SetNull(); |
| 315 } | 324 } |
| 316 | 325 |
| 317 class WorkItemScript : public LayoutTestController::WorkItem { | 326 class WorkItemLoadingScript : public LayoutTestController::WorkItem { |
| 318 public: | 327 public: |
| 319 WorkItemScript(const string& script) : script_(script) {} | 328 WorkItemLoadingScript(const string& script) : script_(script) {} |
| 320 void Run(TestShell* shell) { | 329 bool Run(TestShell* shell) { |
| 321 wstring url = L"javascript:" + UTF8ToWide(script_); | 330 shell->webView()->GetMainFrame()->ExecuteScript( |
| 322 shell->LoadURL(url.c_str()); | 331 WebScriptSource(WebString::fromUTF8(script_))); |
| 332 return true; // TODO(darin): Did it really start a navigation? |
| 323 } | 333 } |
| 324 private: | 334 private: |
| 325 string script_; | 335 string script_; |
| 326 }; | 336 }; |
| 327 | 337 |
| 328 void LayoutTestController::queueScript( | 338 class WorkItemNonLoadingScript : public LayoutTestController::WorkItem { |
| 339 public: |
| 340 WorkItemNonLoadingScript(const string& script) : script_(script) {} |
| 341 bool Run(TestShell* shell) { |
| 342 shell->webView()->GetMainFrame()->ExecuteScript( |
| 343 WebScriptSource(WebString::fromUTF8(script_))); |
| 344 return false; |
| 345 } |
| 346 private: |
| 347 string script_; |
| 348 }; |
| 349 |
| 350 void LayoutTestController::queueLoadingScript( |
| 329 const CppArgumentList& args, CppVariant* result) { | 351 const CppArgumentList& args, CppVariant* result) { |
| 330 if (args.size() > 0 && args[0].isString()) | 352 if (args.size() > 0 && args[0].isString()) |
| 331 work_queue_.AddWork(new WorkItemScript(args[0].ToString())); | 353 work_queue_.AddWork(new WorkItemLoadingScript(args[0].ToString())); |
| 354 result->SetNull(); |
| 355 } |
| 356 |
| 357 void LayoutTestController::queueNonLoadingScript( |
| 358 const CppArgumentList& args, CppVariant* result) { |
| 359 if (args.size() > 0 && args[0].isString()) |
| 360 work_queue_.AddWork(new WorkItemNonLoadingScript(args[0].ToString())); |
| 332 result->SetNull(); | 361 result->SetNull(); |
| 333 } | 362 } |
| 334 | 363 |
| 335 class WorkItemLoad : public LayoutTestController::WorkItem { | 364 class WorkItemLoad : public LayoutTestController::WorkItem { |
| 336 public: | 365 public: |
| 337 WorkItemLoad(const GURL& url, const string& target) | 366 WorkItemLoad(const GURL& url, const string& target) |
| 338 : url_(url), target_(target) {} | 367 : url_(url), target_(target) {} |
| 339 void Run(TestShell* shell) { | 368 bool Run(TestShell* shell) { |
| 340 shell->LoadURLForFrame(UTF8ToWide(url_.spec()).c_str(), | 369 shell->LoadURLForFrame(UTF8ToWide(url_.spec()).c_str(), |
| 341 UTF8ToWide(target_).c_str()); | 370 UTF8ToWide(target_).c_str()); |
| 371 return true; // TODO(darin): Did it really start a navigation? |
| 342 } | 372 } |
| 343 private: | 373 private: |
| 344 GURL url_; | 374 GURL url_; |
| 345 string target_; | 375 string target_; |
| 346 }; | 376 }; |
| 347 | 377 |
| 348 void LayoutTestController::queueLoad( | 378 void LayoutTestController::queueLoad( |
| 349 const CppArgumentList& args, CppVariant* result) { | 379 const CppArgumentList& args, CppVariant* result) { |
| 350 if (args.size() > 0 && args[0].isString()) { | 380 if (args.size() > 0 && args[0].isString()) { |
| 351 GURL current_url = shell_->webView()->GetMainFrame()->GetURL(); | 381 GURL current_url = shell_->webView()->GetMainFrame()->GetURL(); |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 void LayoutTestController::fallbackMethod( | 746 void LayoutTestController::fallbackMethod( |
| 717 const CppArgumentList& args, CppVariant* result) { | 747 const CppArgumentList& args, CppVariant* result) { |
| 718 std::wstring message(L"JavaScript ERROR: unknown method called on LayoutTestCo
ntroller"); | 748 std::wstring message(L"JavaScript ERROR: unknown method called on LayoutTestCo
ntroller"); |
| 719 if (!shell_->layout_test_mode()) { | 749 if (!shell_->layout_test_mode()) { |
| 720 logging::LogMessage("CONSOLE:", 0).stream() << message; | 750 logging::LogMessage("CONSOLE:", 0).stream() << message; |
| 721 } else { | 751 } else { |
| 722 printf("CONSOLE MESSAGE: %S\n", message.c_str()); | 752 printf("CONSOLE MESSAGE: %S\n", message.c_str()); |
| 723 } | 753 } |
| 724 result->SetNull(); | 754 result->SetNull(); |
| 725 } | 755 } |
| OLD | NEW |