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

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

Issue 5441002: Clean up pref change notification handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Danno's feedback. Created 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/extensions/extensions_service_unittest.h" 5 #include "chrome/browser/extensions/extensions_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/browser/extensions/extension_creator.h" 28 #include "chrome/browser/extensions/extension_creator.h"
29 #include "chrome/browser/extensions/extension_error_reporter.h" 29 #include "chrome/browser/extensions/extension_error_reporter.h"
30 #include "chrome/browser/extensions/extensions_service.h" 30 #include "chrome/browser/extensions/extensions_service.h"
31 #include "chrome/browser/extensions/external_extension_provider.h" 31 #include "chrome/browser/extensions/external_extension_provider.h"
32 #include "chrome/browser/extensions/external_pref_extension_provider.h" 32 #include "chrome/browser/extensions/external_pref_extension_provider.h"
33 #include "chrome/browser/extensions/pack_extension_job.cc" 33 #include "chrome/browser/extensions/pack_extension_job.cc"
34 #include "chrome/browser/in_process_webkit/dom_storage_context.h" 34 #include "chrome/browser/in_process_webkit/dom_storage_context.h"
35 #include "chrome/browser/in_process_webkit/webkit_context.h" 35 #include "chrome/browser/in_process_webkit/webkit_context.h"
36 #include "chrome/browser/prefs/browser_prefs.h" 36 #include "chrome/browser/prefs/browser_prefs.h"
37 #include "chrome/browser/prefs/pref_value_store.h" 37 #include "chrome/browser/prefs/pref_value_store.h"
38 #include "chrome/browser/prefs/scoped_pref_update.h"
38 #include "chrome/common/chrome_paths.h" 39 #include "chrome/common/chrome_paths.h"
39 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
40 #include "chrome/common/extensions/extension.h" 41 #include "chrome/common/extensions/extension.h"
41 #include "chrome/common/extensions/extension_constants.h" 42 #include "chrome/common/extensions/extension_constants.h"
42 #include "chrome/common/extensions/extension_resource.h" 43 #include "chrome/common/extensions/extension_resource.h"
43 #include "chrome/common/extensions/url_pattern.h" 44 #include "chrome/common/extensions/url_pattern.h"
44 #include "chrome/common/json_value_serializer.h" 45 #include "chrome/common/json_value_serializer.h"
45 #include "chrome/common/net/url_request_context_getter.h" 46 #include "chrome/common/net/url_request_context_getter.h"
46 #include "chrome/common/notification_registrar.h" 47 #include "chrome/common/notification_registrar.h"
47 #include "chrome/common/notification_service.h" 48 #include "chrome/common/notification_service.h"
(...skipping 2277 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 EXPECT_NE(std::string(good1), loaded_[0]->id()); 2326 EXPECT_NE(std::string(good1), loaded_[0]->id());
2326 EXPECT_NE(std::string(good1), loaded_[1]->id()); 2327 EXPECT_NE(std::string(good1), loaded_[1]->id());
2327 } 2328 }
2328 #endif 2329 #endif
2329 2330
2330 // Will not install extension blacklisted by policy. 2331 // Will not install extension blacklisted by policy.
2331 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) { 2332 TEST_F(ExtensionsServiceTest, BlacklistedByPolicyWillNotInstall) {
2332 InitializeEmptyExtensionsService(); 2333 InitializeEmptyExtensionsService();
2333 2334
2334 ListValue* whitelist = 2335 ListValue* whitelist =
2335 profile_->GetPrefs()->GetMutableList("extensions.install.allowlist"); 2336 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallAllowList);
2336 ListValue* blacklist = 2337 ListValue* blacklist =
2337 profile_->GetPrefs()->GetMutableList("extensions.install.denylist"); 2338 profile_->GetPrefs()->GetMutableList(prefs::kExtensionInstallDenyList);
2338 ASSERT_TRUE(whitelist != NULL && blacklist != NULL); 2339 ASSERT_TRUE(whitelist != NULL && blacklist != NULL);
2339 2340
2340 // Blacklist everything. 2341 // Blacklist everything.
2341 blacklist->Append(Value::CreateStringValue("*")); 2342 blacklist->Append(Value::CreateStringValue("*"));
2342 2343
2343 // Blacklist prevents us from installing good_crx. 2344 // Blacklist prevents us from installing good_crx.
2344 FilePath extensions_path; 2345 FilePath extensions_path;
2345 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2346 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2346 extensions_path = extensions_path.AppendASCII("extensions"); 2347 extensions_path = extensions_path.AppendASCII("extensions");
2347 FilePath path = extensions_path.AppendASCII("good.crx"); 2348 FilePath path = extensions_path.AppendASCII("good.crx");
(...skipping 16 matching lines...) Expand all
2364 2365
2365 // Install good_crx. 2366 // Install good_crx.
2366 FilePath extensions_path; 2367 FilePath extensions_path;
2367 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 2368 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
2368 extensions_path = extensions_path.AppendASCII("extensions"); 2369 extensions_path = extensions_path.AppendASCII("extensions");
2369 FilePath path = extensions_path.AppendASCII("good.crx"); 2370 FilePath path = extensions_path.AppendASCII("good.crx");
2370 service_->InstallExtension(path); 2371 service_->InstallExtension(path);
2371 loop_.RunAllPending(); 2372 loop_.RunAllPending();
2372 EXPECT_EQ(1u, service_->extensions()->size()); 2373 EXPECT_EQ(1u, service_->extensions()->size());
2373 2374
2374 PrefService* prefs = profile_->GetPrefs(); 2375 { // Scope for pref update notification.
2375 ListValue* blacklist = 2376 PrefService* prefs = profile_->GetPrefs();
2376 prefs->GetMutableList("extensions.install.denylist"); 2377 ScopedPrefUpdate pref_update(prefs, prefs::kExtensionInstallDenyList);
2377 ASSERT_TRUE(blacklist != NULL); 2378 ListValue* blacklist =
2379 prefs->GetMutableList(prefs::kExtensionInstallDenyList);
2380 ASSERT_TRUE(blacklist != NULL);
2378 2381
2379 // Blacklist this extension. 2382 // Blacklist this extension.
2380 blacklist->Append(Value::CreateStringValue(good_crx)); 2383 blacklist->Append(Value::CreateStringValue(good_crx));
2381 prefs->ScheduleSavePersistentPrefs(); 2384 prefs->ScheduleSavePersistentPrefs();
2382 2385 }
2383 // Programmatically appending to the prefs doesn't seem to notify the
2384 // observers... :/
2385 prefs->pref_notifier()->FireObservers("extensions.install.denylist");
2386 2386
2387 // Extension should not be running now. 2387 // Extension should not be running now.
2388 loop_.RunAllPending(); 2388 loop_.RunAllPending();
2389 EXPECT_EQ(0u, service_->extensions()->size()); 2389 EXPECT_EQ(0u, service_->extensions()->size());
2390 } 2390 }
2391 2391
2392 // Tests disabling extensions 2392 // Tests disabling extensions
2393 TEST_F(ExtensionsServiceTest, DisableExtension) { 2393 TEST_F(ExtensionsServiceTest, DisableExtension) {
2394 InitializeEmptyExtensionsService(); 2394 InitializeEmptyExtensionsService();
2395 FilePath extensions_path; 2395 FilePath extensions_path;
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 // Component extensions shouldn't get recourded in the prefs. 3141 // Component extensions shouldn't get recourded in the prefs.
3142 ValidatePrefKeyCount(0); 3142 ValidatePrefKeyCount(0);
3143 3143
3144 // Reload all extensions, and make sure it comes back. 3144 // Reload all extensions, and make sure it comes back.
3145 std::string extension_id = service_->extensions()->at(0)->id(); 3145 std::string extension_id = service_->extensions()->at(0)->id();
3146 loaded_.clear(); 3146 loaded_.clear();
3147 service_->ReloadExtensions(); 3147 service_->ReloadExtensions();
3148 ASSERT_EQ(1u, service_->extensions()->size()); 3148 ASSERT_EQ(1u, service_->extensions()->size());
3149 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); 3149 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id());
3150 } 3150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698