| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1574 "http://localhost/autoupdate/updates.xml"); | 1574 "http://localhost/autoupdate/updates.xml"); |
| 1575 } | 1575 } |
| 1576 | 1576 |
| 1577 void TearDown() override { | 1577 void TearDown() override { |
| 1578 supervised_user_service()->SetDelegate(nullptr); | 1578 supervised_user_service()->SetDelegate(nullptr); |
| 1579 | 1579 |
| 1580 ExtensionServiceSyncTest::TearDown(); | 1580 ExtensionServiceSyncTest::TearDown(); |
| 1581 } | 1581 } |
| 1582 | 1582 |
| 1583 protected: | 1583 protected: |
| 1584 void InitNeedCustodianApprovalFieldTrial(bool enabled) { | |
| 1585 // Group name doesn't matter. | |
| 1586 base::FieldTrialList::CreateFieldTrial( | |
| 1587 "SupervisedUserExtensionPermissionIncrease", "group"); | |
| 1588 std::map<std::string, std::string> params; | |
| 1589 params["legacy_supervised_user"] = enabled ? "true" : "false"; | |
| 1590 params["child_account"] = enabled ? "true" : "false"; | |
| 1591 variations::AssociateVariationParams( | |
| 1592 "SupervisedUserExtensionPermissionIncrease", "group", params); | |
| 1593 } | |
| 1594 | |
| 1595 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) { | 1584 void InitSupervisedUserInitiatedExtensionInstallFeature(bool enabled) { |
| 1596 base::FeatureList::ClearInstanceForTesting(); | 1585 base::FeatureList::ClearInstanceForTesting(); |
| 1597 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 1586 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 1598 if (enabled) { | 1587 if (enabled) { |
| 1599 feature_list->InitializeFromCommandLine( | 1588 feature_list->InitializeFromCommandLine( |
| 1600 "SupervisedUserInitiatedExtensionInstall", std::string()); | 1589 "SupervisedUserInitiatedExtensionInstall", std::string()); |
| 1601 } | 1590 } |
| 1602 base::FeatureList::SetInstance(std::move(feature_list)); | 1591 base::FeatureList::SetInstance(std::move(feature_list)); |
| 1603 } | 1592 } |
| 1604 | 1593 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 UpdateNoPermissionsTestExtension(id, version2, ENABLED); | 1982 UpdateNoPermissionsTestExtension(id, version2, ENABLED); |
| 1994 | 1983 |
| 1995 // The extension should still be there and enabled. | 1984 // The extension should still be there and enabled. |
| 1996 const Extension* extension = registry()->enabled_extensions().GetByID(id); | 1985 const Extension* extension = registry()->enabled_extensions().GetByID(id); |
| 1997 ASSERT_TRUE(extension); | 1986 ASSERT_TRUE(extension); |
| 1998 // The version should have changed. | 1987 // The version should have changed. |
| 1999 EXPECT_EQ(*extension->version(), base::Version(version2)); | 1988 EXPECT_EQ(*extension->version(), base::Version(version2)); |
| 2000 EXPECT_FALSE(IsPendingCustodianApproval(id)); | 1989 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2001 } | 1990 } |
| 2002 | 1991 |
| 2003 TEST_F(ExtensionServiceTestSupervised, UpdateWithPermissionIncreaseNoApproval) { | |
| 2004 InitNeedCustodianApprovalFieldTrial(false); | |
| 2005 | |
| 2006 InitServices(true /* profile_is_supervised */); | |
| 2007 | |
| 2008 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | |
| 2009 supervised_user_service()->AddPermissionRequestCreator( | |
| 2010 base::WrapUnique(creator)); | |
| 2011 | |
| 2012 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); | |
| 2013 | |
| 2014 // Update to a new version with increased permissions. | |
| 2015 // Since we don't require the custodian's approval, no permission request | |
| 2016 // should be created. | |
| 2017 const std::string version2("2"); | |
| 2018 EXPECT_CALL(*creator, CreateExtensionUpdateRequest( | |
| 2019 RequestId(id, version2), testing::_)) | |
| 2020 .Times(0); | |
| 2021 UpdatePermissionsTestExtension(id, version2, DISABLED); | |
| 2022 EXPECT_FALSE(IsPendingCustodianApproval(id)); | |
| 2023 } | |
| 2024 | |
| 2025 TEST_F(ExtensionServiceTestSupervised, | 1992 TEST_F(ExtensionServiceTestSupervised, |
| 2026 UpdateWithPermissionIncreaseApprovalOldVersion) { | 1993 UpdateWithPermissionIncreaseApprovalOldVersion) { |
| 2027 InitNeedCustodianApprovalFieldTrial(true); | |
| 2028 | |
| 2029 InitServices(true /* profile_is_supervised */); | 1994 InitServices(true /* profile_is_supervised */); |
| 2030 | 1995 |
| 2031 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 1996 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 2032 supervised_user_service()->AddPermissionRequestCreator( | 1997 supervised_user_service()->AddPermissionRequestCreator( |
| 2033 base::WrapUnique(creator)); | 1998 base::WrapUnique(creator)); |
| 2034 | 1999 |
| 2035 const std::string version1("1"); | 2000 const std::string version1("1"); |
| 2036 const std::string version2("2"); | 2001 const std::string version2("2"); |
| 2037 | 2002 |
| 2038 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); | 2003 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2069 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 2034 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
| 2070 id, base::Version(version1))); | 2035 id, base::Version(version1))); |
| 2071 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( | 2036 EXPECT_FALSE(extension_sync_service()->HasPendingReenable( |
| 2072 id, base::Version(version2))); | 2037 id, base::Version(version2))); |
| 2073 Mock::VerifyAndClearExpectations(creator); | 2038 Mock::VerifyAndClearExpectations(creator); |
| 2074 EXPECT_TRUE(IsPendingCustodianApproval(id)); | 2039 EXPECT_TRUE(IsPendingCustodianApproval(id)); |
| 2075 } | 2040 } |
| 2076 | 2041 |
| 2077 TEST_F(ExtensionServiceTestSupervised, | 2042 TEST_F(ExtensionServiceTestSupervised, |
| 2078 UpdateWithPermissionIncreaseApprovalMatchingVersion) { | 2043 UpdateWithPermissionIncreaseApprovalMatchingVersion) { |
| 2079 InitNeedCustodianApprovalFieldTrial(true); | |
| 2080 | |
| 2081 InitServices(true /* profile_is_supervised */); | 2044 InitServices(true /* profile_is_supervised */); |
| 2082 | 2045 |
| 2083 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2046 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 2084 supervised_user_service()->AddPermissionRequestCreator( | 2047 supervised_user_service()->AddPermissionRequestCreator( |
| 2085 base::WrapUnique(creator)); | 2048 base::WrapUnique(creator)); |
| 2086 | 2049 |
| 2087 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); | 2050 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
| 2088 | 2051 |
| 2089 // Update to a new version with increased permissions. | 2052 // Update to a new version with increased permissions. |
| 2090 const std::string version2("2"); | 2053 const std::string version2("2"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2108 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); | 2071 MakeSyncChangeList(id, specifics, SyncChange::ACTION_UPDATE); |
| 2109 | 2072 |
| 2110 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 2073 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 2111 // The extension should have gotten re-enabled. | 2074 // The extension should have gotten re-enabled. |
| 2112 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 2075 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 2113 EXPECT_FALSE(IsPendingCustodianApproval(id)); | 2076 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2114 } | 2077 } |
| 2115 | 2078 |
| 2116 TEST_F(ExtensionServiceTestSupervised, | 2079 TEST_F(ExtensionServiceTestSupervised, |
| 2117 UpdateWithPermissionIncreaseApprovalNewVersion) { | 2080 UpdateWithPermissionIncreaseApprovalNewVersion) { |
| 2118 InitNeedCustodianApprovalFieldTrial(true); | |
| 2119 | |
| 2120 InitServices(true /* profile_is_supervised */); | 2081 InitServices(true /* profile_is_supervised */); |
| 2121 | 2082 |
| 2122 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2083 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 2123 supervised_user_service()->AddPermissionRequestCreator( | 2084 supervised_user_service()->AddPermissionRequestCreator( |
| 2124 base::WrapUnique(creator)); | 2085 base::WrapUnique(creator)); |
| 2125 | 2086 |
| 2126 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); | 2087 std::string id = InstallPermissionsTestExtension(true /* by_custodian */); |
| 2127 | 2088 |
| 2128 // Update to a new version with increased permissions. | 2089 // Update to a new version with increased permissions. |
| 2129 const std::string version2("2"); | 2090 const std::string version2("2"); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2156 // matching version. | 2117 // matching version. |
| 2157 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); | 2118 EXPECT_FALSE(registry()->enabled_extensions().Contains(id)); |
| 2158 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( | 2119 EXPECT_TRUE(extension_sync_service()->HasPendingReenable( |
| 2159 id, base::Version(version3))); | 2120 id, base::Version(version3))); |
| 2160 | 2121 |
| 2161 // Update to the matching version. Now the extension should get enabled. | 2122 // Update to the matching version. Now the extension should get enabled. |
| 2162 UpdatePermissionsTestExtension(id, version3, ENABLED); | 2123 UpdatePermissionsTestExtension(id, version3, ENABLED); |
| 2163 } | 2124 } |
| 2164 | 2125 |
| 2165 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) { | 2126 TEST_F(ExtensionServiceTestSupervised, SupervisedUserInitiatedInstalls) { |
| 2166 InitNeedCustodianApprovalFieldTrial(true); | |
| 2167 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 2127 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 2168 | 2128 |
| 2169 InitServices(true /* profile_is_supervised */); | 2129 InitServices(true /* profile_is_supervised */); |
| 2170 | 2130 |
| 2171 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; | 2131 MockPermissionRequestCreator* creator = new MockPermissionRequestCreator; |
| 2172 supervised_user_service()->AddPermissionRequestCreator( | 2132 supervised_user_service()->AddPermissionRequestCreator( |
| 2173 base::WrapUnique(creator)); | 2133 base::WrapUnique(creator)); |
| 2174 | 2134 |
| 2175 base::FilePath path = data_dir().AppendASCII("good.crx"); | 2135 base::FilePath path = data_dir().AppendASCII("good.crx"); |
| 2176 std::string version("1.0.0.0"); | 2136 std::string version("1.0.0.0"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2197 SimulateCustodianApprovalChangeViaSync(good_crx, version, | 2157 SimulateCustodianApprovalChangeViaSync(good_crx, version, |
| 2198 SyncChange::ACTION_DELETE); | 2158 SyncChange::ACTION_DELETE); |
| 2199 | 2159 |
| 2200 // The extension should be disabled now. | 2160 // The extension should be disabled now. |
| 2201 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); | 2161 EXPECT_TRUE(registry()->disabled_extensions().Contains(good_crx)); |
| 2202 EXPECT_TRUE(IsPendingCustodianApproval(extension->id())); | 2162 EXPECT_TRUE(IsPendingCustodianApproval(extension->id())); |
| 2203 } | 2163 } |
| 2204 | 2164 |
| 2205 TEST_F(ExtensionServiceTestSupervised, | 2165 TEST_F(ExtensionServiceTestSupervised, |
| 2206 UpdateSUInitiatedInstallWithoutPermissionIncrease) { | 2166 UpdateSUInitiatedInstallWithoutPermissionIncrease) { |
| 2207 InitNeedCustodianApprovalFieldTrial(true); | |
| 2208 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 2167 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 2209 | 2168 |
| 2210 InitServices(true /* profile_is_supervised */); | 2169 InitServices(true /* profile_is_supervised */); |
| 2211 | 2170 |
| 2212 std::string id = InstallNoPermissionsTestExtension(false /* by_custodian */); | 2171 std::string id = InstallNoPermissionsTestExtension(false /* by_custodian */); |
| 2213 std::string version1("1"); | 2172 std::string version1("1"); |
| 2214 | 2173 |
| 2215 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); | 2174 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); |
| 2216 | 2175 |
| 2217 // The extension should be enabled now. | 2176 // The extension should be enabled now. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2236 const base::DictionaryValue* approved_extensions = | 2195 const base::DictionaryValue* approved_extensions = |
| 2237 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions); | 2196 pref_service->GetDictionary(prefs::kSupervisedUserApprovedExtensions); |
| 2238 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version); | 2197 approved_extensions->GetStringWithoutPathExpansion(id, &approved_version); |
| 2239 | 2198 |
| 2240 EXPECT_EQ(base::Version(approved_version), *extension->version()); | 2199 EXPECT_EQ(base::Version(approved_version), *extension->version()); |
| 2241 EXPECT_FALSE(IsPendingCustodianApproval(id)); | 2200 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2242 } | 2201 } |
| 2243 | 2202 |
| 2244 TEST_F(ExtensionServiceTestSupervised, | 2203 TEST_F(ExtensionServiceTestSupervised, |
| 2245 UpdateSUInitiatedInstallWithPermissionIncrease) { | 2204 UpdateSUInitiatedInstallWithPermissionIncrease) { |
| 2246 InitNeedCustodianApprovalFieldTrial(true); | |
| 2247 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 2205 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 2248 | 2206 |
| 2249 InitServices(true /* profile_is_supervised */); | 2207 InitServices(true /* profile_is_supervised */); |
| 2250 | 2208 |
| 2251 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); | 2209 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); |
| 2252 std::string version1("1"); | 2210 std::string version1("1"); |
| 2253 | 2211 |
| 2254 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); | 2212 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); |
| 2255 | 2213 |
| 2256 // The extension should be enabled now. | 2214 // The extension should be enabled now. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2282 SimulateCustodianApprovalChangeViaSync(id, version3, | 2240 SimulateCustodianApprovalChangeViaSync(id, version3, |
| 2283 SyncChange::ACTION_UPDATE); | 2241 SyncChange::ACTION_UPDATE); |
| 2284 | 2242 |
| 2285 // The extension should be enabled again. | 2243 // The extension should be enabled again. |
| 2286 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); | 2244 EXPECT_TRUE(registry()->enabled_extensions().Contains(id)); |
| 2287 EXPECT_FALSE(IsPendingCustodianApproval(id)); | 2245 EXPECT_FALSE(IsPendingCustodianApproval(id)); |
| 2288 } | 2246 } |
| 2289 | 2247 |
| 2290 TEST_F(ExtensionServiceTestSupervised, | 2248 TEST_F(ExtensionServiceTestSupervised, |
| 2291 UpdateSUInitiatedInstallWithPermissionIncreaseApprovalArrivesFirst) { | 2249 UpdateSUInitiatedInstallWithPermissionIncreaseApprovalArrivesFirst) { |
| 2292 InitNeedCustodianApprovalFieldTrial(true); | |
| 2293 InitSupervisedUserInitiatedExtensionInstallFeature(true); | 2250 InitSupervisedUserInitiatedExtensionInstallFeature(true); |
| 2294 | 2251 |
| 2295 InitServices(true /* profile_is_supervised */); | 2252 InitServices(true /* profile_is_supervised */); |
| 2296 | 2253 |
| 2297 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); | 2254 std::string id = InstallPermissionsTestExtension(false /* by_custodian */); |
| 2298 | 2255 |
| 2299 std::string version1("1"); | 2256 std::string version1("1"); |
| 2300 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); | 2257 SimulateCustodianApprovalChangeViaSync(id, version1, SyncChange::ACTION_ADD); |
| 2301 | 2258 |
| 2302 // The extension should be enabled now. | 2259 // The extension should be enabled now. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2510 break; | 2467 break; |
| 2511 } | 2468 } |
| 2512 } | 2469 } |
| 2513 } | 2470 } |
| 2514 EXPECT_TRUE(found_delete); | 2471 EXPECT_TRUE(found_delete); |
| 2515 | 2472 |
| 2516 // Make sure there is one extension, and there are no more apps. | 2473 // Make sure there is one extension, and there are no more apps. |
| 2517 EXPECT_EQ(1u, extensions_processor.data().size()); | 2474 EXPECT_EQ(1u, extensions_processor.data().size()); |
| 2518 EXPECT_TRUE(apps_processor.data().empty()); | 2475 EXPECT_TRUE(apps_processor.data().empty()); |
| 2519 } | 2476 } |
| OLD | NEW |