Home | History | Annotate | Download | only in download
      1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/ui/cocoa/browser_test_helper.h"
      6 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
      7 #include "chrome/browser/ui/cocoa/download/download_shelf_mac.h"
      8 #include "testing/gtest/include/gtest/gtest.h"
      9 #include "testing/platform_test.h"
     10 
     11 // A fake implementation of DownloadShelfController. It implements only the
     12 // methods that DownloadShelfMac call during the tests in this file. We get this
     13 // class into the DownloadShelfMac constructor by some questionable casting --
     14 // Objective C is a dynamic language, so we pretend that's ok.
     15 
     16 @interface FakeDownloadShelfController : NSObject {
     17  @public
     18   int callCountIsVisible;
     19   int callCountShow;
     20   int callCountHide;
     21 }
     22 
     23 - (BOOL)isVisible;
     24 - (IBAction)show:(id)sender;
     25 - (IBAction)hide:(id)sender;
     26 @end
     27 
     28 @implementation FakeDownloadShelfController
     29 
     30 - (BOOL)isVisible {
     31   ++callCountIsVisible;
     32   return YES;
     33 }
     34 
     35 - (IBAction)show:(id)sender {
     36   ++callCountShow;
     37 }
     38 
     39 - (IBAction)hide:(id)sender {
     40   ++callCountHide;
     41 }
     42 
     43 @end
     44 
     45 
     46 namespace {
     47 
     48 class DownloadShelfMacTest : public CocoaTest {
     49 
     50   virtual void SetUp() {
     51     CocoaTest::SetUp();
     52     shelf_controller_.reset([[FakeDownloadShelfController alloc] init]);
     53   }
     54 
     55  protected:
     56   scoped_nsobject<FakeDownloadShelfController> shelf_controller_;
     57   BrowserTestHelper browser_helper_;
     58 };
     59 
     60 TEST_F(DownloadShelfMacTest, CreationDoesNotCallShow) {
     61   // Also make sure the DownloadShelfMacTest constructor doesn't crash.
     62   DownloadShelfMac shelf(browser_helper_.browser(),
     63       (DownloadShelfController*)shelf_controller_.get());
     64   EXPECT_EQ(0, shelf_controller_.get()->callCountShow);
     65 }
     66 
     67 TEST_F(DownloadShelfMacTest, ForwardsShow) {
     68   DownloadShelfMac shelf(browser_helper_.browser(),
     69       (DownloadShelfController*)shelf_controller_.get());
     70   EXPECT_EQ(0, shelf_controller_.get()->callCountShow);
     71   shelf.Show();
     72   EXPECT_EQ(1, shelf_controller_.get()->callCountShow);
     73 }
     74 
     75 TEST_F(DownloadShelfMacTest, ForwardsHide) {
     76   DownloadShelfMac shelf(browser_helper_.browser(),
     77       (DownloadShelfController*)shelf_controller_.get());
     78   EXPECT_EQ(0, shelf_controller_.get()->callCountHide);
     79   shelf.Close();
     80   EXPECT_EQ(1, shelf_controller_.get()->callCountHide);
     81 }
     82 
     83 TEST_F(DownloadShelfMacTest, ForwardsIsShowing) {
     84   DownloadShelfMac shelf(browser_helper_.browser(),
     85       (DownloadShelfController*)shelf_controller_.get());
     86   EXPECT_EQ(0, shelf_controller_.get()->callCountIsVisible);
     87   shelf.IsShowing();
     88   EXPECT_EQ(1, shelf_controller_.get()->callCountIsVisible);
     89 }
     90 
     91 }  // namespace
     92