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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chrome/browser/chrome_notification_types.h" | |
12 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 13 #include "chrome/browser/extensions/extension_test_message_listener.h" |
15 #include "chrome/browser/extensions/external_policy_loader.h" | 14 #include "chrome/browser/extensions/external_policy_loader.h" |
16 #include "chrome/browser/extensions/updater/extension_downloader.h" | 15 #include "chrome/browser/extensions/updater/extension_downloader.h" |
17 #include "chrome/browser/extensions/updater/extension_updater.h" | 16 #include "chrome/browser/extensions/updater/extension_updater.h" |
18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
21 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
26 #include "content/test/net/url_request_prepackaged_interceptor.h" | 25 #include "content/test/net/url_request_prepackaged_interceptor.h" |
27 #include "extensions/browser/extension_host.h" | 26 #include "extensions/browser/extension_host.h" |
28 #include "extensions/browser/extension_prefs.h" | 27 #include "extensions/browser/extension_prefs.h" |
29 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
30 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
| 30 #include "extensions/browser/notification_types.h" |
31 #include "extensions/browser/pref_names.h" | 31 #include "extensions/browser/pref_names.h" |
32 #include "net/url_request/url_fetcher.h" | 32 #include "net/url_request/url_fetcher.h" |
33 | 33 |
34 using extensions::Extension; | 34 using extensions::Extension; |
35 using extensions::ExtensionRegistry; | 35 using extensions::ExtensionRegistry; |
36 using extensions::Manifest; | 36 using extensions::Manifest; |
37 | 37 |
38 class ExtensionManagementTest : public ExtensionBrowserTest { | 38 class ExtensionManagementTest : public ExtensionBrowserTest { |
39 protected: | 39 protected: |
40 // Helper method that returns whether the extension is at the given version. | 40 // Helper method that returns whether the extension is at the given version. |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 EnableExtension(extension_id); | 167 EnableExtension(extension_id); |
168 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); | 168 EXPECT_EQ(size_before + 1, registry->enabled_extensions().size()); |
169 EXPECT_EQ(0u, registry->disabled_extensions().size()); | 169 EXPECT_EQ(0u, registry->disabled_extensions().size()); |
170 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension_id)); | 170 EXPECT_TRUE(manager->GetBackgroundHostForExtension(extension_id)); |
171 } | 171 } |
172 | 172 |
173 // Used for testing notifications sent during extension updates. | 173 // Used for testing notifications sent during extension updates. |
174 class NotificationListener : public content::NotificationObserver { | 174 class NotificationListener : public content::NotificationObserver { |
175 public: | 175 public: |
176 NotificationListener() : started_(false), finished_(false) { | 176 NotificationListener() : started_(false), finished_(false) { |
177 int types[] = { | 177 int types[] = {extensions::NOTIFICATION_EXTENSION_UPDATING_STARTED, |
178 chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED, | 178 extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND}; |
179 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND | |
180 }; | |
181 for (size_t i = 0; i < arraysize(types); i++) { | 179 for (size_t i = 0; i < arraysize(types); i++) { |
182 registrar_.Add( | 180 registrar_.Add( |
183 this, types[i], content::NotificationService::AllSources()); | 181 this, types[i], content::NotificationService::AllSources()); |
184 } | 182 } |
185 } | 183 } |
186 virtual ~NotificationListener() {} | 184 virtual ~NotificationListener() {} |
187 | 185 |
188 bool started() { return started_; } | 186 bool started() { return started_; } |
189 | 187 |
190 bool finished() { return finished_; } | 188 bool finished() { return finished_; } |
191 | 189 |
192 const std::set<std::string>& updates() { return updates_; } | 190 const std::set<std::string>& updates() { return updates_; } |
193 | 191 |
194 void Reset() { | 192 void Reset() { |
195 started_ = false; | 193 started_ = false; |
196 finished_ = false; | 194 finished_ = false; |
197 updates_.clear(); | 195 updates_.clear(); |
198 } | 196 } |
199 | 197 |
200 // Implements content::NotificationObserver interface. | 198 // Implements content::NotificationObserver interface. |
201 virtual void Observe(int type, | 199 virtual void Observe(int type, |
202 const content::NotificationSource& source, | 200 const content::NotificationSource& source, |
203 const content::NotificationDetails& details) OVERRIDE { | 201 const content::NotificationDetails& details) OVERRIDE { |
204 switch (type) { | 202 switch (type) { |
205 case chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED: { | 203 case extensions::NOTIFICATION_EXTENSION_UPDATING_STARTED: { |
206 EXPECT_FALSE(started_); | 204 EXPECT_FALSE(started_); |
207 started_ = true; | 205 started_ = true; |
208 break; | 206 break; |
209 } | 207 } |
210 case chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND: { | 208 case extensions::NOTIFICATION_EXTENSION_UPDATE_FOUND: { |
211 const std::string& id = | 209 const std::string& id = |
212 content::Details<extensions::UpdateDetails>(details)->id; | 210 content::Details<extensions::UpdateDetails>(details)->id; |
213 updates_.insert(id); | 211 updates_.insert(id); |
214 break; | 212 break; |
215 } | 213 } |
216 default: | 214 default: |
217 NOTREACHED(); | 215 NOTREACHED(); |
218 } | 216 } |
219 } | 217 } |
220 | 218 |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 644 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
647 } | 645 } |
648 ASSERT_TRUE(WaitForExtensionInstall()); | 646 ASSERT_TRUE(WaitForExtensionInstall()); |
649 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); | 647 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
650 extension = service->GetExtensionById(kExtensionId, false); | 648 extension = service->GetExtensionById(kExtensionId, false); |
651 ASSERT_TRUE(extension); | 649 ASSERT_TRUE(extension); |
652 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 650 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
653 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 651 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
654 EXPECT_TRUE(registry->disabled_extensions().is_empty()); | 652 EXPECT_TRUE(registry->disabled_extensions().is_empty()); |
655 } | 653 } |
OLD | NEW |