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

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

Issue 17635: Remove HttpTransactionWinHttp and the --winhttp command-line... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
« no previous file with comments | « webkit/tools/test_shell/test_shell_switches.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "webkit/tools/test_shell/test_shell.h"
6
5 #include <windows.h> 7 #include <windows.h>
6 #include <atlbase.h> 8 #include <atlbase.h>
7 #include <commdlg.h> 9 #include <commdlg.h>
8 #include <objbase.h> 10 #include <objbase.h>
9 #include <shlwapi.h> 11 #include <shlwapi.h>
10 #include <wininet.h> 12 #include <wininet.h> // For INTERNET_MAX_URL_LENGTH
11
12 #include "webkit/tools/test_shell/test_shell.h"
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/memory_debug.h" 15 #include "base/memory_debug.h"
16 #include "base/message_loop.h" 16 #include "base/message_loop.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/resource_util.h" 18 #include "base/resource_util.h"
19 #include "base/stack_container.h" 19 #include "base/stack_container.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/trace_event.h" 21 #include "base/trace_event.h"
22 #include "base/win_util.h" 22 #include "base/win_util.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 DWORD num_fonts = 1; 136 DWORD num_fonts = 1;
137 void* font_ptr; 137 void* font_ptr;
138 size_t font_size; 138 size_t font_size;
139 if (base::GetDataResourceFromModule(::GetModuleHandle(NULL), IDR_AHEM_FONT, 139 if (base::GetDataResourceFromModule(::GetModuleHandle(NULL), IDR_AHEM_FONT,
140 &font_ptr, &font_size)) { 140 &font_ptr, &font_size)) {
141 HANDLE rc = AddFontMemResourceEx(font_ptr, font_size, 0, &num_fonts); 141 HANDLE rc = AddFontMemResourceEx(font_ptr, font_size, 0, &num_fonts);
142 DCHECK(rc != 0); 142 DCHECK(rc != 0);
143 } 143 }
144 144
145 CommandLine parsed_command_line; 145 CommandLine parsed_command_line;
146 // Make the selection of network stacks early on before any consumers try to
147 // issue HTTP requests.
148 if (parsed_command_line.HasSwitch(test_shell::kUseWinHttp))
149 net::HttpNetworkLayer::UseWinHttp(true);
150
151 if (parsed_command_line.HasSwitch(test_shell::kCrashDumps)) { 146 if (parsed_command_line.HasSwitch(test_shell::kCrashDumps)) {
152 std::wstring dir( 147 std::wstring dir(
153 parsed_command_line.GetSwitchValue(test_shell::kCrashDumps)); 148 parsed_command_line.GetSwitchValue(test_shell::kCrashDumps));
154 new google_breakpad::ExceptionHandler(dir, 0, &MinidumpCallback, 0, true); 149 new google_breakpad::ExceptionHandler(dir, 0, &MinidumpCallback, 0, true);
155 } 150 }
156 } 151 }
157 152
158 bool TestShell::CreateNewWindow(const std::wstring& startingURL, 153 bool TestShell::CreateNewWindow(const std::wstring& startingURL,
159 TestShell** result) { 154 TestShell** result) {
160 TestShell* shell = new TestShell(); 155 TestShell* shell = new TestShell();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 if (TestShell::windowList()->empty()) { 211 if (TestShell::windowList()->empty()) {
217 LOG(ERROR) << "No windows open."; 212 LOG(ERROR) << "No windows open.";
218 return false; 213 return false;
219 } 214 }
220 215
221 HWND hwnd = *(TestShell::windowList()->begin()); 216 HWND hwnd = *(TestShell::windowList()->begin());
222 TestShell* shell = 217 TestShell* shell =
223 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); 218 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd));
224 shell->ResetTestController(); 219 shell->ResetTestController();
225 220
226 // ResetTestController may have closed the window we were holding on to. 221 // ResetTestController may have closed the window we were holding on to.
227 // Grab the first window again. 222 // Grab the first window again.
228 hwnd = *(TestShell::windowList()->begin()); 223 hwnd = *(TestShell::windowList()->begin());
229 shell = static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); 224 shell = static_cast<TestShell*>(win_util::GetWindowUserData(hwnd));
230 DCHECK(shell); 225 DCHECK(shell);
231 226
232 // Clear focus between tests. 227 // Clear focus between tests.
233 shell->m_focusedWidgetHost = NULL; 228 shell->m_focusedWidgetHost = NULL;
234 229
235 // Make sure the previous load is stopped. 230 // Make sure the previous load is stopped.
236 shell->webView()->StopLoading(); 231 shell->webView()->StopLoading();
(...skipping 28 matching lines...) Expand all
265 if (webFrame) { 260 if (webFrame) {
266 bool should_dump_as_text = 261 bool should_dump_as_text =
267 shell->layout_test_controller_->ShouldDumpAsText(); 262 shell->layout_test_controller_->ShouldDumpAsText();
268 bool dumped_anything = false; 263 bool dumped_anything = false;
269 if (params.dump_tree) { 264 if (params.dump_tree) {
270 dumped_anything = true; 265 dumped_anything = true;
271 // Text output: the test page can request different types of output 266 // Text output: the test page can request different types of output
272 // which we handle here. 267 // which we handle here.
273 if (!should_dump_as_text) { 268 if (!should_dump_as_text) {
274 // Plain text pages should be dumped as text 269 // Plain text pages should be dumped as text
275 std::wstring mime_type = webFrame->GetDataSource()->GetResponseMimeType( ); 270 std::wstring mime_type =
271 webFrame->GetDataSource()->GetResponseMimeType();
276 should_dump_as_text = (mime_type == L"text/plain"); 272 should_dump_as_text = (mime_type == L"text/plain");
277 } 273 }
278 if (should_dump_as_text) { 274 if (should_dump_as_text) {
279 bool recursive = shell->layout_test_controller_-> 275 bool recursive = shell->layout_test_controller_->
280 ShouldDumpChildFramesAsText(); 276 ShouldDumpChildFramesAsText();
281 std::string data_utf8 = WideToUTF8( 277 std::string data_utf8 = WideToUTF8(
282 webkit_glue::DumpFramesAsText(webFrame, recursive)); 278 webkit_glue::DumpFramesAsText(webFrame, recursive));
283 fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout); 279 fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout);
284 } else { 280 } else {
285 printf("%s", WideToUTF8( 281 printf("%s", WideToUTF8(
286 webkit_glue::DumpRenderer(webFrame)).c_str()); 282 webkit_glue::DumpRenderer(webFrame)).c_str());
287 283
288 bool recursive = shell->layout_test_controller_-> 284 bool recursive = shell->layout_test_controller_->
289 ShouldDumpChildFrameScrollPositions(); 285 ShouldDumpChildFrameScrollPositions();
290 printf("%s", WideToUTF8( 286 printf("%s", WideToUTF8(
291 webkit_glue::DumpFrameScrollPosition(webFrame, recursive)).c_str()); 287 webkit_glue::DumpFrameScrollPosition(webFrame, recursive)).c_str());
292 } 288 }
293 289
294 if (shell->layout_test_controller_->ShouldDumpBackForwardList()) { 290 if (shell->layout_test_controller_->ShouldDumpBackForwardList()) {
295 std::wstring bfDump; 291 std::wstring bfDump;
296 DumpBackForwardList(&bfDump); 292 DumpBackForwardList(&bfDump);
297 printf("%s", WideToUTF8(bfDump).c_str()); 293 printf("%s", WideToUTF8(bfDump).c_str());
298 } 294 }
299 } 295 }
300 296
301 if (params.dump_pixels && !should_dump_as_text) { 297 if (params.dump_pixels && !should_dump_as_text) {
302 // Image output: we write the image data to the file given on the 298 // Image output: we write the image data to the file given on the
303 // command line (for the dump pixels argument), and the MD5 sum to 299 // command line (for the dump pixels argument), and the MD5 sum to
304 // stdout. 300 // stdout.
305 dumped_anything = true; 301 dumped_anything = true;
306 std::string md5sum = DumpImage(webFrame, params.pixel_file_name); 302 std::string md5sum = DumpImage(webFrame, params.pixel_file_name);
307 printf("#MD5:%s\n", md5sum.c_str()); 303 printf("#MD5:%s\n", md5sum.c_str());
308 } 304 }
309 if (dumped_anything) 305 if (dumped_anything)
310 printf("#EOF\n"); 306 printf("#EOF\n");
(...skipping 24 matching lines...) Expand all
335 } 331 }
336 return new_url; 332 return new_url;
337 } 333 }
338 334
339 335
340 336
341 ///////////////////////////////////////////////////////////////////////////// 337 /////////////////////////////////////////////////////////////////////////////
342 // TestShell implementation 338 // TestShell implementation
343 339
344 void TestShell::PlatformCleanUp() { 340 void TestShell::PlatformCleanUp() {
345 // When the window is destroyed, tell the Edit field to forget about us, 341 // When the window is destroyed, tell the Edit field to forget about us,
346 // otherwise we will crash. 342 // otherwise we will crash.
347 win_util::SetWindowProc(m_editWnd, default_edit_wnd_proc_); 343 win_util::SetWindowProc(m_editWnd, default_edit_wnd_proc_);
348 win_util::SetWindowUserData(m_editWnd, NULL); 344 win_util::SetWindowUserData(m_editWnd, NULL);
349 } 345 }
350 346
351 bool TestShell::Initialize(const std::wstring& startingURL) { 347 bool TestShell::Initialize(const std::wstring& startingURL) {
352 // Perform application initialization: 348 // Perform application initialization:
353 m_mainWnd = CreateWindow(g_windowClass, g_windowTitle, 349 m_mainWnd = CreateWindow(g_windowClass, g_windowTitle,
354 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, 350 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
355 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 351 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
356 NULL, NULL, instance_handle_, NULL); 352 NULL, NULL, instance_handle_, NULL);
357 win_util::SetWindowUserData(m_mainWnd, this); 353 win_util::SetWindowUserData(m_mainWnd, this);
358 354
359 HWND hwnd; 355 HWND hwnd;
360 int x = 0; 356 int x = 0;
361 357
362 hwnd = CreateWindow(L"BUTTON", L"Back", 358 hwnd = CreateWindow(L"BUTTON", L"Back",
363 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , 359 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
364 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, 360 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
365 m_mainWnd, (HMENU) IDC_NAV_BACK, instance_handle_, 0); 361 m_mainWnd, (HMENU) IDC_NAV_BACK, instance_handle_, 0);
366 x += BUTTON_WIDTH; 362 x += BUTTON_WIDTH;
367 363
368 hwnd = CreateWindow(L"BUTTON", L"Forward", 364 hwnd = CreateWindow(L"BUTTON", L"Forward",
369 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , 365 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
370 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, 366 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
371 m_mainWnd, (HMENU) IDC_NAV_FORWARD, instance_handle_, 0); 367 m_mainWnd, (HMENU) IDC_NAV_FORWARD, instance_handle_, 0);
372 x += BUTTON_WIDTH; 368 x += BUTTON_WIDTH;
373 369
374 hwnd = CreateWindow(L"BUTTON", L"Reload", 370 hwnd = CreateWindow(L"BUTTON", L"Reload",
375 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , 371 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
376 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, 372 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
377 m_mainWnd, (HMENU) IDC_NAV_RELOAD, instance_handle_, 0); 373 m_mainWnd, (HMENU) IDC_NAV_RELOAD, instance_handle_, 0);
378 x += BUTTON_WIDTH; 374 x += BUTTON_WIDTH;
379 375
380 hwnd = CreateWindow(L"BUTTON", L"Stop", 376 hwnd = CreateWindow(L"BUTTON", L"Stop",
381 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , 377 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON ,
382 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, 378 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
383 m_mainWnd, (HMENU) IDC_NAV_STOP, instance_handle_, 0); 379 m_mainWnd, (HMENU) IDC_NAV_STOP, instance_handle_, 0);
384 x += BUTTON_WIDTH; 380 x += BUTTON_WIDTH;
385 381
386 // this control is positioned by ResizeSubViews 382 // this control is positioned by ResizeSubViews
387 m_editWnd = CreateWindow(L"EDIT", 0, 383 m_editWnd = CreateWindow(L"EDIT", 0,
388 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | 384 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
389 ES_AUTOVSCROLL | ES_AUTOHSCROLL, 385 ES_AUTOVSCROLL | ES_AUTOHSCROLL,
390 x, 0, 0, 0, m_mainWnd, 0, instance_handle_, 0); 386 x, 0, 0, 0, m_mainWnd, 0, instance_handle_, 0);
391 387
392 default_edit_wnd_proc_ = 388 default_edit_wnd_proc_ =
393 win_util::SetWindowProc(m_editWnd, TestShell::EditWndProc); 389 win_util::SetWindowProc(m_editWnd, TestShell::EditWndProc);
394 win_util::SetWindowUserData(m_editWnd, this); 390 win_util::SetWindowUserData(m_editWnd, this);
395 391
396 // create webview 392 // create webview
397 m_webViewHost.reset( 393 m_webViewHost.reset(
398 WebViewHost::Create(m_mainWnd, delegate_.get(), *TestShell::web_prefs_)); 394 WebViewHost::Create(m_mainWnd, delegate_.get(), *TestShell::web_prefs_));
399 webView()->SetUseEditorDelegate(true); 395 webView()->SetUseEditorDelegate(true);
400 delegate_->RegisterDragDrop(); 396 delegate_->RegisterDragDrop();
401 397
402 // Load our initial content. 398 // Load our initial content.
403 if (!startingURL.empty()) 399 if (!startingURL.empty())
404 LoadURL(startingURL.c_str()); 400 LoadURL(startingURL.c_str());
405 401
406 ShowWindow(webViewWnd(), SW_SHOW); 402 ShowWindow(webViewWnd(), SW_SHOW);
407 403
408 bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos; 404 bool bIsSVGTest = startingURL.find(L"W3C-SVG-1.1") != std::wstring::npos;
409 405
410 if (bIsSVGTest) { 406 if (bIsSVGTest) {
411 SizeToSVG(); 407 SizeToSVG();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 return 0; 445 return 0;
450 } 446 }
451 447
452 void TestShell::WaitTestFinished() { 448 void TestShell::WaitTestFinished() {
453 DCHECK(!test_is_pending_) << "cannot be used recursively"; 449 DCHECK(!test_is_pending_) << "cannot be used recursively";
454 450
455 test_is_pending_ = true; 451 test_is_pending_ = true;
456 452
457 // Create a watchdog thread which just sets a timer and 453 // Create a watchdog thread which just sets a timer and
458 // kills the process if it times out. This catches really 454 // kills the process if it times out. This catches really
459 // bad hangs where the shell isn't coming back to the 455 // bad hangs where the shell isn't coming back to the
460 // message loop. If the watchdog is what catches a 456 // message loop. If the watchdog is what catches a
461 // timeout, it can't do anything except terminate the test 457 // timeout, it can't do anything except terminate the test
462 // shell, which is unfortunate. 458 // shell, which is unfortunate.
463 finished_event_ = CreateEvent(NULL, TRUE, FALSE, NULL); 459 finished_event_ = CreateEvent(NULL, TRUE, FALSE, NULL);
464 DCHECK(finished_event_ != NULL); 460 DCHECK(finished_event_ != NULL);
465 461
466 HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex( 462 HANDLE thread_handle = reinterpret_cast<HANDLE>(_beginthreadex(
467 NULL, 463 NULL,
468 0, 464 0,
469 &WatchDogThread, 465 &WatchDogThread,
470 this, 466 this,
471 0, 467 0,
472 0)); 468 0));
473 DCHECK(thread_handle != NULL); 469 DCHECK(thread_handle != NULL);
474 470
475 // TestFinished() will post a quit message to break this loop when the page 471 // TestFinished() will post a quit message to break this loop when the page
476 // finishes loading. 472 // finishes loading.
477 while (test_is_pending_) 473 while (test_is_pending_)
478 MessageLoop::current()->Run(); 474 MessageLoop::current()->Run();
479 475
480 // Tell the watchdog that we are finished. 476 // Tell the watchdog that we are finished.
481 SetEvent(finished_event_); 477 SetEvent(finished_event_);
482 478
483 // Wait to join the watchdog thread. (up to 1s, then quit) 479 // Wait to join the watchdog thread. (up to 1s, then quit)
484 WaitForSingleObject(thread_handle, 1000); 480 WaitForSingleObject(thread_handle, 1000);
485 } 481 }
486 482
487 void TestShell::InteractiveSetFocus(WebWidgetHost* host, bool enable) { 483 void TestShell::InteractiveSetFocus(WebWidgetHost* host, bool enable) {
488 if (!enable && ::GetFocus() == host->view_handle()) 484 if (!enable && ::GetFocus() == host->view_handle())
489 ::SetFocus(NULL); 485 ::SetFocus(NULL);
490 } 486 }
491 487
492 WebWidget* TestShell::CreatePopupWidget(WebView* webview) { 488 WebWidget* TestShell::CreatePopupWidget(WebView* webview) {
493 DCHECK(!m_popupHost); 489 DCHECK(!m_popupHost);
494 m_popupHost = WebWidgetHost::Create(NULL, delegate_.get()); 490 m_popupHost = WebWidgetHost::Create(NULL, delegate_.get());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 638
643 LRESULT CALLBACK TestShell::EditWndProc(HWND hwnd, UINT message, 639 LRESULT CALLBACK TestShell::EditWndProc(HWND hwnd, UINT message,
644 WPARAM wParam, LPARAM lParam) { 640 WPARAM wParam, LPARAM lParam) {
645 TestShell* shell = 641 TestShell* shell =
646 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); 642 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd));
647 643
648 switch (message) { 644 switch (message) {
649 case WM_CHAR: 645 case WM_CHAR:
650 if (wParam == VK_RETURN) { 646 if (wParam == VK_RETURN) {
651 wchar_t strPtr[MAX_URL_LENGTH + 1]; // Leave room for adding a NULL; 647 wchar_t strPtr[MAX_URL_LENGTH + 1]; // Leave room for adding a NULL;
652 *((LPWORD)strPtr) = MAX_URL_LENGTH; 648 *((LPWORD)strPtr) = MAX_URL_LENGTH;
653 LRESULT strLen = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)strPtr); 649 LRESULT strLen = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)strPtr);
654 if (strLen > 0) { 650 if (strLen > 0) {
655 strPtr[strLen] = 0; // EM_GETLINE doesn't NULL terminate. 651 strPtr[strLen] = 0; // EM_GETLINE doesn't NULL terminate.
656 shell->LoadURL(strPtr); 652 shell->LoadURL(strPtr);
657 } 653 }
658 654
659 return 0; 655 return 0;
660 } 656 }
661 } 657 }
662 658
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 728
733 bool EnsureFontLoaded(HFONT font) { 729 bool EnsureFontLoaded(HFONT font) {
734 return true; 730 return true;
735 } 731 }
736 732
737 bool DownloadUrl(const std::string& url, HWND caller_window) { 733 bool DownloadUrl(const std::string& url, HWND caller_window) {
738 return false; 734 return false;
739 } 735 }
740 736
741 } // namespace webkit_glue 737 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/tools/test_shell/test_shell_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698