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

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

Issue 7508029: Add origin permissions to the extension permissions API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix dcheck Created 9 years, 4 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) 2011 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" 6 #include "chrome/browser/extensions/extension_prefs.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/extension_permission_set.h" 11 #include "chrome/common/extensions/extension_permission_set.h"
12 #include "net/base/mock_host_resolver.h"
13
14 namespace {
15
16 static void AddPattern(URLPatternSet* extent, const std::string& pattern) {
17 int schemes = URLPattern::SCHEME_ALL;
18 extent->AddPattern(URLPattern(schemes, pattern));
19 }
20
21 } // namespace
12 22
13 class ExperimentalApiTest : public ExtensionApiTest { 23 class ExperimentalApiTest : public ExtensionApiTest {
14 public: 24 public:
15 void SetUpCommandLine(CommandLine* command_line) { 25 void SetUpCommandLine(CommandLine* command_line) {
16 ExtensionApiTest::SetUpCommandLine(command_line); 26 ExtensionApiTest::SetUpCommandLine(command_line);
17 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 27 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
18 } 28 }
19 }; 29 };
20 30
21 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PermissionsFail) { 31 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PermissionsFail) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 ASSERT_TRUE(RunExtensionTest("permissions/always_allowed")) << message_; 63 ASSERT_TRUE(RunExtensionTest("permissions/always_allowed")) << message_;
54 } 64 }
55 65
56 // Tests that the optional permissions API works correctly. 66 // Tests that the optional permissions API works correctly.
57 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsGranted) { 67 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsGranted) {
58 // Mark all the tested APIs as granted to bypass the confirmation UI. 68 // Mark all the tested APIs as granted to bypass the confirmation UI.
59 ExtensionAPIPermissionSet apis; 69 ExtensionAPIPermissionSet apis;
60 apis.insert(ExtensionAPIPermission::kTab); 70 apis.insert(ExtensionAPIPermission::kTab);
61 apis.insert(ExtensionAPIPermission::kManagement); 71 apis.insert(ExtensionAPIPermission::kManagement);
62 apis.insert(ExtensionAPIPermission::kPermissions); 72 apis.insert(ExtensionAPIPermission::kPermissions);
73 URLPatternSet explicit_hosts;
74 AddPattern(&explicit_hosts, "http://a.com/*");
75 AddPattern(&explicit_hosts, "http://*.c.com/*");
63 scoped_refptr<ExtensionPermissionSet> granted_permissions = 76 scoped_refptr<ExtensionPermissionSet> granted_permissions =
64 new ExtensionPermissionSet(apis, URLPatternSet(), URLPatternSet()); 77 new ExtensionPermissionSet(apis, explicit_hosts, URLPatternSet());
65 78
66 ExtensionPrefs* prefs = 79 ExtensionPrefs* prefs =
67 browser()->profile()->GetExtensionService()->extension_prefs(); 80 browser()->profile()->GetExtensionService()->extension_prefs();
68 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo", 81 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo",
69 granted_permissions); 82 granted_permissions);
70 83
84 host_resolver()->AddRule("*.com", "127.0.0.1");
85 ASSERT_TRUE(StartTestServer());
71 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; 86 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_;
72 } 87 }
73 88
74 // Tests that the optional permissions API works correctly. 89 // Tests that the optional permissions API works correctly.
75 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsAutoConfirm) { 90 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsAutoConfirm) {
76 // Rather than setting the granted permissions, set the UI autoconfirm flag 91 // Rather than setting the granted permissions, set the UI autoconfirm flag
77 // and run the same tests. 92 // and run the same tests.
78 RequestPermissionsFunction::SetAutoConfirmForTests(true); 93 RequestPermissionsFunction::SetAutoConfirmForTests(true);
94 host_resolver()->AddRule("*.com", "127.0.0.1");
95 ASSERT_TRUE(StartTestServer());
79 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; 96 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_;
80 } 97 }
81 98
82 // Test that denying the optional permissions confirmation dialog works. 99 // Test that denying the optional permissions confirmation dialog works.
83 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsDeny) { 100 IN_PROC_BROWSER_TEST_F(ExperimentalApiTest, OptionalPermissionsDeny) {
84 RequestPermissionsFunction::SetAutoConfirmForTests(false); 101 RequestPermissionsFunction::SetAutoConfirmForTests(false);
102 host_resolver()->AddRule("*.com", "127.0.0.1");
103 ASSERT_TRUE(StartTestServer());
85 EXPECT_TRUE(RunExtensionTest("permissions/optional_deny")) << message_; 104 EXPECT_TRUE(RunExtensionTest("permissions/optional_deny")) << message_;
86 } 105 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_permissions_api_constants.cc ('k') | chrome/common/extensions/api/extension_api.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698