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

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

Issue 2234873004: Have the RequestCoordinator generate the offline_id (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge, and CR fixes per Dimich Created 4 years, 4 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 "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/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse( 168 OfflinePageModelFactory::GetInstance()->SetTestingFactoryAndUse(
169 browser_context(), BuildTestOfflinePageModel); 169 browser_context(), BuildTestOfflinePageModel);
170 RunUntilIdle(); 170 RunUntilIdle();
171 171
172 // Saves an offline page. 172 // Saves an offline page.
173 OfflinePageModel* model = 173 OfflinePageModel* model =
174 OfflinePageModelFactory::GetForBrowserContext(browser_context()); 174 OfflinePageModelFactory::GetForBrowserContext(browser_context());
175 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 175 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
176 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); 176 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page1.mhtml"))));
177 model->SavePage( 177 model->SavePage(
178 kTestPageUrl, kTestClientId, std::move(archiver), 178 kTestPageUrl, kTestClientId, 0ul, std::move(archiver),
179 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); 179 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr()));
180 RunUntilIdle(); 180 RunUntilIdle();
181 } 181 }
182 182
183 void OfflinePageTabHelperTest::TearDown() { 183 void OfflinePageTabHelperTest::TearDown() {
184 content::RenderViewHostTestHarness::TearDown(); 184 content::RenderViewHostTestHarness::TearDown();
185 } 185 }
186 186
187 void OfflinePageTabHelperTest::RunUntilIdle() { 187 void OfflinePageTabHelperTest::RunUntilIdle() {
188 base::RunLoop().RunUntilIdle(); 188 base::RunLoop().RunUntilIdle();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 TEST_F(OfflinePageTabHelperTest, SelectBestPageForCurrentTab) { 339 TEST_F(OfflinePageTabHelperTest, SelectBestPageForCurrentTab) {
340 // Saves an offline page. 340 // Saves an offline page.
341 OfflinePageModel* model = 341 OfflinePageModel* model =
342 OfflinePageModelFactory::GetForBrowserContext(browser_context()); 342 OfflinePageModelFactory::GetForBrowserContext(browser_context());
343 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 343 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
344 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page2.mhtml")))); 344 kTestPageUrl, base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))));
345 345
346 // We expect this copy to be used later. 346 // We expect this copy to be used later.
347 ClientId client_id(kLastNNamespace, base::IntToString(kTabId)); 347 ClientId client_id(kLastNNamespace, base::IntToString(kTabId));
348 model->SavePage( 348 model->SavePage(
349 kTestPageUrl, client_id, std::move(archiver), 349 kTestPageUrl, client_id, 0ul, std::move(archiver),
350 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); 350 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr()));
351 RunUntilIdle(); 351 RunUntilIdle();
352 const int64_t expected_offline_id = offline_id(); 352 const int64_t expected_offline_id = offline_id();
353 const GURL expected_offline_url = offline_url(); 353 const GURL expected_offline_url = offline_url();
354 354
355 archiver = BuildArchiver(kTestPageUrl, 355 archiver = BuildArchiver(kTestPageUrl,
356 base::FilePath(FILE_PATH_LITERAL("page3.html"))); 356 base::FilePath(FILE_PATH_LITERAL("page3.html")));
357 client_id.id = "39"; 357 client_id.id = "39";
358 model->SavePage( 358 model->SavePage(
359 kTestPageUrl, client_id, std::move(archiver), 359 kTestPageUrl, client_id, 0ul, std::move(archiver),
360 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); 360 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr()));
361 RunUntilIdle(); 361 RunUntilIdle();
362 362
363 SimulateHasNetworkConnectivity(false); 363 SimulateHasNetworkConnectivity(false);
364 StartLoad(kTestPageUrl); 364 StartLoad(kTestPageUrl);
365 // Gives a chance to run delayed task to do redirection. 365 // Gives a chance to run delayed task to do redirection.
366 RunUntilIdle(); 366 RunUntilIdle();
367 367
368 const OfflinePageItem* item = 368 const OfflinePageItem* item =
369 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); 369 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // Saves an offline page. 420 // Saves an offline page.
421 OfflinePageModel* model = 421 OfflinePageModel* model =
422 OfflinePageModelFactory::GetForBrowserContext(browser_context()); 422 OfflinePageModelFactory::GetForBrowserContext(browser_context());
423 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 423 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
424 kTestPageUrl, 424 kTestPageUrl,
425 base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml")))); 425 base::FilePath(FILE_PATH_LITERAL("AsyncLoadedPage.mhtml"))));
426 426
427 // We expect this Async Loading Namespace copy to be used. 427 // We expect this Async Loading Namespace copy to be used.
428 ClientId client_id(kAsyncNamespace, base::IntToString(kTabId)); 428 ClientId client_id(kAsyncNamespace, base::IntToString(kTabId));
429 model->SavePage( 429 model->SavePage(
430 kTestPageUrl, client_id, std::move(archiver), 430 kTestPageUrl, client_id, 0ul, std::move(archiver),
431 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr())); 431 base::Bind(&OfflinePageTabHelperTest::OnSavePageDone, AsWeakPtr()));
432 RunUntilIdle(); 432 RunUntilIdle();
433 const int64_t expected_offline_id = offline_id(); 433 const int64_t expected_offline_id = offline_id();
434 const GURL expected_offline_url = offline_url(); 434 const GURL expected_offline_url = offline_url();
435 435
436 SimulateHasNetworkConnectivity(false); 436 SimulateHasNetworkConnectivity(false);
437 StartLoad(kTestPageUrl); 437 StartLoad(kTestPageUrl);
438 // Gives a chance to run delayed task to do redirection. 438 // Gives a chance to run delayed task to do redirection.
439 RunUntilIdle(); 439 RunUntilIdle();
440 440
441 const OfflinePageItem* item = 441 const OfflinePageItem* item =
442 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents()); 442 OfflinePageUtils::GetOfflinePageFromWebContents(web_contents());
443 EXPECT_EQ(expected_offline_id, item->offline_id); 443 EXPECT_EQ(expected_offline_id, item->offline_id);
444 EXPECT_EQ(expected_offline_url, item->GetOfflineURL()); 444 EXPECT_EQ(expected_offline_url, item->GetOfflineURL());
445 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space); 445 EXPECT_EQ(kAsyncNamespace, item->client_id.name_space);
446 } 446 }
447 447
448 } // namespace offline_pages 448 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698