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/extensions/api/idle/idle_api.h" | 5 #include "chrome/browser/extensions/api/idle/idle_api.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 idle::OnStateChanged::kEventName, extension_id_, GURL(), NULL); | 110 idle::OnStateChanged::kEventName, extension_id_, GURL(), NULL); |
111 idle_manager_->OnListenerAdded(details); | 111 idle_manager_->OnListenerAdded(details); |
112 } | 112 } |
113 | 113 |
114 ScopedListen::~ScopedListen() { | 114 ScopedListen::~ScopedListen() { |
115 const EventListenerInfo details( | 115 const EventListenerInfo details( |
116 idle::OnStateChanged::kEventName, extension_id_, GURL(), NULL); | 116 idle::OnStateChanged::kEventName, extension_id_, GURL(), NULL); |
117 idle_manager_->OnListenerRemoved(details); | 117 idle_manager_->OnListenerRemoved(details); |
118 } | 118 } |
119 | 119 |
120 KeyedService* IdleManagerTestFactory(content::BrowserContext* profile) { | 120 KeyedService* IdleManagerTestFactory(content::BrowserContext* context) { |
121 return new IdleManager(static_cast<Profile*>(profile)); | 121 return new IdleManager(context); |
122 } | 122 } |
123 | 123 |
124 } // namespace | 124 } // namespace |
125 | 125 |
| 126 // TODO(derat): Make this instead derive from extensions::ApiUnitTest after |
| 127 // moving it out of the unit_tests target. Its base class can't be changed |
| 128 // before then since doing so results in crashes due to multiple |
| 129 // content::NotificationService instances being created. |
126 class IdleTest : public ExtensionApiUnittest { | 130 class IdleTest : public ExtensionApiUnittest { |
127 public: | 131 public: |
128 void SetUp() override; | 132 void SetUp() override; |
129 | 133 |
130 protected: | 134 protected: |
131 IdleManager* idle_manager_; | 135 IdleManager* idle_manager_; |
132 TestIdleProvider* idle_provider_; | 136 TestIdleProvider* idle_provider_; |
133 testing::StrictMock<MockEventDelegate>* event_delegate_; | 137 testing::StrictMock<MockEventDelegate>* event_delegate_; |
134 }; | 138 }; |
135 | 139 |
136 void IdleTest::SetUp() { | 140 void IdleTest::SetUp() { |
137 ExtensionApiUnittest::SetUp(); | 141 ExtensionApiUnittest::SetUp(); |
138 | 142 |
139 IdleManagerFactory::GetInstance()->SetTestingFactory(browser()->profile(), | 143 IdleManagerFactory::GetInstance()->SetTestingFactory(browser()->profile(), |
140 &IdleManagerTestFactory); | 144 &IdleManagerTestFactory); |
141 idle_manager_ = IdleManagerFactory::GetForProfile(browser()->profile()); | 145 idle_manager_ = IdleManagerFactory::GetForBrowserContext( |
| 146 browser()->profile()); |
142 | 147 |
143 idle_provider_ = new TestIdleProvider(); | 148 idle_provider_ = new TestIdleProvider(); |
144 idle_manager_->SetIdleTimeProviderForTest( | 149 idle_manager_->SetIdleTimeProviderForTest( |
145 scoped_ptr<IdleManager::IdleTimeProvider>(idle_provider_).Pass()); | 150 scoped_ptr<IdleManager::IdleTimeProvider>(idle_provider_).Pass()); |
146 event_delegate_ = new testing::StrictMock<MockEventDelegate>(); | 151 event_delegate_ = new testing::StrictMock<MockEventDelegate>(); |
147 idle_manager_->SetEventDelegateForTest( | 152 idle_manager_->SetEventDelegateForTest( |
148 scoped_ptr<IdleManager::EventDelegate>(event_delegate_).Pass()); | 153 scoped_ptr<IdleManager::EventDelegate>(event_delegate_).Pass()); |
149 idle_manager_->Init(); | 154 idle_manager_->Init(); |
150 } | 155 } |
151 | 156 |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 564 |
560 { | 565 { |
561 // Nothing should have fired, the listener wasn't added until afterward. | 566 // Nothing should have fired, the listener wasn't added until afterward. |
562 ScopedListen listen(idle_manager_, "test"); | 567 ScopedListen listen(idle_manager_, "test"); |
563 idle_manager_->UpdateIdleState(); | 568 idle_manager_->UpdateIdleState(); |
564 testing::Mock::VerifyAndClearExpectations(event_delegate_); | 569 testing::Mock::VerifyAndClearExpectations(event_delegate_); |
565 } | 570 } |
566 } | 571 } |
567 | 572 |
568 } // namespace extensions | 573 } // namespace extensions |
OLD | NEW |