Chromium Code Reviews| 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" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 public: | 22 public: |
| 23 PermissionMessageCombinationsUnittest() | 23 PermissionMessageCombinationsUnittest() |
| 24 : message_provider_(new ChromePermissionMessageProvider()) {} | 24 : message_provider_(new ChromePermissionMessageProvider()) {} |
| 25 ~PermissionMessageCombinationsUnittest() override {} | 25 ~PermissionMessageCombinationsUnittest() override {} |
| 26 | 26 |
| 27 // Overridden from testing::Test: | 27 // Overridden from testing::Test: |
| 28 void SetUp() override { | 28 void SetUp() override { |
| 29 testing::Test::SetUp(); | 29 testing::Test::SetUp(); |
| 30 // Force creation of ExtensionPrefs before adding extensions. | 30 // Force creation of ExtensionPrefs before adding extensions. |
| 31 env_.GetExtensionPrefs(); | 31 env_.GetExtensionPrefs(); |
| 32 | |
| 33 // Whitelist a known extension id so we can test all permissions. This ID | |
| 34 // will be used for each test app. | |
| 35 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 36 switches::kWhitelistedExtensionID, "ahplfneplbnjcflhdgkkjeiglkkfeelb"); | |
| 32 } | 37 } |
| 33 | 38 |
| 34 protected: | 39 protected: |
| 35 // Create and install an app or extension with the given manifest JSON string. | 40 // 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. | 41 // Single-quotes in the string will be replaced with double quotes. |
| 37 void CreateAndInstall(const std::string& json_manifest) { | 42 void CreateAndInstall(const std::string& json_manifest) { |
| 38 std::string json_manifest_with_double_quotes = json_manifest; | 43 // Add the manifest key so that the ID will be the whitelisted ID. |
| 44 std::string json_manifest_with_key = json_manifest; | |
| 45 json_manifest_with_key.replace(json_manifest.length() - 1, | |
| 46 json_manifest.length(), | |
| 47 ",'key': 'd2hpdGVsaXN0IG1l'}"); | |
|
not at google - send to devlin
2015/04/02 14:31:57
Voodoo... I suppose the 'd2hpdGVsaXN0IG1l' corresp
jackhou1
2015/04/07 23:46:21
Done.
| |
| 48 std::string json_manifest_with_double_quotes = json_manifest_with_key; | |
| 39 std::replace(json_manifest_with_double_quotes.begin(), | 49 std::replace(json_manifest_with_double_quotes.begin(), |
| 40 json_manifest_with_double_quotes.end(), '\'', '"'); | 50 json_manifest_with_double_quotes.end(), '\'', '"'); |
| 41 app_ = env_.MakeExtension( | 51 app_ = env_.MakeExtension( |
| 42 *base::test::ParseJson(json_manifest_with_double_quotes)); | 52 *base::test::ParseJson(json_manifest_with_double_quotes)); |
| 43 // Add the app to any whitelists so we can test all permissions. | |
| 44 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 45 switches::kWhitelistedExtensionID, app_->id()); | |
| 46 } | 53 } |
| 47 | 54 |
| 48 // Checks whether the currently installed app or extension produces the given | 55 // Checks whether the currently installed app or extension produces the given |
| 49 // permission messages. Call this after installing an app with the expected | 56 // permission messages. Call this after installing an app with the expected |
| 50 // permission messages. The messages are tested for existence in any order. | 57 // permission messages. The messages are tested for existence in any order. |
| 51 testing::AssertionResult CheckManifestProducesPermissions() { | 58 testing::AssertionResult CheckManifestProducesPermissions() { |
| 52 return VerifyNoPermissionMessages(app_->permissions_data()); | 59 return VerifyNoPermissionMessages(app_->permissions_data()); |
| 53 } | 60 } |
| 54 testing::AssertionResult CheckManifestProducesPermissions( | 61 testing::AssertionResult CheckManifestProducesPermissions( |
| 55 const std::string& expected_message_1) { | 62 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 | 1170 // 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 | 1171 // a coalesced message can also generate a message on their own (i.e. ensure |
| 1165 // that no permissions only modify other permissions). | 1172 // that no permissions only modify other permissions). |
| 1166 | 1173 |
| 1167 // TODO(sashab): Add a test for every permission message combination that can | 1174 // TODO(sashab): Add a test for every permission message combination that can |
| 1168 // generate a message. | 1175 // generate a message. |
| 1169 | 1176 |
| 1170 // TODO(aboxhall): Add tests for the automation API permission messages. | 1177 // TODO(aboxhall): Add tests for the automation API permission messages. |
| 1171 | 1178 |
| 1172 } // namespace extensions | 1179 } // namespace extensions |
| OLD | NEW |