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/test/base/testing_profile.h"
15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "content/public/browser/notification_service.h"
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/mock_download_item.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/mock_download_manager.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/test/test_browser_thread.h"
19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.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)
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)KeyedService* CreateDownloadService(content::BrowserContext* context) {
32a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  return new DownloadService(Profile::FromBrowserContext(context));
33a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}
34a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class DownloadShelfTest : public testing::Test {
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public:
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  DownloadShelfTest();
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) protected:
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::MockDownloadItem* download_item() {
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return download_item_.get();
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::MockDownloadManager* download_manager() {
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return download_manager_.get();
452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestDownloadShelf* shelf() {
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return &shelf_;
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  }
49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  Profile* profile() { return profile_.get(); }
50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual void SetUp() OVERRIDE {
52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    DownloadServiceFactory::GetInstance()->SetTestingFactory(
53a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)        profile(), &CreateDownloadService);
54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  virtual void TearDown() OVERRIDE {
57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    DownloadServiceFactory::GetInstance()->SetTestingFactory(
58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)        profile(), NULL);
59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  }
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private:
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<content::MockDownloadItem> GetInProgressMockDownload();
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  base::MessageLoopForUI message_loop_;
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  content::TestBrowserThread ui_thread_;
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_ptr<content::MockDownloadItem> download_item_;
6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<content::MockDownloadManager> download_manager_;
682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  TestDownloadShelf shelf_;
69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  scoped_ptr<TestingProfile> profile_;
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)DownloadShelfTest::DownloadShelfTest()
73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)    : ui_thread_(content::BrowserThread::UI, &message_loop_),
74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      profile_(new TestingProfile()) {
752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  download_item_.reset(new ::testing::NiceMock<content::MockDownloadItem>());
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_item_, GetAutoOpened()).WillByDefault(Return(false));
772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_item_, GetMimeType()).WillByDefault(Return("text/plain"));
782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_item_, GetOpenWhenComplete()).WillByDefault(Return(false));
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_item_, GetTargetDisposition())
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillByDefault(Return(DownloadItem::TARGET_DISPOSITION_OVERWRITE));
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_item_, GetURL())
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillByDefault(ReturnRefOfCopy(GURL("http://example.com/foo")));
8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  ON_CALL(*download_item_, GetState())
8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      .WillByDefault(Return(DownloadItem::IN_PROGRESS));
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_item_, IsTemporary()).WillByDefault(Return(false));
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_item_, ShouldOpenFileBasedOnExtension())
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillByDefault(Return(false));
88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ON_CALL(*download_item_, GetBrowserContext())
89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      .WillByDefault(Return(profile()));
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  download_manager_.reset(
9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      new ::testing::NiceMock<content::MockDownloadManager>());
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ON_CALL(*download_manager_, GetDownload(_))
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillByDefault(Return(download_item_.get()));
95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  ON_CALL(*download_manager_, GetBrowserContext())
96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)      .WillByDefault(Return(profile()));
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf_.set_download_manager(download_manager_.get());
992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, ClosesShelfWhenHidden) {
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Show();
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->IsShowing());
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Hide();
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Unhide();
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->IsShowing());
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, CloseWhileHiddenPreventsShowOnUnhide) {
1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Show();
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Hide();
115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  shelf()->Close(DownloadShelf::AUTOMATIC);
1162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Unhide();
1172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
1182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, UnhideDoesntShowIfNotShownOnHide) {
1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Hide();
1222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Unhide();
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDownloadWhileHiddenUnhides) {
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Show();
1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Hide();
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->AddDownload(download_item());
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->IsShowing());
1312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDownloadWhileHiddenUnhidesAndShows) {
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->Hide();
1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->AddDownload(download_item());
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->IsShowing());
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Normal downloads should be added synchronously and cause the shelf to show.
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddNormalDownload) {
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->AddDownload(download_item());
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->did_add_download());
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->IsShowing());
1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Add a transient download. It should not be added immediately. Instead it
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// should be added after a delay. For testing, the delay is set to 0 seconds. So
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the download should be added once the message loop is flushed.
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDelayedDownload) {
1512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension())
1522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillRepeatedly(Return(true));
1532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_TRUE(DownloadItemModel(download_item())
1542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              .ShouldRemoveFromShelfWhenComplete());
1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->AddDownload(download_item());
1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->did_add_download());
1582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
1592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::RunLoop run_loop;
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  run_loop.RunUntilIdle();
1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->did_add_download());
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->IsShowing());
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Add a transient download that completes before the delay. It should not be
1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// displayed on the shelf.
1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDelayedCompletedDownload) {
1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension())
1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillRepeatedly(Return(true));
1722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_TRUE(DownloadItemModel(download_item())
1732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              .ShouldRemoveFromShelfWhenComplete());
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->AddDownload(download_item());
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->did_add_download());
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
17990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*download_item(), GetState())
18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      .WillRepeatedly(Return(DownloadItem::COMPLETE));
181ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch  EXPECT_CALL(*download_item(), GetAutoOpened())
182ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch      .WillRepeatedly(Return(true));
1832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::RunLoop run_loop;
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  run_loop.RunUntilIdle();
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->did_add_download());
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Add a transient download that completes and becomes non-transient before the
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// delay. It should be displayed on the shelf even though it is complete.
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(DownloadShelfTest, AddDelayedCompleteNonTransientDownload) {
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension())
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillRepeatedly(Return(true));
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_TRUE(DownloadItemModel(download_item())
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)              .ShouldRemoveFromShelfWhenComplete());
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  shelf()->AddDownload(download_item());
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->did_add_download());
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_FALSE(shelf()->IsShowing());
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
20390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_CALL(*download_item(), GetState())
20490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      .WillRepeatedly(Return(DownloadItem::COMPLETE));
2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_CALL(*download_item(), ShouldOpenFileBasedOnExtension())
2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      .WillRepeatedly(Return(false));
2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_FALSE(DownloadItemModel(download_item())
2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)               .ShouldRemoveFromShelfWhenComplete());
2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::RunLoop run_loop;
2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  run_loop.RunUntilIdle();
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->did_add_download());
2142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_TRUE(shelf()->IsShowing());
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
216