summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_quota_manager_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/fileapi/file_system_quota_manager_unittest.cc')
-rw-r--r--webkit/fileapi/file_system_quota_manager_unittest.cc154
1 files changed, 55 insertions, 99 deletions
diff --git a/webkit/fileapi/file_system_quota_manager_unittest.cc b/webkit/fileapi/file_system_quota_manager_unittest.cc
index 3bc7ac3..b22a33f9 100644
--- a/webkit/fileapi/file_system_quota_manager_unittest.cc
+++ b/webkit/fileapi/file_system_quota_manager_unittest.cc
@@ -9,24 +9,10 @@
#include "base/scoped_ptr.h"
#include "base/string_number_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "webkit/quota/special_storage_policy.h"
using namespace fileapi;
-class FileSystemQuotaManagerTest : public testing::Test {
- public:
- FileSystemQuotaManagerTest() { }
-
- void SetUp() {
- quota_.reset(new FileSystemQuotaManager(false, false));
- }
-
- FileSystemQuotaManager* quota() const { return quota_.get(); }
-
- protected:
- scoped_ptr<FileSystemQuotaManager> quota_;
- DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaManagerTest);
-};
-
namespace {
static const char* const kTestOrigins[] = {
@@ -36,111 +22,81 @@ static const char* const kTestOrigins[] = {
"file:///",
};
+class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
+ public:
+ virtual bool IsStorageProtected(const GURL& origin) {
+ return false;
+ }
+
+ virtual bool IsStorageUnlimited(const GURL& origin) {
+ return origin == GURL(kTestOrigins[1]);
+ }
+};
+
} // anonymous namespace
-TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaNotAllowed) {
+TEST(FileSystemQuotaManagerTest, CheckNotAllowed) {
+ FileSystemQuotaManager quota(false, false, NULL);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #"
<< i << " " << kTestOrigins[i]);
// Should fail no matter how much size is requested.
- EXPECT_FALSE(quota()->CheckOriginQuota(GURL(kTestOrigins[i]), -1));
- EXPECT_FALSE(quota()->CheckOriginQuota(GURL(kTestOrigins[i]), 0));
- EXPECT_FALSE(quota()->CheckOriginQuota(GURL(kTestOrigins[i]), 100));
+ GURL origin(kTestOrigins[i]);
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, -1));
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, 0));
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, 100));
}
}
-TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaUnlimited) {
- // Tests if SetOriginQuotaUnlimited and ResetOriginQuotaUnlimited
- // are working as expected.
+TEST(FileSystemQuotaManagerTest, CheckUnlimitedFlag) {
+ FileSystemQuotaManager quota(false, true, NULL);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
- SCOPED_TRACE(testing::Message() << "CheckOriginQuotaUnlimited #"
- << i << " " << kTestOrigins[i]);
- GURL url(kTestOrigins[i]);
- EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url));
- EXPECT_FALSE(quota()->CheckOriginQuota(url, 0));
-
- quota()->SetOriginQuotaUnlimited(url);
- EXPECT_TRUE(quota()->CheckIfOriginGrantedUnlimitedQuota(url));
- EXPECT_TRUE(quota()->CheckOriginQuota(url, -1));
- EXPECT_TRUE(quota()->CheckOriginQuota(url, 0));
- EXPECT_TRUE(quota()->CheckOriginQuota(url, 100));
-
- quota()->ResetOriginQuotaUnlimited(url);
- EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url));
- EXPECT_FALSE(quota()->CheckOriginQuota(url, -1));
- EXPECT_FALSE(quota()->CheckOriginQuota(url, 0));
- EXPECT_FALSE(quota()->CheckOriginQuota(url, 100));
- }
-}
-
-TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaWithMixedSet) {
- // Tests setting unlimited quota for some urls doesn't affect
- // other urls.
- GURL test_url1("http://foo.bar.com/");
- GURL test_url2("http://example.com/");
- quota()->SetOriginQuotaUnlimited(test_url1);
- quota()->SetOriginQuotaUnlimited(test_url2);
-
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
- SCOPED_TRACE(testing::Message() << "CheckOriginQuotaMixedSet #"
+ SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #"
<< i << " " << kTestOrigins[i]);
- GURL url(kTestOrigins[i]);
- EXPECT_FALSE(quota()->CheckOriginQuota(url, 0));
- EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url));
+ // Should succeed no matter how much size is requested.
+ GURL origin(kTestOrigins[i]);
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, -1));
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, 0));
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, 100));
}
}
-TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaMixedWithDifferentScheme) {
- // Tests setting unlimited quota for urls doesn't affect
- // pages in the same hosts but with different scheme.
+TEST(FileSystemQuotaManagerTest, CheckAllowFileFlag) {
+ FileSystemQuotaManager quota(true, false, NULL);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
- GURL url(kTestOrigins[i]);
- if (url.SchemeIsFile())
- continue;
- ASSERT_TRUE(url == url.GetOrigin());
- std::string new_scheme = "https";
- if (url.SchemeIsSecure())
- new_scheme = "http";
- else
- ASSERT_TRUE(url.SchemeIs("http"));
- std::string new_url_string = new_scheme + "://" + url.host();
- if (url.has_port())
- new_url_string += ":" + url.port();
- quota()->SetOriginQuotaUnlimited(GURL(new_url_string));
- }
-
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
- SCOPED_TRACE(testing::Message()
- << "CheckOriginQuotaMixedWithDifferentScheme #"
+ SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #"
<< i << " " << kTestOrigins[i]);
- GURL url(kTestOrigins[i]);
- EXPECT_FALSE(quota()->CheckOriginQuota(url, 0));
- EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url));
+ // Should succeed only for file:// urls
+ GURL origin(kTestOrigins[i]);
+ if (origin.SchemeIsFile()) {
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, -1));
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, 0));
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, 100));
+ } else {
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, -1));
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, 0));
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, 100));
+ }
}
}
-TEST_F(FileSystemQuotaManagerTest, CheckOriginQuotaMixedWithDifferentPort) {
- // Tests setting unlimited quota for urls doesn't affect
- // pages in the same scheme/hosts but with different port number.
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
- GURL url(kTestOrigins[i]);
- if (url.SchemeIsFile())
- continue;
- ASSERT_TRUE(url == url.GetOrigin());
- int port = 81;
- if (url.has_port())
- port = url.IntPort() + 1;
- GURL new_url(url.scheme() + "://" + url.host() + ":" +
- base::IntToString(port));
- quota()->SetOriginQuotaUnlimited(new_url);
- }
+TEST(FileSystemQuotaManagerTest, CheckSpecialPolicy) {
+ scoped_refptr<TestSpecialStoragePolicy> policy(new TestSpecialStoragePolicy);
+ FileSystemQuotaManager quota(false, false, policy);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
- SCOPED_TRACE(testing::Message()
- << "CheckOriginQuotaMixedWithDifferentPort #"
+ SCOPED_TRACE(testing::Message() << "CheckOriginQuotaNotAllowed #"
<< i << " " << kTestOrigins[i]);
- GURL url(kTestOrigins[i]);
- EXPECT_FALSE(quota()->CheckOriginQuota(url, 0));
- EXPECT_FALSE(quota()->CheckIfOriginGrantedUnlimitedQuota(url));
+ // Should succeed only for unlimited origins according to the policy.
+ GURL origin(kTestOrigins[i]);
+ if (policy->IsStorageUnlimited(origin)) {
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, -1));
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, 0));
+ EXPECT_TRUE(quota.CheckOriginQuota(origin, 100));
+ } else {
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, -1));
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, 0));
+ EXPECT_FALSE(quota.CheckOriginQuota(origin, 100));
+ }
}
}