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

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

Issue 2338173002: Improve permission persistence tests. (Closed)
Patch Set: Address comments Created 4 years, 3 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
« no previous file with comments | « chrome/browser/geolocation/geolocation_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_context_base.h" 5 #include "chrome/browser/permissions/permission_context_base.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/feature_list.h" 11 #include "base/feature_list.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/test/mock_entropy_provider.h" 15 #include "base/test/mock_entropy_provider.h"
16 #include "base/test/scoped_feature_list.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
18 #include "chrome/browser/infobars/infobar_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
19 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" 20 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
20 #include "chrome/browser/permissions/permission_queue_controller.h" 21 #include "chrome/browser/permissions/permission_queue_controller.h"
21 #include "chrome/browser/permissions/permission_request_id.h" 22 #include "chrome/browser/permissions/permission_request_id.h"
22 #include "chrome/browser/permissions/permission_util.h" 23 #include "chrome/browser/permissions/permission_util.h"
23 #include "chrome/common/chrome_features.h" 24 #include "chrome/common/chrome_features.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 26 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 EXPECT_EQ(CONTENT_SETTING_ASK, 295 EXPECT_EQ(CONTENT_SETTING_ASK,
295 permission_context.GetContentSettingFromMap(url, url)); 296 permission_context.GetContentSettingFromMap(url, url));
296 } 297 }
297 298
298 // Flush the dismissal counts. Enable the block on too many dismissals 299 // Flush the dismissal counts. Enable the block on too many dismissals
299 // feature, which is disabled by default. 300 // feature, which is disabled by default.
300 HostContentSettingsMapFactory::GetForProfile(profile()) 301 HostContentSettingsMapFactory::GetForProfile(profile())
301 ->ClearSettingsForOneType( 302 ->ClearSettingsForOneType(
302 CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT); 303 CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT);
303 304
304 // Set up the custom parameter. 305 base::test::ScopedFeatureList feature_list;
305 base::FieldTrialList field_trials_(nullptr); 306 feature_list.InitAndEnableFeature(features::kBlockPromptsIfDismissedOften);
306 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(
307 kPromptTrialName, kPromptGroupName);
308 base::FeatureList::ClearInstanceForTesting();
309 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
310 feature_list->RegisterFieldTrialOverride(
311 features::kBlockPromptsIfDismissedOften.name,
312 base::FeatureList::OVERRIDE_ENABLE_FEATURE, trial);
313 base::FeatureList::SetInstance(std::move(feature_list));
314 EXPECT_EQ(base::FeatureList::GetFieldTrial(
315 features::kBlockPromptsIfDismissedOften),
316 trial);
317 307
318 EXPECT_TRUE( 308 EXPECT_TRUE(
319 base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften)); 309 base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften));
320 310
321 // Sanity check independence per permission type by checking two of them. 311 // Sanity check independence per permission type by checking two of them.
322 DismissMultipleTimesAndExpectBlock(url, 312 DismissMultipleTimesAndExpectBlock(url,
323 content::PermissionType::GEOLOCATION, 313 content::PermissionType::GEOLOCATION,
324 CONTENT_SETTINGS_TYPE_GEOLOCATION, 3); 314 CONTENT_SETTINGS_TYPE_GEOLOCATION, 3);
325 DismissMultipleTimesAndExpectBlock(url, 315 DismissMultipleTimesAndExpectBlock(url,
326 content::PermissionType::NOTIFICATIONS, 316 content::PermissionType::NOTIFICATIONS,
327 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 3); 317 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 3);
328 base::FeatureList::ClearInstanceForTesting();
329 } 318 }
330 319
331 void TestVariationBlockOnSeveralDismissals_TestContent() { 320 void TestVariationBlockOnSeveralDismissals_TestContent() {
332 GURL url("https://www.google.com"); 321 GURL url("https://www.google.com");
333 NavigateAndCommit(url); 322 NavigateAndCommit(url);
334 base::HistogramTester histograms; 323 base::HistogramTester histograms;
335 324
336 // Set up the custom parameter and custom value. 325 // Set up the custom parameter and custom value.
337 base::FieldTrialList field_trials_(nullptr); 326 base::FieldTrialList field_trials_(nullptr);
338 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( 327 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial(
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 TestParallelRequests(CONTENT_SETTING_ALLOW); 654 TestParallelRequests(CONTENT_SETTING_ALLOW);
666 } 655 }
667 656
668 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) { 657 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) {
669 TestParallelRequests(CONTENT_SETTING_BLOCK); 658 TestParallelRequests(CONTENT_SETTING_BLOCK);
670 } 659 }
671 660
672 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) { 661 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) {
673 TestParallelRequests(CONTENT_SETTING_ASK); 662 TestParallelRequests(CONTENT_SETTING_ASK);
674 } 663 }
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/geolocation_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698