| 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 #undef LOG | 5 #undef LOG |
| 6 | 6 |
| 7 #include "webkit/tools/test_shell/test_shell.h" | 7 #include "webkit/tools/test_shell/test_shell.h" |
| 8 | 8 |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "base/string_util.h" | 24 #include "base/string_util.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "googleurl/src/url_util.h" | 26 #include "googleurl/src/url_util.h" |
| 27 #include "grit/webkit_strings.h" | 27 #include "grit/webkit_strings.h" |
| 28 #include "net/base/mime_util.h" | 28 #include "net/base/mime_util.h" |
| 29 #include "net/url_request/url_request_file_job.h" | 29 #include "net/url_request/url_request_file_job.h" |
| 30 #include "net/url_request/url_request_filter.h" | 30 #include "net/url_request/url_request_filter.h" |
| 31 #include "skia/ext/bitmap_platform_device.h" | 31 #include "skia/ext/bitmap_platform_device.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | 33 #include "third_party/skia/include/core/SkBitmap.h" |
| 34 #include "webkit/api/public/WebFrame.h" |
| 35 #include "webkit/api/public/WebKit.h" |
| 34 #include "webkit/api/public/WebRect.h" | 36 #include "webkit/api/public/WebRect.h" |
| 35 #include "webkit/api/public/WebKit.h" | |
| 36 #include "webkit/api/public/WebSize.h" | 37 #include "webkit/api/public/WebSize.h" |
| 37 #include "webkit/api/public/WebString.h" | 38 #include "webkit/api/public/WebString.h" |
| 38 #include "webkit/api/public/WebURL.h" | 39 #include "webkit/api/public/WebURL.h" |
| 39 #include "webkit/api/public/WebURLRequest.h" | 40 #include "webkit/api/public/WebURLRequest.h" |
| 40 #include "webkit/api/public/WebURLResponse.h" | 41 #include "webkit/api/public/WebURLResponse.h" |
| 41 #include "webkit/glue/glue_serialize.h" | 42 #include "webkit/glue/glue_serialize.h" |
| 42 #include "webkit/glue/webframe.h" | |
| 43 #include "webkit/glue/webkit_glue.h" | 43 #include "webkit/glue/webkit_glue.h" |
| 44 #include "webkit/glue/webpreferences.h" | 44 #include "webkit/glue/webpreferences.h" |
| 45 #include "webkit/glue/webview.h" | 45 #include "webkit/glue/webview.h" |
| 46 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" | 46 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 47 #include "webkit/tools/test_shell/test_navigation_controller.h" | 47 #include "webkit/tools/test_shell/test_navigation_controller.h" |
| 48 #include "webkit/tools/test_shell/test_shell_switches.h" | 48 #include "webkit/tools/test_shell/test_shell_switches.h" |
| 49 | 49 |
| 50 using WebKit::WebFrame; |
| 50 using WebKit::WebNavigationPolicy; | 51 using WebKit::WebNavigationPolicy; |
| 51 using WebKit::WebRect; | 52 using WebKit::WebRect; |
| 52 using WebKit::WebSize; | 53 using WebKit::WebSize; |
| 53 using WebKit::WebURLRequest; | 54 using WebKit::WebURLRequest; |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| 56 | 57 |
| 57 // Default timeout in ms for file page loads when in layout test mode. | 58 // Default timeout in ms for file page loads when in layout test mode. |
| 58 const int kDefaultFileTestTimeoutMillisecs = 10 * 1000; | 59 const int kDefaultFileTestTimeoutMillisecs = 10 * 1000; |
| 59 | 60 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 bool should_dump_as_text = | 195 bool should_dump_as_text = |
| 195 shell->layout_test_controller_->ShouldDumpAsText(); | 196 shell->layout_test_controller_->ShouldDumpAsText(); |
| 196 bool dumped_anything = false; | 197 bool dumped_anything = false; |
| 197 if (params->dump_tree) { | 198 if (params->dump_tree) { |
| 198 dumped_anything = true; | 199 dumped_anything = true; |
| 199 // Text output: the test page can request different types of output | 200 // Text output: the test page can request different types of output |
| 200 // which we handle here. | 201 // which we handle here. |
| 201 if (!should_dump_as_text) { | 202 if (!should_dump_as_text) { |
| 202 // Plain text pages should be dumped as text | 203 // Plain text pages should be dumped as text |
| 203 const string16& mime_type = | 204 const string16& mime_type = |
| 204 frame->GetDataSource()->response().mimeType(); | 205 frame->dataSource()->response().mimeType(); |
| 205 should_dump_as_text = EqualsASCII(mime_type, "text/plain"); | 206 should_dump_as_text = EqualsASCII(mime_type, "text/plain"); |
| 206 } | 207 } |
| 207 if (should_dump_as_text) { | 208 if (should_dump_as_text) { |
| 208 bool recursive = shell->layout_test_controller_-> | 209 bool recursive = shell->layout_test_controller_-> |
| 209 ShouldDumpChildFramesAsText(); | 210 ShouldDumpChildFramesAsText(); |
| 210 std::string data_utf8 = WideToUTF8( | 211 std::string data_utf8 = WideToUTF8( |
| 211 webkit_glue::DumpFramesAsText(frame, recursive)); | 212 webkit_glue::DumpFramesAsText(frame, recursive)); |
| 212 if (fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout) != | 213 if (fwrite(data_utf8.c_str(), 1, data_utf8.size(), stdout) != |
| 213 data_utf8.size()) { | 214 data_utf8.size()) { |
| 214 LOG(FATAL) << "Short write to stdout, disk full?"; | 215 LOG(FATAL) << "Short write to stdout, disk full?"; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 void TestShell::DumpBackForwardList(std::wstring* result) { | 468 void TestShell::DumpBackForwardList(std::wstring* result) { |
| 468 result->append(L"\n============== Back Forward List ==============\n"); | 469 result->append(L"\n============== Back Forward List ==============\n"); |
| 469 | 470 |
| 470 for (int i = 0; i < navigation_controller_->GetEntryCount(); ++i) | 471 for (int i = 0; i < navigation_controller_->GetEntryCount(); ++i) |
| 471 DumpBackForwardEntry(i, result); | 472 DumpBackForwardEntry(i, result); |
| 472 | 473 |
| 473 result->append(L"===============================================\n"); | 474 result->append(L"===============================================\n"); |
| 474 } | 475 } |
| 475 | 476 |
| 476 void TestShell::CallJSGC() { | 477 void TestShell::CallJSGC() { |
| 477 webView()->GetMainFrame()->CallJSGC(); | 478 webView()->GetMainFrame()->collectGarbage(); |
| 478 } | 479 } |
| 479 | 480 |
| 480 WebView* TestShell::CreateWebView(WebView* webview) { | 481 WebView* TestShell::CreateWebView(WebView* webview) { |
| 481 // If we're running layout tests, only open a new window if the test has | 482 // If we're running layout tests, only open a new window if the test has |
| 482 // called layoutTestController.setCanOpenWindows() | 483 // called layoutTestController.setCanOpenWindows() |
| 483 if (layout_test_mode_ && !layout_test_controller_->CanOpenWindows()) | 484 if (layout_test_mode_ && !layout_test_controller_->CanOpenWindows()) |
| 484 return NULL; | 485 return NULL; |
| 485 | 486 |
| 486 TestShell* new_win; | 487 TestShell* new_win; |
| 487 if (!CreateNewWindow(std::wstring(), &new_win)) | 488 if (!CreateNewWindow(std::wstring(), &new_win)) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 // treated as a browser initiated event. Instead, we want it to look as if | 524 // treated as a browser initiated event. Instead, we want it to look as if |
| 524 // the page initiated any load resulting from JS execution. | 525 // the page initiated any load resulting from JS execution. |
| 525 if (!entry.GetURL().SchemeIs("javascript")) { | 526 if (!entry.GetURL().SchemeIs("javascript")) { |
| 526 delegate_->set_pending_extra_data( | 527 delegate_->set_pending_extra_data( |
| 527 new TestShellExtraData(entry.GetPageID())); | 528 new TestShellExtraData(entry.GetPageID())); |
| 528 } | 529 } |
| 529 | 530 |
| 530 // If we are reloading, then WebKit will use the state of the current page. | 531 // If we are reloading, then WebKit will use the state of the current page. |
| 531 // Otherwise, we give it the state to navigate to. | 532 // Otherwise, we give it the state to navigate to. |
| 532 if (reload) { | 533 if (reload) { |
| 533 frame->Reload(); | 534 frame->reload(); |
| 534 } else if (!entry.GetContentState().empty()) { | 535 } else if (!entry.GetContentState().empty()) { |
| 535 DCHECK(entry.GetPageID() != -1); | 536 DCHECK(entry.GetPageID() != -1); |
| 536 frame->LoadHistoryItem( | 537 frame->loadHistoryItem( |
| 537 webkit_glue::HistoryItemFromString(entry.GetContentState())); | 538 webkit_glue::HistoryItemFromString(entry.GetContentState())); |
| 538 } else { | 539 } else { |
| 539 DCHECK(entry.GetPageID() == -1); | 540 DCHECK(entry.GetPageID() == -1); |
| 540 frame->LoadRequest(WebURLRequest(entry.GetURL())); | 541 frame->loadRequest(WebURLRequest(entry.GetURL())); |
| 541 } | 542 } |
| 542 | 543 |
| 543 // In case LoadRequest failed before DidCreateDataSource was called. | 544 // In case LoadRequest failed before DidCreateDataSource was called. |
| 544 delegate_->set_pending_extra_data(NULL); | 545 delegate_->set_pending_extra_data(NULL); |
| 545 | 546 |
| 546 // Restore focus to the main frame prior to loading new request. | 547 // Restore focus to the main frame prior to loading new request. |
| 547 // This makes sure that we don't have a focused iframe. Otherwise, that | 548 // This makes sure that we don't have a focused iframe. Otherwise, that |
| 548 // iframe would keep focus when the SetFocus called immediately after | 549 // iframe would keep focus when the SetFocus called immediately after |
| 549 // LoadRequest, thus making some tests fail (see http://b/issue?id=845337 | 550 // LoadRequest, thus making some tests fail (see http://b/issue?id=845337 |
| 550 // for more details). | 551 // for more details). |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 673 |
| 673 void CloseIdleConnections() { | 674 void CloseIdleConnections() { |
| 674 // Used in benchmarking, Ignored for test_shell. | 675 // Used in benchmarking, Ignored for test_shell. |
| 675 } | 676 } |
| 676 | 677 |
| 677 void SetCacheMode(bool enabled) { | 678 void SetCacheMode(bool enabled) { |
| 678 // Used in benchmarking, Ignored for test_shell. | 679 // Used in benchmarking, Ignored for test_shell. |
| 679 } | 680 } |
| 680 | 681 |
| 681 } // namespace webkit_glue | 682 } // namespace webkit_glue |
| OLD | NEW |