Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / one_click_signin_bubble_controller_unittest.mm
blobdd1b20e820b8cd64cb9d68314b090d0073efae25
1 // Copyright (c) 2012 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.
5 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/bind.h"
10 #include "base/compiler_specific.h"
11 #import "base/mac/scoped_nsobject.h"
12 #include "base/memory/weak_ptr.h"
13 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
14 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
15 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h"
16 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #import "testing/gtest_mac.h"
21 namespace {
23 using ::testing::_;
25 class OneClickSigninBubbleControllerTest : public CocoaProfileTest {
26  public:
27   OneClickSigninBubbleControllerTest()
28       : weak_ptr_factory_(this) {
29     start_sync_callback_ =
30             base::Bind(&OneClickSigninBubbleControllerTest::OnStartSync,
31                        weak_ptr_factory_.GetWeakPtr());
32   }
34   virtual void SetUp() override {
35     CocoaProfileTest::SetUp();
36     BrowserWindowCocoa* browser_window =
37         static_cast<BrowserWindowCocoa*>(browser()->window());
38     controller_.reset([[OneClickSigninBubbleController alloc]
39             initWithBrowserWindowController:browser_window->cocoa_controller()
40                                 webContents:nil
41                                errorMessage:nil
42                                    callback:start_sync_callback_]);
43     [controller_ showWindow:nil];
44     EXPECT_NSEQ(@"OneClickSigninBubble",
45                 [[controller_ viewController] nibName]);
46   }
48   virtual void TearDown() override {
49     controller_.reset();
50     CocoaProfileTest::TearDown();
51   }
53   MOCK_METHOD1(OnStartSync, void(OneClickSigninSyncStarter::StartSyncMode));
55  protected:
56   BrowserWindow::StartSyncCallback start_sync_callback_;
57   base::scoped_nsobject<OneClickSigninBubbleController> controller_;
59  private:
60   base::WeakPtrFactory<OneClickSigninBubbleControllerTest> weak_ptr_factory_;
62   DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleControllerTest);
65 // Test that the bubble does not sync if the OK button is clicked.
66 TEST_F(OneClickSigninBubbleControllerTest, OK) {
67   EXPECT_CALL(*this, OnStartSync(
68       OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS)).Times(0);
69   [[controller_ viewController] ok:nil];
72 // Test that the bubble does not sync if the Undo button
73 // is clicked. Callback should be called to abort the sync.
74 TEST_F(OneClickSigninBubbleControllerTest, Undo) {
75   EXPECT_CALL(*this, OnStartSync(
76       OneClickSigninSyncStarter::UNDO_SYNC)).Times(0);
77   [[controller_ viewController] onClickUndo:nil];
80 // Test that the bubble does not sync if the bubble is closed.
81 TEST_F(OneClickSigninBubbleControllerTest, Close) {
82   EXPECT_CALL(*this, OnStartSync(
83       OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS)).Times(0);
84   [controller_ close];
87 }  // namespace