| 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_path.h" | 12 #include "base/file_path.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 "webkit/api/public/WebFrame.h" |
| 17 #include "webkit/api/public/WebScriptSource.h" | 18 #include "webkit/api/public/WebScriptSource.h" |
| 18 #include "webkit/glue/dom_operations.h" | 19 #include "webkit/glue/dom_operations.h" |
| 19 #include "webkit/glue/webframe.h" | |
| 20 #include "webkit/glue/webpreferences.h" | 20 #include "webkit/glue/webpreferences.h" |
| 21 #include "webkit/glue/webview.h" | 21 #include "webkit/glue/webview.h" |
| 22 #include "webkit/tools/test_shell/test_navigation_controller.h" | 22 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 23 #include "webkit/tools/test_shell/test_shell.h" | 23 #include "webkit/tools/test_shell/test_shell.h" |
| 24 | 24 |
| 25 using std::string; | 25 using std::string; |
| 26 using std::wstring; | 26 using std::wstring; |
| 27 | 27 |
| 28 using WebKit::WebScriptSource; | 28 using WebKit::WebScriptSource; |
| 29 using WebKit::WebString; | 29 using WebKit::WebString; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 void LayoutTestController::queueReload( | 322 void LayoutTestController::queueReload( |
| 323 const CppArgumentList& args, CppVariant* result) { | 323 const CppArgumentList& args, CppVariant* result) { |
| 324 work_queue_.AddWork(new WorkItemReload); | 324 work_queue_.AddWork(new WorkItemReload); |
| 325 result->SetNull(); | 325 result->SetNull(); |
| 326 } | 326 } |
| 327 | 327 |
| 328 class WorkItemLoadingScript : public LayoutTestController::WorkItem { | 328 class WorkItemLoadingScript : public LayoutTestController::WorkItem { |
| 329 public: | 329 public: |
| 330 WorkItemLoadingScript(const string& script) : script_(script) {} | 330 WorkItemLoadingScript(const string& script) : script_(script) {} |
| 331 bool Run(TestShell* shell) { | 331 bool Run(TestShell* shell) { |
| 332 shell->webView()->GetMainFrame()->ExecuteScript( | 332 shell->webView()->GetMainFrame()->executeScript( |
| 333 WebScriptSource(WebString::fromUTF8(script_))); | 333 WebScriptSource(WebString::fromUTF8(script_))); |
| 334 return true; // TODO(darin): Did it really start a navigation? | 334 return true; // TODO(darin): Did it really start a navigation? |
| 335 } | 335 } |
| 336 private: | 336 private: |
| 337 string script_; | 337 string script_; |
| 338 }; | 338 }; |
| 339 | 339 |
| 340 class WorkItemNonLoadingScript : public LayoutTestController::WorkItem { | 340 class WorkItemNonLoadingScript : public LayoutTestController::WorkItem { |
| 341 public: | 341 public: |
| 342 WorkItemNonLoadingScript(const string& script) : script_(script) {} | 342 WorkItemNonLoadingScript(const string& script) : script_(script) {} |
| 343 bool Run(TestShell* shell) { | 343 bool Run(TestShell* shell) { |
| 344 shell->webView()->GetMainFrame()->ExecuteScript( | 344 shell->webView()->GetMainFrame()->executeScript( |
| 345 WebScriptSource(WebString::fromUTF8(script_))); | 345 WebScriptSource(WebString::fromUTF8(script_))); |
| 346 return false; | 346 return false; |
| 347 } | 347 } |
| 348 private: | 348 private: |
| 349 string script_; | 349 string script_; |
| 350 }; | 350 }; |
| 351 | 351 |
| 352 void LayoutTestController::queueLoadingScript( | 352 void LayoutTestController::queueLoadingScript( |
| 353 const CppArgumentList& args, CppVariant* result) { | 353 const CppArgumentList& args, CppVariant* result) { |
| 354 if (args.size() > 0 && args[0].isString()) | 354 if (args.size() > 0 && args[0].isString()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 373 return true; // TODO(darin): Did it really start a navigation? | 373 return true; // TODO(darin): Did it really start a navigation? |
| 374 } | 374 } |
| 375 private: | 375 private: |
| 376 GURL url_; | 376 GURL url_; |
| 377 string target_; | 377 string target_; |
| 378 }; | 378 }; |
| 379 | 379 |
| 380 void LayoutTestController::queueLoad( | 380 void LayoutTestController::queueLoad( |
| 381 const CppArgumentList& args, CppVariant* result) { | 381 const CppArgumentList& args, CppVariant* result) { |
| 382 if (args.size() > 0 && args[0].isString()) { | 382 if (args.size() > 0 && args[0].isString()) { |
| 383 GURL current_url = shell_->webView()->GetMainFrame()->GetURL(); | 383 GURL current_url = shell_->webView()->GetMainFrame()->url(); |
| 384 GURL full_url = current_url.Resolve(args[0].ToString()); | 384 GURL full_url = current_url.Resolve(args[0].ToString()); |
| 385 | 385 |
| 386 string target = ""; | 386 string target = ""; |
| 387 if (args.size() > 1 && args[1].isString()) | 387 if (args.size() > 1 && args[1].isString()) |
| 388 target = args[1].ToString(); | 388 target = args[1].ToString(); |
| 389 | 389 |
| 390 work_queue_.AddWork(new WorkItemLoad(full_url, target)); | 390 work_queue_.AddWork(new WorkItemLoad(full_url, target)); |
| 391 } | 391 } |
| 392 result->SetNull(); | 392 result->SetNull(); |
| 393 } | 393 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 if (args.size() > 0 && args[0].isString()) { | 525 if (args.size() > 0 && args[0].isString()) { |
| 526 std::string command = args[0].ToString(); | 526 std::string command = args[0].ToString(); |
| 527 std::string value(""); | 527 std::string value(""); |
| 528 | 528 |
| 529 // Ignore the second parameter (which is userInterface) | 529 // Ignore the second parameter (which is userInterface) |
| 530 // since this command emulates a manual action. | 530 // since this command emulates a manual action. |
| 531 if (args.size() >= 3 && args[2].isString()) | 531 if (args.size() >= 3 && args[2].isString()) |
| 532 value = args[2].ToString(); | 532 value = args[2].ToString(); |
| 533 | 533 |
| 534 // Note: webkit's version does not return the boolean, so neither do we. | 534 // Note: webkit's version does not return the boolean, so neither do we. |
| 535 shell_->webView()->GetFocusedFrame()->ExecuteEditCommandByName(command, | 535 shell_->webView()->GetFocusedFrame()->executeCommand( |
| 536 value); | 536 WebString::fromUTF8(command), WebString::fromUTF8(value)); |
| 537 } | 537 } |
| 538 result->SetNull(); | 538 result->SetNull(); |
| 539 } | 539 } |
| 540 | 540 |
| 541 void LayoutTestController::isCommandEnabled( | 541 void LayoutTestController::isCommandEnabled( |
| 542 const CppArgumentList& args, CppVariant* result) { | 542 const CppArgumentList& args, CppVariant* result) { |
| 543 if (args.size() <= 0 || !args[0].isString()) { | 543 if (args.size() <= 0 || !args[0].isString()) { |
| 544 result->SetNull(); | 544 result->SetNull(); |
| 545 return; | 545 return; |
| 546 } | 546 } |
| 547 | 547 |
| 548 std::string command = args[0].ToString(); | 548 std::string command = args[0].ToString(); |
| 549 bool rv = shell_->webView()->GetFocusedFrame()->IsEditCommandEnabled(command); | 549 bool rv = shell_->webView()->GetFocusedFrame()->isCommandEnabled( |
| 550 WebString::fromUTF8(command)); |
| 550 result->Set(rv); | 551 result->Set(rv); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void LayoutTestController::setPopupBlockingEnabled( | 554 void LayoutTestController::setPopupBlockingEnabled( |
| 554 const CppArgumentList& args, CppVariant* result) { | 555 const CppArgumentList& args, CppVariant* result) { |
| 555 if (args.size() > 0 && args[0].isBool()) { | 556 if (args.size() > 0 && args[0].isBool()) { |
| 556 bool block_popups = args[0].ToBoolean(); | 557 bool block_popups = args[0].ToBoolean(); |
| 557 WebPreferences* prefs = shell_->GetWebPreferences(); | 558 WebPreferences* prefs = shell_->GetWebPreferences(); |
| 558 prefs->javascript_can_open_windows_automatically = !block_popups; | 559 prefs->javascript_can_open_windows_automatically = !block_popups; |
| 559 | 560 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 preferences->xss_auditor_enabled = args[0].value.boolValue; | 796 preferences->xss_auditor_enabled = args[0].value.boolValue; |
| 796 shell_->webView()->SetPreferences(*preferences); | 797 shell_->webView()->SetPreferences(*preferences); |
| 797 } | 798 } |
| 798 result->SetNull(); | 799 result->SetNull(); |
| 799 } | 800 } |
| 800 | 801 |
| 801 void LayoutTestController::evaluateScriptInIsolatedWorld( | 802 void LayoutTestController::evaluateScriptInIsolatedWorld( |
| 802 const CppArgumentList& args, CppVariant* result) { | 803 const CppArgumentList& args, CppVariant* result) { |
| 803 if (args.size() > 0 && args[0].isString()) { | 804 if (args.size() > 0 && args[0].isString()) { |
| 804 WebScriptSource source(WebString::fromUTF8(args[0].ToString())); | 805 WebScriptSource source(WebString::fromUTF8(args[0].ToString())); |
| 805 shell_->webView()->GetMainFrame()->ExecuteScriptInNewWorld(&source, 1, 1); | 806 shell_->webView()->GetMainFrame()->executeScriptInNewWorld(&source, 1, 1); |
| 806 } | 807 } |
| 807 result->SetNull(); | 808 result->SetNull(); |
| 808 } | 809 } |
| 809 | 810 |
| 810 void LayoutTestController::fallbackMethod( | 811 void LayoutTestController::fallbackMethod( |
| 811 const CppArgumentList& args, CppVariant* result) { | 812 const CppArgumentList& args, CppVariant* result) { |
| 812 std::wstring message(L"JavaScript ERROR: unknown method called on LayoutTestCo
ntroller"); | 813 std::wstring message(L"JavaScript ERROR: unknown method called on LayoutTestCo
ntroller"); |
| 813 if (!shell_->layout_test_mode()) { | 814 if (!shell_->layout_test_mode()) { |
| 814 logging::LogMessage("CONSOLE:", 0).stream() << message; | 815 logging::LogMessage("CONSOLE:", 0).stream() << message; |
| 815 } else { | 816 } else { |
| 816 printf("CONSOLE MESSAGE: %S\n", message.c_str()); | 817 printf("CONSOLE MESSAGE: %S\n", message.c_str()); |
| 817 } | 818 } |
| 818 result->SetNull(); | 819 result->SetNull(); |
| 819 } | 820 } |
| OLD | NEW |