| 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 #include <windows.h> | 5 #include "webkit/tools/test_shell/test_shell.h" |
| 6 #include <atlbase.h> | |
| 7 #include <commdlg.h> | |
| 8 #include <objbase.h> | |
| 9 #include <shlwapi.h> | |
| 10 #include <wininet.h> | |
| 11 | 6 |
| 12 #include "webkit/tools/test_shell/test_shell.h" | 7 #if defined(OS_WIN) |
| 8 #include <hash_map> |
| 9 #else |
| 10 #include <ext/hash_map> |
| 11 #endif |
| 13 | 12 |
| 14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 15 #include "base/debug_on_start.h" | 14 #include "base/debug_on_start.h" |
| 16 #include "base/file_util.h" | 15 #include "base/file_util.h" |
| 17 #include "base/gfx/bitmap_platform_device_win.h" | |
| 18 #include "base/gfx/png_encoder.h" | 16 #include "base/gfx/png_encoder.h" |
| 19 #include "base/gfx/size.h" | 17 #include "base/gfx/size.h" |
| 20 #include "base/icu_util.h" | 18 #include "base/icu_util.h" |
| 21 #include "base/md5.h" | 19 #include "base/md5.h" |
| 22 #include "base/memory_debug.h" | 20 #include "base/memory_debug.h" |
| 23 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
| 24 #include "base/path_service.h" | 22 #include "base/path_service.h" |
| 25 #include "base/stats_table.h" | 23 #include "base/stats_table.h" |
| 26 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 27 #include "base/trace_event.h" | 25 #include "base/trace_event.h" |
| 28 #include "base/win_util.h" | |
| 29 #include "googleurl/src/url_util.h" | 26 #include "googleurl/src/url_util.h" |
| 30 #include "net/base/mime_util.h" | 27 #include "net/base/mime_util.h" |
| 31 #include "net/url_request/url_request_file_job.h" | |
| 32 #include "net/url_request/url_request_filter.h" | |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "webkit/glue/webdatasource.h" | 29 #include "webkit/glue/webdatasource.h" |
| 35 #include "webkit/glue/webframe.h" | 30 #include "webkit/glue/webframe.h" |
| 36 #include "webkit/glue/webkit_glue.h" | 31 #include "webkit/glue/webkit_glue.h" |
| 37 #include "webkit/glue/webkit_resources.h" | 32 #include "webkit/glue/webkit_resources.h" |
| 38 #include "webkit/glue/webpreferences.h" | 33 #include "webkit/glue/webpreferences.h" |
| 39 #include "webkit/glue/weburlrequest.h" | 34 #include "webkit/glue/weburlrequest.h" |
| 40 #include "webkit/glue/webview.h" | 35 #include "webkit/glue/webview.h" |
| 41 #include "webkit/glue/webwidget.h" | 36 #include "webkit/glue/webwidget.h" |
| 42 #include "webkit/glue/plugins/plugin_list.h" | 37 #include "webkit/glue/plugins/plugin_list.h" |
| 43 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 38 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 44 #include "webkit/tools/test_shell/test_navigation_controller.h" | 39 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 45 | 40 |
| 41 #if defined(OS_WIN) |
| 42 #include "webkit/tools/test_shell/test_shell_win.h" |
| 43 #elif defined(OS_LINUX) |
| 44 #include "webkit/tools/test_shell/test_shell_gtk.h" |
| 45 #endif |
| 46 |
| 47 #if defined(OS_WIN) |
| 48 // XXX These files don't depend on Windows, they just haven't been ported yet. |
| 49 #include "net/url_request/url_request_file_job.h" |
| 50 #include "net/url_request/url_request_filter.h" |
| 46 #include "webkit_strings.h" | 51 #include "webkit_strings.h" |
| 52 #endif |
| 47 | 53 |
| 48 #include "SkBitmap.h" | 54 #include "SkBitmap.h" |
| 49 | 55 |
| 50 using std::min; | 56 using std::min; |
| 51 using std::max; | 57 using std::max; |
| 52 | 58 |
| 53 #define MAX_LOADSTRING 100 | 59 #define MAX_LOADSTRING 100 |
| 54 | 60 |
| 55 #define BUTTON_WIDTH 72 | 61 #define BUTTON_WIDTH 72 |
| 56 #define URLBAR_HEIGHT 24 | 62 #define URLBAR_HEIGHT 24 |
| 57 | 63 |
| 58 // Global Variables: | |
| 59 static TCHAR g_windowTitle[MAX_LOADSTRING]; // The title bar text | |
| 60 static TCHAR g_windowClass[MAX_LOADSTRING]; // The main window class name | |
| 61 | |
| 62 // Forward declarations of functions included in this code module: | |
| 63 static INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM); | |
| 64 | |
| 65 // Default timeout for page load when running non-interactive file | 64 // Default timeout for page load when running non-interactive file |
| 66 // tests, in ms. | 65 // tests, in ms. |
| 67 const int kDefaultFileTestTimeoutMillisecs = 10 * 1000; | 66 const int kDefaultFileTestTimeoutMillisecs = 10 * 1000; |
| 68 | 67 |
| 69 // Content area size for newly created windows. | 68 // Content area size for newly created windows. |
| 70 const int kTestWindowWidth = 800; | 69 const int kTestWindowWidth = 800; |
| 71 const int kTestWindowHeight = 600; | 70 const int kTestWindowHeight = 600; |
| 72 | 71 |
| 73 // The W3C SVG layout tests use a different size than the other layout tests | 72 // The W3C SVG layout tests use a different size than the other layout tests |
| 74 const int kSVGTestWindowWidth = 480; | 73 const int kSVGTestWindowWidth = 480; |
| 75 const int kSVGTestWindowHeight = 360; | 74 const int kSVGTestWindowHeight = 360; |
| 76 | 75 |
| 77 // Hide the window offscreen when it is non-interactive. | 76 // Hide the window offscreen when it is non-interactive. |
| 78 // This would correspond with a minimized window position if x = y = -32000. | 77 // This would correspond with a minimized window position if x = y = -32000. |
| 79 // However we shift the x to 0 to pass test cross-frame-access-put.html | 78 // However we shift the x to 0 to pass test cross-frame-access-put.html |
| 80 // which expects screenX/screenLeft to be 0 (http://b/issue?id=1227945). | 79 // which expects screenX/screenLeft to be 0 (http://b/issue?id=1227945). |
| 81 // TODO(ericroman): x should be defined as 0 rather than -4. There is | 80 // TODO(ericroman): x should be defined as 0 rather than -4. There is |
| 82 // probably a frameborder not being accounted for in the setting/getting. | 81 // probably a frameborder not being accounted for in the setting/getting. |
| 83 const int kTestWindowXLocation = -4; | 82 const int kTestWindowXLocation = -4; |
| 84 const int kTestWindowYLocation = -32000; | 83 const int kTestWindowYLocation = -32000; |
| 85 | 84 |
| 86 // Initialize static member variable | 85 // Initialize static member variable |
| 87 WindowList* TestShell::window_list_; | 86 WindowList* TestShell::window_list_; |
| 88 HINSTANCE TestShell::instance_handle_; | |
| 89 WebPreferences* TestShell::web_prefs_ = NULL; | 87 WebPreferences* TestShell::web_prefs_ = NULL; |
| 90 bool TestShell::interactive_ = true; | 88 bool TestShell::interactive_ = true; |
| 91 int TestShell::file_test_timeout_ms_ = kDefaultFileTestTimeoutMillisecs; | 89 int TestShell::file_test_timeout_ms_ = kDefaultFileTestTimeoutMillisecs; |
| 92 | 90 |
| 91 #if defined(OS_WIN) // XXX |
| 93 // URLRequestTestShellFileJob is used to serve the inspector | 92 // URLRequestTestShellFileJob is used to serve the inspector |
| 94 class URLRequestTestShellFileJob : public URLRequestFileJob { | 93 class URLRequestTestShellFileJob : public URLRequestFileJob { |
| 95 public: | 94 public: |
| 96 virtual ~URLRequestTestShellFileJob() { } | 95 virtual ~URLRequestTestShellFileJob() { } |
| 97 | 96 |
| 98 static URLRequestJob* InspectorFactory(URLRequest* request, | 97 static URLRequestJob* InspectorFactory(URLRequest* request, |
| 99 const std::string& scheme) { | 98 const std::string& scheme) { |
| 100 std::wstring path; | 99 std::wstring path; |
| 101 PathService::Get(base::DIR_EXE, &path); | 100 PathService::Get(base::DIR_EXE, &path); |
| 102 file_util::AppendToPath(&path, L"Resources"); | 101 file_util::AppendToPath(&path, L"Resources"); |
| 103 file_util::AppendToPath(&path, L"Inspector"); | 102 file_util::AppendToPath(&path, L"Inspector"); |
| 104 file_util::AppendToPath(&path, UTF8ToWide(request->url().path())); | 103 file_util::AppendToPath(&path, UTF8ToWide(request->url().path())); |
| 105 return new URLRequestTestShellFileJob(request, path); | 104 return new URLRequestTestShellFileJob(request, path); |
| 106 } | 105 } |
| 107 | 106 |
| 108 private: | 107 private: |
| 109 URLRequestTestShellFileJob(URLRequest* request, const std::wstring& path) | 108 URLRequestTestShellFileJob(URLRequest* request, const std::wstring& path) |
| 110 : URLRequestFileJob(request) { | 109 : URLRequestFileJob(request) { |
| 111 this->file_path_ = path; // set URLRequestFileJob::file_path_ | 110 this->file_path_ = path; // set URLRequestFileJob::file_path_ |
| 112 } | 111 } |
| 113 | 112 |
| 114 DISALLOW_EVIL_CONSTRUCTORS(URLRequestTestShellFileJob); | 113 DISALLOW_EVIL_CONSTRUCTORS(URLRequestTestShellFileJob); |
| 115 }; | 114 }; |
| 115 #endif |
| 116 | 116 |
| 117 TestShell::TestShell() | 117 TestShell::TestShell() |
| 118 : m_mainWnd(NULL), | 118 : m_mainWnd(NULL), |
| 119 m_editWnd(NULL), | 119 m_editWnd(NULL), |
| 120 m_webViewHost(NULL), | 120 m_webViewHost(NULL), |
| 121 m_popupHost(NULL), | 121 m_popupHost(NULL), |
| 122 m_focusedWidgetHost(NULL), | 122 m_focusedWidgetHost(NULL), |
| 123 default_edit_wnd_proc_(0), | |
| 124 delegate_(new TestWebViewDelegate(this)), | 123 delegate_(new TestWebViewDelegate(this)), |
| 125 test_is_preparing_(false), | 124 test_is_preparing_(false), |
| 126 test_is_pending_(false), | 125 test_is_pending_(false), |
| 127 is_modal_(false), | 126 is_modal_(false), |
| 128 dump_stats_table_on_exit_(false) { | 127 dump_stats_table_on_exit_(false) { |
| 129 layout_test_controller_.reset(new LayoutTestController(this)); | 128 layout_test_controller_.reset(new LayoutTestController(this)); |
| 130 event_sending_controller_.reset(new EventSendingController(this)); | 129 event_sending_controller_.reset(new EventSendingController(this)); |
| 131 text_input_controller_.reset(new TextInputController(this)); | 130 text_input_controller_.reset(new TextInputController(this)); |
| 132 navigation_controller_.reset(new TestNavigationController(this)); | 131 navigation_controller_.reset(new TestNavigationController(this)); |
| 133 | 132 |
| 133 #if defined(OS_WIN) // XXX |
| 134 URLRequestFilter* filter = URLRequestFilter::GetInstance(); | 134 URLRequestFilter* filter = URLRequestFilter::GetInstance(); |
| 135 filter->AddHostnameHandler("test-shell-resource", "inspector", | 135 filter->AddHostnameHandler("test-shell-resource", "inspector", |
| 136 &URLRequestTestShellFileJob::InspectorFactory); | 136 &URLRequestTestShellFileJob::InspectorFactory); |
| 137 #endif |
| 137 url_util::AddStandardScheme("test-shell-resource"); | 138 url_util::AddStandardScheme("test-shell-resource"); |
| 138 } | 139 } |
| 139 | 140 |
| 140 TestShell::~TestShell() { | 141 TestShell::~TestShell() { |
| 141 | 142 |
| 142 // Call GC twice to clean up garbage. | 143 // Call GC twice to clean up garbage. |
| 143 CallJSGC(); | 144 CallJSGC(); |
| 144 CallJSGC(); | 145 CallJSGC(); |
| 145 | 146 |
| 146 // When the window is destroyed, tell the Edit field to forget about us, | |
| 147 // otherwise we will crash. | |
| 148 win_util::SetWindowProc(m_editWnd, default_edit_wnd_proc_); | |
| 149 win_util::SetWindowUserData(m_editWnd, NULL); | |
| 150 | |
| 151 StatsTable *table = StatsTable::current(); | 147 StatsTable *table = StatsTable::current(); |
| 152 if (dump_stats_table_on_exit_) { | 148 if (dump_stats_table_on_exit_) { |
| 153 // Dump the stats table. | 149 // Dump the stats table. |
| 154 printf("<stats>\n"); | 150 printf("<stats>\n"); |
| 155 if (table != NULL) { | 151 if (table != NULL) { |
| 156 int counter_max = table->GetMaxCounters(); | 152 int counter_max = table->GetMaxCounters(); |
| 157 for (int index=0; index < counter_max; index++) { | 153 for (int index=0; index < counter_max; index++) { |
| 158 std::wstring name(table->GetRowName(index)); | 154 std::wstring name(table->GetRowName(index)); |
| 159 if (name.length() > 0) { | 155 if (name.length() > 0) { |
| 160 int value = table->GetRowValue(index); | 156 int value = table->GetRowValue(index); |
| 161 printf("%s:\t%d\n", WideToUTF8(name).c_str(), value); | 157 printf("%s:\t%d\n", WideToUTF8(name).c_str(), value); |
| 162 } | 158 } |
| 163 } | 159 } |
| 164 } | 160 } |
| 165 printf("</stats>\n"); | 161 printf("</stats>\n"); |
| 166 } | 162 } |
| 167 } | 163 } |
| 168 | 164 |
| 169 // All fatal log messages (e.g. DCHECK failures) imply unit test failures | 165 // All fatal log messages (e.g. DCHECK failures) imply unit test failures |
| 170 static void UnitTestAssertHandler(const std::string& str) { | 166 static void UnitTestAssertHandler(const std::string& str) { |
| 171 FAIL() << str; | 167 FAIL() << str; |
| 172 } | 168 } |
| 173 | 169 |
| 174 // static | 170 // static |
| 175 void TestShell::InitLogging(bool suppress_error_dialogs) { | 171 void TestShell::InitLogging(bool suppress_error_dialogs) { |
| 172 #if defined(OS_WIN) |
| 176 if (!IsDebuggerPresent() && suppress_error_dialogs) { | 173 if (!IsDebuggerPresent() && suppress_error_dialogs) { |
| 177 UINT new_flags = SEM_FAILCRITICALERRORS | | 174 UINT new_flags = SEM_FAILCRITICALERRORS | |
| 178 SEM_NOGPFAULTERRORBOX | | 175 SEM_NOGPFAULTERRORBOX | |
| 179 SEM_NOOPENFILEERRORBOX; | 176 SEM_NOOPENFILEERRORBOX; |
| 180 // Preserve existing error mode, as discussed at http://t/dmea | 177 // Preserve existing error mode, as discussed at http://t/dmea |
| 181 UINT existing_flags = SetErrorMode(new_flags); | 178 UINT existing_flags = SetErrorMode(new_flags); |
| 182 SetErrorMode(existing_flags | new_flags); | 179 SetErrorMode(existing_flags | new_flags); |
| 183 | 180 |
| 184 logging::SetLogAssertHandler(UnitTestAssertHandler); | 181 logging::SetLogAssertHandler(UnitTestAssertHandler); |
| 185 } | 182 } |
| 183 #endif // defined(OS_WIN) |
| 186 | 184 |
| 187 // We might have multiple test_shell processes going at once | 185 // We might have multiple test_shell processes going at once |
| 188 std::wstring log_filename; | 186 std::wstring log_filename; |
| 189 PathService::Get(base::DIR_EXE, &log_filename); | 187 PathService::Get(base::DIR_EXE, &log_filename); |
| 190 file_util::AppendToPath(&log_filename, L"test_shell.log"); | 188 file_util::AppendToPath(&log_filename, L"test_shell.log"); |
| 189 #if defined(OS_WIN) // XXX |
| 191 logging::InitLogging(log_filename.c_str(), | 190 logging::InitLogging(log_filename.c_str(), |
| 192 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, | 191 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, |
| 193 logging::LOCK_LOG_FILE, | 192 logging::LOCK_LOG_FILE, |
| 194 logging::DELETE_OLD_LOG_FILE); | 193 logging::DELETE_OLD_LOG_FILE); |
| 194 #else |
| 195 logging::InitLogging(WideToUTF8(log_filename).c_str(), |
| 196 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG, |
| 197 logging::LOCK_LOG_FILE, |
| 198 logging::DELETE_OLD_LOG_FILE); |
| 199 #endif |
| 195 | 200 |
| 196 // we want process and thread IDs because we may have multiple processes | 201 // we want process and thread IDs because we may have multiple processes |
| 197 logging::SetLogItems(true, true, false, true); | 202 logging::SetLogItems(true, true, false, true); |
| 198 } | 203 } |
| 199 | 204 |
| 200 // static | 205 // static |
| 201 void TestShell::CleanupLogging() { | 206 void TestShell::CleanupLogging() { |
| 202 logging::CloseLogFile(); | 207 logging::CloseLogFile(); |
| 203 } | 208 } |
| 204 | 209 |
| 205 // static | 210 // static |
| 206 void TestShell::InitializeTestShell(bool interactive) { | 211 void TestShell::InitializeTestShell(bool interactive) { |
| 207 // Start COM stuff. | 212 TestShellImpl::InitializeTestShell(interactive); |
| 208 HRESULT res = OleInitialize(NULL); | |
| 209 DCHECK(SUCCEEDED(res)); | |
| 210 | 213 |
| 211 window_list_ = new WindowList; | 214 window_list_ = new WindowList; |
| 212 instance_handle_ = ::GetModuleHandle(NULL); | |
| 213 interactive_ = interactive; | 215 interactive_ = interactive; |
| 214 | 216 |
| 215 web_prefs_ = new WebPreferences; | 217 web_prefs_ = new WebPreferences; |
| 216 | 218 |
| 217 ResetWebPreferences(); | 219 ResetWebPreferences(); |
| 218 } | 220 } |
| 219 | 221 |
| 220 // static | 222 // static |
| 221 void TestShell::ResetWebPreferences() { | 223 void TestShell::ResetWebPreferences() { |
| 222 DCHECK(web_prefs_); | 224 DCHECK(web_prefs_); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 245 web_prefs_->dashboard_compatibility_mode = false; | 247 web_prefs_->dashboard_compatibility_mode = false; |
| 246 web_prefs_->java_enabled = true; | 248 web_prefs_->java_enabled = true; |
| 247 } | 249 } |
| 248 } | 250 } |
| 249 | 251 |
| 250 // static | 252 // static |
| 251 void TestShell::ShutdownTestShell() { | 253 void TestShell::ShutdownTestShell() { |
| 252 delete window_list_; | 254 delete window_list_; |
| 253 SimpleResourceLoaderBridge::Shutdown(); | 255 SimpleResourceLoaderBridge::Shutdown(); |
| 254 delete TestShell::web_prefs_; | 256 delete TestShell::web_prefs_; |
| 255 OleUninitialize(); | 257 TestShellImpl::ShutdownTestShell(); |
| 256 } | 258 } |
| 257 | 259 |
| 258 bool TestShell::Initialize(const std::wstring& startingURL) { | 260 bool TestShell::Initialize(const std::wstring& startingURL) { |
| 259 // Perform application initialization: | 261 m_mainWnd = NULL; // XXX |
| 260 m_mainWnd = CreateWindow(g_windowClass, g_windowTitle, | 262 m_impl->Initialize(startingURL); |
| 261 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, | |
| 262 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, | |
| 263 NULL, NULL, instance_handle_, NULL); | |
| 264 win_util::SetWindowUserData(m_mainWnd, this); | |
| 265 | |
| 266 HWND hwnd; | |
| 267 int x = 0; | |
| 268 | |
| 269 hwnd = CreateWindow(L"BUTTON", L"Back", | |
| 270 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , | |
| 271 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, | |
| 272 m_mainWnd, (HMENU) IDC_NAV_BACK, instance_handle_, 0); | |
| 273 x += BUTTON_WIDTH; | |
| 274 | |
| 275 hwnd = CreateWindow(L"BUTTON", L"Forward", | |
| 276 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , | |
| 277 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, | |
| 278 m_mainWnd, (HMENU) IDC_NAV_FORWARD, instance_handle_, 0)
; | |
| 279 x += BUTTON_WIDTH; | |
| 280 | |
| 281 hwnd = CreateWindow(L"BUTTON", L"Reload", | |
| 282 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , | |
| 283 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, | |
| 284 m_mainWnd, (HMENU) IDC_NAV_RELOAD, instance_handle_, 0); | |
| 285 x += BUTTON_WIDTH; | |
| 286 | |
| 287 hwnd = CreateWindow(L"BUTTON", L"Stop", | |
| 288 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , | |
| 289 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, | |
| 290 m_mainWnd, (HMENU) IDC_NAV_STOP, instance_handle_, 0); | |
| 291 x += BUTTON_WIDTH; | |
| 292 | |
| 293 // this control is positioned by ResizeSubViews | |
| 294 m_editWnd = CreateWindow(L"EDIT", 0, | |
| 295 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | | |
| 296 ES_AUTOVSCROLL | ES_AUTOHSCROLL, | |
| 297 x, 0, 0, 0, m_mainWnd, 0, instance_handle_, 0); | |
| 298 | |
| 299 default_edit_wnd_proc_ = | |
| 300 win_util::SetWindowProc(m_editWnd, TestShell::EditWndProc); | |
| 301 win_util::SetWindowUserData(m_editWnd, this); | |
| 302 | 263 |
| 303 // create webview | 264 // create webview |
| 304 m_webViewHost.reset( | 265 m_webViewHost.reset( |
| 305 WebViewHost::Create(m_mainWnd, delegate_.get(), *TestShell::web_prefs_))
; | 266 WebViewHost::Create(m_mainWnd, delegate_.get(), *TestShell::web_prefs_))
; |
| 306 webView()->SetUseEditorDelegate(true); | 267 webView()->SetUseEditorDelegate(true); |
| 307 delegate_->RegisterDragDrop(); | 268 delegate_->RegisterDragDrop(); |
| 308 | 269 |
| 309 // Load our initial content. | 270 // Load our initial content. |
| 310 if (!startingURL.empty()) | 271 if (!startingURL.empty()) |
| 311 LoadURL(startingURL.c_str()); | 272 LoadURL(startingURL.c_str()); |
| 312 | 273 |
| 313 ShowWindow(webViewWnd(), SW_SHOW); | |
| 314 | |
| 315 bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos; | 274 bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos; |
| 316 | 275 |
| 317 if (bIsSVGTest) { | 276 if (bIsSVGTest) { |
| 318 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); | 277 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); |
| 319 } else { | 278 } else { |
| 320 SizeToDefault(); | 279 SizeToDefault(); |
| 321 } | 280 } |
| 322 | 281 |
| 323 return true; | 282 return true; |
| 324 } | 283 } |
| 325 | 284 |
| 326 void TestShell::TestFinished() { | 285 void TestShell::TestFinished() { |
| 327 if (!test_is_pending_) | 286 if (!test_is_pending_) |
| 328 return; // reached when running under test_shell_tests | 287 return; // reached when running under test_shell_tests |
| 329 | 288 |
| 289 #if defined(OS_WIN) |
| 290 // TODO(port): figure out a better way of doing this. |
| 330 UINT_PTR timer_id = reinterpret_cast<UINT_PTR>(this); | 291 UINT_PTR timer_id = reinterpret_cast<UINT_PTR>(this); |
| 331 KillTimer(mainWnd(), timer_id); | 292 KillTimer(mainWnd(), timer_id); |
| 293 #endif |
| 332 | 294 |
| 333 test_is_pending_ = false; | 295 test_is_pending_ = false; |
| 334 MessageLoop::current()->Quit(); | 296 MessageLoop::current()->Quit(); |
| 335 } | 297 } |
| 336 | 298 |
| 299 #if defined(OS_WIN) // XXX move to windows-specific file? |
| 337 // Thread main to run for the thread which just tests for timeout. | 300 // Thread main to run for the thread which just tests for timeout. |
| 338 unsigned int __stdcall WatchDogThread(void *arg) | 301 unsigned int __stdcall WatchDogThread(void *arg) |
| 339 { | 302 { |
| 340 // If we're debugging a layout test, don't timeout. | 303 // If we're debugging a layout test, don't timeout. |
| 341 if (::IsDebuggerPresent()) | 304 if (::IsDebuggerPresent()) |
| 342 return 0; | 305 return 0; |
| 343 | 306 |
| 344 TestShell* shell = static_cast<TestShell*>(arg); | 307 TestShell* shell = static_cast<TestShell*>(arg); |
| 345 DWORD timeout = static_cast<DWORD>(shell->GetFileTestTimeout() * 2.5); | 308 DWORD timeout = static_cast<DWORD>(shell->GetFileTestTimeout() * 2.5); |
| 346 DWORD rv = WaitForSingleObject(shell->finished_event(), timeout); | 309 DWORD rv = WaitForSingleObject(shell->finished_event(), timeout); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 // finishes loading. | 347 // finishes loading. |
| 385 while (test_is_pending_) | 348 while (test_is_pending_) |
| 386 MessageLoop::current()->Run(); | 349 MessageLoop::current()->Run(); |
| 387 | 350 |
| 388 // Tell the watchdog that we are finished. | 351 // Tell the watchdog that we are finished. |
| 389 SetEvent(finished_event_); | 352 SetEvent(finished_event_); |
| 390 | 353 |
| 391 // Wait to join the watchdog thread. (up to 1s, then quit) | 354 // Wait to join the watchdog thread. (up to 1s, then quit) |
| 392 WaitForSingleObject(thread_handle, 1000); | 355 WaitForSingleObject(thread_handle, 1000); |
| 393 } | 356 } |
| 357 #endif // defined(OS_WIN) |
| 394 | 358 |
| 395 void TestShell::Show(WebView* webview, WindowOpenDisposition disposition) { | 359 void TestShell::Show(WebView* webview, WindowOpenDisposition disposition) { |
| 396 delegate_->Show(webview, disposition); | 360 delegate_->Show(webview, disposition); |
| 397 } | 361 } |
| 398 | 362 |
| 399 void TestShell::SetFocus(WebWidgetHost* host, bool enable) { | 363 void TestShell::SetFocus(WebWidgetHost* host, bool enable) { |
| 400 if (interactive_) { | 364 if (interactive_) { |
| 401 if (enable) { | 365 if (enable) { |
| 402 ::SetFocus(host->window_handle()); | 366 ; // XXX ::SetFocus(host->window_handle()); |
| 403 } else { | 367 } else { |
| 404 if (GetFocus() == host->window_handle()) | 368 ; // XXX if (GetFocus() == host->window_handle()) |
| 405 ::SetFocus(NULL); | 369 ; // XXX ::SetFocus(NULL); |
| 406 } | 370 } |
| 407 } else { | 371 } else { |
| 408 if (enable) { | 372 if (enable) { |
| 409 if (m_focusedWidgetHost != host) { | 373 if (m_focusedWidgetHost != host) { |
| 410 if (m_focusedWidgetHost) | 374 if (m_focusedWidgetHost) |
| 411 m_focusedWidgetHost->webwidget()->SetFocus(false); | 375 m_focusedWidgetHost->webwidget()->SetFocus(false); |
| 412 host->webwidget()->SetFocus(enable); | 376 host->webwidget()->SetFocus(enable); |
| 413 m_focusedWidgetHost = host; | 377 m_focusedWidgetHost = host; |
| 414 } | 378 } |
| 415 } else { | 379 } else { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 TestShell* new_win; | 427 TestShell* new_win; |
| 464 if (!CreateNewWindow(std::wstring(), &new_win)) | 428 if (!CreateNewWindow(std::wstring(), &new_win)) |
| 465 return NULL; | 429 return NULL; |
| 466 | 430 |
| 467 return new_win->webView(); | 431 return new_win->webView(); |
| 468 } | 432 } |
| 469 | 433 |
| 470 WebWidget* TestShell::CreatePopupWidget(WebView* webview) { | 434 WebWidget* TestShell::CreatePopupWidget(WebView* webview) { |
| 471 DCHECK(!m_popupHost); | 435 DCHECK(!m_popupHost); |
| 472 m_popupHost = WebWidgetHost::Create(NULL, delegate_.get()); | 436 m_popupHost = WebWidgetHost::Create(NULL, delegate_.get()); |
| 473 ShowWindow(popupWnd(), SW_SHOW); | 437 // XXX ShowWindow(popupWnd(), SW_SHOW); |
| 474 | 438 |
| 475 return m_popupHost->webwidget(); | 439 return m_popupHost->webwidget(); |
| 476 } | 440 } |
| 477 | 441 |
| 478 void TestShell::ClosePopup() { | 442 void TestShell::ClosePopup() { |
| 479 PostMessage(popupWnd(), WM_CLOSE, 0, 0); | 443 // XXX PostMessage(popupWnd(), WM_CLOSE, 0, 0); |
| 480 m_popupHost = NULL; | 444 m_popupHost = NULL; |
| 481 } | 445 } |
| 482 | 446 |
| 483 void TestShell::SizeToDefault() { | 447 void TestShell::SizeToDefault() { |
| 484 SizeTo(kTestWindowWidth, kTestWindowHeight); | 448 SizeTo(kTestWindowWidth, kTestWindowHeight); |
| 485 } | 449 } |
| 486 | 450 |
| 487 void TestShell::SizeTo(int width, int height) { | 451 void TestShell::SizeTo(int width, int height) { |
| 488 RECT rc, rw; | 452 m_impl->SizeTo(m_mainWnd, width, height); |
| 489 GetClientRect(m_mainWnd, &rc); | |
| 490 GetWindowRect(m_mainWnd, &rw); | |
| 491 | |
| 492 int client_width = rc.right - rc.left; | |
| 493 int window_width = rw.right - rw.left; | |
| 494 window_width = (window_width - client_width) + width; | |
| 495 | |
| 496 int client_height = rc.bottom - rc.top; | |
| 497 int window_height = rw.bottom - rw.top; | |
| 498 window_height = (window_height - client_height) + height; | |
| 499 | |
| 500 // add space for the url bar: | |
| 501 window_height += URLBAR_HEIGHT; | |
| 502 | |
| 503 SetWindowPos(m_mainWnd, NULL, 0, 0, window_width, window_height, | |
| 504 SWP_NOMOVE | SWP_NOZORDER); | |
| 505 } | 453 } |
| 506 | 454 |
| 507 void TestShell::ResizeSubViews() { | 455 void TestShell::ResizeSubViews() { |
| 508 RECT rc; | 456 m_impl->ResizeSubViews(); |
| 509 GetClientRect(m_mainWnd, &rc); | |
| 510 | |
| 511 int x = BUTTON_WIDTH * 4; | |
| 512 MoveWindow(m_editWnd, x, 0, rc.right - x, URLBAR_HEIGHT, TRUE); | |
| 513 | |
| 514 MoveWindow(webViewWnd(), 0, URLBAR_HEIGHT, rc.right, | |
| 515 rc.bottom - URLBAR_HEIGHT, TRUE); | |
| 516 } | 457 } |
| 517 | 458 |
| 518 /* static */ std::string TestShell::DumpImage( | 459 /* static */ std::string TestShell::DumpImage( |
| 519 WebFrame* web_frame, | 460 WebFrame* web_frame, |
| 520 const std::wstring& file_name) { | 461 const std::wstring& file_name) { |
| 521 gfx::BitmapPlatformDeviceWin device(web_frame->CaptureImage(true)); | 462 return TestShellImpl::DumpImage(web_frame, file_name); |
| 522 const SkBitmap& src_bmp = device.accessBitmap(false); | |
| 523 | |
| 524 // Encode image. | |
| 525 std::vector<unsigned char> png; | |
| 526 SkAutoLockPixels src_bmp_lock(src_bmp); | |
| 527 PNGEncoder::Encode( | |
| 528 reinterpret_cast<const unsigned char*>(src_bmp.getPixels()), | |
| 529 PNGEncoder::FORMAT_BGRA, src_bmp.width(), src_bmp.height(), | |
| 530 static_cast<int>(src_bmp.rowBytes()), true, &png); | |
| 531 | |
| 532 // Write to disk. | |
| 533 FILE* file = NULL; | |
| 534 if (_wfopen_s(&file, file_name.c_str(), L"wb") == 0) { | |
| 535 fwrite(&png[0], 1, png.size(), file); | |
| 536 fclose(file); | |
| 537 } | |
| 538 | |
| 539 // Compute MD5 sum. | |
| 540 MD5Context ctx; | |
| 541 MD5Init(&ctx); | |
| 542 MD5Update(&ctx, src_bmp.getPixels(), src_bmp.getSize()); | |
| 543 | |
| 544 MD5Digest digest; | |
| 545 MD5Final(&digest, &ctx); | |
| 546 return MD5DigestToBase16(digest); | |
| 547 } | 463 } |
| 548 | 464 |
| 549 /* static */ void TestShell::DumpBackForwardList(std::wstring* result) { | 465 /* static */ void TestShell::DumpBackForwardList(std::wstring* result) { |
| 550 result->clear(); | 466 result->clear(); |
| 551 for (WindowList::iterator iter = TestShell::windowList()->begin(); | 467 for (WindowList::iterator iter = TestShell::windowList()->begin(); |
| 552 iter != TestShell::windowList()->end(); iter++) { | 468 iter != TestShell::windowList()->end(); iter++) { |
| 553 HWND hwnd = *iter; | 469 TestShell* shell = TestShellImpl::GetTestShellFromWindow(*iter); |
| 554 TestShell* shell = | |
| 555 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | |
| 556 webkit_glue::DumpBackForwardList(shell->webView(), NULL, result); | 470 webkit_glue::DumpBackForwardList(shell->webView(), NULL, result); |
| 557 } | 471 } |
| 558 } | 472 } |
| 559 | 473 |
| 560 /* static */ bool TestShell::RunFileTest(const char *filename, | 474 /* static */ bool TestShell::RunFileTest(const char *filename, |
| 561 const TestParams& params) { | 475 const TestParams& params) { |
| 562 // Load the test file into the first available window. | 476 // Load the test file into the first available window. |
| 563 if (TestShell::windowList()->empty()) { | 477 if (TestShell::windowList()->empty()) { |
| 564 LOG(ERROR) << "No windows open."; | 478 LOG(ERROR) << "No windows open."; |
| 565 return false; | 479 return false; |
| 566 } | 480 } |
| 567 | 481 |
| 568 HWND hwnd = *(TestShell::windowList()->begin()); | |
| 569 TestShell* shell = | 482 TestShell* shell = |
| 570 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | 483 TestShellImpl::GetTestShellFromWindow( |
| 484 *(TestShell::windowList()->begin())); |
| 571 shell->ResetTestController(); | 485 shell->ResetTestController(); |
| 572 | 486 |
| 573 // ResetTestController may have closed the window we were holding on to. | 487 // ResetTestController may have closed the window we were holding on to. |
| 574 // Grab the first window again. | 488 // Grab the first window again. |
| 575 hwnd = *(TestShell::windowList()->begin()); | 489 shell = TestShellImpl::GetTestShellFromWindow(*(TestShell::windowList()->beg
in())); |
| 576 shell = static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | |
| 577 DCHECK(shell); | 490 DCHECK(shell); |
| 578 | 491 |
| 579 // Clear focus between tests. | 492 // Clear focus between tests. |
| 580 shell->m_focusedWidgetHost = NULL; | 493 shell->m_focusedWidgetHost = NULL; |
| 581 | 494 |
| 582 // Make sure the previous load is stopped. | 495 // Make sure the previous load is stopped. |
| 583 shell->webView()->StopLoading(); | 496 shell->webView()->StopLoading(); |
| 584 shell->navigation_controller()->Reset(); | 497 shell->navigation_controller()->Reset(); |
| 585 | 498 |
| 586 // Clean up state between test runs. | 499 // Clean up state between test runs. |
| 587 webkit_glue::ResetBeforeTestRun(shell->webView()); | 500 webkit_glue::ResetBeforeTestRun(shell->webView()); |
| 588 ResetWebPreferences(); | 501 ResetWebPreferences(); |
| 589 shell->webView()->SetPreferences(*web_prefs_); | 502 shell->webView()->SetPreferences(*web_prefs_); |
| 590 | 503 |
| 591 SetWindowPos(shell->m_mainWnd, NULL, | 504 // XXX |
| 505 /*SetWindowPos(shell->m_mainWnd, NULL, |
| 592 kTestWindowXLocation, kTestWindowYLocation, 0, 0, | 506 kTestWindowXLocation, kTestWindowYLocation, 0, 0, |
| 593 SWP_NOSIZE | SWP_NOZORDER); | 507 SWP_NOSIZE | SWP_NOZORDER);*/ |
| 594 shell->ResizeSubViews(); | 508 shell->ResizeSubViews(); |
| 595 | 509 |
| 596 if (strstr(filename, "loading/") || strstr(filename, "loading\\")) | 510 if (strstr(filename, "loading/") || strstr(filename, "loading\\")) |
| 597 shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true); | 511 shell->layout_test_controller()->SetShouldDumpFrameLoadCallbacks(true); |
| 598 | 512 |
| 599 shell->test_is_preparing_ = true; | 513 shell->test_is_preparing_ = true; |
| 600 | 514 |
| 601 std::wstring wstr = UTF8ToWide(filename); | 515 std::wstring wstr = UTF8ToWide(filename); |
| 602 shell->LoadURL(wstr.c_str()); | 516 shell->LoadURL(wstr.c_str()); |
| 603 | 517 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 printf("#MD5:%s\n", md5sum.c_str()); | 569 printf("#MD5:%s\n", md5sum.c_str()); |
| 656 } | 570 } |
| 657 if (dumped_anything) | 571 if (dumped_anything) |
| 658 printf("#EOF\n"); | 572 printf("#EOF\n"); |
| 659 fflush(stdout); | 573 fflush(stdout); |
| 660 } | 574 } |
| 661 | 575 |
| 662 return true; | 576 return true; |
| 663 } | 577 } |
| 664 | 578 |
| 665 | |
| 666 /* static */ | |
| 667 ATOM TestShell::RegisterWindowClass() | |
| 668 { | |
| 669 LoadString(instance_handle_, IDS_APP_TITLE, g_windowTitle, MAX_LOADSTRING); | |
| 670 LoadString(instance_handle_, IDC_TESTSHELL, g_windowClass, MAX_LOADSTRING); | |
| 671 | |
| 672 WNDCLASSEX wcex = { | |
| 673 /* cbSize = */ sizeof(WNDCLASSEX), | |
| 674 /* style = */ CS_HREDRAW | CS_VREDRAW, | |
| 675 /* lpfnWndProc = */ TestShell::WndProc, | |
| 676 /* cbClsExtra = */ 0, | |
| 677 /* cbWndExtra = */ 0, | |
| 678 /* hInstance = */ instance_handle_, | |
| 679 /* hIcon = */ LoadIcon(instance_handle_, MAKEINTRESOURCE(IDI_TESTSHELL)), | |
| 680 /* hCursor = */ LoadCursor(NULL, IDC_ARROW), | |
| 681 /* hbrBackground = */ 0, | |
| 682 /* lpszMenuName = */ MAKEINTRESOURCE(IDC_TESTSHELL), | |
| 683 /* lpszClassName = */ g_windowClass, | |
| 684 /* hIconSm = */ LoadIcon(instance_handle_, MAKEINTRESOURCE(IDI_SMALL)), | |
| 685 }; | |
| 686 return RegisterClassEx(&wcex); | |
| 687 } | |
| 688 | |
| 689 LRESULT CALLBACK TestShell::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPAR
AM lParam) | |
| 690 { | |
| 691 TestShell* shell = static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)
); | |
| 692 | |
| 693 switch (message) { | |
| 694 case WM_COMMAND: | |
| 695 { | |
| 696 int wmId = LOWORD(wParam); | |
| 697 int wmEvent = HIWORD(wParam); | |
| 698 | |
| 699 switch (wmId) { | |
| 700 case IDM_ABOUT: | |
| 701 DialogBox(shell->instance_handle_, MAKEINTRESOURCE(IDD_ABOUTBOX)
, hwnd, | |
| 702 About); | |
| 703 break; | |
| 704 case IDM_EXIT: | |
| 705 DestroyWindow(hwnd); | |
| 706 break; | |
| 707 case IDC_NAV_BACK: | |
| 708 shell->GoBackOrForward(-1); | |
| 709 break; | |
| 710 case IDC_NAV_FORWARD: | |
| 711 shell->GoBackOrForward(1); | |
| 712 break; | |
| 713 case IDC_NAV_RELOAD: | |
| 714 case IDC_NAV_STOP: | |
| 715 { | |
| 716 if (wmId == IDC_NAV_RELOAD) { | |
| 717 shell->Reload(); | |
| 718 } else { | |
| 719 shell->webView()->StopLoading(); | |
| 720 } | |
| 721 } | |
| 722 break; | |
| 723 case IDM_DUMP_BODY_TEXT: | |
| 724 shell->DumpDocumentText(); | |
| 725 break; | |
| 726 case IDM_DUMP_RENDER_TREE: | |
| 727 shell->DumpRenderTree(); | |
| 728 break; | |
| 729 case IDM_SHOW_WEB_INSPECTOR: | |
| 730 shell->webView()->InspectElement(0, 0); | |
| 731 break; | |
| 732 } | |
| 733 } | |
| 734 break; | |
| 735 | |
| 736 case WM_DESTROY: | |
| 737 { | |
| 738 // Dump all in use memory just before shutdown if in use memory | |
| 739 // debugging has been enabled. | |
| 740 base::MemoryDebug::DumpAllMemoryInUse(); | |
| 741 | |
| 742 WindowList::iterator entry = | |
| 743 std::find(TestShell::windowList()->begin(), | |
| 744 TestShell::windowList()->end(), hwnd); | |
| 745 if (entry != TestShell::windowList()->end()) | |
| 746 TestShell::windowList()->erase(entry); | |
| 747 | |
| 748 if (TestShell::windowList()->empty() || shell->is_modal()) { | |
| 749 MessageLoop::current()->PostTask( | |
| 750 FROM_HERE, new MessageLoop::QuitTask()); | |
| 751 } | |
| 752 delete shell; | |
| 753 } | |
| 754 return 0; | |
| 755 | |
| 756 case WM_SIZE: | |
| 757 if (shell->webView()) | |
| 758 shell->ResizeSubViews(); | |
| 759 return 0; | |
| 760 } | |
| 761 | |
| 762 return DefWindowProc(hwnd, message, wParam, lParam); | |
| 763 } | |
| 764 | |
| 765 | |
| 766 #define MAX_URL_LENGTH 1024 | |
| 767 | |
| 768 LRESULT CALLBACK TestShell::EditWndProc(HWND hwnd, UINT message, | |
| 769 WPARAM wParam, LPARAM lParam) | |
| 770 { | |
| 771 TestShell* shell = | |
| 772 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | |
| 773 | |
| 774 switch (message) { | |
| 775 case WM_CHAR: | |
| 776 if (wParam == 13) { // Enter Key | |
| 777 wchar_t strPtr[MAX_URL_LENGTH]; | |
| 778 *((LPWORD)strPtr) = MAX_URL_LENGTH; | |
| 779 LRESULT strLen = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)strPtr
); | |
| 780 if (strLen > 0) | |
| 781 shell->LoadURL(strPtr); | |
| 782 | |
| 783 return 0; | |
| 784 } | |
| 785 } | |
| 786 | |
| 787 return (LRESULT) CallWindowProc(shell->default_edit_wnd_proc_, hwnd, | |
| 788 message, wParam, lParam); | |
| 789 } | |
| 790 | |
| 791 | |
| 792 // Message handler for about box. | |
| 793 INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) | |
| 794 { | |
| 795 UNREFERENCED_PARAMETER(lParam); | |
| 796 switch (message) { | |
| 797 case WM_INITDIALOG: | |
| 798 return (INT_PTR)TRUE; | |
| 799 | |
| 800 case WM_COMMAND: | |
| 801 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { | |
| 802 EndDialog(hDlg, LOWORD(wParam)); | |
| 803 return (INT_PTR)TRUE; | |
| 804 } | |
| 805 break; | |
| 806 } | |
| 807 return (INT_PTR)FALSE; | |
| 808 } | |
| 809 | |
| 810 void TestShell::LoadURL(const wchar_t* url) | 579 void TestShell::LoadURL(const wchar_t* url) |
| 811 { | 580 { |
| 812 LoadURLForFrame(url, NULL); | 581 LoadURLForFrame(url, NULL); |
| 813 } | 582 } |
| 814 | 583 |
| 815 void TestShell::LoadURLForFrame(const wchar_t* url, | 584 void TestShell::LoadURLForFrame(const wchar_t* url, |
| 816 const wchar_t* frame_name) { | 585 const wchar_t* frame_name) { |
| 817 if (!url) | 586 if (!url) |
| 818 return; | 587 return; |
| 819 | 588 |
| 820 TRACE_EVENT_BEGIN("url.load", this, WideToUTF8(url)); | 589 TRACE_EVENT_BEGIN("url.load", this, WideToUTF8(url)); |
| 821 bool bIsSVGTest = wcsstr(url, L"W3C-SVG-1.1") > 0; | 590 bool bIsSVGTest = wcsstr(url, L"W3C-SVG-1.1") > 0; |
| 822 | 591 |
| 823 if (bIsSVGTest) { | 592 if (bIsSVGTest) { |
| 824 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); | 593 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); |
| 825 } else { | 594 } else { |
| 826 SizeToDefault(); | 595 SizeToDefault(); |
| 827 } | 596 } |
| 828 | 597 |
| 829 std::wstring urlString(url); | 598 std::wstring urlString(url); |
| 599 // XXX |
| 600 /* |
| 830 if (!urlString.empty() && (PathFileExists(url) || PathIsUNC(url))) { | 601 if (!urlString.empty() && (PathFileExists(url) || PathIsUNC(url))) { |
| 831 TCHAR fileURL[INTERNET_MAX_URL_LENGTH]; | 602 TCHAR fileURL[INTERNET_MAX_URL_LENGTH]; |
| 832 DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]); | 603 DWORD fileURLLength = sizeof(fileURL)/sizeof(fileURL[0]); |
| 833 if (SUCCEEDED(UrlCreateFromPath(url, fileURL, &fileURLLength, 0))) | 604 if (SUCCEEDED(UrlCreateFromPath(url, fileURL, &fileURLLength, 0))) |
| 834 urlString.assign(fileURL); | 605 urlString.assign(fileURL); |
| 835 } | 606 } |
| 607 */ |
| 836 | 608 |
| 837 std::wstring frame_string; | 609 std::wstring frame_string; |
| 838 if (frame_name) | 610 if (frame_name) |
| 839 frame_string = frame_name; | 611 frame_string = frame_name; |
| 840 | 612 |
| 841 navigation_controller_->LoadEntry(new TestNavigationEntry( | 613 navigation_controller_->LoadEntry(new TestNavigationEntry( |
| 842 -1, GURL(urlString), std::wstring(), frame_string)); | 614 -1, GURL(WideToUTF8(urlString)), std::wstring(), frame_string)); |
| 843 } | 615 } |
| 844 | 616 |
| 845 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { | 617 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { |
| 846 const TestNavigationEntry& test_entry = | 618 const TestNavigationEntry& test_entry = |
| 847 *static_cast<const TestNavigationEntry*>(&entry); | 619 *static_cast<const TestNavigationEntry*>(&entry); |
| 848 | 620 |
| 849 WebRequestCachePolicy cache_policy; | 621 WebRequestCachePolicy cache_policy; |
| 850 if (reload) { | 622 if (reload) { |
| 851 cache_policy = WebRequestReloadIgnoringCacheData; | 623 cache_policy = WebRequestReloadIgnoringCacheData; |
| 852 } else if (entry.GetPageID() != -1) { | 624 } else if (entry.GetPageID() != -1) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 return true; | 656 return true; |
| 885 } | 657 } |
| 886 | 658 |
| 887 void TestShell::GoBackOrForward(int offset) { | 659 void TestShell::GoBackOrForward(int offset) { |
| 888 navigation_controller_->GoToOffset(offset); | 660 navigation_controller_->GoToOffset(offset); |
| 889 } | 661 } |
| 890 | 662 |
| 891 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, | 663 bool TestShell::PromptForSaveFile(const wchar_t* prompt_title, |
| 892 std::wstring* result) | 664 std::wstring* result) |
| 893 { | 665 { |
| 894 wchar_t path_buf[MAX_PATH] = L"data.txt"; | 666 return m_impl->PromptForSaveFile(prompt_title, result); |
| 895 | |
| 896 OPENFILENAME info = {0}; | |
| 897 info.lStructSize = sizeof(info); | |
| 898 info.hwndOwner = m_mainWnd; | |
| 899 info.hInstance = instance_handle_; | |
| 900 info.lpstrFilter = L"*.txt"; | |
| 901 info.lpstrFile = path_buf; | |
| 902 info.nMaxFile = arraysize(path_buf); | |
| 903 info.lpstrTitle = prompt_title; | |
| 904 if (!GetSaveFileName(&info)) | |
| 905 return false; | |
| 906 | |
| 907 result->assign(info.lpstrFile); | |
| 908 return true; | |
| 909 } | 667 } |
| 910 | 668 |
| 911 static void WriteTextToFile(const std::wstring& data, | 669 static void WriteTextToFile(const std::wstring& data, |
| 912 const std::wstring& file_path) | 670 const std::wstring& file_path) |
| 913 { | 671 { |
| 672 // XXX |
| 673 /* |
| 914 FILE* fp; | 674 FILE* fp; |
| 915 errno_t err = _wfopen_s(&fp, file_path.c_str(), L"wt"); | 675 errno_t err = _wfopen_s(&fp, file_path.c_str(), L"wt"); |
| 916 if (err) | 676 if (err) |
| 917 return; | 677 return; |
| 918 std::string data_utf8 = WideToUTF8(data); | 678 std::string data_utf8 = WideToUTF8(data); |
| 919 fwrite(data_utf8.c_str(), 1, data_utf8.size(), fp); | 679 fwrite(data_utf8.c_str(), 1, data_utf8.size(), fp); |
| 920 fclose(fp); | 680 fclose(fp); |
| 681 */ |
| 921 } | 682 } |
| 922 | 683 |
| 923 std::wstring TestShell::GetDocumentText() | 684 std::wstring TestShell::GetDocumentText() |
| 924 { | 685 { |
| 686 /* XXX |
| 925 return webkit_glue::DumpDocumentText(webView()->GetMainFrame()); | 687 return webkit_glue::DumpDocumentText(webView()->GetMainFrame()); |
| 688 */ |
| 689 return L""; |
| 926 } | 690 } |
| 927 | 691 |
| 928 void TestShell::DumpDocumentText() | 692 void TestShell::DumpDocumentText() |
| 929 { | 693 { |
| 930 std::wstring file_path; | 694 std::wstring file_path; |
| 931 if (!PromptForSaveFile(L"Dump document text", &file_path)) | 695 if (!PromptForSaveFile(L"Dump document text", &file_path)) |
| 932 return; | 696 return; |
| 933 | 697 |
| 698 /* XXX |
| 934 WriteTextToFile(webkit_glue::DumpDocumentText(webView()->GetMainFrame()), | 699 WriteTextToFile(webkit_glue::DumpDocumentText(webView()->GetMainFrame()), |
| 935 file_path); | 700 file_path); |
| 701 */ |
| 936 } | 702 } |
| 937 | 703 |
| 938 void TestShell::DumpRenderTree() | 704 void TestShell::DumpRenderTree() |
| 939 { | 705 { |
| 940 std::wstring file_path; | 706 std::wstring file_path; |
| 941 if (!PromptForSaveFile(L"Dump render tree", &file_path)) | 707 if (!PromptForSaveFile(L"Dump render tree", &file_path)) |
| 942 return; | 708 return; |
| 943 | 709 |
| 710 /* XXX |
| 944 WriteTextToFile(webkit_glue::DumpRenderer(webView()->GetMainFrame()), | 711 WriteTextToFile(webkit_glue::DumpRenderer(webView()->GetMainFrame()), |
| 945 file_path); | 712 file_path); |
| 713 */ |
| 946 } | 714 } |
| 947 | 715 |
| 948 void TestShell::Reload() { | 716 void TestShell::Reload() { |
| 949 navigation_controller_->Reload(); | 717 // XXX navigation_controller_->Reload(); |
| 950 } | 718 } |
| 951 | 719 |
| 952 /* static */ | 720 /* static */ |
| 953 std::string TestShell::RewriteLocalUrl(const std::string& url) { | 721 std::string TestShell::RewriteLocalUrl(const std::string& url) { |
| 954 // Convert file:///tmp/LayoutTests urls to the actual location on disk. | 722 // Convert file:///tmp/LayoutTests urls to the actual location on disk. |
| 955 const char kPrefix[] = "file:///tmp/LayoutTests/"; | 723 const char kPrefix[] = "file:///tmp/LayoutTests/"; |
| 956 const int kPrefixLen = arraysize(kPrefix) - 1; | 724 const int kPrefixLen = arraysize(kPrefix) - 1; |
| 957 | 725 |
| 958 std::string new_url(url); | 726 std::string new_url(url); |
| 959 if (url.compare(0, kPrefixLen, kPrefix, kPrefixLen) == 0) { | 727 if (url.compare(0, kPrefixLen, kPrefix, kPrefixLen) == 0) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 984 | 752 |
| 985 void DnsPrefetchUrl(const char16* url, int url_length) {} | 753 void DnsPrefetchUrl(const char16* url, int url_length) {} |
| 986 | 754 |
| 987 void PrecacheUrl(const char16* url, int url_length) {} | 755 void PrecacheUrl(const char16* url, int url_length) {} |
| 988 | 756 |
| 989 void AppendToLog(const char* file, int line, const char* msg) { | 757 void AppendToLog(const char* file, int line, const char* msg) { |
| 990 logging::LogMessage(file, line).stream() << msg; | 758 logging::LogMessage(file, line).stream() << msg; |
| 991 } | 759 } |
| 992 | 760 |
| 993 bool GetMimeTypeFromExtension(std::wstring &ext, std::string *mime_type) { | 761 bool GetMimeTypeFromExtension(std::wstring &ext, std::string *mime_type) { |
| 762 #if defined(OS_WIN) |
| 994 return net::GetMimeTypeFromExtension(ext, mime_type); | 763 return net::GetMimeTypeFromExtension(ext, mime_type); |
| 764 #else |
| 765 NOTIMPLEMENTED(); |
| 766 return false; |
| 767 #endif |
| 995 } | 768 } |
| 996 | 769 |
| 997 bool GetMimeTypeFromFile(const std::wstring &file_path, | 770 bool GetMimeTypeFromFile(const std::wstring &file_path, |
| 998 std::string *mime_type) { | 771 std::string *mime_type) { |
| 772 #if defined(OS_WIN) |
| 999 return net::GetMimeTypeFromFile(file_path, mime_type); | 773 return net::GetMimeTypeFromFile(file_path, mime_type); |
| 774 #else |
| 775 NOTIMPLEMENTED(); |
| 776 return false; |
| 777 #endif |
| 1000 } | 778 } |
| 1001 | 779 |
| 1002 bool GetPreferredExtensionForMimeType(const std::string& mime_type, | 780 bool GetPreferredExtensionForMimeType(const std::string& mime_type, |
| 1003 std::wstring* ext) { | 781 std::wstring* ext) { |
| 782 #if defined(OS_WIN) |
| 1004 return net::GetPreferredExtensionForMimeType(mime_type, ext); | 783 return net::GetPreferredExtensionForMimeType(mime_type, ext); |
| 1005 } | 784 #else |
| 1006 | 785 NOTIMPLEMENTED(); |
| 1007 IMLangFontLink2* GetLangFontLink() { | 786 return false; |
| 1008 return webkit_glue::GetLangFontLinkHelper(); | 787 #endif |
| 1009 } | |
| 1010 | |
| 1011 std::wstring GetLocalizedString(int message_id) { | |
| 1012 const ATLSTRINGRESOURCEIMAGE* image = | |
| 1013 AtlGetStringResourceImage(_AtlBaseModule.GetModuleInstance(), | |
| 1014 message_id); | |
| 1015 if (!image) { | |
| 1016 NOTREACHED(); | |
| 1017 return L"No string for this identifier!"; | |
| 1018 } | |
| 1019 return std::wstring(image->achString, image->nLength); | |
| 1020 } | 788 } |
| 1021 | 789 |
| 1022 std::string GetDataResource(int resource_id) { | 790 std::string GetDataResource(int resource_id) { |
| 1023 if (resource_id == IDR_BROKENIMAGE) { | 791 if (resource_id == IDR_BROKENIMAGE) { |
| 1024 // Use webkit's broken image icon (16x16) | 792 // Use webkit's broken image icon (16x16) |
| 1025 static std::string broken_image_data; | 793 static std::string broken_image_data; |
| 1026 if (broken_image_data.empty()) { | 794 if (broken_image_data.empty()) { |
| 1027 std::wstring path; | 795 std::wstring path; |
| 1028 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 796 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 1029 file_util::AppendToPath(&path, L"webkit"); | 797 file_util::AppendToPath(&path, L"webkit"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1041 // It is necessary to return a feed preview template that contains | 809 // It is necessary to return a feed preview template that contains |
| 1042 // a {{URL}} substring where the feed URL should go; see the code | 810 // a {{URL}} substring where the feed URL should go; see the code |
| 1043 // that computes feed previews in feed_preview.cc:MakeFeedPreview. | 811 // that computes feed previews in feed_preview.cc:MakeFeedPreview. |
| 1044 // This fixes issue #932714. | 812 // This fixes issue #932714. |
| 1045 return std::string("Feed preview for {{URL}}"); | 813 return std::string("Feed preview for {{URL}}"); |
| 1046 } else { | 814 } else { |
| 1047 return std::string(); | 815 return std::string(); |
| 1048 } | 816 } |
| 1049 } | 817 } |
| 1050 | 818 |
| 1051 HCURSOR LoadCursor(int cursor_id) { | |
| 1052 return NULL; | |
| 1053 } | |
| 1054 | |
| 1055 bool GetApplicationDirectory(std::wstring *path) { | 819 bool GetApplicationDirectory(std::wstring *path) { |
| 1056 return PathService::Get(base::DIR_EXE, path); | 820 return PathService::Get(base::DIR_EXE, path); |
| 1057 } | 821 } |
| 1058 | 822 |
| 1059 GURL GetInspectorURL() { | 823 GURL GetInspectorURL() { |
| 1060 return GURL("test-shell-resource://inspector/inspector.html"); | 824 return GURL("test-shell-resource://inspector/inspector.html"); |
| 1061 } | 825 } |
| 1062 | 826 |
| 1063 std::string GetUIResourceProtocol() { | 827 std::string GetUIResourceProtocol() { |
| 1064 return "test-shell-resource"; | 828 return "test-shell-resource"; |
| 1065 } | 829 } |
| 1066 | 830 |
| 1067 bool GetExeDirectory(std::wstring *path) { | 831 bool GetExeDirectory(std::wstring *path) { |
| 1068 return PathService::Get(base::DIR_EXE, path); | 832 return PathService::Get(base::DIR_EXE, path); |
| 1069 } | 833 } |
| 1070 | 834 |
| 1071 bool SpellCheckWord(const wchar_t* word, int word_len, | 835 bool SpellCheckWord(const wchar_t* word, int word_len, |
| 1072 int* misspelling_start, int* misspelling_len) { | 836 int* misspelling_start, int* misspelling_len) { |
| 1073 // Report all words being correctly spelled. | 837 // Report all words being correctly spelled. |
| 1074 *misspelling_start = 0; | 838 *misspelling_start = 0; |
| 1075 *misspelling_len = 0; | 839 *misspelling_len = 0; |
| 1076 return true; | 840 return true; |
| 1077 } | 841 } |
| 1078 | 842 |
| 1079 bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { | 843 bool GetPlugins(bool refresh, std::vector<WebPluginInfo>* plugins) { |
| 844 #if defined(OS_WIN) |
| 1080 return NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); | 845 return NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins); |
| 846 #else |
| 847 NOTIMPLEMENTED(); |
| 848 return false; |
| 849 #endif |
| 1081 } | 850 } |
| 1082 | 851 |
| 1083 bool webkit_glue::IsPluginRunningInRendererProcess() { | 852 bool IsPluginRunningInRendererProcess() { |
| 1084 return true; | 853 return true; |
| 1085 } | 854 } |
| 1086 | 855 |
| 1087 bool EnsureFontLoaded(HFONT font) { | |
| 1088 return true; | |
| 1089 } | |
| 1090 | |
| 1091 MONITORINFOEX GetMonitorInfoForWindow(HWND window) { | |
| 1092 return webkit_glue::GetMonitorInfoForWindowHelper(window); | |
| 1093 } | |
| 1094 | |
| 1095 bool DownloadUrl(const std::string& url, HWND caller_window) { | |
| 1096 return false; | |
| 1097 } | |
| 1098 | |
| 1099 bool GetPluginFinderURL(std::string* plugin_finder_url) { | 856 bool GetPluginFinderURL(std::string* plugin_finder_url) { |
| 1100 return false; | 857 return false; |
| 1101 } | 858 } |
| 1102 | 859 |
| 1103 bool IsDefaultPluginEnabled() { | 860 bool IsDefaultPluginEnabled() { |
| 1104 return false; | 861 return false; |
| 1105 } | 862 } |
| 1106 | 863 |
| 1107 std::wstring GetWebKitLocale() { | 864 std::wstring GetWebKitLocale() { |
| 1108 return L"en-US"; | 865 return L"en-US"; |
| 1109 } | 866 } |
| 1110 | 867 |
| 1111 } // namespace webkit_glue | 868 } // namespace webkit_glue |
| 1112 | |
| OLD | NEW |