Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: chrome/browser/extensions/component_loader_unittest.cc

Issue 8733004: Make ExtensionService use ExtensionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: + Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "chrome/browser/extensions/component_loader.h" 7 #include "chrome/browser/extensions/component_loader.h"
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "chrome/browser/extensions/test_extension_service.h" 11 #include "chrome/browser/extensions/test_extension_service.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/extensions/extension_set.h"
14 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/testing_pref_service.h" 16 #include "chrome/test/base/testing_pref_service.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace { 19 namespace {
19 20
20 class MockExtensionService : public TestExtensionService { 21 class MockExtensionService : public TestExtensionService {
21 private: 22 private:
22 bool ready_; 23 bool ready_;
23 ExtensionList extension_list_; 24 ExtensionSet extension_set_;
24 25
25 public: 26 public:
26 MockExtensionService() : ready_(false) { 27 MockExtensionService() : ready_(false) {
27 } 28 }
28 29
29 virtual void AddExtension(const Extension* extension) OVERRIDE { 30 virtual void AddExtension(const Extension* extension) OVERRIDE {
30 // ExtensionService must become the owner of the extension object. 31 // ExtensionService must become the owner of the extension object.
31 extension_list_.push_back(extension); 32 extension_set_.Insert(extension);
32 } 33 }
33 34
34 virtual void UnloadExtension( 35 virtual void UnloadExtension(
35 const std::string& extension_id, 36 const std::string& extension_id,
36 extension_misc::UnloadedExtensionReason reason) OVERRIDE { 37 extension_misc::UnloadedExtensionReason reason) OVERRIDE {
37 // Remove the extension with the matching id. 38 // Remove the extension with the matching id.
38 for (ExtensionList::iterator it = extension_list_.begin(); 39 extension_set_.Remove(extension_id);
39 it != extension_list_.end();
40 ++it) {
41 if ((*it)->id() == extension_id) {
42 extension_list_.erase(it);
43 return;
44 }
45 }
46 } 40 }
47 41
48 virtual bool is_ready() OVERRIDE { 42 virtual bool is_ready() OVERRIDE {
49 return ready_; 43 return ready_;
50 } 44 }
51 45
52 virtual const ExtensionList* extensions() const OVERRIDE { 46 virtual const ExtensionSet* extensions() const OVERRIDE {
53 return &extension_list_; 47 return &extension_set_;
54 } 48 }
55 49
56 void set_ready(bool ready) { 50 void set_ready(bool ready) {
57 ready_ = ready; 51 ready_ = ready;
58 } 52 }
59 53
60 void clear_extension_list() { 54 void clear_extensions() {
61 extension_list_.clear(); 55 extension_set_.Clear();
62 } 56 }
63 }; 57 };
64 58
65 } // namespace 59 } // namespace
66 60
67 namespace extensions { 61 namespace extensions {
68 62
69 class ComponentLoaderTest : public testing::Test { 63 class ComponentLoaderTest : public testing::Test {
70 public: 64 public:
71 ComponentLoaderTest() : 65 ComponentLoaderTest() :
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 // No extensions should be loaded if none were added. 204 // No extensions should be loaded if none were added.
211 component_loader_.LoadAll(); 205 component_loader_.LoadAll();
212 ASSERT_EQ(0U, extension_service_.extensions()->size()); 206 ASSERT_EQ(0U, extension_service_.extensions()->size());
213 207
214 // Use LoadAll() to load the default extensions. 208 // Use LoadAll() to load the default extensions.
215 component_loader_.AddDefaultComponentExtensions(); 209 component_loader_.AddDefaultComponentExtensions();
216 component_loader_.LoadAll(); 210 component_loader_.LoadAll();
217 unsigned int default_count = extension_service_.extensions()->size(); 211 unsigned int default_count = extension_service_.extensions()->size();
218 212
219 // Clear the list of loaded extensions, and reload with one more. 213 // Clear the list of loaded extensions, and reload with one more.
220 extension_service_.clear_extension_list(); 214 extension_service_.clear_extensions();
221 component_loader_.Add(manifest_contents_, extension_path_); 215 component_loader_.Add(manifest_contents_, extension_path_);
222 component_loader_.LoadAll(); 216 component_loader_.LoadAll();
223 217
224 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size()); 218 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size());
225 } 219 }
226 220
227 TEST_F(ComponentLoaderTest, EnterpriseWebStore) { 221 TEST_F(ComponentLoaderTest, EnterpriseWebStore) {
228 component_loader_.AddDefaultComponentExtensions(); 222 component_loader_.AddDefaultComponentExtensions();
229 component_loader_.LoadAll(); 223 component_loader_.LoadAll();
230 unsigned int default_count = extension_service_.extensions()->size(); 224 unsigned int default_count = extension_service_.extensions()->size();
231 225
232 // Set the pref, and it should get loaded automatically. 226 // Set the pref, and it should get loaded automatically.
233 extension_service_.set_ready(true); 227 extension_service_.set_ready(true);
234 prefs_.SetUserPref(prefs::kEnterpriseWebStoreURL, 228 prefs_.SetUserPref(prefs::kEnterpriseWebStoreURL,
235 Value::CreateStringValue("http://www.google.com")); 229 Value::CreateStringValue("http://www.google.com"));
236 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size()); 230 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size());
237 231
238 // Now that the pref is set, check if it's added by default. 232 // Now that the pref is set, check if it's added by default.
239 extension_service_.set_ready(false); 233 extension_service_.set_ready(false);
240 extension_service_.clear_extension_list(); 234 extension_service_.clear_extensions();
241 component_loader_.ClearAllRegistered(); 235 component_loader_.ClearAllRegistered();
242 component_loader_.AddDefaultComponentExtensions(); 236 component_loader_.AddDefaultComponentExtensions();
243 component_loader_.LoadAll(); 237 component_loader_.LoadAll();
244 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size()); 238 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size());
245 239
246 // Number of loaded extensions should be the same after changing the pref. 240 // Number of loaded extensions should be the same after changing the pref.
247 prefs_.SetUserPref(prefs::kEnterpriseWebStoreURL, 241 prefs_.SetUserPref(prefs::kEnterpriseWebStoreURL,
248 Value::CreateStringValue("http://www.google.de")); 242 Value::CreateStringValue("http://www.google.de"));
249 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size()); 243 ASSERT_EQ(default_count + 1, extension_service_.extensions()->size());
250 } 244 }
251 245
252 } // namespace extensions 246 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/browser_action_apitest.cc ('k') | chrome/browser/extensions/extension_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698