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

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

Issue 156843004: Remove ExtensionService::extension_prefs() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: additional cleanup Created 6 years, 10 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) 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_service.h"
8 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
10 #include "extensions/browser/extension_prefs.h" 9 #include "extensions/browser/extension_prefs.h"
11 #include "extensions/common/permissions/permission_set.h" 10 #include "extensions/common/permissions/permission_set.h"
12 #include "extensions/common/switches.h" 11 #include "extensions/common/switches.h"
13 #include "net/dns/mock_host_resolver.h" 12 #include "net/dns/mock_host_resolver.h"
14 13
15 namespace extensions { 14 namespace extensions {
16 15
17 namespace { 16 namespace {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Mark all the tested APIs as granted to bypass the confirmation UI. 71 // Mark all the tested APIs as granted to bypass the confirmation UI.
73 APIPermissionSet apis; 72 APIPermissionSet apis;
74 apis.insert(APIPermission::kBookmark); 73 apis.insert(APIPermission::kBookmark);
75 ManifestPermissionSet manifest_permissions; 74 ManifestPermissionSet manifest_permissions;
76 URLPatternSet explicit_hosts; 75 URLPatternSet explicit_hosts;
77 AddPattern(&explicit_hosts, "http://*.c.com/*"); 76 AddPattern(&explicit_hosts, "http://*.c.com/*");
78 scoped_refptr<PermissionSet> granted_permissions = 77 scoped_refptr<PermissionSet> granted_permissions =
79 new PermissionSet(apis, manifest_permissions, 78 new PermissionSet(apis, manifest_permissions,
80 explicit_hosts, URLPatternSet()); 79 explicit_hosts, URLPatternSet());
81 80
82 ExtensionPrefs* prefs = 81 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser()->profile());
83 browser()->profile()->GetExtensionService()->extension_prefs();
84 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo", 82 prefs->AddGrantedPermissions("kjmkgkdkpedkejedfhmfcenooemhbpbo",
85 granted_permissions.get()); 83 granted_permissions.get());
86 84
87 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); 85 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
88 host_resolver()->AddRule("*.com", "127.0.0.1"); 86 host_resolver()->AddRule("*.com", "127.0.0.1");
89 ASSERT_TRUE(StartEmbeddedTestServer()); 87 ASSERT_TRUE(StartEmbeddedTestServer());
90 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_; 88 EXPECT_TRUE(RunExtensionTest("permissions/optional")) << message_;
91 } 89 }
92 90
93 // Tests that the optional permissions API works correctly. 91 // Tests that the optional permissions API works correctly.
(...skipping 25 matching lines...) Expand all
119 EXPECT_TRUE(RunExtensionTest("permissions/optional_gesture")) << message_; 117 EXPECT_TRUE(RunExtensionTest("permissions/optional_gesture")) << message_;
120 } 118 }
121 119
122 // Tests that an extension can't gain access to file: URLs without the checkbox 120 // Tests that an extension can't gain access to file: URLs without the checkbox
123 // entry in prefs. There shouldn't be a warning either. 121 // entry in prefs. There shouldn't be a warning either.
124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsFileAccess) { 122 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OptionalPermissionsFileAccess) {
125 // There shouldn't be a warning, so we shouldn't need to autoconfirm. 123 // There shouldn't be a warning, so we shouldn't need to autoconfirm.
126 PermissionsRequestFunction::SetAutoConfirmForTests(false); 124 PermissionsRequestFunction::SetAutoConfirmForTests(false);
127 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); 125 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
128 126
129 ExtensionPrefs* prefs = 127 ExtensionPrefs* prefs = ExtensionPrefs::Get(browser()->profile());
130 browser()->profile()->GetExtensionService()->extension_prefs();
131 128
132 EXPECT_TRUE( 129 EXPECT_TRUE(
133 RunExtensionTestNoFileAccess("permissions/file_access_no")) << message_; 130 RunExtensionTestNoFileAccess("permissions/file_access_no")) << message_;
134 EXPECT_FALSE(prefs->AllowFileAccess("dgloelfbnddbdacakahpogklfdcccbib")); 131 EXPECT_FALSE(prefs->AllowFileAccess("dgloelfbnddbdacakahpogklfdcccbib"));
135 132
136 EXPECT_TRUE(RunExtensionTest("permissions/file_access_yes")) << message_; 133 EXPECT_TRUE(RunExtensionTest("permissions/file_access_yes")) << message_;
137 // TODO(kalman): ugh, it would be nice to test this condition, but it seems 134 // TODO(kalman): ugh, it would be nice to test this condition, but it seems
138 // like there's somehow a race here where the prefs aren't updated in time 135 // like there's somehow a race here where the prefs aren't updated in time
139 // with the "allow file access" bit, so we'll just have to trust that 136 // with the "allow file access" bit, so we'll just have to trust that
140 // RunExtensionTest (unlike RunExtensionTestNoFileAccess) does indeed 137 // RunExtensionTest (unlike RunExtensionTestNoFileAccess) does indeed
141 // not set the allow file access bit. Otherwise this test doesn't mean 138 // not set the allow file access bit. Otherwise this test doesn't mean
142 // a whole lot (i.e. file access works - but it'd better not be the case 139 // a whole lot (i.e. file access works - but it'd better not be the case
143 // that the extension actually has file access, since that'd be the bug 140 // that the extension actually has file access, since that'd be the bug
144 // that this is supposed to be testing). 141 // that this is supposed to be testing).
145 //EXPECT_TRUE(prefs->AllowFileAccess("hlonmbgfjccgolnaboonlakjckinmhmd")); 142 //EXPECT_TRUE(prefs->AllowFileAccess("hlonmbgfjccgolnaboonlakjckinmhmd"));
146 } 143 }
147 144
148 // Test requesting, querying, and removing host permissions for host 145 // Test requesting, querying, and removing host permissions for host
149 // permissions that are a subset of the optional permissions. 146 // permissions that are a subset of the optional permissions.
150 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, HostSubsets) { 147 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, HostSubsets) {
151 PermissionsRequestFunction::SetAutoConfirmForTests(true); 148 PermissionsRequestFunction::SetAutoConfirmForTests(true);
152 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); 149 PermissionsRequestFunction::SetIgnoreUserGestureForTests(true);
153 EXPECT_TRUE(RunExtensionTest("permissions/host_subsets")) << message_; 150 EXPECT_TRUE(RunExtensionTest("permissions/host_subsets")) << message_;
154 } 151 }
155 152
156 } // namespace extensions 153 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698