OLD | NEW |
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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 | 187 |
188 scoped_ptr<ExternalPrefExtensionProvider> provider_; | 188 scoped_ptr<ExternalPrefExtensionProvider> provider_; |
189 scoped_ptr<DictionaryValue> prefs_; | 189 scoped_ptr<DictionaryValue> prefs_; |
190 | 190 |
191 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); | 191 DISALLOW_COPY_AND_ASSIGN(MockProviderVisitor); |
192 }; | 192 }; |
193 | 193 |
194 class ExtensionsServiceTest | 194 class ExtensionsServiceTest |
195 : public testing::Test, public NotificationObserver { | 195 : public testing::Test, public NotificationObserver { |
196 public: | 196 public: |
197 ExtensionsServiceTest() : installed_(NULL) { | 197 ExtensionsServiceTest() |
| 198 : ui_thread_(ChromeThread::UI, &loop_), |
| 199 file_thread_(ChromeThread::FILE, &loop_), |
| 200 installed_(NULL) { |
198 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 201 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
199 NotificationService::AllSources()); | 202 NotificationService::AllSources()); |
200 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 203 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
201 NotificationService::AllSources()); | 204 NotificationService::AllSources()); |
202 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, | 205 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, |
203 NotificationService::AllSources()); | 206 NotificationService::AllSources()); |
204 registrar_.Add(this, NotificationType::THEME_INSTALLED, | 207 registrar_.Add(this, NotificationType::THEME_INSTALLED, |
205 NotificationService::AllSources()); | 208 NotificationService::AllSources()); |
206 } | 209 } |
207 | 210 |
208 virtual void InitializeExtensionsService(const FilePath& pref_file, | 211 virtual void InitializeExtensionsService(const FilePath& pref_file, |
209 const FilePath& extensions_install_dir) { | 212 const FilePath& extensions_install_dir) { |
210 prefs_.reset(new PrefService(pref_file, NULL)); | 213 prefs_.reset(new PrefService(pref_file, NULL)); |
211 profile_.reset(new TestingProfile()); | 214 profile_.reset(new TestingProfile()); |
212 service_ = new ExtensionsService(profile_.get(), | 215 service_ = new ExtensionsService(profile_.get(), |
213 CommandLine::ForCurrentProcess(), | 216 CommandLine::ForCurrentProcess(), |
214 prefs_.get(), | 217 prefs_.get(), |
215 extensions_install_dir, | 218 extensions_install_dir, |
216 &loop_, | |
217 &loop_, | |
218 false); | 219 false); |
219 service_->set_extensions_enabled(true); | 220 service_->set_extensions_enabled(true); |
220 service_->set_show_extensions_prompts(false); | 221 service_->set_show_extensions_prompts(false); |
221 | 222 |
222 // When we start up, we want to make sure there is no external provider, | 223 // When we start up, we want to make sure there is no external provider, |
223 // since the ExtensionService on Windows will use the Registry as a default | 224 // since the ExtensionService on Windows will use the Registry as a default |
224 // provider and if there is something already registered there then it will | 225 // provider and if there is something already registered there then it will |
225 // interfere with the tests. Those tests that need an external provider | 226 // interfere with the tests. Those tests that need an external provider |
226 // will register one specifically. | 227 // will register one specifically. |
227 service_->ClearProvidersForTesting(); | 228 service_->ClearProvidersForTesting(); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 } | 462 } |
462 | 463 |
463 protected: | 464 protected: |
464 ScopedTempDir temp_dir_; | 465 ScopedTempDir temp_dir_; |
465 scoped_ptr<PrefService> prefs_; | 466 scoped_ptr<PrefService> prefs_; |
466 scoped_ptr<Profile> profile_; | 467 scoped_ptr<Profile> profile_; |
467 FilePath extensions_install_dir_; | 468 FilePath extensions_install_dir_; |
468 scoped_refptr<ExtensionsService> service_; | 469 scoped_refptr<ExtensionsService> service_; |
469 size_t total_successes_; | 470 size_t total_successes_; |
470 MessageLoop loop_; | 471 MessageLoop loop_; |
| 472 ChromeThread ui_thread_; |
| 473 ChromeThread file_thread_; |
471 ExtensionList loaded_; | 474 ExtensionList loaded_; |
472 std::string unloaded_id_; | 475 std::string unloaded_id_; |
473 Extension* installed_; | 476 Extension* installed_; |
474 | 477 |
475 private: | 478 private: |
476 NotificationRegistrar registrar_; | 479 NotificationRegistrar registrar_; |
477 }; | 480 }; |
478 | 481 |
479 FilePath::StringType NormalizeSeperators(FilePath::StringType path) { | 482 FilePath::StringType NormalizeSeperators(FilePath::StringType path) { |
480 #if defined(FILE_PATH_USES_WIN_SEPARATORS) | 483 #if defined(FILE_PATH_USES_WIN_SEPARATORS) |
(...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 // Test that we get enabled/disabled correctly for all the pref/command-line | 1523 // Test that we get enabled/disabled correctly for all the pref/command-line |
1521 // combinations. We don't want to derive from the ExtensionsServiceTest class | 1524 // combinations. We don't want to derive from the ExtensionsServiceTest class |
1522 // for this test, so we use ExtensionsServiceTestSimple. | 1525 // for this test, so we use ExtensionsServiceTestSimple. |
1523 // | 1526 // |
1524 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are | 1527 // Also tests that we always fire EXTENSIONS_READY, no matter whether we are |
1525 // enabled or not. | 1528 // enabled or not. |
1526 TEST(ExtensionsServiceTestSimple, Enabledness) { | 1529 TEST(ExtensionsServiceTestSimple, Enabledness) { |
1527 ExtensionsReadyRecorder recorder; | 1530 ExtensionsReadyRecorder recorder; |
1528 TestingProfile profile; | 1531 TestingProfile profile; |
1529 MessageLoop loop; | 1532 MessageLoop loop; |
| 1533 ChromeThread ui_thread(ChromeThread::UI, &loop); |
| 1534 ChromeThread file_thread(ChromeThread::FILE, &loop); |
1530 scoped_ptr<CommandLine> command_line; | 1535 scoped_ptr<CommandLine> command_line; |
1531 scoped_refptr<ExtensionsService> service; | 1536 scoped_refptr<ExtensionsService> service; |
1532 FilePath install_dir = profile.GetPath() | 1537 FilePath install_dir = profile.GetPath() |
1533 .AppendASCII(ExtensionsService::kInstallDirectoryName); | 1538 .AppendASCII(ExtensionsService::kInstallDirectoryName); |
1534 | 1539 |
1535 // By default, we are enabled. | 1540 // By default, we are enabled. |
1536 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); | 1541 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); |
1537 service = new ExtensionsService(&profile, command_line.get(), | 1542 service = new ExtensionsService(&profile, command_line.get(), |
1538 profile.GetPrefs(), install_dir, &loop, &loop, false); | 1543 profile.GetPrefs(), install_dir, false); |
1539 EXPECT_TRUE(service->extensions_enabled()); | 1544 EXPECT_TRUE(service->extensions_enabled()); |
1540 service->Init(); | 1545 service->Init(); |
1541 loop.RunAllPending(); | 1546 loop.RunAllPending(); |
1542 EXPECT_TRUE(recorder.ready()); | 1547 EXPECT_TRUE(recorder.ready()); |
1543 | 1548 |
1544 // If either the command line or pref is set, we are disabled. | 1549 // If either the command line or pref is set, we are disabled. |
1545 recorder.set_ready(false); | 1550 recorder.set_ready(false); |
1546 command_line->AppendSwitch(switches::kDisableExtensions); | 1551 command_line->AppendSwitch(switches::kDisableExtensions); |
1547 service = new ExtensionsService(&profile, command_line.get(), | 1552 service = new ExtensionsService(&profile, command_line.get(), |
1548 profile.GetPrefs(), install_dir, &loop, &loop, false); | 1553 profile.GetPrefs(), install_dir, false); |
1549 EXPECT_FALSE(service->extensions_enabled()); | 1554 EXPECT_FALSE(service->extensions_enabled()); |
1550 service->Init(); | 1555 service->Init(); |
1551 loop.RunAllPending(); | 1556 loop.RunAllPending(); |
1552 EXPECT_TRUE(recorder.ready()); | 1557 EXPECT_TRUE(recorder.ready()); |
1553 | 1558 |
1554 recorder.set_ready(false); | 1559 recorder.set_ready(false); |
1555 profile.GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); | 1560 profile.GetPrefs()->SetBoolean(prefs::kDisableExtensions, true); |
1556 service = new ExtensionsService(&profile, command_line.get(), | 1561 service = new ExtensionsService(&profile, command_line.get(), |
1557 profile.GetPrefs(), install_dir, &loop, &loop, false); | 1562 profile.GetPrefs(), install_dir, false); |
1558 EXPECT_FALSE(service->extensions_enabled()); | 1563 EXPECT_FALSE(service->extensions_enabled()); |
1559 service->Init(); | 1564 service->Init(); |
1560 loop.RunAllPending(); | 1565 loop.RunAllPending(); |
1561 EXPECT_TRUE(recorder.ready()); | 1566 EXPECT_TRUE(recorder.ready()); |
1562 | 1567 |
1563 recorder.set_ready(false); | 1568 recorder.set_ready(false); |
1564 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); | 1569 command_line.reset(new CommandLine(CommandLine::ARGUMENTS_ONLY)); |
1565 service = new ExtensionsService(&profile, command_line.get(), | 1570 service = new ExtensionsService(&profile, command_line.get(), |
1566 profile.GetPrefs(), install_dir, &loop, &loop, false); | 1571 profile.GetPrefs(), install_dir, false); |
1567 EXPECT_FALSE(service->extensions_enabled()); | 1572 EXPECT_FALSE(service->extensions_enabled()); |
1568 service->Init(); | 1573 service->Init(); |
1569 loop.RunAllPending(); | 1574 loop.RunAllPending(); |
1570 EXPECT_TRUE(recorder.ready()); | 1575 EXPECT_TRUE(recorder.ready()); |
1571 } | 1576 } |
OLD | NEW |