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

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

Issue 115974: The extensions service wasn't getting inited despite being used by themes (th... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months 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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json_reader.h" 10 #include "base/json_reader.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 DCHECK(false); 122 DCHECK(false);
123 } 123 }
124 } 124 }
125 125
126 void SetExtensionsEnabled(bool enabled) { 126 void SetExtensionsEnabled(bool enabled) {
127 service_->set_extensions_enabled(enabled); 127 service_->set_extensions_enabled(enabled);
128 } 128 }
129 129
130 void TestInstallExtension(const FilePath& path, 130 void TestInstallExtension(const FilePath& path,
131 bool should_succeed) { 131 bool should_succeed) {
132 InstallExtension(path, should_succeed, false);
133 }
134
135 void TestInstallTheme(const FilePath& path,
136 bool should_succeed) {
137 InstallExtension(path, should_succeed, true);
138 }
139
140 protected:
141 void InstallExtension(const FilePath& path,
142 bool should_succeed,
143 bool is_theme) {
132 ASSERT_TRUE(file_util::PathExists(path)); 144 ASSERT_TRUE(file_util::PathExists(path));
133 service_->InstallExtension(path); 145 service_->InstallExtension(path);
134 loop_.RunAllPending(); 146 loop_.RunAllPending();
135 std::vector<std::string> errors = GetErrors(); 147 std::vector<std::string> errors = GetErrors();
136 if (should_succeed) { 148 if (should_succeed) {
137 ++total_successes_; 149 ++total_successes_;
138 150
139 EXPECT_TRUE(installed_) << path.value(); 151 EXPECT_TRUE(installed_) << path.value();
140 EXPECT_EQ(1u, loaded_.size()) << path.value(); 152
153 // Themes aren't loaded.
154 if (is_theme)
155 EXPECT_EQ(0u, loaded_.size()) << path.value();
156 else
157 EXPECT_EQ(1u, loaded_.size()) << path.value();
158
141 EXPECT_EQ(0u, errors.size()) << path.value(); 159 EXPECT_EQ(0u, errors.size()) << path.value();
142 EXPECT_EQ(total_successes_, service_->extensions()->size()) << 160 EXPECT_EQ(total_successes_, service_->extensions()->size()) <<
143 path.value(); 161 path.value();
144 if (loaded_.size() > 0) { 162 if (loaded_.size() > 0) {
145 EXPECT_TRUE(service_->GetExtensionByID(loaded_[0]->id())) << 163 EXPECT_TRUE(service_->GetExtensionByID(loaded_[0]->id())) <<
146 path.value(); 164 path.value();
147 } 165 }
148 for (std::vector<std::string>::iterator err = errors.begin(); 166 for (std::vector<std::string>::iterator err = errors.begin();
149 err != errors.end(); ++err) { 167 err != errors.end(); ++err) {
150 LOG(ERROR) << *err; 168 LOG(ERROR) << *err;
151 } 169 }
152 } else { 170 } else {
153 EXPECT_FALSE(installed_) << path.value(); 171 EXPECT_FALSE(installed_) << path.value();
154 EXPECT_EQ(1u, errors.size()) << path.value(); 172 EXPECT_EQ(1u, errors.size()) << path.value();
155 } 173 }
156 174
157 installed_ = NULL; 175 installed_ = NULL;
158 loaded_.clear(); 176 loaded_.clear();
159 ExtensionErrorReporter::GetInstance()->ClearErrors(); 177 ExtensionErrorReporter::GetInstance()->ClearErrors();
160 } 178 }
161 179
162 protected:
163 scoped_ptr<TestingProfile> profile_; 180 scoped_ptr<TestingProfile> profile_;
164 scoped_refptr<ExtensionsService> service_; 181 scoped_refptr<ExtensionsService> service_;
165 size_t total_successes_; 182 size_t total_successes_;
166 MessageLoop loop_; 183 MessageLoop loop_;
167 std::vector<Extension*> loaded_; 184 std::vector<Extension*> loaded_;
168 std::string unloaded_id_; 185 std::string unloaded_id_;
169 Extension* installed_; 186 Extension* installed_;
170 std::string registry_path_; 187 std::string registry_path_;
171 188
172 private: 189 private:
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 // TODO(erikkay): add tests for upgrade cases. 365 // TODO(erikkay): add tests for upgrade cases.
349 } 366 }
350 367
351 TEST_F(ExtensionsServiceTest, InstallTheme) { 368 TEST_F(ExtensionsServiceTest, InstallTheme) {
352 FilePath extensions_path; 369 FilePath extensions_path;
353 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 370 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
354 extensions_path = extensions_path.AppendASCII("extensions"); 371 extensions_path = extensions_path.AppendASCII("extensions");
355 372
356 // A theme. 373 // A theme.
357 FilePath path = extensions_path.AppendASCII("theme.crx"); 374 FilePath path = extensions_path.AppendASCII("theme.crx");
358 TestInstallExtension(path, true); 375 TestInstallTheme(path, true);
359 376
360 // A theme when extensions are disabled. 377 // A theme when extensions are disabled.
361 SetExtensionsEnabled(false); 378 SetExtensionsEnabled(false);
362 path = extensions_path.AppendASCII("theme2.crx"); 379 path = extensions_path.AppendASCII("theme2.crx");
363 TestInstallExtension(path, true); 380 TestInstallTheme(path, true);
364 SetExtensionsEnabled(true); 381 SetExtensionsEnabled(true);
365 382
366 // A theme with extension elements. 383 // A theme with extension elements.
367 path = extensions_path.AppendASCII("theme_with_extension.crx"); 384 path = extensions_path.AppendASCII("theme_with_extension.crx");
368 TestInstallExtension(path, false); 385 TestInstallTheme(path, false);
369 } 386 }
370 387
371 // Test that when an extension version is reinstalled, nothing happens. 388 // Test that when an extension version is reinstalled, nothing happens.
372 TEST_F(ExtensionsServiceTest, Reinstall) { 389 TEST_F(ExtensionsServiceTest, Reinstall) {
373 FilePath extensions_path; 390 FilePath extensions_path;
374 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 391 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
375 extensions_path = extensions_path.AppendASCII("extensions"); 392 extensions_path = extensions_path.AppendASCII("extensions");
376 393
377 // A simple extension that should install without error. 394 // A simple extension that should install without error.
378 FilePath path = extensions_path.AppendASCII("good.crx"); 395 FilePath path = extensions_path.AppendASCII("good.crx");
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 service_->Init(); 590 service_->Init();
574 loop_.RunAllPending(); 591 loop_.RunAllPending();
575 ASSERT_EQ(0u, loaded_.size()); 592 ASSERT_EQ(0u, loaded_.size());
576 } 593 }
577 594
578 #else 595 #else
579 596
580 // TODO(port) 597 // TODO(port)
581 598
582 #endif 599 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698