Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "net/url_request/url_request.h" | 7 #include "net/url_request/url_request.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "webkit/appcache/appcache.h" | 9 #include "webkit/appcache/appcache.h" |
| 10 #include "webkit/appcache/appcache_backend_impl.h" | 10 #include "webkit/appcache/appcache_backend_impl.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 EXPECT_EQ(NULL, host.associated_cache()); | 157 EXPECT_EQ(NULL, host.associated_cache()); |
| 158 EXPECT_FALSE(host.is_selection_pending()); | 158 EXPECT_FALSE(host.is_selection_pending()); |
| 159 } | 159 } |
| 160 | 160 |
| 161 TEST_F(AppCacheHostTest, ForeignEntry) { | 161 TEST_F(AppCacheHostTest, ForeignEntry) { |
| 162 // Reset our mock frontend | 162 // Reset our mock frontend |
| 163 mock_frontend_.last_cache_id_ = -333; | 163 mock_frontend_.last_cache_id_ = -333; |
| 164 mock_frontend_.last_host_id_ = -333; | 164 mock_frontend_.last_host_id_ = -333; |
| 165 mock_frontend_.last_status_ = OBSOLETE; | 165 mock_frontend_.last_status_ = OBSOLETE; |
| 166 | 166 |
| 167 // Precondition, a cache with an entry that is not marked as foreign. | |
| 168 const int kCacheId = 22; | |
| 169 const GURL kDocumentURL("http://origin/document"); | |
| 170 scoped_refptr<AppCache> cache = new AppCache(&service_, kCacheId); | |
| 171 cache->AddEntry(kDocumentURL, AppCacheEntry(AppCacheEntry::EXPLICIT)); | |
| 172 | |
| 167 AppCacheHost host(1, &mock_frontend_, &service_); | 173 AppCacheHost host(1, &mock_frontend_, &service_); |
| 168 host.MarkAsForeignEntry(GURL("http://whatever/"), 22); | 174 host.MarkAsForeignEntry(kDocumentURL, kCacheId); |
| 169 | 175 |
| 170 // We should have received an OnCacheSelected msg for kNoCacheId. | 176 // We should have received an OnCacheSelected msg for kNoCacheId. |
| 171 EXPECT_EQ(1, mock_frontend_.last_host_id_); | 177 EXPECT_EQ(1, mock_frontend_.last_host_id_); |
| 172 EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); | 178 EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); |
| 173 EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); | 179 EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); |
| 174 | 180 |
| 175 // See that it respond as if there is no cache selected. | 181 // See that it respond as if there is no cache selected. |
| 176 EXPECT_EQ(1, host.host_id()); | 182 EXPECT_EQ(1, host.host_id()); |
| 177 EXPECT_EQ(&service_, host.service()); | 183 EXPECT_EQ(&service_, host.service()); |
| 178 EXPECT_EQ(&mock_frontend_, host.frontend()); | 184 EXPECT_EQ(&mock_frontend_, host.frontend()); |
| 179 EXPECT_EQ(NULL, host.associated_cache()); | 185 EXPECT_EQ(NULL, host.associated_cache()); |
| 180 EXPECT_FALSE(host.is_selection_pending()); | 186 EXPECT_FALSE(host.is_selection_pending()); |
| 187 | |
| 188 // See that the entry was marked as foreign. | |
| 189 EXPECT_TRUE(cache->GetEntry(kDocumentURL)->IsForeign()); | |
| 190 } | |
| 191 | |
| 192 TEST_F(AppCacheHostTest, ForeignFallbackEntry) { | |
| 193 // Reset our mock frontend | |
| 194 mock_frontend_.last_cache_id_ = -333; | |
| 195 mock_frontend_.last_host_id_ = -333; | |
| 196 mock_frontend_.last_status_ = OBSOLETE; | |
| 197 | |
| 198 // Precondition, a cache with a fallback entry that is not marked as foreign. | |
| 199 const int kCacheId = 22; | |
| 200 const GURL kFallbackURL("http://origin/fallback_resource"); | |
| 201 scoped_refptr<AppCache> cache = new AppCache(&service_, kCacheId); | |
| 202 cache->AddEntry(kFallbackURL, AppCacheEntry(AppCacheEntry::FALLBACK)); | |
| 203 | |
| 204 AppCacheHost host(1, &mock_frontend_, &service_); | |
| 205 host.NotifyMainResourceFallback(kFallbackURL); | |
| 206 host.MarkAsForeignEntry(GURL("http://origin/missing_document"), kCacheId); | |
| 207 | |
| 208 // We should have received an OnCacheSelected msg for kNoCacheId. | |
| 209 EXPECT_EQ(1, mock_frontend_.last_host_id_); | |
| 210 EXPECT_EQ(kNoCacheId, mock_frontend_.last_cache_id_); | |
| 211 EXPECT_EQ(UNCACHED, mock_frontend_.last_status_); | |
| 212 | |
| 213 // See that it respond as if there is no cache selected. | |
| 214 EXPECT_EQ(1, host.host_id()); | |
| 215 EXPECT_EQ(&service_, host.service()); | |
| 216 EXPECT_EQ(&mock_frontend_, host.frontend()); | |
| 217 EXPECT_EQ(NULL, host.associated_cache()); | |
| 218 EXPECT_FALSE(host.is_selection_pending()); | |
|
kinuko
2010/11/02 07:47:23
Do we need to test all of them in both ForeignEntr
michaeln
2010/11/02 20:25:36
It does seem like some of these are redundant. How
kinuko
2010/11/03 00:25:18
sgtm!
| |
| 219 | |
| 220 // See that the fallback entry was marked as foreign. | |
| 221 EXPECT_TRUE(cache->GetEntry(kFallbackURL)->IsForeign()); | |
| 181 } | 222 } |
| 182 | 223 |
| 183 TEST_F(AppCacheHostTest, FailedCacheLoad) { | 224 TEST_F(AppCacheHostTest, FailedCacheLoad) { |
| 184 // Reset our mock frontend | 225 // Reset our mock frontend |
| 185 mock_frontend_.last_cache_id_ = -333; | 226 mock_frontend_.last_cache_id_ = -333; |
| 186 mock_frontend_.last_host_id_ = -333; | 227 mock_frontend_.last_host_id_ = -333; |
| 187 mock_frontend_.last_status_ = OBSOLETE; | 228 mock_frontend_.last_status_ = OBSOLETE; |
| 188 | 229 |
| 189 AppCacheHost host(1, &mock_frontend_, &service_); | 230 AppCacheHost host(1, &mock_frontend_, &service_); |
| 190 EXPECT_FALSE(host.is_selection_pending()); | 231 EXPECT_FALSE(host.is_selection_pending()); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 | 388 |
| 348 // Simulate the parent being torn down. | 389 // Simulate the parent being torn down. |
| 349 backend_impl.UnregisterHost(kParentHostId); | 390 backend_impl.UnregisterHost(kParentHostId); |
| 350 parent_host = NULL; | 391 parent_host = NULL; |
| 351 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId)); | 392 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId)); |
| 352 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost()); | 393 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost()); |
| 353 } | 394 } |
| 354 | 395 |
| 355 } // namespace appcache | 396 } // namespace appcache |
| 356 | 397 |
| OLD | NEW |