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

Side by Side Diff: chrome/browser/permissions/permission_request_manager_browsertest.cc

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: rebase + include content_settings_types.h more Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/permissions/permission_request_manager.h" 5 #include "chrome/browser/permissions/permission_request_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/permissions/permission_context_base.h" 10 #include "chrome/browser/permissions/permission_context_base.h"
11 #include "chrome/browser/permissions/permission_util.h" 11 #include "chrome/browser/permissions/permission_util.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" 14 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
17 #include "components/content_settings/core/common/content_settings_types.h"
17 #include "components/variations/variations_associated_data.h" 18 #include "components/variations/variations_associated_data.h"
18 #include "content/public/browser/permission_type.h"
19 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
20 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
22 22
23 namespace { 23 namespace {
24 24
25 const char* kPermissionsKillSwitchFieldStudy = 25 const char* kPermissionsKillSwitchFieldStudy =
26 PermissionContextBase::kPermissionsKillSwitchFieldStudy; 26 PermissionContextBase::kPermissionsKillSwitchFieldStudy;
27 const char* kPermissionsKillSwitchBlockedValue = 27 const char* kPermissionsKillSwitchBlockedValue =
28 PermissionContextBase::kPermissionsKillSwitchBlockedValue; 28 PermissionContextBase::kPermissionsKillSwitchBlockedValue;
(...skipping 19 matching lines...) Expand all
48 48
49 PermissionRequestManager* GetPermissionRequestManager() { 49 PermissionRequestManager* GetPermissionRequestManager() {
50 return PermissionRequestManager::FromWebContents( 50 return PermissionRequestManager::FromWebContents(
51 browser()->tab_strip_model()->GetActiveWebContents()); 51 browser()->tab_strip_model()->GetActiveWebContents());
52 } 52 }
53 53
54 MockPermissionPromptFactory* bubble_factory() { 54 MockPermissionPromptFactory* bubble_factory() {
55 return mock_permission_prompt_factory_.get(); 55 return mock_permission_prompt_factory_.get();
56 } 56 }
57 57
58 void EnableKillSwitch(content::PermissionType permission_type) { 58 void EnableKillSwitch(ContentSettingsType content_settings_type) {
59 std::map<std::string, std::string> params; 59 std::map<std::string, std::string> params;
60 params[PermissionUtil::GetPermissionString(permission_type)] = 60 params[PermissionUtil::GetPermissionString(content_settings_type)] =
61 kPermissionsKillSwitchBlockedValue; 61 kPermissionsKillSwitchBlockedValue;
62 variations::AssociateVariationParams( 62 variations::AssociateVariationParams(
63 kPermissionsKillSwitchFieldStudy, kPermissionsKillSwitchTestGroup, 63 kPermissionsKillSwitchFieldStudy, kPermissionsKillSwitchTestGroup,
64 params); 64 params);
65 base::FieldTrialList::CreateFieldTrial(kPermissionsKillSwitchFieldStudy, 65 base::FieldTrialList::CreateFieldTrial(kPermissionsKillSwitchFieldStudy,
66 kPermissionsKillSwitchTestGroup); 66 kPermissionsKillSwitchTestGroup);
67 } 67 }
68 68
69 private: 69 private:
70 std::unique_ptr<MockPermissionPromptFactory> mock_permission_prompt_factory_; 70 std::unique_ptr<MockPermissionPromptFactory> mock_permission_prompt_factory_;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // Bubble requests should not be shown when the killswitch is on. 185 // Bubble requests should not be shown when the killswitch is on.
186 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, 186 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest,
187 KillSwitchGeolocation) { 187 KillSwitchGeolocation) {
188 ASSERT_TRUE(embedded_test_server()->Start()); 188 ASSERT_TRUE(embedded_test_server()->Start());
189 189
190 ui_test_utils::NavigateToURL( 190 ui_test_utils::NavigateToURL(
191 browser(), 191 browser(),
192 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); 192 embedded_test_server()->GetURL("/permissions/killswitch_tester.html"));
193 193
194 // Now enable the geolocation killswitch. 194 // Now enable the geolocation killswitch.
195 EnableKillSwitch(content::PermissionType::GEOLOCATION); 195 EnableKillSwitch(CONTENT_SETTINGS_TYPE_GEOLOCATION);
196 content::WebContents* web_contents = 196 content::WebContents* web_contents =
197 browser()->tab_strip_model()->GetActiveWebContents(); 197 browser()->tab_strip_model()->GetActiveWebContents();
198 198
199 std::string result; 199 std::string result;
200 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 200 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
201 web_contents, "requestGeolocation();", &result)); 201 web_contents, "requestGeolocation();", &result));
202 EXPECT_EQ("denied", result); 202 EXPECT_EQ("denied", result);
203 EXPECT_EQ(0, bubble_factory()->show_count()); 203 EXPECT_EQ(0, bubble_factory()->show_count());
204 EXPECT_EQ(0, bubble_factory()->total_request_count()); 204 EXPECT_EQ(0, bubble_factory()->total_request_count());
205 205
(...skipping 15 matching lines...) Expand all
221 // Bubble requests should not be shown when the killswitch is on. 221 // Bubble requests should not be shown when the killswitch is on.
222 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, 222 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest,
223 KillSwitchNotifications) { 223 KillSwitchNotifications) {
224 ASSERT_TRUE(embedded_test_server()->Start()); 224 ASSERT_TRUE(embedded_test_server()->Start());
225 225
226 ui_test_utils::NavigateToURL( 226 ui_test_utils::NavigateToURL(
227 browser(), 227 browser(),
228 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); 228 embedded_test_server()->GetURL("/permissions/killswitch_tester.html"));
229 229
230 // Now enable the notifications killswitch. 230 // Now enable the notifications killswitch.
231 EnableKillSwitch(content::PermissionType::NOTIFICATIONS); 231 EnableKillSwitch(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
232 content::WebContents* web_contents = 232 content::WebContents* web_contents =
233 browser()->tab_strip_model()->GetActiveWebContents(); 233 browser()->tab_strip_model()->GetActiveWebContents();
234 234
235 std::string result; 235 std::string result;
236 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 236 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
237 web_contents, "requestNotification();", &result)); 237 web_contents, "requestNotification();", &result));
238 EXPECT_EQ("denied", result); 238 EXPECT_EQ("denied", result);
239 EXPECT_EQ(0, bubble_factory()->show_count()); 239 EXPECT_EQ(0, bubble_factory()->show_count());
240 EXPECT_EQ(0, bubble_factory()->total_request_count()); 240 EXPECT_EQ(0, bubble_factory()->total_request_count());
241 241
242 // Disable the trial. 242 // Disable the trial.
243 variations::testing::ClearAllVariationParams(); 243 variations::testing::ClearAllVariationParams();
244 244
245 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestNotification();")); 245 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestNotification();"));
246 bubble_factory()->WaitForPermissionBubble(); 246 bubble_factory()->WaitForPermissionBubble();
247 EXPECT_EQ(1, bubble_factory()->show_count()); 247 EXPECT_EQ(1, bubble_factory()->show_count());
248 EXPECT_EQ(1, bubble_factory()->total_request_count()); 248 EXPECT_EQ(1, bubble_factory()->total_request_count());
249 } 249 }
250 250
251 } // anonymous namespace 251 } // anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698