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

Side by Side Diff: content/browser/background_sync/background_sync_manager_unittest.cc

Issue 2908133003: Split GetPermissionStatus into GetPermissionStatusForFrame/Worker
Patch Set: Split GetPermissionStatus into GetPermissionStatusForFrame/Worker Created 3 years, 6 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 "content/browser/background_sync/background_sync_manager.h" 5 #include "content/browser/background_sync/background_sync_manager.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 background_sync_test_util::SetIgnoreNetworkChangeNotifier(true); 122 background_sync_test_util::SetIgnoreNetworkChangeNotifier(true);
123 123
124 // TODO(jkarlin): Create a new object with all of the necessary SW calls 124 // TODO(jkarlin): Create a new object with all of the necessary SW calls
125 // so that we can inject test versions instead of bringing up all of this 125 // so that we can inject test versions instead of bringing up all of this
126 // extra SW stuff. 126 // extra SW stuff.
127 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath())); 127 helper_.reset(new EmbeddedWorkerTestHelper(base::FilePath()));
128 128
129 std::unique_ptr<MockPermissionManager> mock_permission_manager( 129 std::unique_ptr<MockPermissionManager> mock_permission_manager(
130 new testing::NiceMock<MockPermissionManager>()); 130 new testing::NiceMock<MockPermissionManager>());
131 ON_CALL(*mock_permission_manager, 131 ON_CALL(*mock_permission_manager,
132 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, _, _)) 132 GetPermissionStatusForWorker(PermissionType::BACKGROUND_SYNC, _))
133 .WillByDefault(Return(blink::mojom::PermissionStatus::GRANTED)); 133 .WillByDefault(Return(blink::mojom::PermissionStatus::GRANTED));
134 helper_->browser_context()->SetPermissionManager( 134 helper_->browser_context()->SetPermissionManager(
135 std::move(mock_permission_manager)); 135 std::move(mock_permission_manager));
136 136
137 // Create a StoragePartition with the correct BrowserContext so that the 137 // Create a StoragePartition with the correct BrowserContext so that the
138 // BackgroundSyncManager can find the BrowserContext through it. 138 // BackgroundSyncManager can find the BrowserContext through it.
139 storage_partition_impl_.reset(new StoragePartitionImpl( 139 storage_partition_impl_.reset(new StoragePartitionImpl(
140 helper_->browser_context(), base::FilePath(), nullptr)); 140 helper_->browser_context(), base::FilePath(), nullptr));
141 helper_->context_wrapper()->set_storage_partition( 141 helper_->context_wrapper()->set_storage_partition(
142 storage_partition_impl_.get()); 142 storage_partition_impl_.get());
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 test_background_sync_manager_->set_corrupt_backend(false); 462 test_background_sync_manager_->set_corrupt_backend(false);
463 EXPECT_FALSE(Register(sync_options_1_)); 463 EXPECT_FALSE(Register(sync_options_1_));
464 EXPECT_FALSE(GetRegistration(sync_options_1_)); 464 EXPECT_FALSE(GetRegistration(sync_options_1_));
465 } 465 }
466 466
467 TEST_F(BackgroundSyncManagerTest, RegisterPermissionDenied) { 467 TEST_F(BackgroundSyncManagerTest, RegisterPermissionDenied) {
468 GURL expected_origin = GURL(kPattern1).GetOrigin(); 468 GURL expected_origin = GURL(kPattern1).GetOrigin();
469 MockPermissionManager* mock_permission_manager = GetPermissionManager(); 469 MockPermissionManager* mock_permission_manager = GetPermissionManager();
470 470
471 EXPECT_CALL(*mock_permission_manager, 471 EXPECT_CALL(*mock_permission_manager,
472 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, 472 GetPermissionStatusForWorker(PermissionType::BACKGROUND_SYNC,
473 expected_origin, expected_origin)) 473 expected_origin))
474 .WillOnce(testing::Return(blink::mojom::PermissionStatus::DENIED)); 474 .WillOnce(testing::Return(blink::mojom::PermissionStatus::DENIED));
475 EXPECT_FALSE(Register(sync_options_1_)); 475 EXPECT_FALSE(Register(sync_options_1_));
476 } 476 }
477 477
478 TEST_F(BackgroundSyncManagerTest, RegisterPermissionGranted) { 478 TEST_F(BackgroundSyncManagerTest, RegisterPermissionGranted) {
479 GURL expected_origin = GURL(kPattern1).GetOrigin(); 479 GURL expected_origin = GURL(kPattern1).GetOrigin();
480 MockPermissionManager* mock_permission_manager = GetPermissionManager(); 480 MockPermissionManager* mock_permission_manager = GetPermissionManager();
481 481
482 EXPECT_CALL(*mock_permission_manager, 482 EXPECT_CALL(*mock_permission_manager,
483 GetPermissionStatus(PermissionType::BACKGROUND_SYNC, 483 GetPermissionStatusForWorker(PermissionType::BACKGROUND_SYNC,
484 expected_origin, expected_origin)) 484 expected_origin))
485 .WillOnce(testing::Return(blink::mojom::PermissionStatus::GRANTED)); 485 .WillOnce(testing::Return(blink::mojom::PermissionStatus::GRANTED));
486 EXPECT_TRUE(Register(sync_options_1_)); 486 EXPECT_TRUE(Register(sync_options_1_));
487 } 487 }
488 488
489 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) { 489 TEST_F(BackgroundSyncManagerTest, TwoRegistrations) {
490 EXPECT_TRUE(Register(sync_options_1_)); 490 EXPECT_TRUE(Register(sync_options_1_));
491 EXPECT_TRUE(Register(sync_options_2_)); 491 EXPECT_TRUE(Register(sync_options_2_));
492 } 492 }
493 493
494 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) { 494 TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) {
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 // Run it again. 1313 // Run it again.
1314 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta()); 1314 test_clock_->Advance(test_background_sync_manager_->delayed_task_delta());
1315 test_background_sync_manager_->delayed_task().Run(); 1315 test_background_sync_manager_->delayed_task().Run();
1316 base::RunLoop().RunUntilIdle(); 1316 base::RunLoop().RunUntilIdle();
1317 EXPECT_FALSE(GetRegistration(sync_options_1_)); 1317 EXPECT_FALSE(GetRegistration(sync_options_1_));
1318 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE, 1318 EXPECT_EQ(blink::mojom::BackgroundSyncEventLastChance::IS_LAST_CHANCE,
1319 test_background_sync_manager_->last_chance()); 1319 test_background_sync_manager_->last_chance());
1320 } 1320 }
1321 1321
1322 } // namespace content 1322 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698