| OLD | NEW |
| 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" | |
| 13 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 14 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 15 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 16 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 17 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 17 #include "base/test/scoped_feature_list.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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 private: | 77 private: |
| 78 void CreateOfflinePages(); | 78 void CreateOfflinePages(); |
| 79 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver( | 79 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver( |
| 80 const GURL& url, | 80 const GURL& url, |
| 81 const base::FilePath& file_name); | 81 const base::FilePath& file_name); |
| 82 | 82 |
| 83 content::TestBrowserThreadBundle browser_thread_bundle_; | 83 content::TestBrowserThreadBundle browser_thread_bundle_; |
| 84 int64_t offline_id_; | 84 int64_t offline_id_; |
| 85 GURL url_; | 85 GURL url_; |
| 86 TestingProfile profile_; | 86 TestingProfile profile_; |
| 87 base::test::ScopedFeatureList scoped_feature_list_; |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 OfflinePageUtilsTest::OfflinePageUtilsTest() = default; | 90 OfflinePageUtilsTest::OfflinePageUtilsTest() = default; |
| 90 | 91 |
| 91 OfflinePageUtilsTest::~OfflinePageUtilsTest() {} | 92 OfflinePageUtilsTest::~OfflinePageUtilsTest() {} |
| 92 | 93 |
| 93 void OfflinePageUtilsTest::SetUp() { | 94 void OfflinePageUtilsTest::SetUp() { |
| 94 // Enables offline pages feature. | 95 // Enables offline pages feature. |
| 95 // TODO(jianli): Remove this once the feature is completely enabled. | 96 // TODO(jianli): Remove this once the feature is completely enabled. |
| 96 base::FeatureList::ClearInstanceForTesting(); | 97 scoped_feature_list_.InitAndEnableFeature( |
| 97 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 98 offline_pages::kOfflineBookmarksFeature); |
| 98 feature_list->InitializeFromCommandLine( | |
| 99 offline_pages::kOfflineBookmarksFeature.name, ""); | |
| 100 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 101 | 99 |
| 102 // Set up the factory for testing. | 100 // Set up the factory for testing. |
| 103 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( | 101 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( |
| 104 &profile_, BuildTestOfflinePageModel); | 102 &profile_, BuildTestOfflinePageModel); |
| 105 RunUntilIdle(); | 103 RunUntilIdle(); |
| 106 | 104 |
| 107 // Make sure the store contains the right offline pages before the load | 105 // Make sure the store contains the right offline pages before the load |
| 108 // happens. | 106 // happens. |
| 109 CreateOfflinePages(); | 107 CreateOfflinePages(); |
| 110 } | 108 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 EXPECT_TRUE(page_exists); | 189 EXPECT_TRUE(page_exists); |
| 192 // This one should be missing | 190 // This one should be missing |
| 193 OfflinePageUtils::CheckExistenceOfPagesWithURL( | 191 OfflinePageUtils::CheckExistenceOfPagesWithURL( |
| 194 profile(), kDownloadNamespace, kTestPage3Url, | 192 profile(), kDownloadNamespace, kTestPage3Url, |
| 195 base::Bind(&BoolCallback, base::Unretained(&page_exists))); | 193 base::Bind(&BoolCallback, base::Unretained(&page_exists))); |
| 196 RunUntilIdle(); | 194 RunUntilIdle(); |
| 197 EXPECT_FALSE(page_exists); | 195 EXPECT_FALSE(page_exists); |
| 198 } | 196 } |
| 199 | 197 |
| 200 } // namespace offline_pages | 198 } // namespace offline_pages |
| OLD | NEW |