Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/extensions/permissions_updater_delegate_chrome os.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chromeos/login/login_state.h" | |
| 13 #include "extensions/common/extension.h" | |
| 14 #include "extensions/common/manifest.h" | |
| 15 #include "extensions/common/manifest_constants.h" | |
| 16 #include "extensions/common/permissions/permission_set.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 namespace extensions { | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch"; | |
| 24 const char kBogusId[] = "bogus"; | |
| 25 | |
| 26 scoped_refptr<Extension> CreateExtension(const std::string& id) { | |
| 27 std::string error; | |
| 28 base::DictionaryValue manifest; | |
| 29 manifest.SetString(manifest_keys::kName, "test"); | |
| 30 manifest.SetString(manifest_keys::kVersion, "0.1"); | |
| 31 scoped_refptr<Extension> extension = Extension::Create( | |
| 32 base::FilePath(), | |
| 33 Manifest::INTERNAL, | |
| 34 manifest, | |
| 35 Extension::NO_FLAGS, | |
| 36 id, | |
| 37 &error); | |
| 38 return extension; | |
| 39 } | |
| 40 | |
| 41 std::unique_ptr<const PermissionSet> CreatePermissions() { | |
| 42 APIPermissionSet apis; | |
| 43 apis.insert(APIPermission::kAudio); | |
| 44 apis.insert(APIPermission::kClipboardRead); | |
| 45 apis.insert(APIPermission::kFullscreen); | |
| 46 auto permissions = base::MakeUnique<const PermissionSet>( | |
| 47 apis, ManifestPermissionSet(), | |
| 48 URLPatternSet(), URLPatternSet()); | |
| 49 return permissions; | |
| 50 } | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 TEST(PermissionsUpdaterDelegateChromeOSTest, NoFilteringOutsidePublicSession) { | |
| 55 PermissionsUpdaterDelegateChromeOS delegate; | |
| 56 ASSERT_FALSE(chromeos::LoginState::IsInitialized()); | |
| 57 | |
| 58 // Whitelisted extension outside PS, nothing filtered. | |
| 59 auto extension = CreateExtension(kWhitelistedId); | |
| 60 auto granted_permissions = CreatePermissions(); | |
| 61 delegate.InitializePermissions(extension.get(), &granted_permissions); | |
| 62 EXPECT_EQ(*CreatePermissions(), *granted_permissions); | |
|
Andrew T Wilson (Slow)
2017/04/11 11:32:54
This is fine, but I probably would've created sepa
Ivan Šandrk
2017/04/11 13:37:27
Acknowledged. Was thinking about this myself but t
| |
| 63 | |
| 64 // Bogus extension ID (never whitelisted) outside PS, nothing filtered. | |
| 65 extension = CreateExtension(kBogusId); | |
| 66 granted_permissions = CreatePermissions(); | |
| 67 delegate.InitializePermissions(extension.get(), &granted_permissions); | |
| 68 EXPECT_EQ(*CreatePermissions(), *granted_permissions); | |
| 69 } | |
| 70 | |
| 71 TEST(PermissionsUpdaterDelegateChromeOSTest, | |
| 72 FilterNonWhitelistedInsidePublicSession) { | |
| 73 PermissionsUpdaterDelegateChromeOS delegate; | |
| 74 // Set Public Session state. | |
| 75 chromeos::LoginState::Initialize(); | |
| 76 chromeos::LoginState::Get()->SetLoggedInState( | |
| 77 chromeos::LoginState::LOGGED_IN_ACTIVE, | |
| 78 chromeos::LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT); | |
| 79 | |
| 80 // Whitelisted extension, nothing gets filtered. | |
| 81 auto extension = CreateExtension(kWhitelistedId); | |
| 82 auto granted_permissions = CreatePermissions(); | |
| 83 delegate.InitializePermissions(extension.get(), &granted_permissions); | |
| 84 EXPECT_EQ(*CreatePermissions(), *granted_permissions); | |
| 85 | |
| 86 // Bogus extension ID (never whitelisted), ClipboardRead filtered out. | |
| 87 extension = CreateExtension(kBogusId); | |
| 88 granted_permissions = CreatePermissions(); | |
| 89 delegate.InitializePermissions(extension.get(), &granted_permissions); | |
| 90 EXPECT_FALSE(granted_permissions->HasAPIPermission( | |
| 91 APIPermission::kClipboardRead)); | |
| 92 EXPECT_EQ(2u, granted_permissions->apis().size()); | |
| 93 | |
| 94 // Reset state at the end of test. | |
| 95 chromeos::LoginState::Shutdown(); | |
| 96 } | |
| 97 | |
| 98 } // namespace extensions | |
| OLD | NEW |