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

Side by Side Diff: chrome/browser/notifications/notification_permission_context_unittest.cc

Issue 2713083003: Use ContentSetting in chrome/ instead of PermissionStatus (Closed)
Patch Set: maybe fix android compile + address comments + basic tests Created 3 years, 9 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/notifications/notification_permission_context.h" 5 #include "chrome/browser/notifications/notification_permission_context.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/test/scoped_mock_time_message_loop_task_runner.h" 9 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 10 matching lines...) Expand all
21 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 23 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 25 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 namespace { 28 namespace {
29 29
30 void DoNothing(ContentSetting content_setting) {} 30 void DoNothing(ContentSetting content_setting) {}
31 void DoNothing2(blink::mojom::PermissionStatus content_setting) {}
32 31
33 class TestNotificationPermissionContext : public NotificationPermissionContext { 32 class TestNotificationPermissionContext : public NotificationPermissionContext {
34 public: 33 public:
35 explicit TestNotificationPermissionContext(Profile* profile) 34 explicit TestNotificationPermissionContext(Profile* profile)
36 : NotificationPermissionContext(profile, 35 : NotificationPermissionContext(profile,
37 CONTENT_SETTINGS_TYPE_NOTIFICATIONS), 36 CONTENT_SETTINGS_TYPE_NOTIFICATIONS),
38 permission_set_count_(0), 37 permission_set_count_(0),
39 last_permission_set_persisted_(false), 38 last_permission_set_persisted_(false),
40 last_permission_set_setting_(CONTENT_SETTING_DEFAULT) {} 39 last_permission_set_setting_(CONTENT_SETTING_DEFAULT) {}
41 40
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 290
292 PermissionManager* permission_manager = 291 PermissionManager* permission_manager =
293 PermissionManagerFactory::GetForProfile( 292 PermissionManagerFactory::GetForProfile(
294 profile()->GetOffTheRecordProfile()); 293 profile()->GetOffTheRecordProfile());
295 294
296 // Request and cancel the permission via PermissionManager. That way if 295 // Request and cancel the permission via PermissionManager. That way if
297 // https://crbug.com/586944 regresses, then as well as the EXPECT_EQs below 296 // https://crbug.com/586944 regresses, then as well as the EXPECT_EQs below
298 // failing, PermissionManager::OnPermissionsRequestResponseStatus will crash. 297 // failing, PermissionManager::OnPermissionsRequestResponseStatus will crash.
299 int request_id = permission_manager->RequestPermission( 298 int request_id = permission_manager->RequestPermission(
300 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, web_contents()->GetMainFrame(), 299 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, web_contents()->GetMainFrame(),
301 url.GetOrigin(), true /* user_gesture */, base::Bind(&DoNothing2)); 300 url.GetOrigin(), true /* user_gesture */, base::Bind(&DoNothing));
302 301
303 permission_manager->CancelPermissionRequest(request_id); 302 permission_manager->CancelPermissionRequest(request_id);
304 303
305 task_runner->FastForwardBy(base::TimeDelta::FromDays(1)); 304 task_runner->FastForwardBy(base::TimeDelta::FromDays(1));
306 305
307 EXPECT_EQ(0, permission_context.permission_set_count()); 306 EXPECT_EQ(0, permission_context.permission_set_count());
308 EXPECT_EQ(CONTENT_SETTING_ASK, 307 EXPECT_EQ(CONTENT_SETTING_ASK,
309 permission_context.GetContentSettingFromMap(url, url)); 308 permission_context.GetContentSettingFromMap(url, url));
310 } 309 }
311 310
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // After another 2.5 seconds, the second permission request should also have 360 // After another 2.5 seconds, the second permission request should also have
362 // received a response. 361 // received a response.
363 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500)); 362 task_runner->FastForwardBy(base::TimeDelta::FromMilliseconds(2500));
364 EXPECT_EQ(2, permission_context.permission_set_count()); 363 EXPECT_EQ(2, permission_context.permission_set_count());
365 EXPECT_TRUE(permission_context.last_permission_set_persisted()); 364 EXPECT_TRUE(permission_context.last_permission_set_persisted());
366 EXPECT_EQ(CONTENT_SETTING_BLOCK, 365 EXPECT_EQ(CONTENT_SETTING_BLOCK,
367 permission_context.last_permission_set_setting()); 366 permission_context.last_permission_set_setting());
368 EXPECT_EQ(CONTENT_SETTING_BLOCK, 367 EXPECT_EQ(CONTENT_SETTING_BLOCK,
369 permission_context.GetContentSettingFromMap(url, url)); 368 permission_context.GetContentSettingFromMap(url, url));
370 } 369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698