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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_utils_unittest.cc

Issue 2418583002: Fix OfflinePageUtilsTest.CheckExistenceOfPagesWithURL. (Closed)
Patch Set: CR 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/android/offline_pages/offline_page_utils.h" 5 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/feature_list.h" 12 #include "base/feature_list.h"
13 #include "base/files/file.h" 13 #include "base/files/file.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/run_loop.h"
16 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
17 #include "base/test/test_simple_task_runner.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" 19 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
20 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h " 20 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h "
21 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "components/offline_pages/client_namespace_constants.h" 23 #include "components/offline_pages/client_namespace_constants.h"
24 #include "components/offline_pages/offline_page_feature.h" 24 #include "components/offline_pages/offline_page_feature.h"
25 #include "components/offline_pages/offline_page_model.h" 25 #include "components/offline_pages/offline_page_model.h"
26 #include "components/offline_pages/offline_page_test_archiver.h" 26 #include "components/offline_pages/offline_page_test_archiver.h"
27 #include "components/offline_pages/offline_page_test_store.h" 27 #include "components/offline_pages/offline_page_test_store.h"
28 #include "components/offline_pages/offline_page_types.h" 28 #include "components/offline_pages/offline_page_types.h"
29 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "net/base/filename_util.h" 30 #include "net/base/filename_util.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
31 #include "url/gurl.h" 32 #include "url/gurl.h"
32 33
33 namespace offline_pages { 34 namespace offline_pages {
34 namespace { 35 namespace {
35 36
36 const GURL kTestPage1Url("http://test.org/page1"); 37 const GURL kTestPage1Url("http://test.org/page1");
37 const GURL kTestPage2Url("http://test.org/page2"); 38 const GURL kTestPage2Url("http://test.org/page2");
38 const GURL kTestPage3Url("http://test.org/page3"); 39 const GURL kTestPage3Url("http://test.org/page3");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 TestingProfile* profile() { return &profile_; } 73 TestingProfile* profile() { return &profile_; }
73 74
74 int64_t offline_id() const { return offline_id_; } 75 int64_t offline_id() const { return offline_id_; }
75 76
76 private: 77 private:
77 void CreateOfflinePages(); 78 void CreateOfflinePages();
78 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver( 79 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver(
79 const GURL& url, 80 const GURL& url,
80 const base::FilePath& file_name); 81 const base::FilePath& file_name);
81 82
83 content::TestBrowserThreadBundle browser_thread_bundle_;
82 int64_t offline_id_; 84 int64_t offline_id_;
83 GURL url_; 85 GURL url_;
84
85 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
86 base::ThreadTaskRunnerHandle task_runner_handle_;
87 TestingProfile profile_; 86 TestingProfile profile_;
88 }; 87 };
89 88
90 OfflinePageUtilsTest::OfflinePageUtilsTest() 89 OfflinePageUtilsTest::OfflinePageUtilsTest() = default;
91 : task_runner_(new base::TestSimpleTaskRunner),
92 task_runner_handle_(task_runner_) {}
93 90
94 OfflinePageUtilsTest::~OfflinePageUtilsTest() {} 91 OfflinePageUtilsTest::~OfflinePageUtilsTest() {}
95 92
96 void OfflinePageUtilsTest::SetUp() { 93 void OfflinePageUtilsTest::SetUp() {
97 // Enables offline pages feature. 94 // Enables offline pages feature.
98 // TODO(jianli): Remove this once the feature is completely enabled. 95 // TODO(jianli): Remove this once the feature is completely enabled.
99 base::FeatureList::ClearInstanceForTesting(); 96 base::FeatureList::ClearInstanceForTesting();
100 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); 97 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList);
101 feature_list->InitializeFromCommandLine( 98 feature_list->InitializeFromCommandLine(
102 offline_pages::kOfflineBookmarksFeature.name, ""); 99 offline_pages::kOfflineBookmarksFeature.name, "");
103 base::FeatureList::SetInstance(std::move(feature_list)); 100 base::FeatureList::SetInstance(std::move(feature_list));
104 101
105 // Set up the factory for testing. 102 // Set up the factory for testing.
106 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( 103 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse(
107 &profile_, BuildTestOfflinePageModel); 104 &profile_, BuildTestOfflinePageModel);
108 RunUntilIdle(); 105 RunUntilIdle();
109 106
110 // Make sure the store contains the right offline pages before the load 107 // Make sure the store contains the right offline pages before the load
111 // happens. 108 // happens.
112 CreateOfflinePages(); 109 CreateOfflinePages();
113 } 110 }
114 111
115 void OfflinePageUtilsTest::RunUntilIdle() { 112 void OfflinePageUtilsTest::RunUntilIdle() {
116 task_runner_->RunUntilIdle(); 113 base::RunLoop().RunUntilIdle();
117 } 114 }
118 115
119 void OfflinePageUtilsTest::OnSavePageDone(SavePageResult result, 116 void OfflinePageUtilsTest::OnSavePageDone(SavePageResult result,
120 int64_t offline_id) { 117 int64_t offline_id) {
121 offline_id_ = offline_id; 118 offline_id_ = offline_id;
122 } 119 }
123 120
124 void OfflinePageUtilsTest::OnExpirePageDone(bool success) { 121 void OfflinePageUtilsTest::OnExpirePageDone(bool success) {
125 // Result ignored here. 122 // Result ignored here.
126 } 123 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_TRUE(page_exists); 191 EXPECT_TRUE(page_exists);
195 // This one should be missing 192 // This one should be missing
196 OfflinePageUtils::CheckExistenceOfPagesWithURL( 193 OfflinePageUtils::CheckExistenceOfPagesWithURL(
197 profile(), kDownloadNamespace, kTestPage3Url, 194 profile(), kDownloadNamespace, kTestPage3Url,
198 base::Bind(&BoolCallback, base::Unretained(&page_exists))); 195 base::Bind(&BoolCallback, base::Unretained(&page_exists)));
199 RunUntilIdle(); 196 RunUntilIdle();
200 EXPECT_FALSE(page_exists); 197 EXPECT_FALSE(page_exists);
201 } 198 }
202 199
203 } // namespace offline_pages 200 } // namespace offline_pages
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698