| Index: components/offline_pages/offline_page_test_store.cc
|
| diff --git a/components/offline_pages/offline_page_test_store.cc b/components/offline_pages/offline_page_test_store.cc
|
| index 70b91c4e0116306876f4ef4a704cb2a076fa1d14..5d77db6ac3b625783e54b6c5cfb29325c4cece7e 100644
|
| --- a/components/offline_pages/offline_page_test_store.cc
|
| +++ b/components/offline_pages/offline_page_test_store.cc
|
| @@ -14,26 +14,35 @@ namespace offline_pages {
|
|
|
| OfflinePageTestStore::OfflinePageTestStore(
|
| const scoped_refptr<base::SingleThreadTaskRunner>& task_runner)
|
| - : task_runner_(task_runner), scenario_(TestScenario::SUCCESSFUL) {}
|
| + : task_runner_(task_runner),
|
| + scenario_(TestScenario::SUCCESSFUL),
|
| + reset_called_(false),
|
| + store_state_(StoreState::NOT_LOADED) {}
|
|
|
| OfflinePageTestStore::OfflinePageTestStore(
|
| const OfflinePageTestStore& other_store)
|
| : task_runner_(other_store.task_runner_),
|
| scenario_(other_store.scenario_),
|
| + reset_called_(false),
|
| + store_state_(StoreState::NOT_LOADED),
|
| offline_pages_(other_store.offline_pages_) {}
|
|
|
| OfflinePageTestStore::~OfflinePageTestStore() {}
|
|
|
| -void OfflinePageTestStore::GetOfflinePages(const LoadCallback& callback) {
|
| - OfflinePageMetadataStore::LoadStatus load_status;
|
| - if (scenario_ == TestScenario::LOAD_FAILED) {
|
| - load_status = OfflinePageMetadataStore::STORE_LOAD_FAILED;
|
| +void OfflinePageTestStore::GetOfflinePages(
|
| + const GetOfflinePagesCallback& callback) {
|
| + if (scenario_ == TestScenario::RESET_SUCCESS) {
|
| + store_state_ = StoreState::FAILED_LOADING;
|
| + offline_pages_.clear();
|
| + } else if (scenario_ == TestScenario::RESET_FAILED) {
|
| + // Load has to fail first, then reset will fail.
|
| + store_state_ = StoreState::FAILED_LOADING;
|
| offline_pages_.clear();
|
| } else {
|
| - load_status = OfflinePageMetadataStore::LOAD_SUCCEEDED;
|
| + store_state_ = StoreState::LOADED;
|
| }
|
| task_runner_->PostTask(FROM_HERE,
|
| - base::Bind(callback, load_status, GetAllPages()));
|
| + base::Bind(callback, store_state_, GetAllPages()));
|
| }
|
|
|
| void OfflinePageTestStore::AddOfflinePage(const OfflinePageItem& offline_page,
|
| @@ -91,7 +100,7 @@ void OfflinePageTestStore::RemoveOfflinePages(
|
| std::make_pair(offline_id, ItemActionStatus::STORE_ERROR));
|
| }
|
| // Anything different that LOADED is good here.
|
| - result->store_state = StoreState::FAILED_LOADING;
|
| + result->store_state = StoreState::FAILED_OPERATION;
|
| } else {
|
| for (const auto& offline_id : offline_ids) {
|
| auto iter = offline_pages_.find(offline_id);
|
| @@ -113,11 +122,21 @@ void OfflinePageTestStore::RemoveOfflinePages(
|
|
|
| void OfflinePageTestStore::Reset(const ResetCallback& callback) {
|
| offline_pages_.clear();
|
| - task_runner_->PostTask(FROM_HERE, base::Bind(callback, true));
|
| + reset_called_ = true;
|
| + if (scenario_ == TestScenario::RESET_FAILED) {
|
| + store_state_ = StoreState::FAILED_RESET;
|
| + } else {
|
| + // Flip scenario to successful after this, so that next read works.
|
| + store_state_ = StoreState::LOADED;
|
| + scenario_ = TestScenario::SUCCESSFUL;
|
| + }
|
| +
|
| + task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(callback, store_state_ == StoreState::LOADED));
|
| }
|
|
|
| StoreState OfflinePageTestStore::state() const {
|
| - return StoreState::LOADED;
|
| + return store_state_;
|
| }
|
|
|
| void OfflinePageTestStore::UpdateLastAccessTime(
|
|
|