| 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 "base/file_path.h" |
| 6 #include "base/time.h" |
| 7 #include "base/ref_counted.h" |
| 8 #include "base/scoped_ptr.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "webkit/blob/blob_data.h" |
| 11 #include "webkit/blob/blob_storage_controller.h" |
| 12 |
| 13 namespace webkit_blob { |
| 14 |
| 15 TEST(BlobStorageControllerTest, RegisterBlobUrl) { |
| 16 // Setup a set of blob data for testing. |
| 17 base::Time time1, time2; |
| 18 base::Time::FromString(L"Tue, 15 Nov 1994, 12:45:26 GMT", &time1); |
| 19 base::Time::FromString(L"Mon, 14 Nov 1994, 11:30:49 GMT", &time2); |
| 20 |
| 21 scoped_refptr<BlobData> blob_data1 = new BlobData(); |
| 22 blob_data1->AppendData("Data1"); |
| 23 blob_data1->AppendData("Data2"); |
| 24 blob_data1->AppendFile(FilePath(FILE_PATH_LITERAL("File1.txt")), |
| 25 10, 1024, time1); |
| 26 |
| 27 scoped_refptr<BlobData> blob_data2 = new BlobData(); |
| 28 blob_data2->AppendData("Data3"); |
| 29 blob_data2->AppendBlob(GURL("blob://url_1"), 8, 100); |
| 30 blob_data2->AppendFile(FilePath(FILE_PATH_LITERAL("File2.txt")), |
| 31 0, 20, time2); |
| 32 |
| 33 scoped_refptr<BlobData> canonicalized_blob_data2 = new BlobData(); |
| 34 canonicalized_blob_data2->AppendData("Data3"); |
| 35 canonicalized_blob_data2->AppendData("Data2", 3, 2); |
| 36 canonicalized_blob_data2->AppendFile(FilePath(FILE_PATH_LITERAL("File1.txt")), |
| 37 10, 98, time1); |
| 38 canonicalized_blob_data2->AppendFile(FilePath(FILE_PATH_LITERAL("File2.txt")), |
| 39 0, 20, time2); |
| 40 |
| 41 scoped_ptr<BlobStorageController> blob_storage_controller( |
| 42 new BlobStorageController()); |
| 43 |
| 44 // Test registering a blob URL referring to the blob data containing only |
| 45 // data and file. |
| 46 GURL blob_url1("blob://url_1"); |
| 47 blob_storage_controller->RegisterBlobUrl(blob_url1, blob_data1); |
| 48 |
| 49 BlobData* blob_data_found = |
| 50 blob_storage_controller->GetBlobDataFromUrl(blob_url1); |
| 51 ASSERT_TRUE(blob_data_found != NULL); |
| 52 EXPECT_TRUE(*blob_data_found == *blob_data1); |
| 53 |
| 54 // Test registering a blob URL referring to the blob data containing data, |
| 55 // file and blob. |
| 56 GURL blob_url2("blob://url_2"); |
| 57 blob_storage_controller->RegisterBlobUrl(blob_url2, blob_data2); |
| 58 |
| 59 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url2); |
| 60 ASSERT_TRUE(blob_data_found != NULL); |
| 61 EXPECT_TRUE(*blob_data_found == *canonicalized_blob_data2); |
| 62 |
| 63 // Test registering a blob URL referring to existent blob URL. |
| 64 GURL blob_url3("blob://url_3"); |
| 65 blob_storage_controller->RegisterBlobUrlFrom(blob_url3, blob_url1); |
| 66 |
| 67 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url3); |
| 68 ASSERT_TRUE(blob_data_found != NULL); |
| 69 EXPECT_TRUE(*blob_data_found == *blob_data1); |
| 70 |
| 71 // Test registering a blob URL referring to non-existent blob URL. |
| 72 GURL nonexistent_blob_url("blob://url_none"); |
| 73 GURL blob_url4("blob://url_4"); |
| 74 blob_storage_controller->RegisterBlobUrlFrom(blob_url4, nonexistent_blob_url); |
| 75 |
| 76 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url4); |
| 77 EXPECT_FALSE(blob_data_found != NULL); |
| 78 |
| 79 // Test unregistering a blob URL. |
| 80 blob_storage_controller->UnregisterBlobUrl(blob_url3); |
| 81 blob_data_found = blob_storage_controller->GetBlobDataFromUrl(blob_url3); |
| 82 EXPECT_FALSE(blob_data_found != NULL); |
| 83 } |
| 84 |
| 85 } // namespace webkit_blob |
| OLD | NEW |