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

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

Issue 10961030: Avoid accessing uninitialized memory during DownloadManagerTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions_mac.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 22 matching lines...) Expand all
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 "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
37 #include "testing/gmock_mutant.h" 37 #include "testing/gmock_mutant.h"
38 #include "testing/gtest/include/gtest/gtest.h" 38 #include "testing/gtest/include/gtest/gtest.h"
39 39
40 using ::testing::AllOf; 40 using ::testing::AllOf;
41 using ::testing::DoAll; 41 using ::testing::DoAll;
42 using ::testing::Eq; 42 using ::testing::Eq;
43 using ::testing::Field;
44 using ::testing::Pointee;
45 using ::testing::Ref; 43 using ::testing::Ref;
46 using ::testing::Return; 44 using ::testing::Return;
47 using ::testing::ReturnRef; 45 using ::testing::ReturnRef;
48 using ::testing::SetArgPointee; 46 using ::testing::SetArgPointee;
49 using ::testing::StrictMock; 47 using ::testing::StrictMock;
50 using ::testing::_; 48 using ::testing::_;
51 using content::DownloadInterruptReason; 49 using content::DownloadInterruptReason;
52 using content::DownloadItem; 50 using content::DownloadItem;
53 using content::DownloadManager; 51 using content::DownloadManager;
54 using content::WebContents; 52 using content::WebContents;
55 53
56 namespace content { 54 namespace content {
57 class ByteStreamReader; 55 class ByteStreamReader;
58 } 56 }
59 57
60 namespace { 58 namespace {
61 59
60 // Matches a DownloadCreateInfo* that points to the same object as |info| and
61 // has a |default_download_directory| that matches |download_directory|.
62 MATCHER_P2(DownloadCreateInfoWithDefaultPath, info, download_directory, "") {
63 return arg == info &&
64 arg->default_download_directory == download_directory;
65 }
66
62 class MockDownloadItemImpl : public DownloadItemImpl { 67 class MockDownloadItemImpl : public DownloadItemImpl {
63 public: 68 public:
64 // Use history constructor for minimal base object. 69 // Use history constructor for minimal base object.
65 MockDownloadItemImpl(DownloadItemImplDelegate* delegate) 70 MockDownloadItemImpl(DownloadItemImplDelegate* delegate)
66 : DownloadItemImpl(delegate, content::DownloadId(), 71 : DownloadItemImpl(delegate, content::DownloadId(),
67 content::DownloadPersistentStoreInfo(), 72 content::DownloadPersistentStoreInfo(),
68 net::BoundNetLog()) {} 73 net::BoundNetLog()) {}
69 virtual ~MockDownloadItemImpl() {} 74 virtual ~MockDownloadItemImpl() {}
70 75
71 MOCK_METHOD4(OnDownloadTargetDetermined, 76 MOCK_METHOD4(OnDownloadTargetDetermined,
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id)); 588 EXPECT_FALSE(download_manager_->GetActiveDownloadItem(local_id));
584 589
585 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _)) 590 EXPECT_CALL(GetMockObserver(), OnDownloadCreated(download_manager_.get(), _))
586 .WillOnce(Return()); 591 .WillOnce(Return());
587 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId()) 592 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetNextId())
588 .WillOnce(Return(content::DownloadId(this, local_id))); 593 .WillOnce(Return(content::DownloadId(this, local_id)));
589 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash()) 594 EXPECT_CALL(GetMockDownloadManagerDelegate(), GenerateFileHash())
590 .WillOnce(Return(true)); 595 .WillOnce(Return(true));
591 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_,_,_,_)) 596 EXPECT_CALL(GetMockDownloadManagerDelegate(), GetSaveDir(_,_,_,_))
592 .WillOnce(SetArgPointee<2>(download_path)); 597 .WillOnce(SetArgPointee<2>(download_path));
598
593 // The CreateDownloadFile call should specify a DownloadCreateInfo that 599 // The CreateDownloadFile call should specify a DownloadCreateInfo that
594 // includes the result of the GetSaveDir() call. 600 // includes the result of the GetSaveDir() call.
595 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile( 601 EXPECT_CALL(GetMockDownloadFileManager(), MockCreateDownloadFile(
596 AllOf(Eq(info.get()), 602 DownloadCreateInfoWithDefaultPath(info.get(), download_path),
597 Pointee(Field(&DownloadCreateInfo::default_download_directory,
598 download_path))),
599 static_cast<content::ByteStreamReader*>(NULL), 603 static_cast<content::ByteStreamReader*>(NULL),
600 download_manager_.get(), true, _, _)); 604 download_manager_.get(), true, _, _));
601 605
602 download_manager_->StartDownload(info.Pass(), stream.Pass()); 606 download_manager_->StartDownload(info.Pass(), stream.Pass());
603 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id)); 607 EXPECT_TRUE(download_manager_->GetActiveDownloadItem(local_id));
604 } 608 }
605 609
606 // Do the results of an OnDownloadInterrupted get passed through properly 610 // Do the results of an OnDownloadInterrupted get passed through properly
607 // to the DownloadItem? 611 // to the DownloadItem?
608 TEST_F(DownloadManagerTest, OnDownloadInterrupted) { 612 TEST_F(DownloadManagerTest, OnDownloadInterrupted) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 UpdateItemInPersistentStore(&item)); 666 UpdateItemInPersistentStore(&item));
663 EXPECT_CALL(item, GetState()) 667 EXPECT_CALL(item, GetState())
664 .WillRepeatedly(Return(DownloadItem::CANCELLED)); 668 .WillRepeatedly(Return(DownloadItem::CANCELLED));
665 EXPECT_CALL(item, GetDbHandle()) 669 EXPECT_CALL(item, GetDbHandle())
666 .WillRepeatedly(Return(db_handle)); 670 .WillRepeatedly(Return(db_handle));
667 671
668 EXPECT_CALL(item, OffThreadCancel()); 672 EXPECT_CALL(item, OffThreadCancel());
669 DownloadStopped(&item); 673 DownloadStopped(&item);
670 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id)); 674 EXPECT_EQ(NULL, download_manager_->GetActiveDownloadItem(download_id));
671 } 675 }
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/memcheck/suppressions_mac.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698