| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "content/browser/appcache/mock_appcache_policy.h" | 9 #include "content/browser/appcache/mock_appcache_policy.h" |
| 10 #include "content/browser/appcache/mock_appcache_service.h" | 10 #include "content/browser/appcache/mock_appcache_service.h" |
| 11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "webkit/browser/appcache/appcache.h" | 13 #include "webkit/browser/appcache/appcache.h" |
| 14 #include "webkit/browser/appcache/appcache_backend_impl.h" | 14 #include "webkit/browser/appcache/appcache_backend_impl.h" |
| 15 #include "webkit/browser/appcache/appcache_group.h" | 15 #include "webkit/browser/appcache/appcache_group.h" |
| 16 #include "webkit/browser/appcache/appcache_host.h" | 16 #include "webkit/browser/appcache/appcache_host.h" |
| 17 #include "webkit/browser/quota/quota_manager.h" | 17 #include "webkit/browser/quota/quota_manager.h" |
| 18 | 18 |
| 19 using appcache::AppCache; | 19 using appcache::AppCache; |
| 20 using appcache::AppCacheBackendImpl; | 20 using appcache::AppCacheBackendImpl; |
| 21 using appcache::AppCacheEntry; | 21 using appcache::AppCacheEntry; |
| 22 using appcache::AppCacheFrontend; | 22 using appcache::AppCacheFrontend; |
| 23 using appcache::AppCacheGroup; | 23 using appcache::AppCacheGroup; |
| 24 using appcache::AppCacheHost; | 24 using appcache::AppCacheHost; |
| 25 using appcache::kNoCacheId; | 25 using appcache::kNoCacheId; |
| 26 using appcache::ERROR_EVENT; | 26 using appcache::ERROR_EVENT; |
| 27 using appcache::OBSOLETE; | 27 using appcache::OBSOLETE; |
| 28 using appcache::OBSOLETE_EVENT; | 28 using appcache::OBSOLETE_EVENT; |
| 29 using appcache::PROGRESS_EVENT; | 29 using appcache::PROGRESS_EVENT; |
| 30 using appcache::Status; | 30 using appcache::AppCacheStatus; |
| 31 using appcache::UNCACHED; | 31 using appcache::UNCACHED; |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 class AppCacheHostTest : public testing::Test { | 35 class AppCacheHostTest : public testing::Test { |
| 36 public: | 36 public: |
| 37 AppCacheHostTest() { | 37 AppCacheHostTest() { |
| 38 get_status_callback_ = | 38 get_status_callback_ = |
| 39 base::Bind(&AppCacheHostTest::GetStatusCallback, | 39 base::Bind(&AppCacheHostTest::GetStatusCallback, |
| 40 base::Unretained(this)); | 40 base::Unretained(this)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual void OnCacheSelected( | 59 virtual void OnCacheSelected( |
| 60 int host_id, const appcache::AppCacheInfo& info) OVERRIDE { | 60 int host_id, const appcache::AppCacheInfo& info) OVERRIDE { |
| 61 last_host_id_ = host_id; | 61 last_host_id_ = host_id; |
| 62 last_cache_id_ = info.cache_id; | 62 last_cache_id_ = info.cache_id; |
| 63 last_status_ = info.status; | 63 last_status_ = info.status; |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual void OnStatusChanged(const std::vector<int>& host_ids, | 66 virtual void OnStatusChanged(const std::vector<int>& host_ids, |
| 67 appcache::Status status) OVERRIDE { | 67 appcache::AppCacheStatus status) OVERRIDE { |
| 68 last_status_changed_ = status; | 68 last_status_changed_ = status; |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual void OnEventRaised(const std::vector<int>& host_ids, | 71 virtual void OnEventRaised(const std::vector<int>& host_ids, |
| 72 appcache::EventID event_id) OVERRIDE { | 72 appcache::AppCacheEventID event_id) OVERRIDE { |
| 73 last_event_id_ = event_id; | 73 last_event_id_ = event_id; |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual void OnErrorEventRaised(const std::vector<int>& host_ids, | 76 virtual void OnErrorEventRaised( |
| 77 const appcache::ErrorDetails& details) | 77 const std::vector<int>& host_ids, |
| 78 OVERRIDE { | 78 const appcache::AppCacheErrorDetails& details) OVERRIDE { |
| 79 last_event_id_ = ERROR_EVENT; | 79 last_event_id_ = ERROR_EVENT; |
| 80 } | 80 } |
| 81 | 81 |
| 82 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, | 82 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, |
| 83 const GURL& url, | 83 const GURL& url, |
| 84 int num_total, | 84 int num_total, |
| 85 int num_complete) OVERRIDE { | 85 int num_complete) OVERRIDE { |
| 86 last_event_id_ = PROGRESS_EVENT; | 86 last_event_id_ = PROGRESS_EVENT; |
| 87 } | 87 } |
| 88 | 88 |
| 89 virtual void OnLogMessage(int host_id, | 89 virtual void OnLogMessage(int host_id, |
| 90 appcache::LogLevel log_level, | 90 appcache::AppCacheLogLevel log_level, |
| 91 const std::string& message) OVERRIDE { | 91 const std::string& message) OVERRIDE { |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual void OnContentBlocked(int host_id, | 94 virtual void OnContentBlocked(int host_id, |
| 95 const GURL& manifest_url) OVERRIDE { | 95 const GURL& manifest_url) OVERRIDE { |
| 96 content_blocked_ = true; | 96 content_blocked_ = true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 int last_host_id_; | 99 int last_host_id_; |
| 100 int64 last_cache_id_; | 100 int64 last_cache_id_; |
| 101 appcache::Status last_status_; | 101 appcache::AppCacheStatus last_status_; |
| 102 appcache::Status last_status_changed_; | 102 appcache::AppCacheStatus last_status_changed_; |
| 103 appcache::EventID last_event_id_; | 103 appcache::AppCacheEventID last_event_id_; |
| 104 bool content_blocked_; | 104 bool content_blocked_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 class MockQuotaManagerProxy : public quota::QuotaManagerProxy { | 107 class MockQuotaManagerProxy : public quota::QuotaManagerProxy { |
| 108 public: | 108 public: |
| 109 MockQuotaManagerProxy() : QuotaManagerProxy(NULL, NULL) {} | 109 MockQuotaManagerProxy() : QuotaManagerProxy(NULL, NULL) {} |
| 110 | 110 |
| 111 // Not needed for our tests. | 111 // Not needed for our tests. |
| 112 virtual void RegisterClient(quota::QuotaClient* client) OVERRIDE {} | 112 virtual void RegisterClient(quota::QuotaClient* client) OVERRIDE {} |
| 113 virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id, | 113 virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 143 inuse_.clear(); | 143 inuse_.clear(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 // Map from origin to count of inuse notifications. | 146 // Map from origin to count of inuse notifications. |
| 147 std::map<GURL, int> inuse_; | 147 std::map<GURL, int> inuse_; |
| 148 | 148 |
| 149 protected: | 149 protected: |
| 150 virtual ~MockQuotaManagerProxy() {} | 150 virtual ~MockQuotaManagerProxy() {} |
| 151 }; | 151 }; |
| 152 | 152 |
| 153 void GetStatusCallback(Status status, void* param) { | 153 void GetStatusCallback(AppCacheStatus status, void* param) { |
| 154 last_status_result_ = status; | 154 last_status_result_ = status; |
| 155 last_callback_param_ = param; | 155 last_callback_param_ = param; |
| 156 } | 156 } |
| 157 | 157 |
| 158 void StartUpdateCallback(bool result, void* param) { | 158 void StartUpdateCallback(bool result, void* param) { |
| 159 last_start_result_ = result; | 159 last_start_result_ = result; |
| 160 last_callback_param_ = param; | 160 last_callback_param_ = param; |
| 161 } | 161 } |
| 162 | 162 |
| 163 void SwapCacheCallback(bool result, void* param) { | 163 void SwapCacheCallback(bool result, void* param) { |
| 164 last_swap_result_ = result; | 164 last_swap_result_ = result; |
| 165 last_callback_param_ = param; | 165 last_callback_param_ = param; |
| 166 } | 166 } |
| 167 | 167 |
| 168 base::MessageLoop message_loop_; | 168 base::MessageLoop message_loop_; |
| 169 | 169 |
| 170 // Mock classes for the 'host' to work with | 170 // Mock classes for the 'host' to work with |
| 171 MockAppCacheService service_; | 171 MockAppCacheService service_; |
| 172 MockFrontend mock_frontend_; | 172 MockFrontend mock_frontend_; |
| 173 | 173 |
| 174 // Mock callbacks we expect to receive from the 'host' | 174 // Mock callbacks we expect to receive from the 'host' |
| 175 appcache::GetStatusCallback get_status_callback_; | 175 appcache::GetStatusCallback get_status_callback_; |
| 176 appcache::StartUpdateCallback start_update_callback_; | 176 appcache::StartUpdateCallback start_update_callback_; |
| 177 appcache::SwapCacheCallback swap_cache_callback_; | 177 appcache::SwapCacheCallback swap_cache_callback_; |
| 178 | 178 |
| 179 Status last_status_result_; | 179 AppCacheStatus last_status_result_; |
| 180 bool last_swap_result_; | 180 bool last_swap_result_; |
| 181 bool last_start_result_; | 181 bool last_start_result_; |
| 182 void* last_callback_param_; | 182 void* last_callback_param_; |
| 183 }; | 183 }; |
| 184 | 184 |
| 185 TEST_F(AppCacheHostTest, Basic) { | 185 TEST_F(AppCacheHostTest, Basic) { |
| 186 // Construct a host and test what state it appears to be in. | 186 // Construct a host and test what state it appears to be in. |
| 187 AppCacheHost host(1, &mock_frontend_, &service_); | 187 AppCacheHost host(1, &mock_frontend_, &service_); |
| 188 EXPECT_EQ(1, host.host_id()); | 188 EXPECT_EQ(1, host.host_id()); |
| 189 EXPECT_EQ(&service_, host.service()); | 189 EXPECT_EQ(&service_, host.service()); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 EXPECT_EQ(&mock_frontend_, host.frontend()); | 545 EXPECT_EQ(&mock_frontend_, host.frontend()); |
| 546 EXPECT_EQ(NULL, host.associated_cache()); | 546 EXPECT_EQ(NULL, host.associated_cache()); |
| 547 EXPECT_FALSE(host.is_selection_pending()); | 547 EXPECT_FALSE(host.is_selection_pending()); |
| 548 EXPECT_TRUE(host.preferred_manifest_url().is_empty()); | 548 EXPECT_TRUE(host.preferred_manifest_url().is_empty()); |
| 549 } | 549 } |
| 550 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); | 550 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); |
| 551 service_.set_quota_manager_proxy(NULL); | 551 service_.set_quota_manager_proxy(NULL); |
| 552 } | 552 } |
| 553 | 553 |
| 554 } // namespace content | 554 } // namespace content |
| OLD | NEW |