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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 URLPatternSet explicit_hosts; | 78 URLPatternSet explicit_hosts; |
79 AddPattern(&explicit_hosts, "http://*.c.com/*"); | 79 AddPattern(&explicit_hosts, "http://*.c.com/*"); |
80 scoped_refptr<PermissionSet> granted_permissions = | 80 scoped_refptr<PermissionSet> granted_permissions = |
81 new PermissionSet(apis, explicit_hosts, URLPatternSet()); | 81 new PermissionSet(apis, explicit_hosts, URLPatternSet()); |
82 | 82 |
83 extensions::ExtensionPrefs* prefs = | 83 extensions::ExtensionPrefs* prefs = |
84 browser()->profile()->GetExtensionService()->extension_prefs(); | 84 browser()->profile()->GetExtensionService()->extension_prefs(); |
85 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo", | 85 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo", |
86 granted_permissions); | 86 granted_permissions); |
87 | 87 |
88 RequestPermissionsFunction::SetIgnoreUserGestureForTests(true); | 88 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
89 host_resolver()->AddRule("*.com", "127.0.0.1"); | 89 host_resolver()->AddRule("*.com", "127.0.0.1"); |
90 ASSERT_TRUE(StartTestServer()); | 90 ASSERT_TRUE(StartTestServer()); |
91 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; | 91 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; |
92 } | 92 } |
93 | 93 |
94 // Tests that the optional permissions API works correctly. | 94 // Tests that the optional permissions API works correctly. |
95 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsAutoConfirm) { | 95 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsAutoConfirm) { |
96 // Rather than setting the granted permissions, set the UI autoconfirm flag | 96 // Rather than setting the granted permissions, set the UI autoconfirm flag |
97 // and run the same tests. | 97 // and run the same tests. |
98 RequestPermissionsFunction::SetAutoConfirmForTests(true); | 98 PermissionsRequestFunction::SetAutoConfirmForTests(true); |
99 RequestPermissionsFunction::SetIgnoreUserGestureForTests(true); | 99 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
100 host_resolver()->AddRule("*.com", "127.0.0.1"); | 100 host_resolver()->AddRule("*.com", "127.0.0.1"); |
101 ASSERT_TRUE(StartTestServer()); | 101 ASSERT_TRUE(StartTestServer()); |
102 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; | 102 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; |
103 } | 103 } |
104 | 104 |
105 // Tests that the optional permissions API works correctly with complex | 105 // Tests that the optional permissions API works correctly with complex |
106 // permissions. | 106 // permissions. |
107 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ComplexOptionalPermissions) { | 107 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ComplexOptionalPermissions) { |
108 // Rather than setting the granted permissions, set the UI autoconfirm flag | 108 // Rather than setting the granted permissions, set the UI autoconfirm flag |
109 // and run the same tests. | 109 // and run the same tests. |
110 RequestPermissionsFunction::SetAutoConfirmForTests(true); | 110 PermissionsRequestFunction::SetAutoConfirmForTests(true); |
111 RequestPermissionsFunction::SetIgnoreUserGestureForTests(true); | 111 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
112 EXPECT_TRUE(RunExtensionTest("permissions/complex_optional")) << message_; | 112 EXPECT_TRUE(RunExtensionTest("permissions/complex_optional")) << message_; |
113 } | 113 } |
114 | 114 |
115 // Test that denying the optional permissions confirmation dialog works. | 115 // Test that denying the optional permissions confirmation dialog works. |
116 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsDeny) { | 116 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsDeny) { |
117 RequestPermissionsFunction::SetAutoConfirmForTests(false); | 117 PermissionsRequestFunction::SetAutoConfirmForTests(false); |
118 RequestPermissionsFunction::SetIgnoreUserGestureForTests(true); | 118 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
119 host_resolver()->AddRule("*.com", "127.0.0.1"); | 119 host_resolver()->AddRule("*.com", "127.0.0.1"); |
120 ASSERT_TRUE(StartTestServer()); | 120 ASSERT_TRUE(StartTestServer()); |
121 EXPECT_TRUE(RunExtensionTest("permissions/optional_deny")) << message_; | 121 EXPECT_TRUE(RunExtensionTest("permissions/optional_deny")) << message_; |
122 } | 122 } |
123 | 123 |
124 // Tests that the permissions.request function must be called from within a | 124 // Tests that the permissions.request function must be called from within a |
125 // user gesture. | 125 // user gesture. |
126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsGesture) { | 126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsGesture) { |
127 RequestPermissionsFunction::SetIgnoreUserGestureForTests(false); | 127 PermissionsRequestFunction::SetIgnoreUserGestureForTests(false); |
128 host_resolver()->AddRule("*.com", "127.0.0.1"); | 128 host_resolver()->AddRule("*.com", "127.0.0.1"); |
129 ASSERT_TRUE(StartTestServer()); | 129 ASSERT_TRUE(StartTestServer()); |
130 EXPECT_TRUE(RunExtensionTest("permissions/optional_gesture")) << message_; | 130 EXPECT_TRUE(RunExtensionTest("permissions/optional_gesture")) << message_; |
131 } | 131 } |
OLD | NEW |