| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/test/ui_test_utils.h" | 5 #include "chrome/test/ui_test_utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 ListValue* list = static_cast<ListValue*>(root_val.get()); | 334 ListValue* list = static_cast<ListValue*>(root_val.get()); |
| 335 Value* result_val; | 335 Value* result_val; |
| 336 if (!list || !list->GetSize() || | 336 if (!list || !list->GetSize() || |
| 337 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. | 337 !list->Remove(0, &result_val)) // Remove gives us ownership of the value. |
| 338 return false; | 338 return false; |
| 339 | 339 |
| 340 result->reset(result_val); | 340 result->reset(result_val); |
| 341 return true; | 341 return true; |
| 342 } | 342 } |
| 343 | 343 |
| 344 void Checkpoint(const char* message, const base::TimeTicks& start_time) { | |
| 345 LOG(INFO) << message << " : " | |
| 346 << (base::TimeTicks::Now() - start_time).InMilliseconds() | |
| 347 << " ms" << std::flush; | |
| 348 } | |
| 349 | |
| 350 } // namespace | 344 } // namespace |
| 351 | 345 |
| 352 void RunMessageLoop() { | 346 void RunMessageLoop() { |
| 353 MessageLoopForUI* loop = MessageLoopForUI::current(); | 347 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 354 bool did_allow_task_nesting = loop->NestableTasksAllowed(); | 348 bool did_allow_task_nesting = loop->NestableTasksAllowed(); |
| 355 loop->SetNestableTasksAllowed(true); | 349 loop->SetNestableTasksAllowed(true); |
| 356 #if defined(TOOLKIT_VIEWS) | 350 #if defined(TOOLKIT_VIEWS) |
| 357 views::AcceleratorHandler handler; | 351 views::AcceleratorHandler handler; |
| 358 loop->Run(&handler); | 352 loop->Run(&handler); |
| 359 #elif defined(OS_LINUX) | 353 #elif defined(OS_LINUX) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 return true; | 599 return true; |
| 606 } | 600 } |
| 607 | 601 |
| 608 bool SendKeyPressSync(const Browser* browser, | 602 bool SendKeyPressSync(const Browser* browser, |
| 609 app::KeyboardCode key, | 603 app::KeyboardCode key, |
| 610 bool control, | 604 bool control, |
| 611 bool shift, | 605 bool shift, |
| 612 bool alt, | 606 bool alt, |
| 613 bool command) { | 607 bool command) { |
| 614 base::TimeTicks start_time = base::TimeTicks::Now(); | 608 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 615 Checkpoint("SendKeyPressSync", start_time); | |
| 616 | 609 |
| 617 gfx::NativeWindow window = NULL; | 610 gfx::NativeWindow window = NULL; |
| 618 if (!GetNativeWindow(browser, &window)) | 611 if (!GetNativeWindow(browser, &window)) |
| 619 return false; | 612 return false; |
| 620 | 613 |
| 621 Checkpoint("SendKeyPressNotifyWhenDone", start_time); | |
| 622 if (!ui_controls::SendKeyPressNotifyWhenDone( | 614 if (!ui_controls::SendKeyPressNotifyWhenDone( |
| 623 window, key, control, shift, alt, command, | 615 window, key, control, shift, alt, command, |
| 624 new MessageLoop::QuitTask())) { | 616 new MessageLoop::QuitTask())) { |
| 625 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; | 617 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; |
| 626 return false; | 618 return false; |
| 627 } | 619 } |
| 628 // Run the message loop. It'll stop running when either the key was received | 620 // Run the message loop. It'll stop running when either the key was received |
| 629 // or the test timed out (in which case testing::Test::HasFatalFailure should | 621 // or the test timed out (in which case testing::Test::HasFatalFailure should |
| 630 // be set). | 622 // be set). |
| 631 Checkpoint("Running loop", start_time); | |
| 632 RunMessageLoop(); | 623 RunMessageLoop(); |
| 633 Checkpoint("Check if HasFatalFailure", start_time); | |
| 634 return !testing::Test::HasFatalFailure(); | 624 return !testing::Test::HasFatalFailure(); |
| 635 } | 625 } |
| 636 | 626 |
| 637 bool SendKeyPressAndWait(const Browser* browser, | 627 bool SendKeyPressAndWait(const Browser* browser, |
| 638 app::KeyboardCode key, | 628 app::KeyboardCode key, |
| 639 bool control, | 629 bool control, |
| 640 bool shift, | 630 bool shift, |
| 641 bool alt, | 631 bool alt, |
| 642 bool command, | 632 bool command, |
| 643 NotificationType type, | 633 NotificationType type, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 if (waiting_for_ == source) { | 796 if (waiting_for_ == source) { |
| 807 seen_ = true; | 797 seen_ = true; |
| 808 if (running_) | 798 if (running_) |
| 809 MessageLoopForUI::current()->Quit(); | 799 MessageLoopForUI::current()->Quit(); |
| 810 } else { | 800 } else { |
| 811 sources_seen_.insert(source.map_key()); | 801 sources_seen_.insert(source.map_key()); |
| 812 } | 802 } |
| 813 } | 803 } |
| 814 | 804 |
| 815 } // namespace ui_test_utils | 805 } // namespace ui_test_utils |
| OLD | NEW |