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

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

Issue 2342443006: [Offline pages] Use the new policy bits (Closed)
Patch Set: i think i got it! Made sure it compiles Created 4 years, 2 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/strings/utf_string_conversions.h"
20 #include "base/test/test_mock_time_task_runner.h" 20 #include "base/test/test_mock_time_task_runner.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "components/offline_pages/client_namespace_constants.h" 23 #include "components/offline_pages/client_namespace_constants.h"
24 #include "components/offline_pages/client_policy_controller.h"
24 #include "components/offline_pages/stub_offline_page_model.h" 25 #include "components/offline_pages/stub_offline_page_model.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 namespace offline_pages { 28 namespace offline_pages {
28 29
29 namespace { 30 namespace {
30 // Constants for a test OfflinePageItem. 31 // Constants for a test OfflinePageItem.
31 static const int kTestOfflineId1 = 1; 32 static const int kTestOfflineId1 = 1;
32 static const int kTestOfflineId2 = 2; 33 static const int kTestOfflineId2 = 2;
33 static const int kTestOfflineId3 = 3; 34 static const int kTestOfflineId3 = 3;
(...skipping 10 matching lines...) Expand all
44 static const int kFileSize = 1000; 45 static const int kFileSize = 1000;
45 static const base::Time kTestCreationTime = base::Time::Now(); 46 static const base::Time kTestCreationTime = base::Time::Now();
46 static const base::string16 kTestTitle = base::ASCIIToUTF16("test title"); 47 static const base::string16 kTestTitle = base::ASCIIToUTF16("test title");
47 } // namespace 48 } // namespace
48 49
49 // Mock OfflinePageModel for testing the SavePage calls. 50 // Mock OfflinePageModel for testing the SavePage calls.
50 class MockOfflinePageModel : public StubOfflinePageModel { 51 class MockOfflinePageModel : public StubOfflinePageModel {
51 public: 52 public:
52 MockOfflinePageModel(base::TestMockTimeTaskRunner* task_runner) 53 MockOfflinePageModel(base::TestMockTimeTaskRunner* task_runner)
53 : observer_(nullptr), 54 : observer_(nullptr),
54 task_runner_(task_runner) { 55 task_runner_(task_runner),
56 policy_controller_(new ClientPolicyController()) {
55 adapter.reset(new DownloadUIAdapter(this)); 57 adapter.reset(new DownloadUIAdapter(this));
56 // Add one page. 58 // Add one page.
57 OfflinePageItem page(GURL(kTestUrl), 59 OfflinePageItem page(GURL(kTestUrl),
58 kTestOfflineId1, 60 kTestOfflineId1,
59 kTestClientId1, 61 kTestClientId1,
60 kTestFilePath, 62 kTestFilePath,
61 kFileSize, 63 kFileSize,
62 kTestCreationTime); 64 kTestCreationTime);
63 page.title = kTestTitle; 65 page.title = kTestTitle;
64 pages[kTestOfflineId1] = page; 66 pages[kTestOfflineId1] = page;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 104 }
103 } 105 }
104 } 106 }
105 107
106 void AddPageAndNotifyAdapter(const OfflinePageItem& page) { 108 void AddPageAndNotifyAdapter(const OfflinePageItem& page) {
107 EXPECT_EQ(pages.end(), pages.find(page.offline_id)); 109 EXPECT_EQ(pages.end(), pages.find(page.offline_id));
108 pages[page.offline_id] = page; 110 pages[page.offline_id] = page;
109 observer_->OfflinePageModelChanged(this); 111 observer_->OfflinePageModelChanged(this);
110 } 112 }
111 113
114 ClientPolicyController* GetPolicyController() override {
115 return policy_controller_.get();
116 }
117
112 // Normally, OfflinePageModel owns this adapter, so lets test it this way. 118 // Normally, OfflinePageModel owns this adapter, so lets test it this way.
113 std::unique_ptr<DownloadUIAdapter> adapter; 119 std::unique_ptr<DownloadUIAdapter> adapter;
114 120
115 std::map<int64_t, OfflinePageItem> pages; 121 std::map<int64_t, OfflinePageItem> pages;
116 122
117 private: 123 private:
118 OfflinePageModel::Observer* observer_; 124 OfflinePageModel::Observer* observer_;
119 base::TestMockTimeTaskRunner* task_runner_; 125 base::TestMockTimeTaskRunner* task_runner_;
126 // Normally owned by OfflinePageModel.
127 std::unique_ptr<ClientPolicyController> policy_controller_;
120 128
121 DISALLOW_COPY_AND_ASSIGN(MockOfflinePageModel); 129 DISALLOW_COPY_AND_ASSIGN(MockOfflinePageModel);
122 }; 130 };
123 131
124 class DownloadUIAdapterTest 132 class DownloadUIAdapterTest
125 : public testing::Test, 133 : public testing::Test,
126 public DownloadUIAdapter::Observer { 134 public DownloadUIAdapter::Observer {
127 public: 135 public:
128 DownloadUIAdapterTest(); 136 DownloadUIAdapterTest();
129 ~DownloadUIAdapterTest() override; 137 ~DownloadUIAdapterTest() override;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 model->adapter->RemoveObserver(this); 296 model->adapter->RemoveObserver(this);
289 // This will complete async fetch of items, but... 297 // This will complete async fetch of items, but...
290 PumpLoop(); 298 PumpLoop();
291 // items should not be loaded when there is no observers! 299 // items should not be loaded when there is no observers!
292 EXPECT_FALSE(items_loaded); 300 EXPECT_FALSE(items_loaded);
293 // This should not crash. 301 // This should not crash.
294 model->adapter->AddObserver(this); 302 model->adapter->AddObserver(this);
295 } 303 }
296 304
297 } // namespace offline_pages 305 } // namespace offline_pages
OLDNEW
« no previous file with comments | « components/offline_pages/downloads/download_ui_adapter.cc ('k') | components/offline_pages/offline_page_model_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698