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

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

Issue 132045: Re-enable the --enable-extensions flag. Fix a bunch of bugs (Closed)
Patch Set: unblech 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
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h"
8 #include "base/file_path.h" 9 #include "base/file_path.h"
9 #include "base/file_util.h" 10 #include "base/file_util.h"
10 #include "base/json_reader.h" 11 #include "base/json_reader.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/string_util.h" 14 #include "base/string_util.h"
14 #include "base/time.h" 15 #include "base/time.h"
15 #include "chrome/browser/extensions/extension_creator.h" 16 #include "chrome/browser/extensions/extension_creator.h"
16 #include "chrome/browser/extensions/extensions_service.h" 17 #include "chrome/browser/extensions/extensions_service.h"
17 #include "chrome/browser/extensions/external_extension_provider.h" 18 #include "chrome/browser/extensions/external_extension_provider.h"
18 #include "chrome/common/extensions/extension.h" 19 #include "chrome/common/extensions/extension.h"
19 #include "chrome/common/extensions/url_pattern.h" 20 #include "chrome/common/extensions/url_pattern.h"
20 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/extensions/extension_error_reporter.h" 23 #include "chrome/common/extensions/extension_error_reporter.h"
23 #include "chrome/common/json_value_serializer.h" 24 #include "chrome/common/json_value_serializer.h"
24 #include "chrome/common/notification_registrar.h" 25 #include "chrome/common/notification_registrar.h"
25 #include "chrome/common/notification_service.h" 26 #include "chrome/common/notification_service.h"
26 #include "chrome/common/notification_type.h" 27 #include "chrome/common/notification_type.h"
28 #include "chrome/common/pref_names.h"
27 #include "chrome/test/testing_profile.h" 29 #include "chrome/test/testing_profile.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 #include "testing/platform_test.h" 31 #include "testing/platform_test.h"
30 32
31 namespace { 33 namespace {
32 34
33 // Extension ids used during testing. 35 // Extension ids used during testing.
34 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 36 const char* const all_zero = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
35 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; 37 const char* const zero_n_one = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab";
36 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj"; 38 const char* const good0 = "behllobkkfkfnphdnhnkndlbkcpglgmj";
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, 125 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED,
124 NotificationService::AllSources()); 126 NotificationService::AllSources());
125 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 127 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
126 NotificationService::AllSources()); 128 NotificationService::AllSources());
127 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, 129 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED,
128 NotificationService::AllSources()); 130 NotificationService::AllSources());
129 registrar_.Add(this, NotificationType::THEME_INSTALLED, 131 registrar_.Add(this, NotificationType::THEME_INSTALLED,
130 NotificationService::AllSources()); 132 NotificationService::AllSources());
131 133
132 profile_.reset(new TestingProfile()); 134 profile_.reset(new TestingProfile());
133 service_ = new ExtensionsService(profile_.get(), &loop_, &loop_); 135 service_ = new ExtensionsService(
136 profile_.get(), CommandLine::ForCurrentProcess(), &loop_, &loop_);
134 service_->SetExtensionsEnabled(true); 137 service_->SetExtensionsEnabled(true);
135 service_->set_show_extensions_prompts(false); 138 service_->set_show_extensions_prompts(false);
136 139
137 // When we start up, we want to make sure there is no external provider, 140 // When we start up, we want to make sure there is no external provider,
138 // since the ExtensionService on Windows will use the Registry as a default 141 // since the ExtensionService on Windows will use the Registry as a default
139 // provider and if there is something already registered there then it will 142 // provider and if there is something already registered there then it will
140 // interfere with the tests. Those tests that need an external provider 143 // interfere with the tests. Those tests that need an external provider
141 // will register one specifically. 144 // will register one specifically.
142 service_->ClearProvidersForTesting(); 145 service_->ClearProvidersForTesting();
143 146
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 // This shouldn't work if extensions are disabled. 1019 // This shouldn't work if extensions are disabled.
1017 SetExtensionsEnabled(false); 1020 SetExtensionsEnabled(false);
1018 1021
1019 pref_provider->UpdateOrAddExtension(good_crx, "1.0", source_path); 1022 pref_provider->UpdateOrAddExtension(good_crx, "1.0", source_path);
1020 service_->CheckForUpdates(); 1023 service_->CheckForUpdates();
1021 loop_.RunAllPending(); 1024 loop_.RunAllPending();
1022 1025
1023 ASSERT_EQ(0u, loaded_.size()); 1026 ASSERT_EQ(0u, loaded_.size());
1024 ASSERT_EQ(1u, GetErrors().size()); 1027 ASSERT_EQ(1u, GetErrors().size());
1025 } 1028 }
1029
1030 // Test that we get enabled/disabled correctly for all the pref/command-line
1031 // combinations.
1032 TEST(ExtensionsServiceTest2, Enabledness) {
1033 TestingProfile profile;
1034 MessageLoop loop;
1035 scoped_ptr<CommandLine> command_line;
1036 scoped_refptr<ExtensionsService> service;
1037
1038 // By default, we are disabled.
1039 command_line.reset(new CommandLine(L""));
1040 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
1041 EXPECT_FALSE(service->extensions_enabled());
1042
1043 // If either the command line or pref is set, we are enabled.
1044 command_line->AppendSwitch(switches::kEnableExtensions);
1045 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
1046 EXPECT_TRUE(service->extensions_enabled());
1047
1048 profile.GetPrefs()->SetBoolean(prefs::kEnableExtensions, true);
1049 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
1050 EXPECT_TRUE(service->extensions_enabled());
1051
1052 command_line.reset(new CommandLine(L""));
1053 service = new ExtensionsService(&profile, command_line.get(), &loop, &loop);
1054 EXPECT_TRUE(service->extensions_enabled());
1055 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extensions_service.cc ('k') | chrome/browser/profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698