| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/extensions/permissions_updater_delegate_chrome
os.h" | 5 #include "chrome/browser/chromeos/extensions/permissions_updater_delegate_chrome
os.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chromeos/login/login_state.h" | 12 #include "chromeos/login/login_state.h" |
| 13 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
| 14 #include "extensions/common/manifest.h" | 14 #include "extensions/common/manifest.h" |
| 15 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
| 16 #include "extensions/common/permissions/api_permission.h" | 16 #include "extensions/common/permissions/api_permission.h" |
| 17 #include "extensions/common/permissions/api_permission_set.h" | 17 #include "extensions/common/permissions/api_permission_set.h" |
| 18 #include "extensions/common/permissions/manifest_permission.h" | |
| 19 #include "extensions/common/permissions/manifest_permission_set.h" | 18 #include "extensions/common/permissions/manifest_permission_set.h" |
| 19 #include "extensions/common/permissions/mock_manifest_permission.h" |
| 20 #include "extensions/common/permissions/permission_set.h" | 20 #include "extensions/common/permissions/permission_set.h" |
| 21 #include "extensions/common/url_pattern.h" | 21 #include "extensions/common/url_pattern.h" |
| 22 #include "extensions/common/url_pattern_set.h" | 22 #include "extensions/common/url_pattern_set.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch"; | 29 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch"; |
| 30 const char kBogusId[] = "bogus"; | 30 const char kBogusId[] = "bogus"; |
| 31 | 31 |
| 32 // TODO(isandrk, crbug.com/715638): Extract MockManifestPermission into its own | |
| 33 // file (since it's duplicated in two places). | |
| 34 class MockManifestPermission : public ManifestPermission { | |
| 35 public: | |
| 36 MockManifestPermission(const std::string& name) | |
| 37 : name_(name) { | |
| 38 } | |
| 39 | |
| 40 std::string name() const override { return name_; } | |
| 41 | |
| 42 std::string id() const override { return name(); } | |
| 43 | |
| 44 PermissionIDSet GetPermissions() const override { return PermissionIDSet(); } | |
| 45 | |
| 46 bool FromValue(const base::Value* value) override { return true; } | |
| 47 | |
| 48 std::unique_ptr<base::Value> ToValue() const override { | |
| 49 return base::MakeUnique<base::Value>(); | |
| 50 } | |
| 51 | |
| 52 ManifestPermission* Diff(const ManifestPermission* rhs) const override { | |
| 53 const MockManifestPermission* other = | |
| 54 static_cast<const MockManifestPermission*>(rhs); | |
| 55 EXPECT_EQ(name_, other->name_); | |
| 56 return NULL; | |
| 57 } | |
| 58 | |
| 59 ManifestPermission* Union(const ManifestPermission* rhs) const override { | |
| 60 const MockManifestPermission* other = | |
| 61 static_cast<const MockManifestPermission*>(rhs); | |
| 62 EXPECT_EQ(name_, other->name_); | |
| 63 return new MockManifestPermission(name_); | |
| 64 } | |
| 65 | |
| 66 ManifestPermission* Intersect(const ManifestPermission* rhs) const override { | |
| 67 const MockManifestPermission* other = | |
| 68 static_cast<const MockManifestPermission*>(rhs); | |
| 69 EXPECT_EQ(name_, other->name_); | |
| 70 return new MockManifestPermission(name_); | |
| 71 } | |
| 72 | |
| 73 private: | |
| 74 std::string name_; | |
| 75 }; | |
| 76 | |
| 77 scoped_refptr<Extension> CreateExtension(const std::string& id) { | 32 scoped_refptr<Extension> CreateExtension(const std::string& id) { |
| 78 std::string error; | 33 std::string error; |
| 79 base::DictionaryValue manifest; | 34 base::DictionaryValue manifest; |
| 80 manifest.SetString(manifest_keys::kName, "test"); | 35 manifest.SetString(manifest_keys::kName, "test"); |
| 81 manifest.SetString(manifest_keys::kVersion, "0.1"); | 36 manifest.SetString(manifest_keys::kVersion, "0.1"); |
| 82 scoped_refptr<Extension> extension = Extension::Create( | 37 scoped_refptr<Extension> extension = Extension::Create( |
| 83 base::FilePath(), | 38 base::FilePath(), |
| 84 Manifest::INTERNAL, | 39 Manifest::INTERNAL, |
| 85 manifest, | 40 manifest, |
| 86 Extension::NO_FLAGS, | 41 Extension::NO_FLAGS, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 extension = CreateExtension(kBogusId); | 103 extension = CreateExtension(kBogusId); |
| 149 granted_permissions = CreatePermissions(); | 104 granted_permissions = CreatePermissions(); |
| 150 delegate.InitializePermissions(extension.get(), &granted_permissions); | 105 delegate.InitializePermissions(extension.get(), &granted_permissions); |
| 151 EXPECT_EQ(*CreatePermissions(false), *granted_permissions); | 106 EXPECT_EQ(*CreatePermissions(false), *granted_permissions); |
| 152 | 107 |
| 153 // Reset state at the end of test. | 108 // Reset state at the end of test. |
| 154 chromeos::LoginState::Shutdown(); | 109 chromeos::LoginState::Shutdown(); |
| 155 } | 110 } |
| 156 | 111 |
| 157 } // namespace extensions | 112 } // namespace extensions |
| OLD | NEW |