| 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/browser/ui/panels/test_panel_active_state_observer.h" | 5 #include "chrome/browser/ui/panels/test_panel_notification_observer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/panels/panel.h" | |
| 8 #include "chrome/common/chrome_notification_types.h" | 7 #include "chrome/common/chrome_notification_types.h" |
| 9 #include "content/public/browser/notification_source.h" | 8 #include "content/public/browser/notification_source.h" |
| 10 #include "content/public/test/test_utils.h" | 9 #include "content/public/test/test_utils.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 11 |
| 13 PanelActiveStateObserver::PanelActiveStateObserver( | 12 TestPanelNotificationObserver::TestPanelNotificationObserver( |
| 14 Panel* panel, | 13 int notification, |
| 15 bool expect_active) | 14 const content::NotificationSource& source) |
| 16 : panel_(panel), | 15 : seen_(false), |
| 17 expect_active_(expect_active), | |
| 18 seen_(false), | |
| 19 running_(false) { | 16 running_(false) { |
| 20 registrar_.Add(this, chrome::NOTIFICATION_PANEL_CHANGED_ACTIVE_STATUS, | 17 registrar_.Add(this, notification, source); |
| 21 content::Source<Panel>(panel)); | |
| 22 } | 18 } |
| 23 | 19 |
| 24 PanelActiveStateObserver::~PanelActiveStateObserver() {} | 20 TestPanelNotificationObserver::~TestPanelNotificationObserver() {} |
| 25 | 21 |
| 26 void PanelActiveStateObserver::Wait() { | 22 void TestPanelNotificationObserver::Wait() { |
| 27 if (seen_ || AtExpectedState()) | 23 if (seen_ || AtExpectedState()) |
| 28 return; | 24 return; |
| 29 | 25 |
| 30 running_ = true; | 26 running_ = true; |
| 31 message_loop_runner_ = new content::MessageLoopRunner; | 27 message_loop_runner_ = new content::MessageLoopRunner; |
| 32 message_loop_runner_->Run(); | 28 message_loop_runner_->Run(); |
| 33 EXPECT_TRUE(seen_); | 29 EXPECT_TRUE(seen_); |
| 34 } | 30 } |
| 35 | 31 |
| 36 bool PanelActiveStateObserver::AtExpectedState() { | 32 void TestPanelNotificationObserver::Observe( |
| 37 return panel_->IsActive() == expect_active_; | |
| 38 } | |
| 39 | |
| 40 void PanelActiveStateObserver::Observe( | |
| 41 int type, | 33 int type, |
| 42 const content::NotificationSource& source, | 34 const content::NotificationSource& source, |
| 43 const content::NotificationDetails& details) { | 35 const content::NotificationDetails& details) { |
| 44 if (!running_) | 36 if (!running_) |
| 45 return; | 37 return; |
| 46 | 38 |
| 47 if (AtExpectedState()) { | 39 if (AtExpectedState()) { |
| 48 seen_ = true; | 40 seen_ = true; |
| 49 message_loop_runner_->Quit(); | 41 message_loop_runner_->Quit(); |
| 50 running_ = false; | 42 running_ = false; |
| 51 } | 43 } |
| 52 } | 44 } |
| OLD | NEW |