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

Side by Side Diff: webkit/browser/database/database_quota_client_unittest.cc

Issue 16879013: Use chromium logic for database identifier<->origin conversions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove webkit/base/origin_url_conversions Created 7 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <map> 5 #include <map>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "net/base/completion_callback.h" 12 #include "net/base/completion_callback.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webkit/base/origin_url_conversions.h"
16 #include "webkit/browser/database/database_quota_client.h" 15 #include "webkit/browser/database/database_quota_client.h"
17 #include "webkit/browser/database/database_tracker.h" 16 #include "webkit/browser/database/database_tracker.h"
18 #include "webkit/browser/database/database_util.h" 17 #include "webkit/browser/database/database_util.h"
18 #include "webkit/common/database/database_identifier.h"
19 19
20 namespace webkit_database { 20 namespace webkit_database {
21 21
22 // Declared to shorten the line lengths. 22 // Declared to shorten the line lengths.
23 static const quota::StorageType kTemp = quota::kStorageTypeTemporary; 23 static const quota::StorageType kTemp = quota::kStorageTypeTemporary;
24 static const quota::StorageType kPerm = quota::kStorageTypePersistent; 24 static const quota::StorageType kPerm = quota::kStorageTypePersistent;
25 25
26 // Mock tracker class the mocks up those methods of the tracker 26 // Mock tracker class the mocks up those methods of the tracker
27 // that are used by the QuotaClient. 27 // that are used by the QuotaClient.
28 class MockDatabaseTracker : public DatabaseTracker { 28 class MockDatabaseTracker : public DatabaseTracker {
29 public: 29 public:
30 MockDatabaseTracker() 30 MockDatabaseTracker()
31 : DatabaseTracker(base::FilePath(), false, NULL, NULL, NULL), 31 : DatabaseTracker(base::FilePath(), false, NULL, NULL, NULL),
32 delete_called_count_(0), 32 delete_called_count_(0),
33 async_delete_(false) {} 33 async_delete_(false) {}
34 34
35 virtual bool GetOriginInfo( 35 virtual bool GetOriginInfo(
36 const std::string& origin_identifier, 36 const std::string& origin_identifier,
37 OriginInfo* info) OVERRIDE { 37 OriginInfo* info) OVERRIDE {
38 std::map<GURL, MockOriginInfo>::const_iterator found = 38 std::map<GURL, MockOriginInfo>::const_iterator found =
39 mock_origin_infos_.find( 39 mock_origin_infos_.find(
40 webkit_base::GetOriginURLFromIdentifier(origin_identifier)); 40 webkit_database::GetOriginFromIdentifier(origin_identifier));
41 if (found == mock_origin_infos_.end()) 41 if (found == mock_origin_infos_.end())
42 return false; 42 return false;
43 *info = OriginInfo(found->second); 43 *info = OriginInfo(found->second);
44 return true; 44 return true;
45 } 45 }
46 46
47 virtual bool GetAllOriginIdentifiers( 47 virtual bool GetAllOriginIdentifiers(
48 std::vector<std::string>* origins_identifiers) OVERRIDE { 48 std::vector<std::string>* origins_identifiers) OVERRIDE {
49 std::map<GURL, MockOriginInfo>::const_iterator iter; 49 std::map<GURL, MockOriginInfo>::const_iterator iter;
50 for (iter = mock_origin_infos_.begin(); 50 for (iter = mock_origin_infos_.begin();
(...skipping 28 matching lines...) Expand all
79 } 79 }
80 return net::OK; 80 return net::OK;
81 } 81 }
82 82
83 void AsyncDeleteDataForOrigin(const net::CompletionCallback& callback) { 83 void AsyncDeleteDataForOrigin(const net::CompletionCallback& callback) {
84 callback.Run(net::OK); 84 callback.Run(net::OK);
85 } 85 }
86 86
87 void AddMockDatabase(const GURL& origin, const char* name, int size) { 87 void AddMockDatabase(const GURL& origin, const char* name, int size) {
88 MockOriginInfo& info = mock_origin_infos_[origin]; 88 MockOriginInfo& info = mock_origin_infos_[origin];
89 info.set_origin(webkit_base::GetOriginIdentifierFromURL(origin)); 89 info.set_origin(webkit_database::GetIdentifierFromOrigin(origin));
90 info.AddMockDatabase(ASCIIToUTF16(name), size); 90 info.AddMockDatabase(ASCIIToUTF16(name), size);
91 } 91 }
92 92
93 int delete_called_count() { return delete_called_count_; } 93 int delete_called_count() { return delete_called_count_; }
94 bool async_delete() { return async_delete_; } 94 bool async_delete() { return async_delete_; }
95 void set_async_delete(bool async) { async_delete_ = async; } 95 void set_async_delete(bool async) { async_delete_ = async; }
96 96
97 protected: 97 protected:
98 virtual ~MockDatabaseTracker() {} 98 virtual ~MockDatabaseTracker() {}
99 99
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 mock_tracker()->set_async_delete(false); 276 mock_tracker()->set_async_delete(false);
277 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); 277 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA));
278 EXPECT_EQ(1, mock_tracker()->delete_called_count()); 278 EXPECT_EQ(1, mock_tracker()->delete_called_count());
279 279
280 mock_tracker()->set_async_delete(true); 280 mock_tracker()->set_async_delete(true);
281 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA)); 281 EXPECT_TRUE(DeleteOriginData(&client, kTemp, kOriginA));
282 EXPECT_EQ(2, mock_tracker()->delete_called_count()); 282 EXPECT_EQ(2, mock_tracker()->delete_called_count());
283 } 283 }
284 284
285 } // namespace webkit_database 285 } // namespace webkit_database
OLDNEW
« no previous file with comments | « webkit/browser/database/database_quota_client.cc ('k') | webkit/browser/database/database_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698