| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "content/browser/appcache/appcache.h" | 8 #include "content/browser/appcache/appcache.h" |
| 9 #include "content/browser/appcache/appcache_group.h" | 9 #include "content/browser/appcache/appcache_group.h" |
| 10 #include "content/browser/appcache/appcache_host.h" | 10 #include "content/browser/appcache/appcache_host.h" |
| 11 #include "content/browser/appcache/appcache_update_job.h" | 11 #include "content/browser/appcache/appcache_update_job.h" |
| 12 #include "content/browser/appcache/mock_appcache_service.h" | 12 #include "content/browser/appcache/mock_appcache_service.h" |
| 13 #include "content/common/appcache_interfaces.h" | 13 #include "content/common/appcache_interfaces.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 class TestAppCacheFrontend : public content::AppCacheFrontend { | 18 class TestAppCacheFrontend : public content::AppCacheFrontend { |
| 19 public: | 19 public: |
| 20 TestAppCacheFrontend() | 20 TestAppCacheFrontend() |
| 21 : last_host_id_(-1), last_cache_id_(-1), | 21 : last_host_id_(-1), last_cache_id_(-1), |
| 22 last_status_(content::APPCACHE_STATUS_OBSOLETE) { | 22 last_status_(content::APPCACHE_STATUS_OBSOLETE) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 virtual void OnCacheSelected( | 25 void OnCacheSelected(int host_id, |
| 26 int host_id, const content::AppCacheInfo& info) override { | 26 const content::AppCacheInfo& info) override { |
| 27 last_host_id_ = host_id; | 27 last_host_id_ = host_id; |
| 28 last_cache_id_ = info.cache_id; | 28 last_cache_id_ = info.cache_id; |
| 29 last_status_ = info.status; | 29 last_status_ = info.status; |
| 30 } | 30 } |
| 31 | 31 |
| 32 virtual void OnStatusChanged(const std::vector<int>& host_ids, | 32 void OnStatusChanged(const std::vector<int>& host_ids, |
| 33 content::AppCacheStatus status) override { | 33 content::AppCacheStatus status) override {} |
| 34 } | |
| 35 | 34 |
| 36 virtual void OnEventRaised(const std::vector<int>& host_ids, | 35 void OnEventRaised(const std::vector<int>& host_ids, |
| 37 content::AppCacheEventID event_id) override { | 36 content::AppCacheEventID event_id) override {} |
| 38 } | |
| 39 | 37 |
| 40 virtual void OnErrorEventRaised(const std::vector<int>& host_ids, | 38 void OnErrorEventRaised( |
| 41 const content::AppCacheErrorDetails& details) | 39 const std::vector<int>& host_ids, |
| 42 override {} | 40 const content::AppCacheErrorDetails& details) override {} |
| 43 | 41 |
| 44 virtual void OnProgressEventRaised(const std::vector<int>& host_ids, | 42 void OnProgressEventRaised(const std::vector<int>& host_ids, |
| 45 const GURL& url, | 43 const GURL& url, |
| 46 int num_total, int num_complete) override { | 44 int num_total, |
| 47 } | 45 int num_complete) override {} |
| 48 | 46 |
| 49 virtual void OnLogMessage(int host_id, content::AppCacheLogLevel log_level, | 47 void OnLogMessage(int host_id, |
| 50 const std::string& message) override { | 48 content::AppCacheLogLevel log_level, |
| 51 } | 49 const std::string& message) override {} |
| 52 | 50 |
| 53 virtual void OnContentBlocked(int host_id, | 51 void OnContentBlocked(int host_id, const GURL& manifest_url) override {} |
| 54 const GURL& manifest_url) override { | |
| 55 } | |
| 56 | 52 |
| 57 int last_host_id_; | 53 int last_host_id_; |
| 58 int64 last_cache_id_; | 54 int64 last_cache_id_; |
| 59 content::AppCacheStatus last_status_; | 55 content::AppCacheStatus last_status_; |
| 60 }; | 56 }; |
| 61 | 57 |
| 62 } // namespace anon | 58 } // namespace anon |
| 63 | 59 |
| 64 namespace content { | 60 namespace content { |
| 65 | 61 |
| 66 class TestUpdateObserver : public AppCacheGroup::UpdateObserver { | 62 class TestUpdateObserver : public AppCacheGroup::UpdateObserver { |
| 67 public: | 63 public: |
| 68 TestUpdateObserver() : update_completed_(false), group_has_cache_(false) { | 64 TestUpdateObserver() : update_completed_(false), group_has_cache_(false) { |
| 69 } | 65 } |
| 70 | 66 |
| 71 virtual void OnUpdateComplete(AppCacheGroup* group) override { | 67 void OnUpdateComplete(AppCacheGroup* group) override { |
| 72 update_completed_ = true; | 68 update_completed_ = true; |
| 73 group_has_cache_ = group->HasCache(); | 69 group_has_cache_ = group->HasCache(); |
| 74 } | 70 } |
| 75 | 71 |
| 76 virtual void OnContentBlocked(AppCacheGroup* group) { | 72 virtual void OnContentBlocked(AppCacheGroup* group) { |
| 77 } | 73 } |
| 78 | 74 |
| 79 bool update_completed_; | 75 bool update_completed_; |
| 80 bool group_has_cache_; | 76 bool group_has_cache_; |
| 81 }; | 77 }; |
| 82 | 78 |
| 83 class TestAppCacheHost : public AppCacheHost { | 79 class TestAppCacheHost : public AppCacheHost { |
| 84 public: | 80 public: |
| 85 TestAppCacheHost(int host_id, AppCacheFrontend* frontend, | 81 TestAppCacheHost(int host_id, AppCacheFrontend* frontend, |
| 86 AppCacheServiceImpl* service) | 82 AppCacheServiceImpl* service) |
| 87 : AppCacheHost(host_id, frontend, service), | 83 : AppCacheHost(host_id, frontend, service), |
| 88 update_completed_(false) { | 84 update_completed_(false) { |
| 89 } | 85 } |
| 90 | 86 |
| 91 virtual void OnUpdateComplete(AppCacheGroup* group) override { | 87 void OnUpdateComplete(AppCacheGroup* group) override { |
| 92 update_completed_ = true; | 88 update_completed_ = true; |
| 93 } | 89 } |
| 94 | 90 |
| 95 bool update_completed_; | 91 bool update_completed_; |
| 96 }; | 92 }; |
| 97 | 93 |
| 98 class AppCacheGroupTest : public testing::Test { | 94 class AppCacheGroupTest : public testing::Test { |
| 99 private: | 95 private: |
| 100 base::MessageLoop message_loop_; | 96 base::MessageLoop message_loop_; |
| 101 }; | 97 }; |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 EXPECT_TRUE(group->FindObserver(&host, group->observers_)); | 289 EXPECT_TRUE(group->FindObserver(&host, group->observers_)); |
| 294 | 290 |
| 295 // Delete update to cause it to complete. Verify host is notified. | 291 // Delete update to cause it to complete. Verify host is notified. |
| 296 delete group->update_job_; | 292 delete group->update_job_; |
| 297 EXPECT_EQ(AppCacheGroup::IDLE, group->update_status_); | 293 EXPECT_EQ(AppCacheGroup::IDLE, group->update_status_); |
| 298 EXPECT_TRUE(group->restart_update_task_.IsCancelled()); | 294 EXPECT_TRUE(group->restart_update_task_.IsCancelled()); |
| 299 EXPECT_TRUE(host.update_completed_); | 295 EXPECT_TRUE(host.update_completed_); |
| 300 } | 296 } |
| 301 | 297 |
| 302 } // namespace content | 298 } // namespace content |
| OLD | NEW |