| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/api/permissions/permissions_api.h" | 5 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
| 6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
| 7 #include "chrome/browser/extensions/extension_prefs.h" | 7 #include "chrome/browser/extensions/extension_prefs.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 scoped_refptr<PermissionSet> granted_permissions = | 77 scoped_refptr<PermissionSet> granted_permissions = |
| 78 new PermissionSet(apis, explicit_hosts, URLPatternSet()); | 78 new PermissionSet(apis, explicit_hosts, URLPatternSet()); |
| 79 | 79 |
| 80 ExtensionPrefs* prefs = | 80 ExtensionPrefs* prefs = |
| 81 browser()->profile()->GetExtensionService()->extension_prefs(); | 81 browser()->profile()->GetExtensionService()->extension_prefs(); |
| 82 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo", | 82 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo", |
| 83 granted_permissions.get()); | 83 granted_permissions.get()); |
| 84 | 84 |
| 85 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 85 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 86 host_resolver()->AddRule("*.com", "127.0.0.1"); | 86 host_resolver()->AddRule("*.com", "127.0.0.1"); |
| 87 ASSERT_TRUE(StartTestServer()); | 87 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 88 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; | 88 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Tests that the optional permissions API works correctly. | 91 // Tests that the optional permissions API works correctly. |
| 92 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsAutoConfirm) { | 92 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsAutoConfirm) { |
| 93 // Rather than setting the granted permissions, set the UI autoconfirm flag | 93 // Rather than setting the granted permissions, set the UI autoconfirm flag |
| 94 // and run the same tests. | 94 // and run the same tests. |
| 95 PermissionsRequestFunction::SetAutoConfirmForTests(true); | 95 PermissionsRequestFunction::SetAutoConfirmForTests(true); |
| 96 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 96 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 97 host_resolver()->AddRule("*.com", "127.0.0.1"); | 97 host_resolver()->AddRule("*.com", "127.0.0.1"); |
| 98 ASSERT_TRUE(StartTestServer()); | 98 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 99 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; | 99 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Tests that the optional permissions API works correctly with complex | 102 // Tests that the optional permissions API works correctly with complex |
| 103 // permissions. | 103 // permissions. |
| 104 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ComplexOptionalPermissions) { | 104 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ComplexOptionalPermissions) { |
| 105 // Rather than setting the granted permissions, set the UI autoconfirm flag | 105 // Rather than setting the granted permissions, set the UI autoconfirm flag |
| 106 // and run the same tests. | 106 // and run the same tests. |
| 107 PermissionsRequestFunction::SetAutoConfirmForTests(true); | 107 PermissionsRequestFunction::SetAutoConfirmForTests(true); |
| 108 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 108 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 109 EXPECT_TRUE(RunExtensionTest("permissions/complex_optional")) << message_; | 109 EXPECT_TRUE(RunExtensionTest("permissions/complex_optional")) << message_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 // Test that denying the optional permissions confirmation dialog works. | 112 // Test that denying the optional permissions confirmation dialog works. |
| 113 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsDeny) { | 113 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsDeny) { |
| 114 PermissionsRequestFunction::SetAutoConfirmForTests(false); | 114 PermissionsRequestFunction::SetAutoConfirmForTests(false); |
| 115 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 115 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 116 host_resolver()->AddRule("*.com", "127.0.0.1"); | 116 host_resolver()->AddRule("*.com", "127.0.0.1"); |
| 117 ASSERT_TRUE(StartTestServer()); | 117 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 118 EXPECT_TRUE(RunExtensionTest("permissions/optional_deny")) << message_; | 118 EXPECT_TRUE(RunExtensionTest("permissions/optional_deny")) << message_; |
| 119 } | 119 } |
| 120 | 120 |
| 121 // Tests that the permissions.request function must be called from within a | 121 // Tests that the permissions.request function must be called from within a |
| 122 // user gesture. | 122 // user gesture. |
| 123 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsGesture) { | 123 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsGesture) { |
| 124 PermissionsRequestFunction::SetIgnoreUserGestureForTests(false); | 124 PermissionsRequestFunction::SetIgnoreUserGestureForTests(false); |
| 125 host_resolver()->AddRule("*.com", "127.0.0.1"); | 125 host_resolver()->AddRule("*.com", "127.0.0.1"); |
| 126 ASSERT_TRUE(StartTestServer()); | 126 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 127 EXPECT_TRUE(RunExtensionTest("permissions/optional_gesture")) << message_; | 127 EXPECT_TRUE(RunExtensionTest("permissions/optional_gesture")) << message_; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Tests that an extension can't gain access to file: URLs without the checkbox | 130 // Tests that an extension can't gain access to file: URLs without the checkbox |
| 131 // entry in prefs. There shouldn't be a warning either. | 131 // entry in prefs. There shouldn't be a warning either. |
| 132 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsFileAccess) { | 132 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsFileAccess) { |
| 133 // There shouldn't be a warning, so we shouldn't need to autoconfirm. | 133 // There shouldn't be a warning, so we shouldn't need to autoconfirm. |
| 134 PermissionsRequestFunction::SetAutoConfirmForTests(false); | 134 PermissionsRequestFunction::SetAutoConfirmForTests(false); |
| 135 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 135 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 136 | 136 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 155 | 155 |
| 156 // Test requesting, querying, and removing host permissions for host | 156 // Test requesting, querying, and removing host permissions for host |
| 157 // permissions that are a subset of the optional permissions. | 157 // permissions that are a subset of the optional permissions. |
| 158 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, HostSubsets) { | 158 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, HostSubsets) { |
| 159 PermissionsRequestFunction::SetAutoConfirmForTests(true); | 159 PermissionsRequestFunction::SetAutoConfirmForTests(true); |
| 160 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 160 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
| 161 EXPECT_TRUE(RunExtensionTest("permissions/host_subsets")) << message_; | 161 EXPECT_TRUE(RunExtensionTest("permissions/host_subsets")) << message_; |
| 162 } | 162 } |
| 163 | 163 |
| 164 } // namespace extensions | 164 } // namespace extensions |
| OLD | NEW |