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/permissions/permission_message_test_util.h" | 11 #include "extensions/common/permissions/permission_message_test_util.h" |
12 #include "extensions/common/permissions/permissions_data.h" | 12 #include "extensions/common/permissions/permissions_data.h" |
13 #include "extensions/common/switches.h" | 13 #include "extensions/common/switches.h" |
| 14 #include "extensions/common/test/scoped_command_line_switch.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 |
19 // Tests that ChromePermissionMessageProvider produces the expected messages for | 20 // Tests that ChromePermissionMessageProvider produces the expected messages for |
20 // various combinations of app/extension permissions. | 21 // various combinations of app/extension permissions. |
21 class PermissionMessageCombinationsUnittest : public testing::Test { | 22 class PermissionMessageCombinationsUnittest : public testing::Test { |
22 public: | 23 public: |
23 PermissionMessageCombinationsUnittest() | 24 PermissionMessageCombinationsUnittest() |
24 : message_provider_(new ChromePermissionMessageProvider()) {} | 25 : message_provider_(new ChromePermissionMessageProvider()) {} |
25 ~PermissionMessageCombinationsUnittest() override {} | 26 ~PermissionMessageCombinationsUnittest() override {} |
26 | 27 |
27 // Overridden from testing::Test: | 28 // Overridden from testing::Test: |
28 void SetUp() override { | 29 void SetUp() override { |
29 testing::Test::SetUp(); | 30 testing::Test::SetUp(); |
30 // Force creation of ExtensionPrefs before adding extensions. | 31 // Force creation of ExtensionPrefs before adding extensions. |
31 env_.GetExtensionPrefs(); | 32 env_.GetExtensionPrefs(); |
32 | 33 |
33 // Whitelist a known extension id so we can test all permissions. This ID | 34 // Whitelist a known extension id so we can test all permissions. This ID |
34 // will be used for each test app. | 35 // will be used for each test app. |
35 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 36 command_line_.reset(new ScopedCommandLineSwitch( |
36 switches::kWhitelistedExtensionID, "ahplfneplbnjcflhdgkkjeiglkkfeelb"); | 37 switches::kWhitelistedExtensionID, "ahplfneplbnjcflhdgkkjeiglkkfeelb")); |
37 } | 38 } |
38 | 39 |
39 protected: | 40 protected: |
40 // Create and install an app or extension with the given manifest JSON string. | 41 // Create and install an app or extension with the given manifest JSON string. |
41 // Single-quotes in the string will be replaced with double quotes. | 42 // Single-quotes in the string will be replaced with double quotes. |
42 void CreateAndInstall(const std::string& json_manifest) { | 43 void CreateAndInstall(const std::string& json_manifest) { |
43 // Add the manifest key so that the ID will be the whitelisted ID. | 44 // Add the manifest key so that the ID will be the whitelisted ID. |
44 std::string json_manifest_with_key = json_manifest; | 45 std::string json_manifest_with_key = json_manifest; |
45 json_manifest_with_key.replace(json_manifest.length() - 1, | 46 json_manifest_with_key.replace(json_manifest.length() - 1, |
46 json_manifest.length(), | 47 json_manifest.length(), |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 expected_submessages.push_back(expected_submessages_5); | 198 expected_submessages.push_back(expected_submessages_5); |
198 return VerifyPermissionMessagesWithSubmessages(app_->permissions_data(), | 199 return VerifyPermissionMessagesWithSubmessages(app_->permissions_data(), |
199 expected_messages, | 200 expected_messages, |
200 expected_submessages, false); | 201 expected_submessages, false); |
201 } | 202 } |
202 | 203 |
203 private: | 204 private: |
204 extensions::TestExtensionEnvironment env_; | 205 extensions::TestExtensionEnvironment env_; |
205 scoped_ptr<ChromePermissionMessageProvider> message_provider_; | 206 scoped_ptr<ChromePermissionMessageProvider> message_provider_; |
206 scoped_refptr<const Extension> app_; | 207 scoped_refptr<const Extension> app_; |
| 208 // Whitelist a known extension id so we can test all permissions. This ID |
| 209 // will be used for each test app. |
| 210 scoped_ptr<ScopedCommandLineSwitch> command_line_; |
207 | 211 |
208 DISALLOW_COPY_AND_ASSIGN(PermissionMessageCombinationsUnittest); | 212 DISALLOW_COPY_AND_ASSIGN(PermissionMessageCombinationsUnittest); |
209 }; | 213 }; |
210 | 214 |
211 // Test that the USB, Bluetooth and Serial permissions do not coalesce on their | 215 // Test that the USB, Bluetooth and Serial permissions do not coalesce on their |
212 // own, but do coalesce when more than 1 is present. | 216 // own, but do coalesce when more than 1 is present. |
213 TEST_F(PermissionMessageCombinationsUnittest, USBSerialBluetoothCoalescing) { | 217 TEST_F(PermissionMessageCombinationsUnittest, USBSerialBluetoothCoalescing) { |
214 // Test that the USB permission does not coalesce on its own. | 218 // Test that the USB permission does not coalesce on its own. |
215 CreateAndInstall( | 219 CreateAndInstall( |
216 "{" | 220 "{" |
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1170 // TODO(sashab): Add a test that ensures that all permissions that can generate | 1174 // TODO(sashab): Add a test that ensures that all permissions that can generate |
1171 // a coalesced message can also generate a message on their own (i.e. ensure | 1175 // a coalesced message can also generate a message on their own (i.e. ensure |
1172 // that no permissions only modify other permissions). | 1176 // that no permissions only modify other permissions). |
1173 | 1177 |
1174 // TODO(sashab): Add a test for every permission message combination that can | 1178 // TODO(sashab): Add a test for every permission message combination that can |
1175 // generate a message. | 1179 // generate a message. |
1176 | 1180 |
1177 // TODO(aboxhall): Add tests for the automation API permission messages. | 1181 // TODO(aboxhall): Add tests for the automation API permission messages. |
1178 | 1182 |
1179 } // namespace extensions | 1183 } // namespace extensions |
OLD | NEW |