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

Side by Side Diff: components/offline_pages/downloads/download_ui_adapter_unittest.cc

Issue 2263753002: Add 'title' field to DownloadUIItem and thread through bridges to OfflinePageDownloadItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR feedback Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/downloads/download_ui_adapter.h" 5 #include "components/offline_pages/downloads/download_ui_adapter.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/strings/utf_string_conversions.h"
19 #include "base/test/test_mock_time_task_runner.h" 20 #include "base/test/test_mock_time_task_runner.h"
20 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
22 #include "components/offline_pages/client_namespace_constants.h" 23 #include "components/offline_pages/client_namespace_constants.h"
23 #include "components/offline_pages/stub_offline_page_model.h" 24 #include "components/offline_pages/stub_offline_page_model.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 namespace offline_pages { 27 namespace offline_pages {
27 28
28 namespace { 29 namespace {
29 // Constants for a test OfflinePageItem. 30 // Constants for a test OfflinePageItem.
30 static const int kTestOfflineId1 = 1; 31 static const int kTestOfflineId1 = 1;
31 static const int kTestOfflineId2 = 2; 32 static const int kTestOfflineId2 = 2;
32 static const int kTestOfflineId3 = 3; 33 static const int kTestOfflineId3 = 3;
33 static const char kTestUrl[] = "http://foo.com/bar.mhtml"; 34 static const char kTestUrl[] = "http://foo.com/bar.mhtml";
34 static const char kTestGuid1[] = "cccccccc-cccc-4ccc-0ccc-ccccccccccc1"; 35 static const char kTestGuid1[] = "cccccccc-cccc-4ccc-0ccc-ccccccccccc1";
35 static const char kTestGuid2[] = "cccccccc-cccc-4ccc-0ccc-ccccccccccc2"; 36 static const char kTestGuid2[] = "cccccccc-cccc-4ccc-0ccc-ccccccccccc2";
36 static const char kTestBadGuid[] = "ccccccc-cccc-0ccc-0ccc-ccccccccccc0"; 37 static const char kTestBadGuid[] = "ccccccc-cccc-0ccc-0ccc-ccccccccccc0";
37 static const ClientId kTestClientIdOtherNamespace(kLastNNamespace, kTestGuid1); 38 static const ClientId kTestClientIdOtherNamespace(kLastNNamespace, kTestGuid1);
38 static const ClientId kTestClientIdOtherGuid(kLastNNamespace, kTestBadGuid); 39 static const ClientId kTestClientIdOtherGuid(kLastNNamespace, kTestBadGuid);
39 static const ClientId kTestClientId1(kAsyncNamespace, kTestGuid1); 40 static const ClientId kTestClientId1(kAsyncNamespace, kTestGuid1);
40 static const ClientId kTestClientId2(kAsyncNamespace, kTestGuid2); 41 static const ClientId kTestClientId2(kAsyncNamespace, kTestGuid2);
41 static const base::FilePath kTestFilePath = 42 static const base::FilePath kTestFilePath =
42 base::FilePath(FILE_PATH_LITERAL("foo/bar.mhtml")); 43 base::FilePath(FILE_PATH_LITERAL("foo/bar.mhtml"));
43 static const int kFileSize = 1000; 44 static const int kFileSize = 1000;
44 static const base::Time kTestCreationTime = base::Time::Now(); 45 static const base::Time kTestCreationTime = base::Time::Now();
46 static const base::string16 kTestTitle = base::ASCIIToUTF16("test title");
45 } // namespace 47 } // namespace
46 48
47 // Mock OfflinePageModel for testing the SavePage calls. 49 // Mock OfflinePageModel for testing the SavePage calls.
48 class MockOfflinePageModel : public StubOfflinePageModel { 50 class MockOfflinePageModel : public StubOfflinePageModel {
49 public: 51 public:
50 MockOfflinePageModel(base::TestMockTimeTaskRunner* task_runner) 52 MockOfflinePageModel(base::TestMockTimeTaskRunner* task_runner)
51 : observer_(nullptr), 53 : observer_(nullptr),
52 task_runner_(task_runner) { 54 task_runner_(task_runner) {
53 adapter.reset(new DownloadUIAdapter(this)); 55 adapter.reset(new DownloadUIAdapter(this));
54 // Add one page. 56 // Add one page.
55 OfflinePageItem page(GURL(kTestUrl), 57 OfflinePageItem page(GURL(kTestUrl),
56 kTestOfflineId1, 58 kTestOfflineId1,
57 kTestClientId1, 59 kTestClientId1,
58 kTestFilePath, 60 kTestFilePath,
59 kFileSize, 61 kFileSize,
60 kTestCreationTime); 62 kTestCreationTime);
63 page.title = kTestTitle;
61 pages[kTestOfflineId1] = page; 64 pages[kTestOfflineId1] = page;
62 } 65 }
63 66
64 ~MockOfflinePageModel() override {} 67 ~MockOfflinePageModel() override {}
65 68
66 // OfflinePageModel overrides. 69 // OfflinePageModel overrides.
67 void AddObserver(Observer* observer) override { 70 void AddObserver(Observer* observer) override {
68 EXPECT_TRUE(observer != nullptr); 71 EXPECT_TRUE(observer != nullptr);
69 observer_ = observer; 72 observer_ = observer;
70 } 73 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 TEST_F(DownloadUIAdapterTest, InitialItemConversion) { 194 TEST_F(DownloadUIAdapterTest, InitialItemConversion) {
192 EXPECT_EQ(1UL, model->pages.size()); 195 EXPECT_EQ(1UL, model->pages.size());
193 EXPECT_EQ(kTestGuid1, model->pages[kTestOfflineId1].client_id.id); 196 EXPECT_EQ(kTestGuid1, model->pages[kTestOfflineId1].client_id.id);
194 PumpLoop(); 197 PumpLoop();
195 const DownloadUIItem* item = model->adapter->GetItem(kTestGuid1); 198 const DownloadUIItem* item = model->adapter->GetItem(kTestGuid1);
196 EXPECT_EQ(kTestGuid1, item->guid); 199 EXPECT_EQ(kTestGuid1, item->guid);
197 EXPECT_EQ(kTestUrl, item->url.spec()); 200 EXPECT_EQ(kTestUrl, item->url.spec());
198 EXPECT_EQ(kTestFilePath, item->target_path); 201 EXPECT_EQ(kTestFilePath, item->target_path);
199 EXPECT_EQ(kTestCreationTime, item->start_time); 202 EXPECT_EQ(kTestCreationTime, item->start_time);
200 EXPECT_EQ(kFileSize, item->total_bytes); 203 EXPECT_EQ(kFileSize, item->total_bytes);
204 EXPECT_EQ(kTestTitle, item->title);
201 } 205 }
202 206
203 TEST_F(DownloadUIAdapterTest, ItemDeletedAdded) { 207 TEST_F(DownloadUIAdapterTest, ItemDeletedAdded) {
204 PumpLoop(); 208 PumpLoop();
205 // Add page, notify adapter. 209 // Add page, notify adapter.
206 OfflinePageItem page(GURL(kTestUrl), 210 OfflinePageItem page(GURL(kTestUrl),
207 kTestOfflineId2, 211 kTestOfflineId2,
208 kTestClientId2, 212 kTestClientId2,
209 base::FilePath(kTestFilePath), 213 base::FilePath(kTestFilePath),
210 kFileSize, 214 kFileSize,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 PumpLoop(); 275 PumpLoop();
272 EXPECT_EQ(1UL, added_guids.size()); 276 EXPECT_EQ(1UL, added_guids.size());
273 EXPECT_EQ(kTestGuid2, added_guids[0]); 277 EXPECT_EQ(kTestGuid2, added_guids[0]);
274 // TODO(dimich): we currently don't report updated items since OPM doesn't 278 // TODO(dimich): we currently don't report updated items since OPM doesn't
275 // have support for that. Add as needed, this will have to be updated when 279 // have support for that. Add as needed, this will have to be updated when
276 // support is added. 280 // support is added.
277 EXPECT_EQ(0UL, updated_guids.size()); 281 EXPECT_EQ(0UL, updated_guids.size());
278 } 282 }
279 283
280 } // namespace offline_pages 284 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698