| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 BindMethod("waitForPolicyDelegate", &LayoutTestController::waitForPolicyDelega
te); | 122 BindMethod("waitForPolicyDelegate", &LayoutTestController::waitForPolicyDelega
te); |
| 123 BindMethod("setWillSendRequestReturnsNullOnRedirect", &LayoutTestController::s
etWillSendRequestReturnsNullOnRedirect); | 123 BindMethod("setWillSendRequestReturnsNullOnRedirect", &LayoutTestController::s
etWillSendRequestReturnsNullOnRedirect); |
| 124 BindMethod("setWillSendRequestReturnsNull", &LayoutTestController::setWillSend
RequestReturnsNull); | 124 BindMethod("setWillSendRequestReturnsNull", &LayoutTestController::setWillSend
RequestReturnsNull); |
| 125 BindMethod("whiteListAccessFromOrigin", &LayoutTestController::whiteListAccess
FromOrigin); | 125 BindMethod("whiteListAccessFromOrigin", &LayoutTestController::whiteListAccess
FromOrigin); |
| 126 BindMethod("clearAllDatabases", &LayoutTestController::clearAllDatabases); | 126 BindMethod("clearAllDatabases", &LayoutTestController::clearAllDatabases); |
| 127 BindMethod("setDatabaseQuota", &LayoutTestController::setDatabaseQuota); | 127 BindMethod("setDatabaseQuota", &LayoutTestController::setDatabaseQuota); |
| 128 BindMethod("setPOSIXLocale", &LayoutTestController::setPOSIXLocale); | 128 BindMethod("setPOSIXLocale", &LayoutTestController::setPOSIXLocale); |
| 129 BindMethod("counterValueForElementById", &LayoutTestController::counterValueFo
rElementById); | 129 BindMethod("counterValueForElementById", &LayoutTestController::counterValueFo
rElementById); |
| 130 BindMethod("addUserScript", &LayoutTestController::addUserScript); | 130 BindMethod("addUserScript", &LayoutTestController::addUserScript); |
| 131 BindMethod("pageNumberForElementById", &LayoutTestController::pageNumberForEle
mentById); | 131 BindMethod("pageNumberForElementById", &LayoutTestController::pageNumberForEle
mentById); |
| 132 BindMethod("numberOfPages", &LayoutTestController::numberOfPages); |
| 132 | 133 |
| 133 // The following are stubs. | 134 // The following are stubs. |
| 134 BindMethod("dumpAsWebArchive", &LayoutTestController::dumpAsWebArchive); | 135 BindMethod("dumpAsWebArchive", &LayoutTestController::dumpAsWebArchive); |
| 135 BindMethod("setMainFrameIsFirstResponder", &LayoutTestController::setMainFrame
IsFirstResponder); | 136 BindMethod("setMainFrameIsFirstResponder", &LayoutTestController::setMainFrame
IsFirstResponder); |
| 136 BindMethod("dumpSelectionRect", &LayoutTestController::dumpSelectionRect); | 137 BindMethod("dumpSelectionRect", &LayoutTestController::dumpSelectionRect); |
| 137 BindMethod("display", &LayoutTestController::display); | 138 BindMethod("display", &LayoutTestController::display); |
| 138 BindMethod("testRepaint", &LayoutTestController::testRepaint); | 139 BindMethod("testRepaint", &LayoutTestController::testRepaint); |
| 139 BindMethod("repaintSweepHorizontally", &LayoutTestController::repaintSweepHori
zontally); | 140 BindMethod("repaintSweepHorizontally", &LayoutTestController::repaintSweepHori
zontally); |
| 140 BindMethod("clearBackForwardList", &LayoutTestController::clearBackForwardList
); | 141 BindMethod("clearBackForwardList", &LayoutTestController::clearBackForwardList
); |
| 141 BindMethod("keepWebHistory", &LayoutTestController::keepWebHistory); | 142 BindMethod("keepWebHistory", &LayoutTestController::keepWebHistory); |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 if (args.size() < 1 || !args[0].isString()) | 1065 if (args.size() < 1 || !args[0].isString()) |
| 1065 return; | 1066 return; |
| 1066 std::wstring counterValue; | 1067 std::wstring counterValue; |
| 1067 if (!webkit_glue::CounterValueForElementById(shell_->webView()->mainFrame(), | 1068 if (!webkit_glue::CounterValueForElementById(shell_->webView()->mainFrame(), |
| 1068 args[0].ToString(), | 1069 args[0].ToString(), |
| 1069 &counterValue)) | 1070 &counterValue)) |
| 1070 return; | 1071 return; |
| 1071 result->Set(WideToUTF8(counterValue)); | 1072 result->Set(WideToUTF8(counterValue)); |
| 1072 } | 1073 } |
| 1073 | 1074 |
| 1075 static bool ParsePageSizeParameters(const CppArgumentList& args, |
| 1076 int arg_offset, |
| 1077 float* page_width_in_pixels, |
| 1078 float* page_height_in_pixels) { |
| 1079 // WebKit is using the window width/height of DumpRenderTree as the |
| 1080 // default value of the page size. |
| 1081 // TODO(hamaji): Once chromium DumpRenderTree is implemented, |
| 1082 // share these values with other ports. |
| 1083 *page_width_in_pixels = 800; |
| 1084 *page_height_in_pixels = 600; |
| 1085 switch (args.size() - arg_offset) { |
| 1086 case 2: |
| 1087 if (!args[arg_offset].isNumber() || !args[1 + arg_offset].isNumber()) |
| 1088 return false; |
| 1089 *page_width_in_pixels = static_cast<float>(args[arg_offset].ToInt32()); |
| 1090 *page_height_in_pixels = static_cast<float>(args[1 + arg_offset].ToInt32()); |
| 1091 // fall through. |
| 1092 case 0: |
| 1093 break; |
| 1094 default: |
| 1095 return false; |
| 1096 } |
| 1097 return true; |
| 1098 } |
| 1099 |
| 1074 void LayoutTestController::pageNumberForElementById( | 1100 void LayoutTestController::pageNumberForElementById( |
| 1075 const CppArgumentList& args, CppVariant* result) { | 1101 const CppArgumentList& args, CppVariant* result) { |
| 1076 result->SetNull(); | 1102 result->SetNull(); |
| 1077 // WebKit is using the window width/height of DumpRenderTree as the | 1103 float page_width_in_pixels = 0; |
| 1078 // default value of the page size. | 1104 float page_height_in_pixels = 0; |
| 1079 // TODO(hamaji): Once chromium DumpRenderTree is implemented, | 1105 if (!ParsePageSizeParameters(args, 1, |
| 1080 // share these values with other ports. | 1106 &page_width_in_pixels, &page_height_in_pixels)) |
| 1081 float page_width_in_pixels = 800; | |
| 1082 float page_height_in_pixels = 600; | |
| 1083 switch (args.size()) { | |
| 1084 case 3: | |
| 1085 if (!args[1].isNumber() || !args[2].isNumber()) | |
| 1086 return; | |
| 1087 page_width_in_pixels = static_cast<float>(args[1].ToInt32()); | |
| 1088 page_height_in_pixels = static_cast<float>(args[2].ToInt32()); | |
| 1089 case 1: // fall through. | |
| 1090 if (!args[0].isString()) | |
| 1091 return; | |
| 1092 break; | |
| 1093 default: | |
| 1094 return; | 1107 return; |
| 1095 } | 1108 if (!args[0].isString()) |
| 1109 return; |
| 1110 |
| 1096 int page_number = webkit_glue::PageNumberForElementById( | 1111 int page_number = webkit_glue::PageNumberForElementById( |
| 1097 shell_->webView()->mainFrame(), | 1112 shell_->webView()->mainFrame(), |
| 1098 args[0].ToString(), | 1113 args[0].ToString(), |
| 1099 page_width_in_pixels, | 1114 page_width_in_pixels, |
| 1100 page_height_in_pixels); | 1115 page_height_in_pixels); |
| 1101 result->Set(page_number); | 1116 result->Set(page_number); |
| 1102 } | 1117 } |
| 1103 | 1118 |
| 1119 void LayoutTestController::numberOfPages( |
| 1120 const CppArgumentList& args, CppVariant* result) { |
| 1121 result->SetNull(); |
| 1122 float page_width_in_pixels = 0; |
| 1123 float page_height_in_pixels = 0; |
| 1124 if (!ParsePageSizeParameters(args, 0, |
| 1125 &page_width_in_pixels, &page_height_in_pixels)) |
| 1126 return; |
| 1127 |
| 1128 int page_number = webkit_glue::NumberOfPages(shell_->webView()->mainFrame(), |
| 1129 page_width_in_pixels, |
| 1130 page_height_in_pixels); |
| 1131 result->Set(page_number); |
| 1132 } |
| 1133 |
| 1104 void LayoutTestController::LogErrorToConsole(const std::string& text) { | 1134 void LayoutTestController::LogErrorToConsole(const std::string& text) { |
| 1105 shell_->delegate()->didAddMessageToConsole( | 1135 shell_->delegate()->didAddMessageToConsole( |
| 1106 WebConsoleMessage(WebConsoleMessage::LevelError, | 1136 WebConsoleMessage(WebConsoleMessage::LevelError, |
| 1107 WebString::fromUTF8(text)), | 1137 WebString::fromUTF8(text)), |
| 1108 WebString(), 0); | 1138 WebString(), 0); |
| 1109 } | 1139 } |
| 1110 | 1140 |
| 1111 void LayoutTestController::setTimelineProfilingEnabled( | 1141 void LayoutTestController::setTimelineProfilingEnabled( |
| 1112 const CppArgumentList& args, CppVariant* result) { | 1142 const CppArgumentList& args, CppVariant* result) { |
| 1113 result->SetNull(); | 1143 result->SetNull(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1133 } | 1163 } |
| 1134 | 1164 |
| 1135 void LayoutTestController::addUserScript(const CppArgumentList& args, | 1165 void LayoutTestController::addUserScript(const CppArgumentList& args, |
| 1136 CppVariant* result) { | 1166 CppVariant* result) { |
| 1137 result->SetNull(); | 1167 result->SetNull(); |
| 1138 if (args.size() < 1 || !args[0].isString() || !args[1].isBool()) | 1168 if (args.size() < 1 || !args[0].isString() || !args[1].isBool()) |
| 1139 return; | 1169 return; |
| 1140 shell_->webView()->addUserScript(WebString::fromUTF8(args[0].ToString()), | 1170 shell_->webView()->addUserScript(WebString::fromUTF8(args[0].ToString()), |
| 1141 args[1].ToBoolean()); | 1171 args[1].ToBoolean()); |
| 1142 } | 1172 } |
| OLD | NEW |