| OLD | NEW | 
|---|
| 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 "chrome/browser/android/offline_pages/offline_page_tab_helper.h" | 5 #include "chrome/browser/android/offline_pages/offline_page_tab_helper.h" | 
| 6 | 6 | 
| 7 #include <memory> | 7 #include <memory> | 
| 8 | 8 | 
| 9 #include "base/bind.h" | 9 #include "base/bind.h" | 
| 10 #include "base/command_line.h" | 10 #include "base/feature_list.h" | 
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" | 
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" | 
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" | 
| 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 14 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 
| 15 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h
     " | 15 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h
     " | 
| 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 
|  | 17 #include "components/offline_pages/offline_page_feature.h" | 
| 17 #include "components/offline_pages/offline_page_item.h" | 18 #include "components/offline_pages/offline_page_item.h" | 
| 18 #include "components/offline_pages/offline_page_model.h" | 19 #include "components/offline_pages/offline_page_model.h" | 
| 19 #include "components/offline_pages/offline_page_switches.h" |  | 
| 20 #include "components/offline_pages/offline_page_test_archiver.h" | 20 #include "components/offline_pages/offline_page_test_archiver.h" | 
| 21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" | 
| 22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" | 
| 23 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" | 
| 24 #include "net/base/network_change_notifier.h" | 24 #include "net/base/network_change_notifier.h" | 
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" | 
| 26 | 26 | 
| 27 namespace offline_pages { | 27 namespace offline_pages { | 
| 28 | 28 | 
| 29 namespace { | 29 namespace { | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 88 | 88 | 
| 89   std::unique_ptr<TestNetworkChangeNotifier> network_change_notifier_; | 89   std::unique_ptr<TestNetworkChangeNotifier> network_change_notifier_; | 
| 90   OfflinePageTabHelper* offline_page_tab_helper_;  // Not owned. | 90   OfflinePageTabHelper* offline_page_tab_helper_;  // Not owned. | 
| 91 | 91 | 
| 92   int64_t offline_id_; | 92   int64_t offline_id_; | 
| 93 | 93 | 
| 94   DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelperTest); | 94   DISALLOW_COPY_AND_ASSIGN(OfflinePageTabHelperTest); | 
| 95 }; | 95 }; | 
| 96 | 96 | 
| 97 void OfflinePageTabHelperTest::SetUp() { | 97 void OfflinePageTabHelperTest::SetUp() { | 
|  | 98   // Enables offline pages feature. | 
|  | 99   // TODO(jianli): Remove this once the feature is completely enabled. | 
|  | 100   base::FeatureList::ClearInstanceForTesting(); | 
|  | 101   scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | 
|  | 102   feature_list->InitializeFromCommandLine( | 
|  | 103       offline_pages::kOfflineBookmarksFeature.name, ""); | 
|  | 104   base::FeatureList::SetInstance(std::move(feature_list)); | 
|  | 105 | 
| 98   // Creates a test web contents. | 106   // Creates a test web contents. | 
| 99   content::RenderViewHostTestHarness::SetUp(); | 107   content::RenderViewHostTestHarness::SetUp(); | 
| 100   OfflinePageTabHelper::CreateForWebContents(web_contents()); | 108   OfflinePageTabHelper::CreateForWebContents(web_contents()); | 
| 101   offline_page_tab_helper_ = | 109   offline_page_tab_helper_ = | 
| 102       OfflinePageTabHelper::FromWebContents(web_contents()); | 110       OfflinePageTabHelper::FromWebContents(web_contents()); | 
| 103 | 111 | 
| 104   // Enables offline pages feature. |  | 
| 105   // TODO(jianli): Remove this once the feature is completely enabled. |  | 
| 106   base::CommandLine::ForCurrentProcess()->AppendSwitch( |  | 
| 107       switches::kEnableOfflinePages); |  | 
| 108 |  | 
| 109   // Sets up the factory for testing. | 112   // Sets up the factory for testing. | 
| 110   OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( | 113   OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( | 
| 111       browser_context(), BuildTestOfflinePageModel); | 114       browser_context(), BuildTestOfflinePageModel); | 
| 112   RunUntilIdle(); | 115   RunUntilIdle(); | 
| 113 | 116 | 
| 114   // Saves an offline page. | 117   // Saves an offline page. | 
| 115   OfflinePageModel* model = | 118   OfflinePageModel* model = | 
| 116       OfflinePageModelFactory::GetForBrowserContext(browser_context()); | 119       OfflinePageModelFactory::GetForBrowserContext(browser_context()); | 
| 117   std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 120   std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 
| 118       kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); | 121       kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); | 
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 200   GURL online_url = page->url; | 203   GURL online_url = page->url; | 
| 201 | 204 | 
| 202   StartLoad(online_url); | 205   StartLoad(online_url); | 
| 203   EXPECT_EQ(online_url, controller().GetPendingEntry()->GetURL()); | 206   EXPECT_EQ(online_url, controller().GetPendingEntry()->GetURL()); | 
| 204 | 207 | 
| 205   FailLoad(online_url); | 208   FailLoad(online_url); | 
| 206   EXPECT_EQ(offline_url, controller().GetPendingEntry()->GetURL()); | 209   EXPECT_EQ(offline_url, controller().GetPendingEntry()->GetURL()); | 
| 207 } | 210 } | 
| 208 | 211 | 
| 209 }  // namespace offline_pages | 212 }  // namespace offline_pages | 
| OLD | NEW | 
|---|