Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/cocoa/one_click_signin_bubble_controller_unittest.mm

Issue 10332185: Update behavior of one-click infobar to remove modal dialog, add "undo". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't call ok in tests of advanced link Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h" 5 #import "chrome/browser/ui/cocoa/one_click_signin_bubble_controller.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #import "base/memory/scoped_nsobject.h" 11 #import "base/memory/scoped_nsobject.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" 13 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
14 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 14 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #import "testing/gtest_mac.h" 17 #import "testing/gtest_mac.h"
18 18
19 namespace { 19 namespace {
20 20
21 class OneClickSigninBubbleControllerTest : public CocoaProfileTest { 21 class OneClickSigninBubbleControllerTest : public CocoaProfileTest {
22 public: 22 public:
23 OneClickSigninBubbleControllerTest() 23 OneClickSigninBubbleControllerTest()
24 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 24 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
25 learn_more_callback_( 25 start_sync_callback_(
26 base::Bind(&OneClickSigninBubbleControllerTest::OnLearnMore, 26 base::Bind(&OneClickSigninBubbleControllerTest::OnStartSync,
27 weak_ptr_factory_.GetWeakPtr())),
28 advanced_callback_(
29 base::Bind(&OneClickSigninBubbleControllerTest::OnAdvanced,
30 weak_ptr_factory_.GetWeakPtr())) {} 27 weak_ptr_factory_.GetWeakPtr())) {}
31 28
32 virtual void SetUp() { 29 virtual void SetUp() {
33 CocoaProfileTest::SetUp(); 30 CocoaProfileTest::SetUp();
34 BrowserWindowCocoa* browser_window = 31 BrowserWindowCocoa* browser_window =
35 static_cast<BrowserWindowCocoa*>(CreateBrowserWindow()); 32 static_cast<BrowserWindowCocoa*>(CreateBrowserWindow());
36 controller_.reset( 33 controller_.reset(
37 [[OneClickSigninBubbleController alloc] 34 [[OneClickSigninBubbleController alloc]
38 initWithBrowserWindowController:browser_window->cocoa_controller() 35 initWithBrowserWindowController:browser_window->cocoa_controller()
39 learnMoreCallback:learn_more_callback_ 36 start_sync_callback:start_sync_callback_]);
40 advancedCallback:advanced_callback_]);
41 } 37 }
42 38
43 virtual void TearDown() { 39 virtual void TearDown() {
44 controller_.reset(); 40 controller_.reset();
45 CocoaProfileTest::TearDown(); 41 CocoaProfileTest::TearDown();
46 } 42 }
47 43
48 MOCK_METHOD0(OnLearnMore, void()); 44 MOCK_METHOD1(OnStartSync, void(bool));
49 MOCK_METHOD0(OnAdvanced, void());
50 45
51 protected: 46 protected:
52 base::WeakPtrFactory<OneClickSigninBubbleControllerTest> weak_ptr_factory_; 47 base::WeakPtrFactory<OneClickSigninBubbleControllerTest> weak_ptr_factory_;
53 base::Closure learn_more_callback_; 48 base::Callback<void(bool)> start_sync_callback_;
54 base::Closure advanced_callback_;
55 scoped_nsobject<OneClickSigninBubbleController> controller_; 49 scoped_nsobject<OneClickSigninBubbleController> controller_;
56 }; 50 };
57 51
58 // Test that the dialog loads from its nib properly. 52 // Test that the dialog loads from its nib properly.
59 TEST_F(OneClickSigninBubbleControllerTest, NibLoad) { 53 TEST_F(OneClickSigninBubbleControllerTest, NibLoad) {
60 EXPECT_CALL(*this, OnLearnMore()).Times(0); 54 EXPECT_CALL(*this, OnStartSync()).Times(0);
akalin 2012/05/17 00:39:24 you want _
Roger Tawa OOO till Jul 10th 2012/05/17 21:17:37 Done.
61 EXPECT_CALL(*this, OnAdvanced()).Times(0);
62 55
63 // Force nib load. 56 // Force nib load.
64 [controller_ window]; 57 [controller_ window];
65 EXPECT_NSEQ(@"OneClickSigninBubble", [controller_ windowNibName]); 58 EXPECT_NSEQ(@"OneClickSigninBubble", [controller_ windowNibName]);
66 } 59 }
67 60
68 // Test that the dialog doesn't call any callback if the OK button is 61 // Test that the dialog calls the callback if the OK button is clicked.
69 // clicked.
70 TEST_F(OneClickSigninBubbleControllerTest, ShowAndOK) { 62 TEST_F(OneClickSigninBubbleControllerTest, ShowAndOK) {
71 EXPECT_CALL(*this, OnLearnMore()).Times(0); 63 EXPECT_CALL(*this, OnStartSync(true)).Times(1);
72 EXPECT_CALL(*this, OnAdvanced()).Times(0);
73 64
74 [controller_ showWindow:nil]; 65 [controller_ showWindow:nil];
75 [controller_.release() ok:nil]; 66 [controller_.release() ok:nil];
76 } 67 }
77 68
78 // Test that the learn more callback is run if its corresponding 69 // Test that the dialog doesn't calls the callback if the Undo button is
79 // button is clicked. 70 // clicked.
80 TEST_F(OneClickSigninBubbleControllerTest, ShowAndClickLearnMore) { 71 TEST_F(OneClickSigninBubbleControllerTest, ShowAndUndo) {
81 EXPECT_CALL(*this, OnLearnMore()).Times(1); 72 EXPECT_CALL(*this, OnStartSync(testing::_)).Times(0);
akalin 2012/05/17 00:39:24 put 'using ::testing::_;' at top of file
Roger Tawa OOO till Jul 10th 2012/05/17 21:17:37 Done.
82 EXPECT_CALL(*this, OnAdvanced()).Times(0);
83 73
84 [controller_ showWindow:nil]; 74 [controller_ showWindow:nil];
85 [controller_ onClickLearnMoreLink:nil]; 75 [controller_.release() undo:nil];
86 [controller_.release() ok:nil];
87 } 76 }
88 77
89 // Test that the advanced callback is run if its corresponding button 78 // Test that the advanced callback is run if its corresponding button
90 // is clicked. 79 // is clicked.
91 TEST_F(OneClickSigninBubbleControllerTest, ShowAndClickAdvanced) { 80 TEST_F(OneClickSigninBubbleControllerTest, ShowAndClickAdvanced) {
92 EXPECT_CALL(*this, OnLearnMore()).Times(0); 81 EXPECT_CALL(*this, OnStartSync(false)).Times(1);
93 EXPECT_CALL(*this, OnAdvanced()).Times(1);
94 82
95 [controller_ showWindow:nil]; 83 [controller_ showWindow:nil];
96 [controller_ onClickAdvancedLink:nil]; 84 [controller_ onClickAdvancedLink:nil];
97 [controller_.release() ok:nil]; 85 [controller_.release() close:nil];
akalin 2012/05/17 00:39:24 you'll want to remove the close line and instead h
Roger Tawa OOO till Jul 10th 2012/05/17 21:17:37 Done.
98 } 86 }
99 87
100 // Test that the callbacks can be run multiple times. 88 // Test that the callbacks can be run multiple times.
89 // TODO(rogerta: what is the point of this test?
akalin 2012/05/17 00:39:24 if you change the advanced handler to auto-close,
Roger Tawa OOO till Jul 10th 2012/05/17 21:17:37 Added a TODO comment.
101 TEST_F(OneClickSigninBubbleControllerTest, ShowAndClickMultiple) { 90 TEST_F(OneClickSigninBubbleControllerTest, ShowAndClickMultiple) {
102 EXPECT_CALL(*this, OnLearnMore()).Times(3); 91 EXPECT_CALL(*this, OnStartSync(false)).Times(3);
103 EXPECT_CALL(*this, OnAdvanced()).Times(4);
104 92
105 [controller_ showWindow:nil]; 93 [controller_ showWindow:nil];
106 for (int i = 0; i < 3; ++i) { 94 for (int i = 0; i < 3; ++i) {
107 [controller_ onClickLearnMoreLink:nil];
108 [controller_ onClickAdvancedLink:nil]; 95 [controller_ onClickAdvancedLink:nil];
109 } 96 }
110 [controller_ onClickAdvancedLink:nil]; 97 [controller_.release() close:nil];
111 [controller_.release() ok:nil];
112 } 98 }
113 99
114 } // namespace 100 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698