OLD | NEW |
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 "chrome/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 void SetPrefInteg(const std::string& extension_id, | 847 void SetPrefInteg(const std::string& extension_id, |
848 const std::string& pref_path, | 848 const std::string& pref_path, |
849 int value) { | 849 int value) { |
850 std::string msg = " while setting: "; | 850 std::string msg = " while setting: "; |
851 msg += extension_id; | 851 msg += extension_id; |
852 msg += " "; | 852 msg += " "; |
853 msg += pref_path; | 853 msg += pref_path; |
854 msg += " = "; | 854 msg += " = "; |
855 msg += base::IntToString(value); | 855 msg += base::IntToString(value); |
856 | 856 |
857 SetPref(extension_id, pref_path, Value::CreateIntegerValue(value), msg); | 857 SetPref(extension_id, pref_path, base::NumberValue::New(value), msg); |
858 } | 858 } |
859 | 859 |
860 void SetPrefBool(const std::string& extension_id, | 860 void SetPrefBool(const std::string& extension_id, |
861 const std::string& pref_path, | 861 const std::string& pref_path, |
862 bool value) { | 862 bool value) { |
863 std::string msg = " while setting: "; | 863 std::string msg = " while setting: "; |
864 msg += extension_id + " " + pref_path; | 864 msg += extension_id + " " + pref_path; |
865 msg += " = "; | 865 msg += " = "; |
866 msg += (value ? "true" : "false"); | 866 msg += (value ? "true" : "false"); |
867 | 867 |
868 SetPref(extension_id, pref_path, Value::CreateBooleanValue(value), msg); | 868 SetPref(extension_id, pref_path, base::BooleanValue::New(value), msg); |
869 } | 869 } |
870 | 870 |
871 void ClearPref(const std::string& extension_id, | 871 void ClearPref(const std::string& extension_id, |
872 const std::string& pref_path) { | 872 const std::string& pref_path) { |
873 std::string msg = " while clearing: "; | 873 std::string msg = " while clearing: "; |
874 msg += extension_id + " " + pref_path; | 874 msg += extension_id + " " + pref_path; |
875 | 875 |
876 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); | 876 DictionaryPrefUpdate update(profile_->GetPrefs(), "extensions.settings"); |
877 DictionaryValue* dict = update.Get(); | 877 DictionaryValue* dict = update.Get(); |
878 ASSERT_TRUE(dict != NULL) << msg; | 878 ASSERT_TRUE(dict != NULL) << msg; |
879 DictionaryValue* pref = NULL; | 879 DictionaryValue* pref = NULL; |
880 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; | 880 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; |
881 EXPECT_TRUE(pref != NULL) << msg; | 881 EXPECT_TRUE(pref != NULL) << msg; |
882 pref->Remove(pref_path, NULL); | 882 pref->Remove(pref_path, NULL); |
883 } | 883 } |
884 | 884 |
885 void SetPrefStringSet(const std::string& extension_id, | 885 void SetPrefStringSet(const std::string& extension_id, |
886 const std::string& pref_path, | 886 const std::string& pref_path, |
887 const std::set<std::string>& value) { | 887 const std::set<std::string>& value) { |
888 std::string msg = " while setting: "; | 888 std::string msg = " while setting: "; |
889 msg += extension_id + " " + pref_path; | 889 msg += extension_id + " " + pref_path; |
890 | 890 |
891 ListValue* list_value = new ListValue(); | 891 ListValue* list_value = new ListValue(); |
892 for (std::set<std::string>::const_iterator iter = value.begin(); | 892 for (std::set<std::string>::const_iterator iter = value.begin(); |
893 iter != value.end(); ++iter) | 893 iter != value.end(); ++iter) |
894 list_value->Append(Value::CreateStringValue(*iter)); | 894 list_value->Append(base::StringValue::New(*iter)); |
895 | 895 |
896 SetPref(extension_id, pref_path, list_value, msg); | 896 SetPref(extension_id, pref_path, list_value, msg); |
897 } | 897 } |
898 | 898 |
899 protected: | 899 protected: |
900 ExtensionList loaded_; | 900 ExtensionList loaded_; |
901 std::string unloaded_id_; | 901 std::string unloaded_id_; |
902 const Extension* installed_; | 902 const Extension* installed_; |
903 | 903 |
904 private: | 904 private: |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 // permissions). | 1493 // permissions). |
1494 host_permissions.clear(); | 1494 host_permissions.clear(); |
1495 current_perms = NULL; | 1495 current_perms = NULL; |
1496 | 1496 |
1497 host_permissions.insert("http://*.google.com/*"); | 1497 host_permissions.insert("http://*.google.com/*"); |
1498 host_permissions.insert("https://*.google.com/*"); | 1498 host_permissions.insert("https://*.google.com/*"); |
1499 host_permissions.insert("http://*.google.com.hk/*"); | 1499 host_permissions.insert("http://*.google.com.hk/*"); |
1500 | 1500 |
1501 ListValue* api_permissions = new ListValue(); | 1501 ListValue* api_permissions = new ListValue(); |
1502 api_permissions->Append( | 1502 api_permissions->Append( |
1503 Value::CreateIntegerValue(ExtensionAPIPermission::kTab)); | 1503 base::NumberValue::New(ExtensionAPIPermission::kTab)); |
1504 SetPref(extension_id, "granted_permissions.api", | 1504 SetPref(extension_id, "granted_permissions.api", |
1505 api_permissions, "granted_permissions.api"); | 1505 api_permissions, "granted_permissions.api"); |
1506 SetPrefStringSet( | 1506 SetPrefStringSet( |
1507 extension_id, "granted_permissions.scriptable_host", host_permissions); | 1507 extension_id, "granted_permissions.scriptable_host", host_permissions); |
1508 | 1508 |
1509 service_->ReloadExtensions(); | 1509 service_->ReloadExtensions(); |
1510 | 1510 |
1511 EXPECT_EQ(1u, service_->disabled_extensions()->size()); | 1511 EXPECT_EQ(1u, service_->disabled_extensions()->size()); |
1512 extension = service_->disabled_extensions()->at(0); | 1512 extension = service_->disabled_extensions()->at(0); |
1513 | 1513 |
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2487 | 2487 |
2488 // Will not install extension blacklisted by policy. | 2488 // Will not install extension blacklisted by policy. |
2489 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { | 2489 TEST_F(ExtensionServiceTest, BlacklistedByPolicyWillNotInstall) { |
2490 InitializeEmptyExtensionService(); | 2490 InitializeEmptyExtensionService(); |
2491 | 2491 |
2492 // Blacklist everything. | 2492 // Blacklist everything. |
2493 { | 2493 { |
2494 ListPrefUpdate update(profile_->GetPrefs(), | 2494 ListPrefUpdate update(profile_->GetPrefs(), |
2495 prefs::kExtensionInstallDenyList); | 2495 prefs::kExtensionInstallDenyList); |
2496 ListValue* blacklist = update.Get(); | 2496 ListValue* blacklist = update.Get(); |
2497 blacklist->Append(Value::CreateStringValue("*")); | 2497 blacklist->Append(base::StringValue::New("*")); |
2498 } | 2498 } |
2499 | 2499 |
2500 // Blacklist prevents us from installing good_crx. | 2500 // Blacklist prevents us from installing good_crx. |
2501 FilePath path = data_dir_.AppendASCII("good.crx"); | 2501 FilePath path = data_dir_.AppendASCII("good.crx"); |
2502 StartCrxInstall(path); | 2502 StartCrxInstall(path); |
2503 loop_.RunAllPending(); | 2503 loop_.RunAllPending(); |
2504 EXPECT_EQ(0u, service_->extensions()->size()); | 2504 EXPECT_EQ(0u, service_->extensions()->size()); |
2505 | 2505 |
2506 // Now whitelist this particular extension. | 2506 // Now whitelist this particular extension. |
2507 { | 2507 { |
2508 ListPrefUpdate update(profile_->GetPrefs(), | 2508 ListPrefUpdate update(profile_->GetPrefs(), |
2509 prefs::kExtensionInstallAllowList); | 2509 prefs::kExtensionInstallAllowList); |
2510 ListValue* whitelist = update.Get(); | 2510 ListValue* whitelist = update.Get(); |
2511 whitelist->Append(Value::CreateStringValue(good_crx)); | 2511 whitelist->Append(base::StringValue::New(good_crx)); |
2512 } | 2512 } |
2513 | 2513 |
2514 | 2514 |
2515 // Ensure we can now install good_crx. | 2515 // Ensure we can now install good_crx. |
2516 StartCrxInstall(path); | 2516 StartCrxInstall(path); |
2517 loop_.RunAllPending(); | 2517 loop_.RunAllPending(); |
2518 EXPECT_EQ(1u, service_->extensions()->size()); | 2518 EXPECT_EQ(1u, service_->extensions()->size()); |
2519 } | 2519 } |
2520 | 2520 |
2521 // Extension blacklisted by policy get unloaded after installing. | 2521 // Extension blacklisted by policy get unloaded after installing. |
2522 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { | 2522 TEST_F(ExtensionServiceTest, BlacklistedByPolicyRemovedIfRunning) { |
2523 InitializeEmptyExtensionService(); | 2523 InitializeEmptyExtensionService(); |
2524 | 2524 |
2525 // Install good_crx. | 2525 // Install good_crx. |
2526 FilePath path = data_dir_.AppendASCII("good.crx"); | 2526 FilePath path = data_dir_.AppendASCII("good.crx"); |
2527 StartCrxInstall(path); | 2527 StartCrxInstall(path); |
2528 loop_.RunAllPending(); | 2528 loop_.RunAllPending(); |
2529 EXPECT_EQ(1u, service_->extensions()->size()); | 2529 EXPECT_EQ(1u, service_->extensions()->size()); |
2530 | 2530 |
2531 { // Scope for pref update notification. | 2531 { // Scope for pref update notification. |
2532 PrefService* prefs = profile_->GetPrefs(); | 2532 PrefService* prefs = profile_->GetPrefs(); |
2533 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); | 2533 ListPrefUpdate update(prefs, prefs::kExtensionInstallDenyList); |
2534 ListValue* blacklist = update.Get(); | 2534 ListValue* blacklist = update.Get(); |
2535 ASSERT_TRUE(blacklist != NULL); | 2535 ASSERT_TRUE(blacklist != NULL); |
2536 | 2536 |
2537 // Blacklist this extension. | 2537 // Blacklist this extension. |
2538 blacklist->Append(Value::CreateStringValue(good_crx)); | 2538 blacklist->Append(base::StringValue::New(good_crx)); |
2539 prefs->ScheduleSavePersistentPrefs(); | 2539 prefs->ScheduleSavePersistentPrefs(); |
2540 } | 2540 } |
2541 | 2541 |
2542 // Extension should not be running now. | 2542 // Extension should not be running now. |
2543 loop_.RunAllPending(); | 2543 loop_.RunAllPending(); |
2544 EXPECT_EQ(0u, service_->extensions()->size()); | 2544 EXPECT_EQ(0u, service_->extensions()->size()); |
2545 } | 2545 } |
2546 | 2546 |
2547 // Tests disabling extensions | 2547 // Tests disabling extensions |
2548 TEST_F(ExtensionServiceTest, DisableExtension) { | 2548 TEST_F(ExtensionServiceTest, DisableExtension) { |
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3875 ASSERT_FALSE(AddPendingSyncInstall()); | 3875 ASSERT_FALSE(AddPendingSyncInstall()); |
3876 | 3876 |
3877 // Wait for the external source to install. | 3877 // Wait for the external source to install. |
3878 WaitForCrxInstall(crx_path_, true); | 3878 WaitForCrxInstall(crx_path_, true); |
3879 ASSERT_TRUE(IsCrxInstalled()); | 3879 ASSERT_TRUE(IsCrxInstalled()); |
3880 | 3880 |
3881 // Now that the extension is installed, sync request should fail | 3881 // Now that the extension is installed, sync request should fail |
3882 // because the extension is already installed. | 3882 // because the extension is already installed. |
3883 ASSERT_FALSE(AddPendingSyncInstall()); | 3883 ASSERT_FALSE(AddPendingSyncInstall()); |
3884 } | 3884 } |
OLD | NEW |