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 #include "webkit/tools/test_shell/test_shell.h" | 5 #include "webkit/tools/test_shell/test_shell.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <commdlg.h> | 8 #include <commdlg.h> |
9 #include <objbase.h> | 9 #include <objbase.h> |
10 #include <process.h> | 10 #include <process.h> |
11 #include <shlwapi.h> | 11 #include <shlwapi.h> |
12 | 12 |
| 13 #include "app/win/hwnd_util.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/debug/trace_event.h" | 15 #include "base/debug/trace_event.h" |
15 #include "base/file_util.h" | 16 #include "base/file_util.h" |
16 #include "base/memory_debug.h" | 17 #include "base/memory_debug.h" |
17 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
18 #include "base/path_service.h" | 19 #include "base/path_service.h" |
19 #include "base/resource_util.h" | 20 #include "base/resource_util.h" |
20 #include "base/stack_container.h" | 21 #include "base/stack_container.h" |
21 #include "base/string_piece.h" | 22 #include "base/string_piece.h" |
22 #include "base/string_util.h" | 23 #include "base/string_util.h" |
23 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
24 #include "base/win_util.h" | |
25 #include "breakpad/src/client/windows/handler/exception_handler.h" | 25 #include "breakpad/src/client/windows/handler/exception_handler.h" |
26 #include "grit/webkit_resources.h" | 26 #include "grit/webkit_resources.h" |
27 #include "grit/webkit_chromium_resources.h" | 27 #include "grit/webkit_chromium_resources.h" |
28 #include "net/base/net_module.h" | 28 #include "net/base/net_module.h" |
29 #include "net/url_request/url_request_file_job.h" | 29 #include "net/url_request/url_request_file_job.h" |
30 #include "skia/ext/bitmap_platform_device.h" | 30 #include "skia/ext/bitmap_platform_device.h" |
31 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" | 31 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" |
32 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 32 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
33 #include "webkit/glue/webkit_glue.h" | 33 #include "webkit/glue/webkit_glue.h" |
34 #include "webkit/glue/webpreferences.h" | 34 #include "webkit/glue/webpreferences.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 }; | 226 }; |
227 return RegisterClassEx(&wcex); | 227 return RegisterClassEx(&wcex); |
228 } | 228 } |
229 | 229 |
230 void TestShell::DumpAllBackForwardLists(string16* result) { | 230 void TestShell::DumpAllBackForwardLists(string16* result) { |
231 result->clear(); | 231 result->clear(); |
232 for (WindowList::iterator iter = TestShell::windowList()->begin(); | 232 for (WindowList::iterator iter = TestShell::windowList()->begin(); |
233 iter != TestShell::windowList()->end(); iter++) { | 233 iter != TestShell::windowList()->end(); iter++) { |
234 HWND hwnd = *iter; | 234 HWND hwnd = *iter; |
235 TestShell* shell = | 235 TestShell* shell = |
236 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | 236 static_cast<TestShell*>(app::win::GetWindowUserData(hwnd)); |
237 shell->DumpBackForwardList(result); | 237 shell->DumpBackForwardList(result); |
238 } | 238 } |
239 } | 239 } |
240 | 240 |
241 bool TestShell::RunFileTest(const TestParams& params) { | 241 bool TestShell::RunFileTest(const TestParams& params) { |
242 SetCurrentTestName(params.test_url.c_str()); | 242 SetCurrentTestName(params.test_url.c_str()); |
243 | 243 |
244 // Load the test file into the first available window. | 244 // Load the test file into the first available window. |
245 if (TestShell::windowList()->empty()) { | 245 if (TestShell::windowList()->empty()) { |
246 LOG(ERROR) << "No windows open."; | 246 LOG(ERROR) << "No windows open."; |
247 return false; | 247 return false; |
248 } | 248 } |
249 | 249 |
250 HWND hwnd = *(TestShell::windowList()->begin()); | 250 HWND hwnd = *(TestShell::windowList()->begin()); |
251 TestShell* shell = | 251 TestShell* shell = |
252 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | 252 static_cast<TestShell*>(app::win::GetWindowUserData(hwnd)); |
253 | 253 |
254 // Clear focus between tests. | 254 // Clear focus between tests. |
255 shell->m_focusedWidgetHost = NULL; | 255 shell->m_focusedWidgetHost = NULL; |
256 | 256 |
257 // Make sure the previous load is stopped. | 257 // Make sure the previous load is stopped. |
258 shell->webView()->mainFrame()->stopLoading(); | 258 shell->webView()->mainFrame()->stopLoading(); |
259 shell->navigation_controller()->Reset(); | 259 shell->navigation_controller()->Reset(); |
260 | 260 |
261 // StopLoading may update state maintained in the test controller (for | 261 // StopLoading may update state maintained in the test controller (for |
262 // example, whether the WorkQueue is frozen) as such, we need to reset it | 262 // example, whether the WorkQueue is frozen) as such, we need to reset it |
263 // after we invoke StopLoading. | 263 // after we invoke StopLoading. |
264 shell->ResetTestController(); | 264 shell->ResetTestController(); |
265 | 265 |
266 // ResetTestController may have closed the window we were holding on to. | 266 // ResetTestController may have closed the window we were holding on to. |
267 // Grab the first window again. | 267 // Grab the first window again. |
268 hwnd = *(TestShell::windowList()->begin()); | 268 hwnd = *(TestShell::windowList()->begin()); |
269 shell = static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | 269 shell = static_cast<TestShell*>(app::win::GetWindowUserData(hwnd)); |
270 DCHECK(shell); | 270 DCHECK(shell); |
271 | 271 |
272 // Whether DevTools should be open before loading the page. | 272 // Whether DevTools should be open before loading the page. |
273 bool inspector_test_mode = strstr(params.test_url.c_str(), "/inspector/") || | 273 bool inspector_test_mode = strstr(params.test_url.c_str(), "/inspector/") || |
274 strstr(params.test_url.c_str(), "\\inspector\\"); | 274 strstr(params.test_url.c_str(), "\\inspector\\"); |
275 | 275 |
276 developer_extras_enabled_ = inspector_test_mode || | 276 developer_extras_enabled_ = inspector_test_mode || |
277 strstr(params.test_url.c_str(), "/inspector-enabled/") || | 277 strstr(params.test_url.c_str(), "/inspector-enabled/") || |
278 strstr(params.test_url.c_str(), "\\inspector-enabled\\"); | 278 strstr(params.test_url.c_str(), "\\inspector-enabled\\"); |
279 | 279 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 332 } |
333 | 333 |
334 | 334 |
335 | 335 |
336 ///////////////////////////////////////////////////////////////////////////// | 336 ///////////////////////////////////////////////////////////////////////////// |
337 // TestShell implementation | 337 // TestShell implementation |
338 | 338 |
339 void TestShell::PlatformCleanUp() { | 339 void TestShell::PlatformCleanUp() { |
340 // When the window is destroyed, tell the Edit field to forget about us, | 340 // When the window is destroyed, tell the Edit field to forget about us, |
341 // otherwise we will crash. | 341 // otherwise we will crash. |
342 win_util::SetWindowProc(m_editWnd, default_edit_wnd_proc_); | 342 app::win::SetWindowProc(m_editWnd, default_edit_wnd_proc_); |
343 win_util::SetWindowUserData(m_editWnd, NULL); | 343 app::win::SetWindowUserData(m_editWnd, NULL); |
344 } | 344 } |
345 | 345 |
346 void TestShell::EnableUIControl(UIControl control, bool is_enabled) { | 346 void TestShell::EnableUIControl(UIControl control, bool is_enabled) { |
347 int id; | 347 int id; |
348 switch (control) { | 348 switch (control) { |
349 case BACK_BUTTON: | 349 case BACK_BUTTON: |
350 id = IDC_NAV_BACK; | 350 id = IDC_NAV_BACK; |
351 break; | 351 break; |
352 case FORWARD_BUTTON: | 352 case FORWARD_BUTTON: |
353 id = IDC_NAV_FORWARD; | 353 id = IDC_NAV_FORWARD; |
354 break; | 354 break; |
355 case STOP_BUTTON: | 355 case STOP_BUTTON: |
356 id = IDC_NAV_STOP; | 356 id = IDC_NAV_STOP; |
357 break; | 357 break; |
358 default: | 358 default: |
359 NOTREACHED() << "Unknown UI control"; | 359 NOTREACHED() << "Unknown UI control"; |
360 return; | 360 return; |
361 } | 361 } |
362 EnableWindow(GetDlgItem(m_mainWnd, id), is_enabled); | 362 EnableWindow(GetDlgItem(m_mainWnd, id), is_enabled); |
363 } | 363 } |
364 | 364 |
365 bool TestShell::Initialize(const GURL& starting_url) { | 365 bool TestShell::Initialize(const GURL& starting_url) { |
366 // Perform application initialization: | 366 // Perform application initialization: |
367 m_mainWnd = CreateWindow(g_windowClass, g_windowTitle, | 367 m_mainWnd = CreateWindow(g_windowClass, g_windowTitle, |
368 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, | 368 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, |
369 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, | 369 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, |
370 NULL, NULL, instance_handle_, NULL); | 370 NULL, NULL, instance_handle_, NULL); |
371 win_util::SetWindowUserData(m_mainWnd, this); | 371 app::win::SetWindowUserData(m_mainWnd, this); |
372 | 372 |
373 HWND hwnd; | 373 HWND hwnd; |
374 int x = 0; | 374 int x = 0; |
375 | 375 |
376 hwnd = CreateWindow(L"BUTTON", L"Back", | 376 hwnd = CreateWindow(L"BUTTON", L"Back", |
377 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , | 377 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , |
378 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, | 378 x, 0, BUTTON_WIDTH, URLBAR_HEIGHT, |
379 m_mainWnd, (HMENU) IDC_NAV_BACK, instance_handle_, 0); | 379 m_mainWnd, (HMENU) IDC_NAV_BACK, instance_handle_, 0); |
380 x += BUTTON_WIDTH; | 380 x += BUTTON_WIDTH; |
381 | 381 |
(...skipping 15 matching lines...) Expand all Loading... |
397 m_mainWnd, (HMENU) IDC_NAV_STOP, instance_handle_, 0); | 397 m_mainWnd, (HMENU) IDC_NAV_STOP, instance_handle_, 0); |
398 x += BUTTON_WIDTH; | 398 x += BUTTON_WIDTH; |
399 | 399 |
400 // this control is positioned by ResizeSubViews | 400 // this control is positioned by ResizeSubViews |
401 m_editWnd = CreateWindow(L"EDIT", 0, | 401 m_editWnd = CreateWindow(L"EDIT", 0, |
402 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | | 402 WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT | |
403 ES_AUTOVSCROLL | ES_AUTOHSCROLL, | 403 ES_AUTOVSCROLL | ES_AUTOHSCROLL, |
404 x, 0, 0, 0, m_mainWnd, 0, instance_handle_, 0); | 404 x, 0, 0, 0, m_mainWnd, 0, instance_handle_, 0); |
405 | 405 |
406 default_edit_wnd_proc_ = | 406 default_edit_wnd_proc_ = |
407 win_util::SetWindowProc(m_editWnd, TestShell::EditWndProc); | 407 app::win::SetWindowProc(m_editWnd, TestShell::EditWndProc); |
408 win_util::SetWindowUserData(m_editWnd, this); | 408 app::win::SetWindowUserData(m_editWnd, this); |
409 | 409 |
410 dev_tools_agent_.reset(new TestShellDevToolsAgent()); | 410 dev_tools_agent_.reset(new TestShellDevToolsAgent()); |
411 | 411 |
412 // create webview | 412 // create webview |
413 m_webViewHost.reset( | 413 m_webViewHost.reset( |
414 WebViewHost::Create(m_mainWnd, | 414 WebViewHost::Create(m_mainWnd, |
415 delegate_.get(), | 415 delegate_.get(), |
416 dev_tools_agent_.get(), | 416 dev_tools_agent_.get(), |
417 *TestShell::web_prefs_)); | 417 *TestShell::web_prefs_)); |
418 dev_tools_agent_->SetWebView(m_webViewHost->webview()); | 418 dev_tools_agent_->SetWebView(m_webViewHost->webview()); |
(...skipping 15 matching lines...) Expand all Loading... |
434 } | 434 } |
435 | 435 |
436 void TestShell::TestFinished() { | 436 void TestShell::TestFinished() { |
437 if (!test_is_pending_) | 437 if (!test_is_pending_) |
438 return; // reached when running under test_shell_tests | 438 return; // reached when running under test_shell_tests |
439 | 439 |
440 test_is_pending_ = false; | 440 test_is_pending_ = false; |
441 if (dump_when_finished_) { | 441 if (dump_when_finished_) { |
442 HWND hwnd = *(TestShell::windowList()->begin()); | 442 HWND hwnd = *(TestShell::windowList()->begin()); |
443 TestShell* shell = | 443 TestShell* shell = |
444 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | 444 static_cast<TestShell*>(app::win::GetWindowUserData(hwnd)); |
445 TestShell::Dump(shell); | 445 TestShell::Dump(shell); |
446 } | 446 } |
447 | 447 |
448 UINT_PTR timer_id = reinterpret_cast<UINT_PTR>(this); | 448 UINT_PTR timer_id = reinterpret_cast<UINT_PTR>(this); |
449 KillTimer(mainWnd(), timer_id); | 449 KillTimer(mainWnd(), timer_id); |
450 | 450 |
451 MessageLoop::current()->Quit(); | 451 MessageLoop::current()->Quit(); |
452 } | 452 } |
453 | 453 |
454 // Thread main to run for the thread which just tests for timeout. | 454 // Thread main to run for the thread which just tests for timeout. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 if (layout_test_mode()) | 571 if (layout_test_mode()) |
572 SizeToDefault(); | 572 SizeToDefault(); |
573 } | 573 } |
574 | 574 |
575 navigation_controller_->LoadEntry( | 575 navigation_controller_->LoadEntry( |
576 new TestNavigationEntry(-1, url, std::wstring(), frame_name)); | 576 new TestNavigationEntry(-1, url, std::wstring(), frame_name)); |
577 } | 577 } |
578 | 578 |
579 LRESULT CALLBACK TestShell::WndProc(HWND hwnd, UINT message, WPARAM wParam, | 579 LRESULT CALLBACK TestShell::WndProc(HWND hwnd, UINT message, WPARAM wParam, |
580 LPARAM lParam) { | 580 LPARAM lParam) { |
581 TestShell* shell = static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | 581 TestShell* shell = static_cast<TestShell*>(app::win::GetWindowUserData(hwnd)); |
582 | 582 |
583 switch (message) { | 583 switch (message) { |
584 case WM_COMMAND: | 584 case WM_COMMAND: |
585 { | 585 { |
586 int wmId = LOWORD(wParam); | 586 int wmId = LOWORD(wParam); |
587 int wmEvent = HIWORD(wParam); | 587 int wmEvent = HIWORD(wParam); |
588 | 588 |
589 switch (wmId) { | 589 switch (wmId) { |
590 case IDM_ABOUT: | 590 case IDM_ABOUT: |
591 DialogBox(shell->instance_handle_, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, | 591 DialogBox(shell->instance_handle_, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 | 669 |
670 return DefWindowProc(hwnd, message, wParam, lParam); | 670 return DefWindowProc(hwnd, message, wParam, lParam); |
671 } | 671 } |
672 | 672 |
673 | 673 |
674 #define MAX_URL_LENGTH 1024 | 674 #define MAX_URL_LENGTH 1024 |
675 | 675 |
676 LRESULT CALLBACK TestShell::EditWndProc(HWND hwnd, UINT message, | 676 LRESULT CALLBACK TestShell::EditWndProc(HWND hwnd, UINT message, |
677 WPARAM wParam, LPARAM lParam) { | 677 WPARAM wParam, LPARAM lParam) { |
678 TestShell* shell = | 678 TestShell* shell = |
679 static_cast<TestShell*>(win_util::GetWindowUserData(hwnd)); | 679 static_cast<TestShell*>(app::win::GetWindowUserData(hwnd)); |
680 | 680 |
681 switch (message) { | 681 switch (message) { |
682 case WM_CHAR: | 682 case WM_CHAR: |
683 if (wParam == VK_RETURN) { | 683 if (wParam == VK_RETURN) { |
684 wchar_t str[MAX_URL_LENGTH + 1]; // Leave room for adding a NULL; | 684 wchar_t str[MAX_URL_LENGTH + 1]; // Leave room for adding a NULL; |
685 *((LPWORD)str) = MAX_URL_LENGTH; | 685 *((LPWORD)str) = MAX_URL_LENGTH; |
686 LRESULT str_len = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)str); | 686 LRESULT str_len = SendMessage(hwnd, EM_GETLINE, 0, (LPARAM)str); |
687 if (str_len > 0) { | 687 if (str_len > 0) { |
688 str[str_len] = 0; // EM_GETLINE doesn't NULL terminate. | 688 str[str_len] = 0; // EM_GETLINE doesn't NULL terminate. |
689 shell->LoadURL(GURL(str)); | 689 shell->LoadURL(GURL(str)); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
822 | 822 |
823 bool EnsureFontLoaded(HFONT font) { | 823 bool EnsureFontLoaded(HFONT font) { |
824 return true; | 824 return true; |
825 } | 825 } |
826 | 826 |
827 bool DownloadUrl(const std::string& url, HWND caller_window) { | 827 bool DownloadUrl(const std::string& url, HWND caller_window) { |
828 return false; | 828 return false; |
829 } | 829 } |
830 | 830 |
831 } // namespace webkit_glue | 831 } // namespace webkit_glue |
OLD | NEW |