OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 #include "chrome/browser/extensions/extension_prefs.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" |
6 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/extensions/extension_permission_set.h" |
7 | 12 |
8 class ExperimentalApiTest : public ExtensionApiTest { | 13 class ExperimentalApiTest : public ExtensionApiTest { |
9 public: | 14 public: |
10 void SetUpCommandLine(CommandLine* command_line) { | 15 void SetUpCommandLine(CommandLine* command_line) { |
11 ExtensionApiTest::SetUpCommandLine(command_line); | 16 ExtensionApiTest::SetUpCommandLine(command_line); |
12 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 17 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
13 } | 18 } |
14 }; | 19 }; |
15 | 20 |
16 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PermissionsFail) { | 21 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PermissionsFail) { |
(...skipping 23 matching lines...) Expand all Loading... |
40 | 45 |
41 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FaviconPermission) { | 46 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FaviconPermission) { |
42 ASSERT_TRUE(RunExtensionTest("permissions/favicon")) << message_; | 47 ASSERT_TRUE(RunExtensionTest("permissions/favicon")) << message_; |
43 } | 48 } |
44 | 49 |
45 // Test functions and APIs that are always allowed (even if you ask for no | 50 // Test functions and APIs that are always allowed (even if you ask for no |
46 // permissions). | 51 // permissions). |
47 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, AlwaysAllowed) { | 52 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, AlwaysAllowed) { |
48 ASSERT_TRUE(RunExtensionTest("permissions/always_allowed")) << message_; | 53 ASSERT_TRUE(RunExtensionTest("permissions/always_allowed")) << message_; |
49 } | 54 } |
| 55 |
| 56 // Tests that the optional permissions API works correctly. |
| 57 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsGranted) { |
| 58 // Mark all the tested APIs as granted to bypass the confirmation UI. |
| 59 ExtensionAPIPermissionSet apis; |
| 60 apis.insert(ExtensionAPIPermission::kTab); |
| 61 apis.insert(ExtensionAPIPermission::kManagement); |
| 62 apis.insert(ExtensionAPIPermission::kPermissions); |
| 63 scoped_refptr<ExtensionPermissionSet> granted_permissions = |
| 64 new ExtensionPermissionSet(apis, URLPatternSet(), URLPatternSet()); |
| 65 |
| 66 ExtensionPrefs* prefs = |
| 67 browser()->profile()->GetExtensionService()->extension_prefs(); |
| 68 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo", |
| 69 granted_permissions); |
| 70 |
| 71 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; |
| 72 } |
| 73 |
| 74 // Tests that the optional permissions API works correctly. |
| 75 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsAutoConfirm) { |
| 76 // Rather than setting the granted permissions, set the UI autoconfirm flag |
| 77 // and run the same tests. |
| 78 RequestPermissionsFunction::SetAutoConfirmForTests(true); |
| 79 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; |
| 80 } |
| 81 |
| 82 // Test that denying the optional permissions confirmation dialog works. |
| 83 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsDeny) { |
| 84 RequestPermissionsFunction::SetAutoConfirmForTests(false); |
| 85 EXPECT_TRUE(RunExtensionTest("permissions/optional_deny")) << message_; |
| 86 } |
OLD | NEW |