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

Side by Side Diff: components/safe_browsing_db/v4_store_unittest.cc

Issue 2598733002: Fix handling of store-write failures in Pver4 (Closed)
Patch Set: Change the way I generate a non-writable file, for Windows Created 4 years 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 | « components/safe_browsing_db/v4_store.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/base64.h" 5 #include "base/base64.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 EXPECT_EQ(69, store.file_size_); 818 EXPECT_EQ(69, store.file_size_);
819 819
820 EXPECT_TRUE(another_store.VerifyChecksum()); 820 EXPECT_TRUE(another_store.VerifyChecksum());
821 } 821 }
822 822
823 TEST_F(V4StoreTest, WriteToDiskFails) { 823 TEST_F(V4StoreTest, WriteToDiskFails) {
824 // Pass the directory name as file name so that when the code tries to rename 824 // Pass the directory name as file name so that when the code tries to rename
825 // the temp store file to |store_path_| it fails. 825 // the temp store file to |store_path_| it fails.
826 EXPECT_EQ(UNABLE_TO_RENAME_FAILURE, 826 EXPECT_EQ(UNABLE_TO_RENAME_FAILURE,
827 V4Store(task_runner_, temp_dir_.GetPath()).WriteToDisk(Checksum())); 827 V4Store(task_runner_, temp_dir_.GetPath()).WriteToDisk(Checksum()));
828
829 // Give a location that isn't writable, even for the tmp file.
830 base::FilePath non_writable_dir =
831 temp_dir_.GetPath()
832 .Append(FILE_PATH_LITERAL("nonexistent_dir"))
833 .Append(FILE_PATH_LITERAL("some.store"));
834 EXPECT_EQ(UNEXPECTED_BYTES_WRITTEN_FAILURE,
835 V4Store(task_runner_, non_writable_dir).WriteToDisk(Checksum()));
828 } 836 }
829 837
830 TEST_F(V4StoreTest, FullUpdateFailsChecksumSynchronously) { 838 TEST_F(V4StoreTest, FullUpdateFailsChecksumSynchronously) {
831 V4Store store(task_runner_, store_path_); 839 V4Store store(task_runner_, store_path_);
832 bool called_back = false; 840 bool called_back = false;
833 UpdatedStoreReadyCallback store_ready_callback = 841 UpdatedStoreReadyCallback store_ready_callback =
834 base::Bind(&V4StoreTest::UpdatedStoreReady, base::Unretained(this), 842 base::Bind(&V4StoreTest::UpdatedStoreReady, base::Unretained(this),
835 &called_back, false /* expect_store */); 843 &called_back, false /* expect_store */);
836 EXPECT_FALSE(base::PathExists(store.store_path_)); 844 EXPECT_FALSE(base::PathExists(store.store_path_));
837 845
838 // Now create a response with invalid checksum. 846 // Now create a response with invalid checksum.
839 std::unique_ptr<ListUpdateResponse> lur(new ListUpdateResponse); 847 std::unique_ptr<ListUpdateResponse> lur(new ListUpdateResponse);
840 lur->set_response_type(ListUpdateResponse::FULL_UPDATE); 848 lur->set_response_type(ListUpdateResponse::FULL_UPDATE);
841 lur->mutable_checksum()->set_sha256(std::string(crypto::kSHA256Length, 0)); 849 lur->mutable_checksum()->set_sha256(std::string(crypto::kSHA256Length, 0));
842 store.ApplyUpdate(std::move(lur), task_runner_, store_ready_callback); 850 store.ApplyUpdate(std::move(lur), task_runner_, store_ready_callback);
843 // The update should fail synchronously and not create a store file. 851 // The update should fail synchronously and not create a store file.
844 EXPECT_FALSE(base::PathExists(store.store_path_)); 852 EXPECT_FALSE(base::PathExists(store.store_path_));
845 853
846 // Run everything on the task runner to ensure there are no pending tasks. 854 // Run everything on the task runner to ensure there are no pending tasks.
847 task_runner_->RunPendingTasks(); 855 task_runner_->RunPendingTasks();
848 base::RunLoop().RunUntilIdle(); 856 base::RunLoop().RunUntilIdle();
849 857
850 // This ensures that the callback was called. 858 // This ensures that the callback was called.
851 EXPECT_TRUE(called_back); 859 EXPECT_TRUE(called_back);
852 // Ensure that the file is still not created. 860 // Ensure that the file is still not created.
853 EXPECT_FALSE(base::PathExists(store.store_path_)); 861 EXPECT_FALSE(base::PathExists(store.store_path_));
854 } 862 }
855 863
856 } // namespace safe_browsing 864 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698