OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #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" |
11 #include "base/debug_on_start.h" | 11 #include "base/debug_on_start.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/gfx/png_encoder.h" | 14 #include "base/gfx/png_encoder.h" |
15 #include "base/gfx/size.h" | 15 #include "base/gfx/size.h" |
16 #include "base/icu_util.h" | 16 #include "base/icu_util.h" |
17 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
18 #include "base/mac_util.h" | 18 #include "base/mac_util.h" |
19 #endif | 19 #endif |
20 #include "base/md5.h" | 20 #include "base/md5.h" |
21 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
23 #include "base/stats_table.h" | 23 #include "base/stats_table.h" |
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/base/net_util.h" |
29 #include "net/url_request/url_request_file_job.h" | 30 #include "net/url_request/url_request_file_job.h" |
30 #include "net/url_request/url_request_filter.h" | 31 #include "net/url_request/url_request_filter.h" |
31 #include "skia/ext/bitmap_platform_device.h" | 32 #include "skia/ext/bitmap_platform_device.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
34 #include "webkit/api/public/WebFrame.h" | 35 #include "webkit/api/public/WebFrame.h" |
35 #include "webkit/api/public/WebKit.h" | 36 #include "webkit/api/public/WebKit.h" |
36 #include "webkit/api/public/WebRect.h" | 37 #include "webkit/api/public/WebRect.h" |
37 #include "webkit/api/public/WebSize.h" | 38 #include "webkit/api/public/WebSize.h" |
38 #include "webkit/api/public/WebString.h" | 39 #include "webkit/api/public/WebString.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 filter->AddHostnameHandler("test-shell-resource", "inspector", | 125 filter->AddHostnameHandler("test-shell-resource", "inspector", |
125 &URLRequestTestShellFileJob::InspectorFactory); | 126 &URLRequestTestShellFileJob::InspectorFactory); |
126 url_util::AddStandardScheme("test-shell-resource"); | 127 url_util::AddStandardScheme("test-shell-resource"); |
127 } | 128 } |
128 | 129 |
129 TestShell::~TestShell() { | 130 TestShell::~TestShell() { |
130 delegate_->RevokeDragDrop(); | 131 delegate_->RevokeDragDrop(); |
131 | 132 |
132 // Navigate to an empty page to fire all the destruction logic for the | 133 // Navigate to an empty page to fire all the destruction logic for the |
133 // current page. | 134 // current page. |
134 LoadURL(L"about:blank"); | 135 LoadURL(GURL("about:blank")); |
135 | 136 |
136 // Call GC twice to clean up garbage. | 137 // Call GC twice to clean up garbage. |
137 CallJSGC(); | 138 CallJSGC(); |
138 CallJSGC(); | 139 CallJSGC(); |
139 | 140 |
140 // Destroy the WebView before the TestWebViewDelegate. | 141 // Destroy the WebView before the TestWebViewDelegate. |
141 m_webViewHost.reset(); | 142 m_webViewHost.reset(); |
142 | 143 |
143 PlatformCleanUp(); | 144 PlatformCleanUp(); |
144 | 145 |
145 StatsTable *table = StatsTable::current(); | 146 StatsTable *table = StatsTable::current(); |
146 if (dump_stats_table_on_exit_) { | 147 if (dump_stats_table_on_exit_) { |
147 // Dump the stats table. | 148 // Dump the stats table. |
148 printf("<stats>\n"); | 149 printf("<stats>\n"); |
149 if (table != NULL) { | 150 if (table != NULL) { |
150 int counter_max = table->GetMaxCounters(); | 151 int counter_max = table->GetMaxCounters(); |
151 for (int index=0; index < counter_max; index++) { | 152 for (int index=0; index < counter_max; index++) { |
152 std::string name(table->GetRowName(index)); | 153 std::string name(table->GetRowName(index)); |
153 if (name.length() > 0) { | 154 if (name.length() > 0) { |
154 int value = table->GetRowValue(index); | 155 int value = table->GetRowValue(index); |
155 printf("%s:\t%d\n", name.c_str(), value); | 156 printf("%s:\t%d\n", name.c_str(), value); |
156 } | 157 } |
157 } | 158 } |
158 } | 159 } |
159 printf("</stats>\n"); | 160 printf("</stats>\n"); |
160 } | 161 } |
161 } | 162 } |
162 | 163 |
163 bool TestShell::CreateNewWindow(const std::wstring& startingURL, | 164 bool TestShell::CreateNewWindow(const GURL& starting_url, |
164 TestShell** result) { | 165 TestShell** result) { |
165 TestShell* shell = new TestShell(); | 166 TestShell* shell = new TestShell(); |
166 bool rv = shell->Initialize(startingURL); | 167 bool rv = shell->Initialize(starting_url); |
167 if (rv) { | 168 if (rv) { |
168 if (result) | 169 if (result) |
169 *result = shell; | 170 *result = shell; |
170 TestShell::windowList()->push_back(shell->m_mainWnd); | 171 TestShell::windowList()->push_back(shell->m_mainWnd); |
171 } | 172 } |
172 return rv; | 173 return rv; |
173 } | 174 } |
174 | 175 |
175 void TestShell::ShutdownTestShell() { | 176 void TestShell::ShutdownTestShell() { |
176 PlatformShutdown(); | 177 PlatformShutdown(); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 webView()->GetMainFrame()->collectGarbage(); | 480 webView()->GetMainFrame()->collectGarbage(); |
480 } | 481 } |
481 | 482 |
482 WebView* TestShell::CreateWebView(WebView* webview) { | 483 WebView* TestShell::CreateWebView(WebView* webview) { |
483 // If we're running layout tests, only open a new window if the test has | 484 // If we're running layout tests, only open a new window if the test has |
484 // called layoutTestController.setCanOpenWindows() | 485 // called layoutTestController.setCanOpenWindows() |
485 if (layout_test_mode_ && !layout_test_controller_->CanOpenWindows()) | 486 if (layout_test_mode_ && !layout_test_controller_->CanOpenWindows()) |
486 return NULL; | 487 return NULL; |
487 | 488 |
488 TestShell* new_win; | 489 TestShell* new_win; |
489 if (!CreateNewWindow(std::wstring(), &new_win)) | 490 if (!CreateNewWindow(GURL(), &new_win)) |
490 return NULL; | 491 return NULL; |
491 | 492 |
492 return new_win->webView(); | 493 return new_win->webView(); |
493 } | 494 } |
494 | 495 |
| 496 bool TestShell::IsSVGTestURL(const GURL& url) { |
| 497 return url.is_valid() && url.spec().find("W3C-SVG-1.1") != std::string::npos; |
| 498 } |
| 499 |
495 void TestShell::SizeToSVG() { | 500 void TestShell::SizeToSVG() { |
496 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); | 501 SizeTo(kSVGTestWindowWidth, kSVGTestWindowHeight); |
497 } | 502 } |
498 | 503 |
499 void TestShell::SizeToDefault() { | 504 void TestShell::SizeToDefault() { |
500 SizeTo(kTestWindowWidth, kTestWindowHeight); | 505 SizeTo(kTestWindowWidth, kTestWindowHeight); |
501 } | 506 } |
502 | 507 |
503 void TestShell::ResetTestController() { | 508 void TestShell::ResetTestController() { |
504 layout_test_controller_->Reset(); | 509 layout_test_controller_->Reset(); |
505 event_sending_controller_->Reset(); | 510 event_sending_controller_->Reset(); |
506 delegate_->Reset(); | 511 delegate_->Reset(); |
507 } | 512 } |
508 | 513 |
509 void TestShell::LoadURL(const wchar_t* url) { | 514 void TestShell::LoadFile(const FilePath& file) { |
510 LoadURLForFrame(url, NULL); | 515 LoadURLForFrame(net::FilePathToFileURL(file), std::wstring()); |
| 516 } |
| 517 |
| 518 void TestShell::LoadURL(const GURL& url) { |
| 519 LoadURLForFrame(url, std::wstring()); |
511 } | 520 } |
512 | 521 |
513 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { | 522 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { |
514 // Get the right target frame for the entry. | 523 // Get the right target frame for the entry. |
515 WebFrame* frame = webView()->GetMainFrame(); | 524 WebFrame* frame = webView()->GetMainFrame(); |
516 if (!entry.GetTargetFrame().empty()) { | 525 if (!entry.GetTargetFrame().empty()) { |
517 frame = webView()->GetFrameWithName( | 526 frame = webView()->GetFrameWithName( |
518 WideToUTF16Hack(entry.GetTargetFrame())); | 527 WideToUTF16Hack(entry.GetTargetFrame())); |
519 } | 528 } |
520 // TODO(mpcomplete): should we clear the target frame, or should | 529 // TODO(mpcomplete): should we clear the target frame, or should |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 | 678 |
670 void CloseIdleConnections() { | 679 void CloseIdleConnections() { |
671 // Used in benchmarking, Ignored for test_shell. | 680 // Used in benchmarking, Ignored for test_shell. |
672 } | 681 } |
673 | 682 |
674 void SetCacheMode(bool enabled) { | 683 void SetCacheMode(bool enabled) { |
675 // Used in benchmarking, Ignored for test_shell. | 684 // Used in benchmarking, Ignored for test_shell. |
676 } | 685 } |
677 | 686 |
678 } // namespace webkit_glue | 687 } // namespace webkit_glue |
OLD | NEW |