Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: components/offline_pages/offline_page_metadata_store_impl_unittest.cc

Issue 2343743002: [Offline pages] Updating the UpdateCallback in OPMStoreSQL (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/offline_pages/offline_page_metadata_store.h" 5 #include "components/offline_pages/offline_page_metadata_store.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/test/test_simple_task_runner.h" 16 #include "base/test/test_simple_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "components/offline_pages/offline_page_item.h" 18 #include "components/offline_pages/offline_page_item.h"
19 #include "components/offline_pages/offline_page_metadata_store_sql.h" 19 #include "components/offline_pages/offline_page_metadata_store_sql.h"
20 #include "components/offline_pages/offline_page_model.h" 20 #include "components/offline_pages/offline_page_model.h"
21 #include "sql/connection.h" 21 #include "sql/connection.h"
22 #include "sql/statement.h" 22 #include "sql/statement.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 namespace offline_pages { 25 namespace offline_pages {
26 26
27 namespace { 27 namespace {
28 28
29 using ItemActionStatus = OfflinePageMetadataStore::ItemActionStatus;
30
29 #define OFFLINE_PAGES_TABLE_V1 "offlinepages_v1" 31 #define OFFLINE_PAGES_TABLE_V1 "offlinepages_v1"
30 32
31 const char kTestClientNamespace[] = "CLIENT_NAMESPACE"; 33 const char kTestClientNamespace[] = "CLIENT_NAMESPACE";
32 const char kTestURL[] = "https://example.com"; 34 const char kTestURL[] = "https://example.com";
33 const ClientId kTestClientId1(kTestClientNamespace, "1234"); 35 const ClientId kTestClientId1(kTestClientNamespace, "1234");
34 const ClientId kTestClientId2(kTestClientNamespace, "5678"); 36 const ClientId kTestClientId2(kTestClientNamespace, "5678");
35 const base::FilePath::CharType kFilePath[] = 37 const base::FilePath::CharType kFilePath[] =
36 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml"); 38 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml");
37 int64_t kFileSize = 234567LL; 39 int64_t kFileSize = 234567LL;
38 int64_t kOfflineId = 12345LL; 40 int64_t kOfflineId = 12345LL;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 std::unique_ptr<OfflinePageMetadataStore> BuildStore(); 228 std::unique_ptr<OfflinePageMetadataStore> BuildStore();
227 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM52(); 229 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM52();
228 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM53(); 230 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM53();
229 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM54(); 231 std::unique_ptr<OfflinePageMetadataStore> BuildStoreWithSchemaFromM54();
230 232
231 void PumpLoop(); 233 void PumpLoop();
232 234
233 void GetOfflinePagesCallback( 235 void GetOfflinePagesCallback(
234 OfflinePageMetadataStore::LoadStatus load_status, 236 OfflinePageMetadataStore::LoadStatus load_status,
235 const std::vector<OfflinePageItem>& offline_pages); 237 const std::vector<OfflinePageItem>& offline_pages);
236 void AddCallback(OfflinePageMetadataStore::ItemActionStatus status); 238 void AddCallback(ItemActionStatus status);
237 void UpdateCallback(CalledCallback called_callback, bool success); 239 void UpdateCallback(CalledCallback called_callback,
240 const std::map<int64_t, ItemActionStatus>& failed_items,
241 const std::vector<OfflinePageItem>& updated_items);
242 void ResetCallback(bool status);
238 243
239 void ClearResults(); 244 void ClearResults();
240 245
241 OfflinePageItem CheckThatStoreHasOneItem(); 246 OfflinePageItem CheckThatStoreHasOneItem();
242 void CheckThatOfflinePageCanBeSaved( 247 void CheckThatOfflinePageCanBeSaved(
243 std::unique_ptr<OfflinePageMetadataStore> store); 248 std::unique_ptr<OfflinePageMetadataStore> store);
244 249
245 protected: 250 protected:
246 CalledCallback last_called_callback_; 251 CalledCallback last_called_callback_;
247 Status last_status_; 252 Status last_status_;
(...skipping 21 matching lines...) Expand all
269 274
270 void OfflinePageMetadataStoreTest::GetOfflinePagesCallback( 275 void OfflinePageMetadataStoreTest::GetOfflinePagesCallback(
271 OfflinePageMetadataStore::LoadStatus load_status, 276 OfflinePageMetadataStore::LoadStatus load_status,
272 const std::vector<OfflinePageItem>& offline_pages) { 277 const std::vector<OfflinePageItem>& offline_pages) {
273 last_called_callback_ = LOAD; 278 last_called_callback_ = LOAD;
274 last_status_ = load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED ? 279 last_status_ = load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED ?
275 STATUS_TRUE : STATUS_FALSE; 280 STATUS_TRUE : STATUS_FALSE;
276 offline_pages_.swap(const_cast<std::vector<OfflinePageItem>&>(offline_pages)); 281 offline_pages_.swap(const_cast<std::vector<OfflinePageItem>&>(offline_pages));
277 } 282 }
278 283
279 void OfflinePageMetadataStoreTest::AddCallback( 284 void OfflinePageMetadataStoreTest::AddCallback(ItemActionStatus status) {
280 OfflinePageMetadataStore::ItemActionStatus status) {
281 last_called_callback_ = ADD; 285 last_called_callback_ = ADD;
282 // TODO(fgorski): Add specific add status. 286 // TODO(fgorski): Add specific add status.
283 // last_item_status_ = status; 287 // last_item_status_ = status;
284 last_status_ = 288 last_status_ =
285 status == OfflinePageMetadataStore::SUCCESS ? STATUS_TRUE : STATUS_FALSE; 289 status == OfflinePageMetadataStore::SUCCESS ? STATUS_TRUE : STATUS_FALSE;
286 } 290 }
287 291
288 void OfflinePageMetadataStoreTest::UpdateCallback( 292 void OfflinePageMetadataStoreTest::UpdateCallback(
289 CalledCallback called_callback, 293 CalledCallback called_callback,
290 bool status) { 294 const std::map<int64_t, ItemActionStatus>& failed_items,
295 const std::vector<OfflinePageItem>& updated_items) {
291 last_called_callback_ = called_callback; 296 last_called_callback_ = called_callback;
297 last_status_ = updated_items.size() > 0 ? STATUS_TRUE : STATUS_FALSE;
Pete Williamson 2016/09/15 18:05:43 Should we save more information here? This doesn'
fgorski 2016/09/19 23:24:30 Done. I actually take the ownership of the result.
298 }
299
300 void OfflinePageMetadataStoreTest::ResetCallback(bool status) {
301 last_called_callback_ = RESET;
292 last_status_ = status ? STATUS_TRUE : STATUS_FALSE; 302 last_status_ = status ? STATUS_TRUE : STATUS_FALSE;
293 } 303 }
294 304
295 void OfflinePageMetadataStoreTest::ClearResults() { 305 void OfflinePageMetadataStoreTest::ClearResults() {
296 last_called_callback_ = NONE; 306 last_called_callback_ = NONE;
297 last_status_ = STATUS_NONE; 307 last_status_ = STATUS_NONE;
298 offline_pages_.clear(); 308 offline_pages_.clear();
299 } 309 }
300 310
301 OfflinePageItem OfflinePageMetadataStoreTest::CheckThatStoreHasOneItem() { 311 OfflinePageItem OfflinePageMetadataStoreTest::CheckThatStoreHasOneItem() {
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 store->GetOfflinePages( 710 store->GetOfflinePages(
701 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, 711 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback,
702 base::Unretained(this))); 712 base::Unretained(this)));
703 PumpLoop(); 713 PumpLoop();
704 714
705 EXPECT_EQ(LOAD, last_called_callback_); 715 EXPECT_EQ(LOAD, last_called_callback_);
706 EXPECT_EQ(STATUS_TRUE, last_status_); 716 EXPECT_EQ(STATUS_TRUE, last_status_);
707 EXPECT_EQ(2U, offline_pages_.size()); 717 EXPECT_EQ(2U, offline_pages_.size());
708 718
709 // Clear all records from the store. 719 // Clear all records from the store.
710 store->Reset(base::Bind(&OfflinePageMetadataStoreTest::UpdateCallback, 720 store->Reset(base::Bind(&OfflinePageMetadataStoreTest::ResetCallback,
711 base::Unretained(this), RESET)); 721 base::Unretained(this)));
712 PumpLoop(); 722 PumpLoop();
713 EXPECT_EQ(RESET, last_called_callback_); 723 EXPECT_EQ(RESET, last_called_callback_);
714 EXPECT_EQ(STATUS_TRUE, last_status_); 724 EXPECT_EQ(STATUS_TRUE, last_status_);
715 725
716 // Load the store. 726 // Load the store.
717 store->GetOfflinePages( 727 store->GetOfflinePages(
718 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback, 728 base::Bind(&OfflinePageMetadataStoreTest::GetOfflinePagesCallback,
719 base::Unretained(this))); 729 base::Unretained(this)));
720 PumpLoop(); 730 PumpLoop();
721 731
722 EXPECT_EQ(LOAD, last_called_callback_); 732 EXPECT_EQ(LOAD, last_called_callback_);
723 EXPECT_EQ(STATUS_TRUE, last_status_); 733 EXPECT_EQ(STATUS_TRUE, last_status_);
724 ASSERT_EQ(0U, offline_pages_.size()); 734 ASSERT_EQ(0U, offline_pages_.size());
725 } 735 }
726 736
727 } // namespace 737 } // namespace
728 } // namespace offline_pages 738 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698