Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/browser/extensions/permission_message_combinations_unittest.cc

Issue 1076393002: Revert of Cache --whitelisted-extension-id in SimpleFeature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/test_extension_environment.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
12 #include "extensions/common/permissions/permission_message_test_util.h" 11 #include "extensions/common/permissions/permission_message_test_util.h"
13 #include "extensions/common/permissions/permissions_data.h" 12 #include "extensions/common/permissions/permissions_data.h"
14 #include "extensions/common/switches.h" 13 #include "extensions/common/switches.h"
15 #include "testing/gmock/include/gmock/gmock-matchers.h" 14 #include "testing/gmock/include/gmock/gmock-matchers.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 namespace extensions { 17 namespace extensions {
19 18
20 const char kWhitelistedExtensionID[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
21
22 // Tests that ChromePermissionMessageProvider produces the expected messages for 19 // Tests that ChromePermissionMessageProvider produces the expected messages for
23 // various combinations of app/extension permissions. 20 // various combinations of app/extension permissions.
24 class PermissionMessageCombinationsUnittest : public testing::Test { 21 class PermissionMessageCombinationsUnittest : public testing::Test {
25 public: 22 public:
26 PermissionMessageCombinationsUnittest() 23 PermissionMessageCombinationsUnittest()
27 : message_provider_(new ChromePermissionMessageProvider()), 24 : message_provider_(new ChromePermissionMessageProvider()) {}
28 whitelisted_extension_id_(kWhitelistedExtensionID) {}
29 ~PermissionMessageCombinationsUnittest() override {} 25 ~PermissionMessageCombinationsUnittest() override {}
30 26
31 // Overridden from testing::Test: 27 // Overridden from testing::Test:
32 void SetUp() override { 28 void SetUp() override {
33 testing::Test::SetUp(); 29 testing::Test::SetUp();
34 // Force creation of ExtensionPrefs before adding extensions. 30 // Force creation of ExtensionPrefs before adding extensions.
35 env_.GetExtensionPrefs(); 31 env_.GetExtensionPrefs();
36 } 32 }
37 33
38 protected: 34 protected:
39 // Create and install an app or extension with the given manifest JSON string. 35 // Create and install an app or extension with the given manifest JSON string.
40 // Single-quotes in the string will be replaced with double quotes. 36 // Single-quotes in the string will be replaced with double quotes.
41 void CreateAndInstall(const std::string& json_manifest) { 37 void CreateAndInstall(const std::string& json_manifest) {
42 std::string json_manifest_with_double_quotes = json_manifest; 38 std::string json_manifest_with_double_quotes = json_manifest;
43 std::replace(json_manifest_with_double_quotes.begin(), 39 std::replace(json_manifest_with_double_quotes.begin(),
44 json_manifest_with_double_quotes.end(), '\'', '"'); 40 json_manifest_with_double_quotes.end(), '\'', '"');
45 app_ = env_.MakeExtension( 41 app_ = env_.MakeExtension(
46 *base::test::ParseJson(json_manifest_with_double_quotes), 42 *base::test::ParseJson(json_manifest_with_double_quotes));
47 kWhitelistedExtensionID); 43 // Add the app to any whitelists so we can test all permissions.
44 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
45 switches::kWhitelistedExtensionID, app_->id());
48 } 46 }
49 47
50 // Checks whether the currently installed app or extension produces the given 48 // Checks whether the currently installed app or extension produces the given
51 // permission messages. Call this after installing an app with the expected 49 // permission messages. Call this after installing an app with the expected
52 // permission messages. The messages are tested for existence in any order. 50 // permission messages. The messages are tested for existence in any order.
53 testing::AssertionResult CheckManifestProducesPermissions() { 51 testing::AssertionResult CheckManifestProducesPermissions() {
54 return VerifyNoPermissionMessages(app_->permissions_data()); 52 return VerifyNoPermissionMessages(app_->permissions_data());
55 } 53 }
56 testing::AssertionResult CheckManifestProducesPermissions( 54 testing::AssertionResult CheckManifestProducesPermissions(
57 const std::string& expected_message_1) { 55 const std::string& expected_message_1) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 expected_submessages.push_back(expected_submessages_5); 190 expected_submessages.push_back(expected_submessages_5);
193 return VerifyPermissionMessagesWithSubmessages(app_->permissions_data(), 191 return VerifyPermissionMessagesWithSubmessages(app_->permissions_data(),
194 expected_messages, 192 expected_messages,
195 expected_submessages, false); 193 expected_submessages, false);
196 } 194 }
197 195
198 private: 196 private:
199 extensions::TestExtensionEnvironment env_; 197 extensions::TestExtensionEnvironment env_;
200 scoped_ptr<ChromePermissionMessageProvider> message_provider_; 198 scoped_ptr<ChromePermissionMessageProvider> message_provider_;
201 scoped_refptr<const Extension> app_; 199 scoped_refptr<const Extension> app_;
202 // Whitelist a known extension id so we can test all permissions. This ID
203 // will be used for each test app.
204 extensions::SimpleFeature::ScopedWhitelistForTest whitelisted_extension_id_;
205 200
206 DISALLOW_COPY_AND_ASSIGN(PermissionMessageCombinationsUnittest); 201 DISALLOW_COPY_AND_ASSIGN(PermissionMessageCombinationsUnittest);
207 }; 202 };
208 203
209 // Test that the USB, Bluetooth and Serial permissions do not coalesce on their 204 // Test that the USB, Bluetooth and Serial permissions do not coalesce on their
210 // own, but do coalesce when more than 1 is present. 205 // own, but do coalesce when more than 1 is present.
211 TEST_F(PermissionMessageCombinationsUnittest, USBSerialBluetoothCoalescing) { 206 TEST_F(PermissionMessageCombinationsUnittest, USBSerialBluetoothCoalescing) {
212 // Test that the USB permission does not coalesce on its own. 207 // Test that the USB permission does not coalesce on its own.
213 CreateAndInstall( 208 CreateAndInstall(
214 "{" 209 "{"
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 // TODO(sashab): Add a test that ensures that all permissions that can generate 1163 // TODO(sashab): Add a test that ensures that all permissions that can generate
1169 // a coalesced message can also generate a message on their own (i.e. ensure 1164 // a coalesced message can also generate a message on their own (i.e. ensure
1170 // that no permissions only modify other permissions). 1165 // that no permissions only modify other permissions).
1171 1166
1172 // TODO(sashab): Add a test for every permission message combination that can 1167 // TODO(sashab): Add a test for every permission message combination that can
1173 // generate a message. 1168 // generate a message.
1174 1169
1175 // TODO(aboxhall): Add tests for the automation API permission messages. 1170 // TODO(aboxhall): Add tests for the automation API permission messages.
1176 1171
1177 } // namespace extensions 1172 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/test_extension_environment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698