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

Side by Side Diff: content/browser/download/download_manager_impl_unittest.cc

Issue 1251243003: Support restricting browsing data removal for downloads by origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Use base/callback_forward.h. Created 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 19 matching lines...) Expand all
30 #include "content/public/browser/download_manager_delegate.h" 30 #include "content/public/browser/download_manager_delegate.h"
31 #include "content/public/browser/zoom_level_delegate.h" 31 #include "content/public/browser/zoom_level_delegate.h"
32 #include "content/public/test/mock_download_item.h" 32 #include "content/public/test/mock_download_item.h"
33 #include "content/public/test/test_browser_context.h" 33 #include "content/public/test/test_browser_context.h"
34 #include "content/public/test/test_browser_thread.h" 34 #include "content/public/test/test_browser_thread.h"
35 #include "net/base/net_util.h" 35 #include "net/base/net_util.h"
36 #include "net/log/net_log.h" 36 #include "net/log/net_log.h"
37 #include "testing/gmock/include/gmock/gmock.h" 37 #include "testing/gmock/include/gmock/gmock.h"
38 #include "testing/gmock_mutant.h" 38 #include "testing/gmock_mutant.h"
39 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
40 #include "url/origin.h"
40 41
41 using ::testing::AllOf; 42 using ::testing::AllOf;
42 using ::testing::DoAll; 43 using ::testing::DoAll;
43 using ::testing::Eq; 44 using ::testing::Eq;
44 using ::testing::Ref; 45 using ::testing::Ref;
45 using ::testing::Return; 46 using ::testing::Return;
46 using ::testing::ReturnRef; 47 using ::testing::ReturnRef;
47 using ::testing::SetArgPointee; 48 using ::testing::SetArgPointee;
48 using ::testing::StrictMock; 49 using ::testing::StrictMock;
49 using ::testing::_; 50 using ::testing::_;
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 MOCK_METHOD2(SelectFileDialogDisplayed, void( 439 MOCK_METHOD2(SelectFileDialogDisplayed, void(
439 DownloadManager*, int32)); 440 DownloadManager*, int32));
440 }; 441 };
441 442
442 } // namespace 443 } // namespace
443 444
444 class DownloadManagerTest : public testing::Test { 445 class DownloadManagerTest : public testing::Test {
445 public: 446 public:
446 static const char* kTestData; 447 static const char* kTestData;
447 static const size_t kTestDataLen; 448 static const size_t kTestDataLen;
449 std::vector<GURL> download_urls;
448 450
449 DownloadManagerTest() 451 DownloadManagerTest()
450 : callback_called_(false), 452 : callback_called_(false),
451 ui_thread_(BrowserThread::UI, &message_loop_), 453 ui_thread_(BrowserThread::UI, &message_loop_),
452 file_thread_(BrowserThread::FILE, &message_loop_), 454 file_thread_(BrowserThread::FILE, &message_loop_),
453 next_download_id_(0) { 455 next_download_id_(0) {
456 download_urls.push_back(GURL("http://www.url1.com"));
457 download_urls.push_back(GURL("http://www.url2.com"));
458 download_urls.push_back(GURL("http://www.url3.com"));
459 download_urls.push_back(GURL("http://www.url4.com"));
Charlie Reis 2015/08/05 22:19:19 It's generally not a good idea to set up state in
Timo Reimann 2015/08/06 01:13:45 Done.
454 } 460 }
455 461
456 // We tear down everything in TearDown(). 462 // We tear down everything in TearDown().
457 ~DownloadManagerTest() override {} 463 ~DownloadManagerTest() override {}
458 464
459 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate, 465 // Create a MockDownloadItemFactory and MockDownloadManagerDelegate,
460 // then create a DownloadManager that points 466 // then create a DownloadManager that points
461 // at all of those. 467 // at all of those.
462 void SetUp() override { 468 void SetUp() override {
463 DCHECK(!download_manager_); 469 DCHECK(!download_manager_);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 ++next_download_id_; 520 ++next_download_id_;
515 info.request_handle = DownloadRequestHandle(); 521 info.request_handle = DownloadRequestHandle();
516 download_manager_->CreateActiveItem(id, info); 522 download_manager_->CreateActiveItem(id, info);
517 DCHECK(mock_download_item_factory_->GetItem(id)); 523 DCHECK(mock_download_item_factory_->GetItem(id));
518 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id)); 524 MockDownloadItemImpl& item(*mock_download_item_factory_->GetItem(id));
519 // Satisfy expectation. If the item is created in StartDownload(), 525 // Satisfy expectation. If the item is created in StartDownload(),
520 // we call Start on it immediately, so we need to set that expectation 526 // we call Start on it immediately, so we need to set that expectation
521 // in the factory. 527 // in the factory.
522 scoped_ptr<DownloadRequestHandleInterface> req_handle; 528 scoped_ptr<DownloadRequestHandleInterface> req_handle;
523 item.Start(scoped_ptr<DownloadFile>(), req_handle.Pass()); 529 item.Start(scoped_ptr<DownloadFile>(), req_handle.Pass());
530 DCHECK(id < download_urls.size());
531 EXPECT_CALL(item, GetURL()).WillRepeatedly(ReturnRef(download_urls[id]));
524 532
525 return item; 533 return item;
526 } 534 }
527 535
528 MockDownloadItemImpl& GetMockDownloadItem(int id) { 536 MockDownloadItemImpl& GetMockDownloadItem(int id) {
529 MockDownloadItemImpl* itemp = mock_download_item_factory_->GetItem(id); 537 MockDownloadItemImpl* itemp = mock_download_item_factory_->GetItem(id);
530 538
531 DCHECK(itemp); 539 DCHECK(itemp);
532 return *itemp; 540 return *itemp;
533 } 541 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 EXPECT_CALL(GetMockDownloadItem(2), Remove()) 695 EXPECT_CALL(GetMockDownloadItem(2), Remove())
688 .WillOnce(Return()); 696 .WillOnce(Return());
689 EXPECT_CALL(GetMockDownloadItem(3), Remove()) 697 EXPECT_CALL(GetMockDownloadItem(3), Remove())
690 .Times(0); 698 .Times(0);
691 699
692 download_manager_->RemoveAllDownloads(); 700 download_manager_->RemoveAllDownloads();
693 // Because we're mocking the download item, the Remove call doesn't 701 // Because we're mocking the download item, the Remove call doesn't
694 // result in them being removed from the DownloadManager list. 702 // result in them being removed from the DownloadManager list.
695 } 703 }
696 704
705 // Confirm that only downloads with same origin are removed.
706 TEST_F(DownloadManagerTest, RemoveSameOriginDownloads) {
707 base::Time now(base::Time::Now());
708 for (uint32 i = 0; i < 2; ++i) {
709 MockDownloadItemImpl& item(AddItemToManager());
710 EXPECT_CALL(item, GetStartTime()).WillRepeatedly(Return(now));
711 EXPECT_CALL(item, GetState())
712 .WillRepeatedly(Return(DownloadItem::COMPLETE));
713 }
714
715 EXPECT_CALL(GetMockDownloadItem(0), Remove());
716 EXPECT_CALL(GetMockDownloadItem(1), Remove()).Times(0);
717
718 url::Origin origin_to_clear(download_urls[0]);
719 int remove_count = download_manager_->RemoveDownloadsByOriginAndTime(
720 origin_to_clear, base::Time(), base::Time::Max());
721 EXPECT_EQ(remove_count, 1);
722 }
723
697 } // namespace content 724 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698