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/fileapi/file_system_context.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/scoped_ptr.h" |
| 12 #include "base/string_number_conversions.h" |
| 13 #include "googleurl/src/gurl.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "webkit/quota/special_storage_policy.h" |
| 16 |
| 17 using namespace fileapi; |
| 18 |
| 19 namespace { |
| 20 |
| 21 static const char* const kTestOrigins[] = { |
| 22 "https://a.com/", |
| 23 "http://b.com/", |
| 24 "http://c.com:1/", |
| 25 "file:///", |
| 26 }; |
| 27 |
| 28 class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy { |
| 29 public: |
| 30 virtual bool IsStorageProtected(const GURL& origin) { |
| 31 return false; |
| 32 } |
| 33 |
| 34 virtual bool IsStorageUnlimited(const GURL& origin) { |
| 35 return origin == GURL(kTestOrigins[1]); |
| 36 } |
| 37 }; |
| 38 |
| 39 scoped_refptr<FileSystemContext> NewFileSystemContext( |
| 40 bool allow_file_access, |
| 41 bool unlimited_quota, |
| 42 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
| 43 return new FileSystemContext(base::MessageLoopProxy::CreateForCurrentThread(), |
| 44 base::MessageLoopProxy::CreateForCurrentThread(), |
| 45 special_storage_policy, |
| 46 FilePath(), false /* is_incognito */, |
| 47 allow_file_access, unlimited_quota); |
| 48 } |
| 49 |
| 50 } // anonymous namespace |
| 51 |
| 52 TEST(FileSystemContextTest, IsStorageUnlimited) { |
| 53 // Regular cases. |
| 54 scoped_refptr<FileSystemContext> context( |
| 55 NewFileSystemContext(false, false, NULL)); |
| 56 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { |
| 57 SCOPED_TRACE(testing::Message() << "IsStorageUnlimited w/o policy #" |
| 58 << i << " " << kTestOrigins[i]); |
| 59 EXPECT_FALSE(context->IsStorageUnlimited(GURL(kTestOrigins[i]))); |
| 60 } |
| 61 |
| 62 // With allow_file_access=true cases. |
| 63 context = NewFileSystemContext(true, false, NULL); |
| 64 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { |
| 65 GURL origin(kTestOrigins[i]); |
| 66 EXPECT_EQ(origin.SchemeIsFile(), context->IsStorageUnlimited(origin)); |
| 67 } |
| 68 |
| 69 // With unlimited_quota=true cases. |
| 70 context = NewFileSystemContext(false, true, NULL); |
| 71 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { |
| 72 EXPECT_TRUE(context->IsStorageUnlimited(GURL(kTestOrigins[i]))); |
| 73 } |
| 74 |
| 75 // With SpecialStoragePolicy. |
| 76 scoped_refptr<TestSpecialStoragePolicy> policy(new TestSpecialStoragePolicy); |
| 77 context = NewFileSystemContext(false, false, policy); |
| 78 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { |
| 79 SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w policy #" |
| 80 << i << " " << kTestOrigins[i]); |
| 81 GURL origin(kTestOrigins[i]); |
| 82 EXPECT_EQ(policy->IsStorageUnlimited(origin), |
| 83 context->IsStorageUnlimited(origin)); |
| 84 } |
| 85 } |
OLD | NEW |