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 #include "chrome/test/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 scoped_refptr<content::MessageLoopRunner> runner = | 533 scoped_refptr<content::MessageLoopRunner> runner = |
534 new content::MessageLoopRunner; | 534 new content::MessageLoopRunner; |
535 WaitHistoryLoadedObserver observer(runner.get()); | 535 WaitHistoryLoadedObserver observer(runner.get()); |
536 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> | 536 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> |
537 scoped_observer(&observer); | 537 scoped_observer(&observer); |
538 scoped_observer.Add(history_service); | 538 scoped_observer.Add(history_service); |
539 runner->Run(); | 539 runner->Run(); |
540 } | 540 } |
541 } | 541 } |
542 | 542 |
| 543 BrowserActivationWaiter::BrowserActivationWaiter(Browser* browser) |
| 544 : browser_(browser), observed_(false) { |
| 545 if (chrome::FindLastActive() == browser_) { |
| 546 observed_ = true; |
| 547 return; |
| 548 } |
| 549 BrowserList::AddObserver(this); |
| 550 } |
| 551 |
| 552 BrowserActivationWaiter::~BrowserActivationWaiter() {} |
| 553 |
| 554 void BrowserActivationWaiter::WaitForActivation() { |
| 555 if (observed_) |
| 556 return; |
| 557 message_loop_runner_ = new content::MessageLoopRunner; |
| 558 message_loop_runner_->Run(); |
| 559 } |
| 560 |
| 561 void BrowserActivationWaiter::OnBrowserSetLastActive(Browser* browser) { |
| 562 if (browser != browser_) |
| 563 return; |
| 564 |
| 565 observed_ = true; |
| 566 BrowserList::RemoveObserver(this); |
| 567 if (message_loop_runner_.get() && message_loop_runner_->loop_running()) |
| 568 message_loop_runner_->Quit(); |
| 569 } |
| 570 |
543 } // namespace ui_test_utils | 571 } // namespace ui_test_utils |
OLD | NEW |