| 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 |
| 344 } // namespace | 350 } // namespace |
| 345 | 351 |
| 346 void RunMessageLoop() { | 352 void RunMessageLoop() { |
| 347 MessageLoopForUI* loop = MessageLoopForUI::current(); | 353 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 348 bool did_allow_task_nesting = loop->NestableTasksAllowed(); | 354 bool did_allow_task_nesting = loop->NestableTasksAllowed(); |
| 349 loop->SetNestableTasksAllowed(true); | 355 loop->SetNestableTasksAllowed(true); |
| 350 #if defined(TOOLKIT_VIEWS) | 356 #if defined(TOOLKIT_VIEWS) |
| 351 views::AcceleratorHandler handler; | 357 views::AcceleratorHandler handler; |
| 352 loop->Run(&handler); | 358 loop->Run(&handler); |
| 353 #elif defined(OS_LINUX) | 359 #elif defined(OS_LINUX) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 return true; | 605 return true; |
| 600 } | 606 } |
| 601 | 607 |
| 602 bool SendKeyPressSync(const Browser* browser, | 608 bool SendKeyPressSync(const Browser* browser, |
| 603 app::KeyboardCode key, | 609 app::KeyboardCode key, |
| 604 bool control, | 610 bool control, |
| 605 bool shift, | 611 bool shift, |
| 606 bool alt, | 612 bool alt, |
| 607 bool command) { | 613 bool command) { |
| 608 base::TimeTicks start_time = base::TimeTicks::Now(); | 614 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 615 Checkpoint("SendKeyPressSync", start_time); |
| 609 | 616 |
| 610 gfx::NativeWindow window = NULL; | 617 gfx::NativeWindow window = NULL; |
| 611 if (!GetNativeWindow(browser, &window)) | 618 if (!GetNativeWindow(browser, &window)) |
| 612 return false; | 619 return false; |
| 613 | 620 |
| 621 Checkpoint("SendKeyPressNotifyWhenDone", start_time); |
| 614 if (!ui_controls::SendKeyPressNotifyWhenDone( | 622 if (!ui_controls::SendKeyPressNotifyWhenDone( |
| 615 window, key, control, shift, alt, command, | 623 window, key, control, shift, alt, command, |
| 616 new MessageLoop::QuitTask())) { | 624 new MessageLoop::QuitTask())) { |
| 617 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; | 625 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; |
| 618 return false; | 626 return false; |
| 619 } | 627 } |
| 620 // Run the message loop. It'll stop running when either the key was received | 628 // Run the message loop. It'll stop running when either the key was received |
| 621 // or the test timed out (in which case testing::Test::HasFatalFailure should | 629 // or the test timed out (in which case testing::Test::HasFatalFailure should |
| 622 // be set). | 630 // be set). |
| 631 Checkpoint("Running loop", start_time); |
| 623 RunMessageLoop(); | 632 RunMessageLoop(); |
| 633 Checkpoint("Check if HasFatalFailure", start_time); |
| 624 return !testing::Test::HasFatalFailure(); | 634 return !testing::Test::HasFatalFailure(); |
| 625 } | 635 } |
| 626 | 636 |
| 627 bool SendKeyPressAndWait(const Browser* browser, | 637 bool SendKeyPressAndWait(const Browser* browser, |
| 628 app::KeyboardCode key, | 638 app::KeyboardCode key, |
| 629 bool control, | 639 bool control, |
| 630 bool shift, | 640 bool shift, |
| 631 bool alt, | 641 bool alt, |
| 632 bool command, | 642 bool command, |
| 633 NotificationType type, | 643 NotificationType type, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 if (waiting_for_ == source) { | 806 if (waiting_for_ == source) { |
| 797 seen_ = true; | 807 seen_ = true; |
| 798 if (running_) | 808 if (running_) |
| 799 MessageLoopForUI::current()->Quit(); | 809 MessageLoopForUI::current()->Quit(); |
| 800 } else { | 810 } else { |
| 801 sources_seen_.insert(source.map_key()); | 811 sources_seen_.insert(source.map_key()); |
| 802 } | 812 } |
| 803 } | 813 } |
| 804 | 814 |
| 805 } // namespace ui_test_utils | 815 } // namespace ui_test_utils |
| OLD | NEW |