| OLD | NEW | 
|    1 // Copyright (c) 2010 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 "base/message_loop.h" |    5 #include "base/message_loop.h" | 
|    6 #include "testing/gtest/include/gtest/gtest.h" |    6 #include "testing/gtest/include/gtest/gtest.h" | 
|    7 #include "webkit/appcache/appcache.h" |    7 #include "webkit/appcache/appcache.h" | 
|    8 #include "webkit/appcache/appcache_group.h" |    8 #include "webkit/appcache/appcache_group.h" | 
|    9 #include "webkit/appcache/appcache_response.h" |    9 #include "webkit/appcache/appcache_response.h" | 
|   10 #include "webkit/appcache/appcache_storage.h" |   10 #include "webkit/appcache/appcache_storage.h" | 
|   11 #include "webkit/appcache/mock_appcache_service.h" |   11 #include "webkit/appcache/mock_appcache_service.h" | 
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  387 TEST_F(MockAppCacheStorageTest, FindNoMainResponse) { |  387 TEST_F(MockAppCacheStorageTest, FindNoMainResponse) { | 
|  388   // Should complete asyncly. |  388   // Should complete asyncly. | 
|  389   MockAppCacheService service; |  389   MockAppCacheService service; | 
|  390   MockAppCacheStorage* storage = |  390   MockAppCacheStorage* storage = | 
|  391       reinterpret_cast<MockAppCacheStorage*>(service.storage()); |  391       reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 
|  392  |  392  | 
|  393   // Conduct the test. |  393   // Conduct the test. | 
|  394   MockStorageDelegate delegate; |  394   MockStorageDelegate delegate; | 
|  395   GURL url("http://blah/some_url"); |  395   GURL url("http://blah/some_url"); | 
|  396   EXPECT_NE(url, delegate.found_url_); |  396   EXPECT_NE(url, delegate.found_url_); | 
|  397   storage->FindResponseForMainRequest(url, &delegate); |  397   storage->FindResponseForMainRequest(url, GURL(), &delegate); | 
|  398   EXPECT_NE(url, delegate.found_url_); |  398   EXPECT_NE(url, delegate.found_url_); | 
|  399   MessageLoop::current()->RunAllPending();  // Do async task execution. |  399   MessageLoop::current()->RunAllPending();  // Do async task execution. | 
|  400   EXPECT_EQ(url, delegate.found_url_); |  400   EXPECT_EQ(url, delegate.found_url_); | 
|  401   EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |  401   EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 
|  402   EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |  402   EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 
|  403   EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |  403   EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 
|  404   EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |  404   EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 
|  405   EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |  405   EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); | 
|  406   EXPECT_EQ(0, delegate.found_entry_.types()); |  406   EXPECT_EQ(0, delegate.found_entry_.types()); | 
|  407   EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |  407   EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|  424   cache->set_complete(true); |  424   cache->set_complete(true); | 
|  425   scoped_refptr<AppCacheGroup> group( |  425   scoped_refptr<AppCacheGroup> group( | 
|  426       new AppCacheGroup(&service, kManifestUrl, 111)); |  426       new AppCacheGroup(&service, kManifestUrl, 111)); | 
|  427   group->AddCache(cache); |  427   group->AddCache(cache); | 
|  428   storage->AddStoredGroup(group); |  428   storage->AddStoredGroup(group); | 
|  429   storage->AddStoredCache(cache); |  429   storage->AddStoredCache(cache); | 
|  430  |  430  | 
|  431   // Conduct the test. |  431   // Conduct the test. | 
|  432   MockStorageDelegate delegate; |  432   MockStorageDelegate delegate; | 
|  433   EXPECT_NE(kEntryUrl, delegate.found_url_); |  433   EXPECT_NE(kEntryUrl, delegate.found_url_); | 
|  434   storage->FindResponseForMainRequest(kEntryUrl, &delegate); |  434   storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 
|  435   EXPECT_NE(kEntryUrl, delegate.found_url_); |  435   EXPECT_NE(kEntryUrl, delegate.found_url_); | 
|  436   MessageLoop::current()->RunAllPending();  // Do async task execution. |  436   MessageLoop::current()->RunAllPending();  // Do async task execution. | 
|  437   EXPECT_EQ(kEntryUrl, delegate.found_url_); |  437   EXPECT_EQ(kEntryUrl, delegate.found_url_); | 
|  438   EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); |  438   EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); | 
|  439   EXPECT_EQ(kCacheId, delegate.found_cache_id_); |  439   EXPECT_EQ(kCacheId, delegate.found_cache_id_); | 
|  440   EXPECT_EQ(kResponseId, delegate.found_entry_.response_id()); |  440   EXPECT_EQ(kResponseId, delegate.found_entry_.response_id()); | 
|  441   EXPECT_TRUE(delegate.found_entry_.IsExplicit()); |  441   EXPECT_TRUE(delegate.found_entry_.IsExplicit()); | 
|  442   EXPECT_FALSE(delegate.found_fallback_entry_.has_response_id()); |  442   EXPECT_FALSE(delegate.found_fallback_entry_.has_response_id()); | 
|  443 } |  443 } | 
|  444  |  444  | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  479   storage->AddStoredGroup(group); |  479   storage->AddStoredGroup(group); | 
|  480   storage->AddStoredCache(cache); |  480   storage->AddStoredCache(cache); | 
|  481  |  481  | 
|  482   // The test url is in both fallback namespace urls, but should match |  482   // The test url is in both fallback namespace urls, but should match | 
|  483   // the longer of the two. |  483   // the longer of the two. | 
|  484   const GURL kTestUrl("http://blah/fallback_namespace/longer/test"); |  484   const GURL kTestUrl("http://blah/fallback_namespace/longer/test"); | 
|  485  |  485  | 
|  486   // Conduct the test. |  486   // Conduct the test. | 
|  487   MockStorageDelegate delegate; |  487   MockStorageDelegate delegate; | 
|  488   EXPECT_NE(kTestUrl, delegate.found_url_); |  488   EXPECT_NE(kTestUrl, delegate.found_url_); | 
|  489   storage->FindResponseForMainRequest(kTestUrl, &delegate); |  489   storage->FindResponseForMainRequest(kTestUrl, GURL(), &delegate); | 
|  490   EXPECT_NE(kTestUrl, delegate.found_url_); |  490   EXPECT_NE(kTestUrl, delegate.found_url_); | 
|  491   MessageLoop::current()->RunAllPending();  // Do async task execution. |  491   MessageLoop::current()->RunAllPending();  // Do async task execution. | 
|  492   EXPECT_EQ(kTestUrl, delegate.found_url_); |  492   EXPECT_EQ(kTestUrl, delegate.found_url_); | 
|  493   EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); |  493   EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); | 
|  494   EXPECT_EQ(kCacheId, delegate.found_cache_id_); |  494   EXPECT_EQ(kCacheId, delegate.found_cache_id_); | 
|  495   EXPECT_FALSE(delegate.found_entry_.has_response_id()); |  495   EXPECT_FALSE(delegate.found_entry_.has_response_id()); | 
|  496   EXPECT_EQ(kResponseId2, delegate.found_fallback_entry_.response_id()); |  496   EXPECT_EQ(kResponseId2, delegate.found_fallback_entry_.response_id()); | 
|  497   EXPECT_EQ(kFallbackEntryUrl2, delegate.found_fallback_url_); |  497   EXPECT_EQ(kFallbackEntryUrl2, delegate.found_fallback_url_); | 
|  498   EXPECT_TRUE(delegate.found_fallback_entry_.IsFallback()); |  498   EXPECT_TRUE(delegate.found_fallback_entry_.IsFallback()); | 
|  499 } |  499 } | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  536   cache->set_complete(true); |  536   cache->set_complete(true); | 
|  537   group = new AppCacheGroup(&service, kManifestUrl2, 222); |  537   group = new AppCacheGroup(&service, kManifestUrl2, 222); | 
|  538   group->AddCache(cache); |  538   group->AddCache(cache); | 
|  539   storage->AddStoredGroup(group); |  539   storage->AddStoredGroup(group); | 
|  540   storage->AddStoredCache(cache); |  540   storage->AddStoredCache(cache); | 
|  541  |  541  | 
|  542   // Conduct the test, we should find the response from the second cache |  542   // Conduct the test, we should find the response from the second cache | 
|  543   // since it's "in use". |  543   // since it's "in use". | 
|  544   MockStorageDelegate delegate; |  544   MockStorageDelegate delegate; | 
|  545   EXPECT_NE(kEntryUrl, delegate.found_url_); |  545   EXPECT_NE(kEntryUrl, delegate.found_url_); | 
|  546   storage->FindResponseForMainRequest(kEntryUrl, &delegate); |  546   storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 
|  547   EXPECT_NE(kEntryUrl, delegate.found_url_); |  547   EXPECT_NE(kEntryUrl, delegate.found_url_); | 
|  548   MessageLoop::current()->RunAllPending();  // Do async task execution. |  548   MessageLoop::current()->RunAllPending();  // Do async task execution. | 
|  549   EXPECT_EQ(kEntryUrl, delegate.found_url_); |  549   EXPECT_EQ(kEntryUrl, delegate.found_url_); | 
|  550   EXPECT_EQ(kManifestUrl2, delegate.found_manifest_url_); |  550   EXPECT_EQ(kManifestUrl2, delegate.found_manifest_url_); | 
|  551   EXPECT_EQ(kCacheId2, delegate.found_cache_id_); |  551   EXPECT_EQ(kCacheId2, delegate.found_cache_id_); | 
|  552   EXPECT_EQ(kResponseId2, delegate.found_entry_.response_id()); |  552   EXPECT_EQ(kResponseId2, delegate.found_entry_.response_id()); | 
|  553   EXPECT_TRUE(delegate.found_entry_.IsExplicit()); |  553   EXPECT_TRUE(delegate.found_entry_.IsExplicit()); | 
|  554   EXPECT_FALSE(delegate.found_fallback_entry_.has_response_id()); |  554   EXPECT_FALSE(delegate.found_fallback_entry_.has_response_id()); | 
|  555 } |  555 } | 
|  556  |  556  | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|  582   scoped_refptr<AppCacheGroup> group( |  582   scoped_refptr<AppCacheGroup> group( | 
|  583       new AppCacheGroup(&service, kManifestUrl, 111)); |  583       new AppCacheGroup(&service, kManifestUrl, 111)); | 
|  584   group->AddCache(cache); |  584   group->AddCache(cache); | 
|  585   storage->AddStoredGroup(group); |  585   storage->AddStoredGroup(group); | 
|  586   storage->AddStoredCache(cache); |  586   storage->AddStoredCache(cache); | 
|  587  |  587  | 
|  588   MockStorageDelegate delegate; |  588   MockStorageDelegate delegate; | 
|  589  |  589  | 
|  590   // We should not find anything for the foreign entry. |  590   // We should not find anything for the foreign entry. | 
|  591   EXPECT_NE(kEntryUrl, delegate.found_url_); |  591   EXPECT_NE(kEntryUrl, delegate.found_url_); | 
|  592   storage->FindResponseForMainRequest(kEntryUrl, &delegate); |  592   storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 
|  593   EXPECT_NE(kEntryUrl, delegate.found_url_); |  593   EXPECT_NE(kEntryUrl, delegate.found_url_); | 
|  594   MessageLoop::current()->RunAllPending();  // Do async task execution. |  594   MessageLoop::current()->RunAllPending();  // Do async task execution. | 
|  595   EXPECT_EQ(kEntryUrl, delegate.found_url_); |  595   EXPECT_EQ(kEntryUrl, delegate.found_url_); | 
|  596   EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |  596   EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 
|  597   EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |  597   EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 
|  598   EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |  598   EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 
|  599   EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |  599   EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 
|  600   EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |  600   EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); | 
|  601   EXPECT_EQ(0, delegate.found_entry_.types()); |  601   EXPECT_EQ(0, delegate.found_entry_.types()); | 
|  602   EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |  602   EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 
|  603  |  603  | 
|  604   // We should not find anything for the online namespace. |  604   // We should not find anything for the online namespace. | 
|  605   EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); |  605   EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); | 
|  606   storage->FindResponseForMainRequest(kOnlineNamespaceUrl, &delegate); |  606   storage->FindResponseForMainRequest(kOnlineNamespaceUrl, GURL(), &delegate); | 
|  607   EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); |  607   EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); | 
|  608   MessageLoop::current()->RunAllPending();  // Do async task execution. |  608   MessageLoop::current()->RunAllPending();  // Do async task execution. | 
|  609   EXPECT_EQ(kOnlineNamespaceUrl, delegate.found_url_); |  609   EXPECT_EQ(kOnlineNamespaceUrl, delegate.found_url_); | 
|  610   EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |  610   EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 
|  611   EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |  611   EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 
|  612   EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |  612   EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 
|  613   EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |  613   EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 
|  614   EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |  614   EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); | 
|  615   EXPECT_EQ(0, delegate.found_entry_.types()); |  615   EXPECT_EQ(0, delegate.found_entry_.types()); | 
|  616   EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |  616   EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 
|  617 } |  617 } | 
|  618  |  618  | 
|  619 }  // namespace appcache |  619 }  // namespace appcache | 
|  620  |  620  | 
| OLD | NEW |