| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const int kSVGTestWindowWidth = 480; | 81 const int kSVGTestWindowWidth = 480; |
| 82 const int kSVGTestWindowHeight = 360; | 82 const int kSVGTestWindowHeight = 360; |
| 83 | 83 |
| 84 // URLRequestTestShellFileJob is used to serve the inspector | 84 // URLRequestTestShellFileJob is used to serve the inspector |
| 85 class URLRequestTestShellFileJob : public net::URLRequestFileJob { | 85 class URLRequestTestShellFileJob : public net::URLRequestFileJob { |
| 86 public: | 86 public: |
| 87 static net::URLRequestJob* InspectorFactory( | 87 static net::URLRequestJob* InspectorFactory( |
| 88 net::URLRequest* request, | 88 net::URLRequest* request, |
| 89 net::NetworkDelegate* network_delegate, | 89 net::NetworkDelegate* network_delegate, |
| 90 const std::string& scheme) { | 90 const std::string& scheme) { |
| 91 FilePath path; | 91 base::FilePath path; |
| 92 PathService::Get(base::DIR_EXE, &path); | 92 PathService::Get(base::DIR_EXE, &path); |
| 93 path = path.AppendASCII("resources"); | 93 path = path.AppendASCII("resources"); |
| 94 path = path.AppendASCII("inspector"); | 94 path = path.AppendASCII("inspector"); |
| 95 path = path.AppendASCII(request->url().path().substr(1)); | 95 path = path.AppendASCII(request->url().path().substr(1)); |
| 96 return new URLRequestTestShellFileJob(request, network_delegate, path); | 96 return new URLRequestTestShellFileJob(request, network_delegate, path); |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 URLRequestTestShellFileJob(net::URLRequest* request, | 100 URLRequestTestShellFileJob(net::URLRequest* request, |
| 101 net::NetworkDelegate* network_delegate, | 101 net::NetworkDelegate* network_delegate, |
| 102 const FilePath& path) | 102 const base::FilePath& path) |
| 103 : net::URLRequestFileJob(request, network_delegate, path) { | 103 : net::URLRequestFileJob(request, network_delegate, path) { |
| 104 } | 104 } |
| 105 virtual ~URLRequestTestShellFileJob() { } | 105 virtual ~URLRequestTestShellFileJob() { } |
| 106 | 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(URLRequestTestShellFileJob); | 107 DISALLOW_COPY_AND_ASSIGN(URLRequestTestShellFileJob); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 | 110 |
| 111 } // namespace | 111 } // namespace |
| 112 | 112 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 #endif | 256 #endif |
| 257 | 257 |
| 258 // Only log to a file if we're running layout tests. This prevents debugging | 258 // Only log to a file if we're running layout tests. This prevents debugging |
| 259 // output from disrupting whether or not we pass. | 259 // output from disrupting whether or not we pass. |
| 260 logging::LoggingDestination destination = | 260 logging::LoggingDestination destination = |
| 261 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG; | 261 logging::LOG_TO_BOTH_FILE_AND_SYSTEM_DEBUG_LOG; |
| 262 if (layout_test_mode) | 262 if (layout_test_mode) |
| 263 destination = logging::LOG_ONLY_TO_FILE; | 263 destination = logging::LOG_ONLY_TO_FILE; |
| 264 | 264 |
| 265 // We might have multiple test_shell processes going at once | 265 // We might have multiple test_shell processes going at once |
| 266 FilePath log_filename; | 266 base::FilePath log_filename; |
| 267 PathService::Get(base::DIR_EXE, &log_filename); | 267 PathService::Get(base::DIR_EXE, &log_filename); |
| 268 log_filename = log_filename.AppendASCII("test_shell.log"); | 268 log_filename = log_filename.AppendASCII("test_shell.log"); |
| 269 logging::InitLogging( | 269 logging::InitLogging( |
| 270 log_filename.value().c_str(), | 270 log_filename.value().c_str(), |
| 271 destination, | 271 destination, |
| 272 logging::LOCK_LOG_FILE, | 272 logging::LOCK_LOG_FILE, |
| 273 logging::DELETE_OLD_LOG_FILE, | 273 logging::DELETE_OLD_LOG_FILE, |
| 274 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | 274 logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
| 275 | 275 |
| 276 // we want process and thread IDs because we may have multiple processes | 276 // we want process and thread IDs because we may have multiple processes |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 452 |
| 453 TestShell* new_win; | 453 TestShell* new_win; |
| 454 if (!CreateNewWindow(GURL(), &new_win)) | 454 if (!CreateNewWindow(GURL(), &new_win)) |
| 455 return NULL; | 455 return NULL; |
| 456 | 456 |
| 457 return new_win->webView(); | 457 return new_win->webView(); |
| 458 } | 458 } |
| 459 | 459 |
| 460 void TestShell::ShowDevTools() { | 460 void TestShell::ShowDevTools() { |
| 461 if (!devtools_shell_) { | 461 if (!devtools_shell_) { |
| 462 FilePath dir_exe; | 462 base::FilePath dir_exe; |
| 463 PathService::Get(base::DIR_EXE, &dir_exe); | 463 PathService::Get(base::DIR_EXE, &dir_exe); |
| 464 FilePath devtools_path = | 464 base::FilePath devtools_path = |
| 465 dir_exe.AppendASCII("resources/inspector/devtools.html"); | 465 dir_exe.AppendASCII("resources/inspector/devtools.html"); |
| 466 TestShell* devtools_shell; | 466 TestShell* devtools_shell; |
| 467 TestShell::CreateNewWindow(GURL(devtools_path.value()), | 467 TestShell::CreateNewWindow(GURL(devtools_path.value()), |
| 468 &devtools_shell); | 468 &devtools_shell); |
| 469 devtools_shell_ = devtools_shell->AsWeakPtr(); | 469 devtools_shell_ = devtools_shell->AsWeakPtr(); |
| 470 devtools_shell_->CreateDevToolsClient(dev_tools_agent_.get()); | 470 devtools_shell_->CreateDevToolsClient(dev_tools_agent_.get()); |
| 471 } | 471 } |
| 472 DCHECK(devtools_shell_); | 472 DCHECK(devtools_shell_); |
| 473 devtools_shell_->Show(WebKit::WebNavigationPolicyNewWindow); | 473 devtools_shell_->Show(WebKit::WebNavigationPolicyNewWindow); |
| 474 } | 474 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 495 SizeTo(kTestWindowWidth, kTestWindowHeight); | 495 SizeTo(kTestWindowWidth, kTestWindowHeight); |
| 496 } | 496 } |
| 497 | 497 |
| 498 void TestShell::ResetTestController() { | 498 void TestShell::ResetTestController() { |
| 499 notification_presenter_->Reset(); | 499 notification_presenter_->Reset(); |
| 500 delegate_->Reset(); | 500 delegate_->Reset(); |
| 501 if (geolocation_client_mock_.get()) | 501 if (geolocation_client_mock_.get()) |
| 502 geolocation_client_mock_->resetMock(); | 502 geolocation_client_mock_->resetMock(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void TestShell::LoadFile(const FilePath& file) { | 505 void TestShell::LoadFile(const base::FilePath& file) { |
| 506 LoadURLForFrame(net::FilePathToFileURL(file), string16()); | 506 LoadURLForFrame(net::FilePathToFileURL(file), string16()); |
| 507 } | 507 } |
| 508 | 508 |
| 509 void TestShell::LoadURL(const GURL& url) { | 509 void TestShell::LoadURL(const GURL& url) { |
| 510 LoadURLForFrame(url, string16()); | 510 LoadURLForFrame(url, string16()); |
| 511 } | 511 } |
| 512 | 512 |
| 513 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { | 513 bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { |
| 514 // Get the right target frame for the entry. | 514 // Get the right target frame for the entry. |
| 515 WebFrame* frame = webView()->mainFrame(); | 515 WebFrame* frame = webView()->mainFrame(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 SetFocus(webViewHost(), true); | 552 SetFocus(webViewHost(), true); |
| 553 | 553 |
| 554 return true; | 554 return true; |
| 555 } | 555 } |
| 556 | 556 |
| 557 void TestShell::GoBackOrForward(int offset) { | 557 void TestShell::GoBackOrForward(int offset) { |
| 558 navigation_controller_->GoToOffset(offset); | 558 navigation_controller_->GoToOffset(offset); |
| 559 } | 559 } |
| 560 | 560 |
| 561 void TestShell::DumpDocumentText() { | 561 void TestShell::DumpDocumentText() { |
| 562 FilePath file_path; | 562 base::FilePath file_path; |
| 563 if (!PromptForSaveFile(L"Dump document text", &file_path)) | 563 if (!PromptForSaveFile(L"Dump document text", &file_path)) |
| 564 return; | 564 return; |
| 565 | 565 |
| 566 const std::string data = | 566 const std::string data = |
| 567 UTF16ToUTF8(webkit_glue::DumpDocumentText(webView()->mainFrame())); | 567 UTF16ToUTF8(webkit_glue::DumpDocumentText(webView()->mainFrame())); |
| 568 file_util::WriteFile(file_path, data.c_str(), data.length()); | 568 file_util::WriteFile(file_path, data.c_str(), data.length()); |
| 569 } | 569 } |
| 570 | 570 |
| 571 void TestShell::DumpRenderTree() { | 571 void TestShell::DumpRenderTree() { |
| 572 FilePath file_path; | 572 base::FilePath file_path; |
| 573 if (!PromptForSaveFile(L"Dump render tree", &file_path)) | 573 if (!PromptForSaveFile(L"Dump render tree", &file_path)) |
| 574 return; | 574 return; |
| 575 | 575 |
| 576 const std::string data = | 576 const std::string data = |
| 577 UTF16ToUTF8(webkit_glue::DumpRenderer(webView()->mainFrame())); | 577 UTF16ToUTF8(webkit_glue::DumpRenderer(webView()->mainFrame())); |
| 578 file_util::WriteFile(file_path, data.c_str(), data.length()); | 578 file_util::WriteFile(file_path, data.c_str(), data.length()); |
| 579 } | 579 } |
| 580 | 580 |
| 581 string16 TestShell::GetDocumentText() { | 581 string16 TestShell::GetDocumentText() { |
| 582 return webkit_glue::DumpDocumentText(webView()->mainFrame()); | 582 return webkit_glue::DumpDocumentText(webView()->mainFrame()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 return device_orientation_client_mock_.get(); | 619 return device_orientation_client_mock_.get(); |
| 620 } | 620 } |
| 621 | 621 |
| 622 WebKit::WebGeolocationClientMock* TestShell::geolocation_client_mock() { | 622 WebKit::WebGeolocationClientMock* TestShell::geolocation_client_mock() { |
| 623 if (!geolocation_client_mock_.get()) { | 623 if (!geolocation_client_mock_.get()) { |
| 624 geolocation_client_mock_.reset( | 624 geolocation_client_mock_.reset( |
| 625 WebKit::WebGeolocationClientMock::create()); | 625 WebKit::WebGeolocationClientMock::create()); |
| 626 } | 626 } |
| 627 return geolocation_client_mock_.get(); | 627 return geolocation_client_mock_.get(); |
| 628 } | 628 } |
| OLD | NEW |