| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/test/values_test_util.h" | 7 #include "base/test/values_test_util.h" |
| 8 #include "chrome/browser/extensions/test_extension_environment.h" | 8 #include "chrome/browser/extensions/test_extension_environment.h" |
| 9 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" | 9 #include "chrome/common/extensions/permissions/chrome_permission_message_provide
r.h" |
| 10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
| 11 #include "extensions/common/features/simple_feature.h" |
| 11 #include "extensions/common/permissions/permission_message_test_util.h" | 12 #include "extensions/common/permissions/permission_message_test_util.h" |
| 12 #include "extensions/common/permissions/permissions_data.h" | 13 #include "extensions/common/permissions/permissions_data.h" |
| 13 #include "extensions/common/switches.h" | 14 #include "extensions/common/switches.h" |
| 14 #include "testing/gmock/include/gmock/gmock-matchers.h" | 15 #include "testing/gmock/include/gmock/gmock-matchers.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 20 const char kWhitelistedExtensionID[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 21 |
| 19 // Tests that ChromePermissionMessageProvider produces the expected messages for | 22 // Tests that ChromePermissionMessageProvider produces the expected messages for |
| 20 // various combinations of app/extension permissions. | 23 // various combinations of app/extension permissions. |
| 21 class PermissionMessageCombinationsUnittest : public testing::Test { | 24 class PermissionMessageCombinationsUnittest : public testing::Test { |
| 22 public: | 25 public: |
| 23 PermissionMessageCombinationsUnittest() | 26 PermissionMessageCombinationsUnittest() |
| 24 : message_provider_(new ChromePermissionMessageProvider()) {} | 27 : message_provider_(new ChromePermissionMessageProvider()) {} |
| 25 ~PermissionMessageCombinationsUnittest() override {} | 28 ~PermissionMessageCombinationsUnittest() override {} |
| 26 | 29 |
| 27 // Overridden from testing::Test: | 30 // Overridden from testing::Test: |
| 28 void SetUp() override { | 31 void SetUp() override { |
| 29 testing::Test::SetUp(); | 32 testing::Test::SetUp(); |
| 30 // Force creation of ExtensionPrefs before adding extensions. | 33 // Force creation of ExtensionPrefs before adding extensions. |
| 31 env_.GetExtensionPrefs(); | 34 env_.GetExtensionPrefs(); |
| 35 |
| 36 // Whitelist a known extension id so we can test all permissions. This ID |
| 37 // will be used for each test app. |
| 38 extensions::SimpleFeature::SetWhitelistedExtensionId( |
| 39 kWhitelistedExtensionID); |
| 32 } | 40 } |
| 33 | 41 |
| 34 protected: | 42 protected: |
| 35 // Create and install an app or extension with the given manifest JSON string. | 43 // Create and install an app or extension with the given manifest JSON string. |
| 36 // Single-quotes in the string will be replaced with double quotes. | 44 // Single-quotes in the string will be replaced with double quotes. |
| 37 void CreateAndInstall(const std::string& json_manifest) { | 45 void CreateAndInstall(const std::string& json_manifest) { |
| 38 std::string json_manifest_with_double_quotes = json_manifest; | 46 std::string json_manifest_with_double_quotes = json_manifest; |
| 39 std::replace(json_manifest_with_double_quotes.begin(), | 47 std::replace(json_manifest_with_double_quotes.begin(), |
| 40 json_manifest_with_double_quotes.end(), '\'', '"'); | 48 json_manifest_with_double_quotes.end(), '\'', '"'); |
| 41 app_ = env_.MakeExtension( | 49 app_ = env_.MakeExtension( |
| 42 *base::test::ParseJson(json_manifest_with_double_quotes)); | 50 *base::test::ParseJson(json_manifest_with_double_quotes), |
| 43 // Add the app to any whitelists so we can test all permissions. | 51 kWhitelistedExtensionID); |
| 44 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 45 switches::kWhitelistedExtensionID, app_->id()); | |
| 46 } | 52 } |
| 47 | 53 |
| 48 // Checks whether the currently installed app or extension produces the given | 54 // Checks whether the currently installed app or extension produces the given |
| 49 // permission messages. Call this after installing an app with the expected | 55 // permission messages. Call this after installing an app with the expected |
| 50 // permission messages. The messages are tested for existence in any order. | 56 // permission messages. The messages are tested for existence in any order. |
| 51 testing::AssertionResult CheckManifestProducesPermissions() { | 57 testing::AssertionResult CheckManifestProducesPermissions() { |
| 52 return VerifyNoPermissionMessages(app_->permissions_data()); | 58 return VerifyNoPermissionMessages(app_->permissions_data()); |
| 53 } | 59 } |
| 54 testing::AssertionResult CheckManifestProducesPermissions( | 60 testing::AssertionResult CheckManifestProducesPermissions( |
| 55 const std::string& expected_message_1) { | 61 const std::string& expected_message_1) { |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 // TODO(sashab): Add a test that ensures that all permissions that can generate | 1169 // TODO(sashab): Add a test that ensures that all permissions that can generate |
| 1164 // a coalesced message can also generate a message on their own (i.e. ensure | 1170 // a coalesced message can also generate a message on their own (i.e. ensure |
| 1165 // that no permissions only modify other permissions). | 1171 // that no permissions only modify other permissions). |
| 1166 | 1172 |
| 1167 // TODO(sashab): Add a test for every permission message combination that can | 1173 // TODO(sashab): Add a test for every permission message combination that can |
| 1168 // generate a message. | 1174 // generate a message. |
| 1169 | 1175 |
| 1170 // TODO(aboxhall): Add tests for the automation API permission messages. | 1176 // TODO(aboxhall): Add tests for the automation API permission messages. |
| 1171 | 1177 |
| 1172 } // namespace extensions | 1178 } // namespace extensions |
| OLD | NEW |