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

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

Issue 7432006: Add an experimental permissions API for extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698