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

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

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

Powered by Google App Engine
This is Rietveld 408576698