15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 79ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/run_loop.h" 9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/chrome_notification_types.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/download/download_item_model.h" 11a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/download/download_service.h" 12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/download/download_service_factory.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/download/test_download_shelf.h" 14a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/common/extensions/extension.h" 15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/test/base/testing_profile.h" 16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "content/public/browser/notification_service.h" 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/mock_download_item.h" 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/mock_download_manager.h" 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/test_browser_thread.h" 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gmock/include/gmock/gmock.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using ::testing::Return; 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using ::testing::ReturnRefOfCopy; 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using ::testing::SaveArg; 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using ::testing::_; 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)using content::DownloadItem; 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace { 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 31a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)BrowserContextKeyedService* CreateDownloadService( 32a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) content::BrowserContext* context) { 33a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) return new DownloadService(Profile::FromBrowserContext(context)); 34a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 35a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DownloadShelfTest : public testing::Test { 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DownloadShelfTest(); 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected: 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::MockDownloadItem* download_item() { 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return download_item_.get(); 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::MockDownloadManager* download_manager() { 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return download_manager_.get(); 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestDownloadShelf* shelf() { 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return &shelf_; 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Profile* profile() { return profile_.get(); } 51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void SetUp() OVERRIDE { 53a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DownloadServiceFactory::GetInstance()->SetTestingFactory( 54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) profile(), &CreateDownloadService); 55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) } 56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void TearDown() OVERRIDE { 58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DownloadServiceFactory::GetInstance()->SetTestingFactory( 59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) profile(), NULL); 60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) } 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<content::MockDownloadItem> GetInProgressMockDownload(); 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) base::MessageLoopForUI message_loop_; 662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) content::TestBrowserThread ui_thread_; 672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_ptr<content::MockDownloadItem> download_item_; 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) scoped_ptr<content::MockDownloadManager> download_manager_; 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) TestDownloadShelf shelf_; 70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scoped_ptr<TestingProfile> profile_; 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)DownloadShelfTest::DownloadShelfTest() 74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) : ui_thread_(content::BrowserThread::UI, &message_loop_), 75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) profile_(new TestingProfile()) { 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) download_item_.reset(new ::testing::NiceMock<content::MockDownloadItem>()); 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_item_, GetAutoOpened()).WillByDefault(Return(false)); 782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_item_, GetMimeType()).WillByDefault(Return("text/plain")); 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_item_, GetOpenWhenComplete()).WillByDefault(Return(false)); 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_item_, GetTargetDisposition()) 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillByDefault(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE)); 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_item_, GetURL()) 832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillByDefault(ReturnRefOfCopy(GURL("http://example.com/foo"))); 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ON_CALL(*download_item_, GetState()) 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) .WillByDefault(Return(DownloadItem::IN_PROGRESS)); 862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_item_, IsTemporary()).WillByDefault(Return(false)); 872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_item_, ShouldOpenFileBasedOnExtension()) 882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillByDefault(Return(false)); 89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ON_CALL(*download_item_, GetBrowserContext()) 90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) .WillByDefault(Return(profile())); 912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) download_manager_.reset( 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) new ::testing::NiceMock<content::MockDownloadManager>()); 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ON_CALL(*download_manager_, GetDownload(_)) 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillByDefault(Return(download_item_.get())); 96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ON_CALL(*download_manager_, GetBrowserContext()) 97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) .WillByDefault(Return(profile())); 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf_.set_download_manager(download_manager_.get()); 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, ClosesShelfWhenHidden) { 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Show(); 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->IsShowing()); 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Hide(); 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Unhide(); 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->IsShowing()); 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, CloseWhileHiddenPreventsShowOnUnhide) { 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Show(); 1152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Hide(); 116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) shelf()->Close(DownloadShelf::AUTOMATIC); 1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Unhide(); 1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, UnhideDoesntShowIfNotShownOnHide) { 1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Hide(); 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Unhide(); 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDownloadWhileHiddenUnhides) { 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Show(); 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Hide(); 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->AddDownload(download_item()); 1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->IsShowing()); 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDownloadWhileHiddenUnhidesAndShows) { 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->Hide(); 1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->AddDownload(download_item()); 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->IsShowing()); 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Normal downloads should be added synchronously and cause the shelf to show. 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddNormalDownload) { 1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->AddDownload(download_item()); 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->did_add_download()); 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->IsShowing()); 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Add a transient download. It should not be added immediately. Instead it 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// should be added after a delay. For testing, the delay is set to 0 seconds. So 1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the download should be added once the message loop is flushed. 1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDelayedDownload) { 1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension()) 1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillRepeatedly(Return(true)); 1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(DownloadItemModel(download_item()) 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .ShouldRemoveFromShelfWhenComplete()); 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->AddDownload(download_item()); 1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->did_add_download()); 1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::RunLoop run_loop; 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) run_loop.RunUntilIdle(); 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->did_add_download()); 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->IsShowing()); 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Add a transient download that completes before the delay. It should not be 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// displayed on the shelf. 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDelayedCompletedDownload) { 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension()) 1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillRepeatedly(Return(true)); 1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(DownloadItemModel(download_item()) 1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .ShouldRemoveFromShelfWhenComplete()); 1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->AddDownload(download_item()); 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->did_add_download()); 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*download_item(), GetState()) 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) .WillRepeatedly(Return(DownloadItem::COMPLETE)); 182ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch EXPECT_CALL(*download_item(), GetAutoOpened()) 183ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch .WillRepeatedly(Return(true)); 1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::RunLoop run_loop; 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) run_loop.RunUntilIdle(); 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->did_add_download()); 1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Add a transient download that completes and becomes non-transient before the 1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// delay. It should be displayed on the shelf even though it is complete. 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDelayedCompleteNonTransientDownload) { 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension()) 1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillRepeatedly(Return(true)); 1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_TRUE(DownloadItemModel(download_item()) 1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .ShouldRemoveFromShelfWhenComplete()); 1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) shelf()->AddDownload(download_item()); 2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->did_add_download()); 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(shelf()->IsShowing()); 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 20490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_CALL(*download_item(), GetState()) 20590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) .WillRepeatedly(Return(DownloadItem::COMPLETE)); 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension()) 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .WillRepeatedly(Return(false)); 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_FALSE(DownloadItemModel(download_item()) 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) .ShouldRemoveFromShelfWhenComplete()); 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::RunLoop run_loop; 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) run_loop.RunUntilIdle(); 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->did_add_download()); 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(shelf()->IsShowing()); 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 217