summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_shelf_unittest.cc
blob: 162c9ce86a9bba2828dcc692509563442e7a8aa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "testing/gtest/include/gtest/gtest.h"

#include "base/compiler_specific.h"
#include "chrome/browser/download/download_shelf.h"

class TestDownloadShelf : public DownloadShelf {
 public:
  TestDownloadShelf() : is_showing_(false) {}

  virtual bool IsShowing() const OVERRIDE {
    return is_showing_;
  }

  virtual bool IsClosing() const OVERRIDE {
    return false;
  }

  virtual Browser* browser() const OVERRIDE {
    return NULL;
  }

 protected:
  virtual void DoAddDownload(BaseDownloadItemModel* download_mode) OVERRIDE {}

  virtual void DoShow() OVERRIDE {
    is_showing_ = true;
  }

  virtual void DoClose() OVERRIDE {
    is_showing_ = false;
  }

 private:
  bool is_showing_;
};

TEST(DownloadShelfTest, ClosesShelfWhenHidden) {
  TestDownloadShelf shelf;
  shelf.Show();
  EXPECT_TRUE(shelf.IsShowing());
  shelf.Hide();
  EXPECT_FALSE(shelf.IsShowing());
  shelf.Unhide();
  EXPECT_TRUE(shelf.IsShowing());
}

TEST(DownloadShelfTest, CloseWhileHiddenPreventsShowOnUnhide) {
  TestDownloadShelf shelf;
  shelf.Show();
  shelf.Hide();
  shelf.Close();
  shelf.Unhide();
  EXPECT_FALSE(shelf.IsShowing());
}

TEST(DownloadShelfTest, UnhideDoesntShowIfNotShownOnHide) {
  TestDownloadShelf shelf;
  shelf.Hide();
  shelf.Unhide();
  EXPECT_FALSE(shelf.IsShowing());
}

TEST(DownloadShelfTest, AddDownloadWhileHiddenUnhides) {
  TestDownloadShelf shelf;
  shelf.Show();
  shelf.Hide();
  shelf.AddDownload(NULL);
  EXPECT_TRUE(shelf.IsShowing());
}

TEST(DownloadShelfTest, AddDownloadWhileHiddenUnhidesAndShows) {
  TestDownloadShelf shelf;
  shelf.Hide();
  shelf.AddDownload(NULL);
  EXPECT_TRUE(shelf.IsShowing());
}