| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/blob/deletable_file_reference.h" | |
| 6 | |
| 7 #include "base/file_util.h" | |
| 8 #include "base/message_loop.h" | |
| 9 #include "base/message_loop_proxy.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace webkit_blob { | |
| 13 | |
| 14 TEST(DeletableFileReferenceTest, TestReferences) { | |
| 15 scoped_refptr<base::MessageLoopProxy> loop_proxy = | |
| 16 base::MessageLoopProxy::CreateForCurrentThread(); | |
| 17 | |
| 18 // Create a file. | |
| 19 FilePath file; | |
| 20 file_util::CreateTemporaryFile(&file); | |
| 21 EXPECT_TRUE(file_util::PathExists(file)); | |
| 22 | |
| 23 // Create a first reference to that file. | |
| 24 scoped_refptr<DeletableFileReference> reference1; | |
| 25 reference1 = DeletableFileReference::Get(file); | |
| 26 EXPECT_FALSE(reference1.get()); | |
| 27 reference1 = DeletableFileReference::GetOrCreate(file, loop_proxy); | |
| 28 EXPECT_TRUE(reference1.get()); | |
| 29 EXPECT_TRUE(file == reference1->path()); | |
| 30 | |
| 31 // Get a second reference to that file. | |
| 32 scoped_refptr<DeletableFileReference> reference2; | |
| 33 reference2 = DeletableFileReference::Get(file); | |
| 34 EXPECT_EQ(reference1.get(), reference2.get()); | |
| 35 reference2 = DeletableFileReference::GetOrCreate(file, loop_proxy); | |
| 36 EXPECT_EQ(reference1.get(), reference2.get()); | |
| 37 | |
| 38 // Drop the first reference, the file and reference should still be there. | |
| 39 reference1 = NULL; | |
| 40 EXPECT_TRUE(DeletableFileReference::Get(file).get()); | |
| 41 MessageLoop::current()->RunAllPending(); | |
| 42 EXPECT_TRUE(file_util::PathExists(file)); | |
| 43 | |
| 44 // Drop the second reference, the file and reference should get deleted. | |
| 45 reference2 = NULL; | |
| 46 EXPECT_FALSE(DeletableFileReference::Get(file).get()); | |
| 47 MessageLoop::current()->RunAllPending(); | |
| 48 EXPECT_FALSE(file_util::PathExists(file)); | |
| 49 } | |
| 50 | |
| 51 } // namespace webkit_blob | |
| OLD | NEW |