Home | History | Annotate | Download | only in location_bar
      1 // Copyright (c) 2011 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 "base/memory/scoped_nsobject.h"
      6 #include "base/memory/scoped_ptr.h"
      7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
      8 #import "chrome/browser/ui/cocoa/location_bar/instant_opt_in_controller.h"
      9 #include "testing/gmock/include/gmock/gmock.h"
     10 #include "testing/gtest/include/gtest/gtest.h"
     11 #include "testing/platform_test.h"
     12 
     13 @interface InstantOptInController (ExposedForTesting)
     14 - (NSButton*)okButton;
     15 - (NSButton*)cancelButton;
     16 @end
     17 
     18 @implementation InstantOptInController (ExposedForTesting)
     19 - (NSButton*)okButton {
     20   return okButton_;
     21 }
     22 
     23 - (NSButton*)cancelButton {
     24   return cancelButton_;
     25 }
     26 @end
     27 
     28 
     29 namespace {
     30 
     31 class MockDelegate : public InstantOptInControllerDelegate {
     32  public:
     33   MOCK_METHOD1(UserPressedOptIn, void(bool opt_in));
     34 };
     35 
     36 class InstantOptInControllerTest : public CocoaTest {
     37  public:
     38   void SetUp() {
     39     CocoaTest::SetUp();
     40 
     41     controller_.reset(
     42         [[InstantOptInController alloc] initWithDelegate:&delegate_]);
     43 
     44     NSView* parent = [test_window() contentView];
     45     [parent addSubview:[controller_ view]];
     46   }
     47 
     48   MockDelegate delegate_;
     49   scoped_nsobject<InstantOptInController> controller_;
     50 };
     51 
     52 TEST_F(InstantOptInControllerTest, OkButtonCallback) {
     53   EXPECT_CALL(delegate_, UserPressedOptIn(true));
     54   [[controller_ okButton] performClick:nil];
     55 }
     56 
     57 TEST_F(InstantOptInControllerTest, CancelButtonCallback) {
     58   EXPECT_CALL(delegate_, UserPressedOptIn(false));
     59   [[controller_ cancelButton] performClick:nil];
     60 }
     61 
     62 }  // namespace
     63