| 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/recent_tab_helper.h" | 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
| 10 #include "base/test/scoped_feature_list.h" | 10 #include "base/test/scoped_feature_list.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 TEST_F(RecentTabHelperTest, Basic) { | 206 TEST_F(RecentTabHelperTest, Basic) { |
| 207 base::test::ScopedFeatureList scoped_feature_list; | 207 base::test::ScopedFeatureList scoped_feature_list; |
| 208 scoped_feature_list.Init(); | 208 scoped_feature_list.Init(); |
| 209 EXPECT_NE(nullptr, recent_tab_helper()); | 209 EXPECT_NE(nullptr, recent_tab_helper()); |
| 210 } | 210 } |
| 211 | 211 |
| 212 TEST_F(RecentTabHelperTest, SimpleCapture) { | 212 TEST_F(RecentTabHelperTest, SimpleCapture) { |
| 213 NavigateAndCommit(kTestPageUrl); | 213 NavigateAndCommit(kTestPageUrl); |
| 214 EXPECT_FALSE(recent_tab_helper()->is_page_ready_for_snapshot()); | |
| 215 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 214 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 216 RunUntilIdle(); | 215 RunUntilIdle(); |
| 217 EXPECT_TRUE(recent_tab_helper()->is_page_ready_for_snapshot()); | |
| 218 EXPECT_TRUE(model()->is_loaded()); | 216 EXPECT_TRUE(model()->is_loaded()); |
| 219 GetAllPages(); | 217 GetAllPages(); |
| 220 EXPECT_EQ(1U, all_pages().size()); | 218 EXPECT_EQ(1U, all_pages().size()); |
| 221 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); | 219 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); |
| 222 } | 220 } |
| 223 | 221 |
| 224 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) { | 222 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) { |
| 225 // Create delegate that returns 'false' as TabId retrieval result. | 223 // Create delegate that returns 'false' as TabId retrieval result. |
| 226 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>( | 224 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>( |
| 227 this, task_runner(), kTabId, false)); | 225 this, task_runner(), kTabId, false)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 scoped_feature_list.Init(); | 304 scoped_feature_list.Init(); |
| 307 NavigateAndCommit(kTestPageUrl); | 305 NavigateAndCommit(kTestPageUrl); |
| 308 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); | 306 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 309 RunUntilIdle(); | 307 RunUntilIdle(); |
| 310 EXPECT_TRUE(model()->is_loaded()); | 308 EXPECT_TRUE(model()->is_loaded()); |
| 311 GetAllPages(); | 309 GetAllPages(); |
| 312 // No page should be captured. | 310 // No page should be captured. |
| 313 EXPECT_EQ(0U, all_pages().size()); | 311 EXPECT_EQ(0U, all_pages().size()); |
| 314 } | 312 } |
| 315 | 313 |
| 314 TEST_F(RecentTabHelperTest, DownloadRequest) { |
| 315 NavigateAndCommit(kTestPageUrl); |
| 316 recent_tab_helper()->ObserveAndDownloadCurrentPage( |
| 317 ClientId("download", "id1"), 153l); |
| 318 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); |
| 319 RunUntilIdle(); |
| 320 EXPECT_TRUE(model()->is_loaded()); |
| 321 GetAllPages(); |
| 322 EXPECT_EQ(1U, all_pages().size()); |
| 323 const OfflinePageItem& page = all_pages()[0]; |
| 324 EXPECT_EQ(kTestPageUrl, page.url); |
| 325 EXPECT_EQ("download", page.client_id.name_space); |
| 326 EXPECT_EQ("id1", page.client_id.id); |
| 327 EXPECT_EQ(153l, page.offline_id); |
| 328 } |
| 329 |
| 316 } // namespace offline_pages | 330 } // namespace offline_pages |
| OLD | NEW |