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

Side by Side Diff: webkit/fileapi/file_system_context_unittest.cc

Issue 7633016: Test cleanup: Using MockSpecialStoragePolicy instead of local subclasses of SpecialStoragePolicy. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Keeping up to date with trunk. Created 9 years, 4 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_context.h" 5 #include "webkit/fileapi/file_system_context.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webkit/quota/mock_special_storage_policy.h"
15 #include "webkit/quota/quota_manager.h" 16 #include "webkit/quota/quota_manager.h"
16 17
17 namespace fileapi { 18 namespace fileapi {
18 namespace { 19 namespace {
19 20
20 static const char* const kTestOrigins[] = { 21 static const char* const kTestOrigins[] = {
21 "https://a.com/", 22 "https://a.com/",
22 "http://b.com/", 23 "http://b.com/",
23 "http://c.com:1/", 24 "http://c.com:1/",
24 "file:///", 25 "file:///",
25 }; 26 };
26 27
27 class TestSpecialStoragePolicy : public quota::SpecialStoragePolicy {
28 public:
29 virtual bool IsStorageProtected(const GURL& origin) {
30 return false;
31 }
32
33 virtual bool IsStorageUnlimited(const GURL& origin) {
34 return origin == GURL(kTestOrigins[1]);
35 }
36
37 virtual bool IsFileHandler(const std::string& extension_id) {
38 return false;
39 }
40 };
41
42 scoped_refptr<FileSystemContext> NewFileSystemContext( 28 scoped_refptr<FileSystemContext> NewFileSystemContext(
43 bool allow_file_access, 29 bool allow_file_access,
44 bool unlimited_quota, 30 bool unlimited_quota,
45 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { 31 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) {
46 return new FileSystemContext(base::MessageLoopProxy::current(), 32 return new FileSystemContext(base::MessageLoopProxy::current(),
47 base::MessageLoopProxy::current(), 33 base::MessageLoopProxy::current(),
48 special_storage_policy, 34 special_storage_policy,
49 NULL /* quota manager */, 35 NULL /* quota manager */,
50 FilePath(), false /* is_incognito */, 36 FilePath(), false /* is_incognito */,
51 allow_file_access, unlimited_quota, NULL); 37 allow_file_access, unlimited_quota, NULL);
(...skipping 22 matching lines...) Expand all
74 60
75 // With unlimited_quota=true cases. 61 // With unlimited_quota=true cases.
76 context = NewFileSystemContext(false, true, NULL); 62 context = NewFileSystemContext(false, true, NULL);
77 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { 63 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
78 SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w " 64 SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w "
79 "unlimited_quota=true #" << i << " " << kTestOrigins[i]); 65 "unlimited_quota=true #" << i << " " << kTestOrigins[i]);
80 EXPECT_TRUE(context->IsStorageUnlimited(GURL(kTestOrigins[i]))); 66 EXPECT_TRUE(context->IsStorageUnlimited(GURL(kTestOrigins[i])));
81 } 67 }
82 68
83 // With SpecialStoragePolicy. 69 // With SpecialStoragePolicy.
84 scoped_refptr<TestSpecialStoragePolicy> policy(new TestSpecialStoragePolicy); 70 scoped_refptr<quota::MockSpecialStoragePolicy> policy(
71 new quota::MockSpecialStoragePolicy);
72 policy->AddUnlimited(GURL(kTestOrigins[1]));
73
85 context = NewFileSystemContext(false, false, policy); 74 context = NewFileSystemContext(false, false, policy);
86 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) { 75 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestOrigins); ++i) {
87 SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w policy #" 76 SCOPED_TRACE(testing::Message() << "IsStorageUnlimited /w policy #"
88 << i << " " << kTestOrigins[i]); 77 << i << " " << kTestOrigins[i]);
89 GURL origin(kTestOrigins[i]); 78 GURL origin(kTestOrigins[i]);
90 EXPECT_EQ(policy->IsStorageUnlimited(origin), 79 EXPECT_EQ(policy->IsStorageUnlimited(origin),
91 context->IsStorageUnlimited(origin)); 80 context->IsStorageUnlimited(origin));
92 } 81 }
93 } 82 }
94 83
95 } // namespace fileapi 84 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/database/database_tracker_unittest.cc ('k') | webkit/fileapi/file_system_dir_url_request_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698