Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: webkit/tools/test_shell/layout_test_controller.cc

Issue 196128: Hook up WebViewClient, part 1.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/WebConsoleMessage.h"
17 #include "webkit/api/public/WebFrame.h" 18 #include "webkit/api/public/WebFrame.h"
18 #include "webkit/api/public/WebKit.h" 19 #include "webkit/api/public/WebKit.h"
19 #include "webkit/api/public/WebScriptSource.h" 20 #include "webkit/api/public/WebScriptSource.h"
20 #include "webkit/api/public/WebURL.h" 21 #include "webkit/api/public/WebURL.h"
21 #include "webkit/glue/dom_operations.h" 22 #include "webkit/glue/dom_operations.h"
22 #include "webkit/glue/webpreferences.h" 23 #include "webkit/glue/webpreferences.h"
23 #include "webkit/glue/webview.h" 24 #include "webkit/glue/webview.h"
24 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" 25 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h"
25 #include "webkit/tools/test_shell/test_navigation_controller.h" 26 #include "webkit/tools/test_shell/test_navigation_controller.h"
26 #include "webkit/tools/test_shell/test_shell.h" 27 #include "webkit/tools/test_shell/test_shell.h"
27 28
28 using std::string; 29 using std::string;
29 using std::wstring; 30 using std::wstring;
30 31
32 using WebKit::WebConsoleMessage;
31 using WebKit::WebScriptSource; 33 using WebKit::WebScriptSource;
32 using WebKit::WebString; 34 using WebKit::WebString;
33 35
34 #if defined(OS_WIN) 36 #if defined(OS_WIN)
35 namespace { 37 namespace {
36 38
37 // Stops the test from running and prints a brief warning to stdout. Called 39 // Stops the test from running and prints a brief warning to stdout. Called
38 // when the timer for loading a layout test expires. 40 // when the timer for loading a layout test expires.
39 VOID CALLBACK TestTimeout(HWND hwnd, UINT msg, UINT_PTR timer_id, DWORD ms) { 41 VOID CALLBACK TestTimeout(HWND hwnd, UINT msg, UINT_PTR timer_id, DWORD ms) {
40 puts("#TEST_TIMED_OUT\n"); 42 puts("#TEST_TIMED_OUT\n");
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 return value.ToBoolean(); 834 return value.ToBoolean();
833 else if (value.isInt32()) 835 else if (value.isInt32())
834 return 0 != value.ToInt32(); 836 return 0 != value.ToInt32();
835 else if (value.isString()) { 837 else if (value.isString()) {
836 std::string valueString = value.ToString(); 838 std::string valueString = value.ToString();
837 if (valueString == "true") 839 if (valueString == "true")
838 return true; 840 return true;
839 if (valueString == "false") 841 if (valueString == "false")
840 return false; 842 return false;
841 } 843 }
842 shell_->delegate()->AddMessageToConsole(shell_->webView(), 844 LogErrorToConsole("Invalid value. Expected boolean value.");
843 L"Invalid value. Expected boolean value.", 0, L"");
844 return false; 845 return false;
845 } 846 }
846 847
847 int32 LayoutTestController::CppVariantToInt32(const CppVariant& value) { 848 int32 LayoutTestController::CppVariantToInt32(const CppVariant& value) {
848 if (value.isInt32()) 849 if (value.isInt32())
849 return value.ToInt32(); 850 return value.ToInt32();
850 else if (value.isString()) { 851 else if (value.isString()) {
851 int number; 852 int number;
852 if (StringToInt(value.ToString(), &number)) 853 if (StringToInt(value.ToString(), &number))
853 return number; 854 return number;
854 } 855 }
855 shell_->delegate()->AddMessageToConsole(shell_->webView(), 856 LogErrorToConsole("Invalid value for preference. Expected integer value.");
856 L"Invalid value for preference. Expected integer value.", 0, L"");
857 return 0; 857 return 0;
858 } 858 }
859 859
860 std::wstring LayoutTestController::CppVariantToWstring( 860 std::wstring LayoutTestController::CppVariantToWstring(
861 const CppVariant& value) { 861 const CppVariant& value) {
862 if (value.isString()) 862 if (value.isString())
863 return UTF8ToWide(value.ToString()); 863 return UTF8ToWide(value.ToString());
864 shell_->delegate()->AddMessageToConsole(shell_->webView(), 864 LogErrorToConsole("Invalid value for preference. Expected string value.");
865 L"Invalid value for preference. Expected string value.", 0, L"");
866 return std::wstring(); 865 return std::wstring();
867 } 866 }
868 867
869 void LayoutTestController::overridePreference( 868 void LayoutTestController::overridePreference(
870 const CppArgumentList& args, CppVariant* result) { 869 const CppArgumentList& args, CppVariant* result) {
871 if (args.size() == 2 && args[0].isString()) { 870 if (args.size() == 2 && args[0].isString()) {
872 std::string key = args[0].ToString(); 871 std::string key = args[0].ToString();
873 CppVariant value = args[1]; 872 CppVariant value = args[1];
874 WebPreferences* preferences = shell_->GetWebPreferences(); 873 WebPreferences* preferences = shell_->GetWebPreferences();
875 if (key == "WebKitStandardFont") 874 if (key == "WebKitStandardFont")
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 preferences->java_enabled = CppVariantToBool(value); 916 preferences->java_enabled = CppVariantToBool(value);
918 else if (key == "WebKitUsesPageCachePreferenceKey") 917 else if (key == "WebKitUsesPageCachePreferenceKey")
919 preferences->uses_page_cache = CppVariantToBool(value); 918 preferences->uses_page_cache = CppVariantToBool(value);
920 else if (key == "WebKitXSSAuditorEnabled") 919 else if (key == "WebKitXSSAuditorEnabled")
921 preferences->xss_auditor_enabled = CppVariantToBool(value); 920 preferences->xss_auditor_enabled = CppVariantToBool(value);
922 else if (key == "WebKitLocalStorageEnabledPreferenceKey") 921 else if (key == "WebKitLocalStorageEnabledPreferenceKey")
923 preferences->local_storage_enabled = CppVariantToBool(value); 922 preferences->local_storage_enabled = CppVariantToBool(value);
924 else if (key == "WebKitOfflineWebApplicationCacheEnabled") 923 else if (key == "WebKitOfflineWebApplicationCacheEnabled")
925 preferences->application_cache_enabled = CppVariantToBool(value); 924 preferences->application_cache_enabled = CppVariantToBool(value);
926 else { 925 else {
927 std::wstring message(L"Invalid name for preference: "); 926 std::string message("Invalid name for preference: ");
928 message.append(ASCIIToWide(key)); 927 message.append(key);
929 shell_->delegate()->AddMessageToConsole(shell_->webView(), 928 LogErrorToConsole(message);
930 message, 0, L"");
931 } 929 }
932 preferences->Apply(shell_->webView()); 930 preferences->Apply(shell_->webView());
933 } 931 }
934 result->SetNull(); 932 result->SetNull();
935 } 933 }
936 934
937 void LayoutTestController::fallbackMethod( 935 void LayoutTestController::fallbackMethod(
938 const CppArgumentList& args, CppVariant* result) { 936 const CppArgumentList& args, CppVariant* result) {
939 std::wstring message(L"JavaScript ERROR: unknown method called on LayoutTestCo ntroller"); 937 std::wstring message(L"JavaScript ERROR: unknown method called on LayoutTestCo ntroller");
940 if (!shell_->layout_test_mode()) { 938 if (!shell_->layout_test_mode()) {
(...skipping 15 matching lines...) Expand all
956 954
957 WebKit::WebURL url(GURL(args[0].ToString())); 955 WebKit::WebURL url(GURL(args[0].ToString()));
958 if (!url.isValid()) 956 if (!url.isValid())
959 return; 957 return;
960 958
961 WebKit::whiteListAccessFromOrigin(url, 959 WebKit::whiteListAccessFromOrigin(url,
962 WebString::fromUTF8(args[1].ToString()), 960 WebString::fromUTF8(args[1].ToString()),
963 WebString::fromUTF8(args[2].ToString()), 961 WebString::fromUTF8(args[2].ToString()),
964 args[3].ToBoolean()); 962 args[3].ToBoolean());
965 } 963 }
964
965 void LayoutTestController::LogErrorToConsole(const std::string& text) {
966 shell_->webView()->GetMainFrame()->addMessageToConsole(
967 WebConsoleMessage(WebConsoleMessage::LevelError,
968 WebString::fromUTF8(text)));
969 }
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/layout_test_controller.h ('k') | webkit/tools/test_shell/mac/test_webview_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698