| OLD | NEW |
| 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 #include "chrome/browser/ui/gtk/one_click_signin_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/one_click_signin_bubble_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.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 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 13 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 class OneClickSigninBubbleGtkTest : public InProcessBrowserTest { | 19 class OneClickSigninBubbleGtkTest : public InProcessBrowserTest { |
| 20 public: | 20 public: |
| 21 OneClickSigninBubbleGtkTest() | 21 OneClickSigninBubbleGtkTest() |
| 22 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 22 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 23 learn_more_callback_( | 23 start_sync_callback_( |
| 24 base::Bind(&OneClickSigninBubbleGtkTest::OnLearnMore, | 24 base::Bind(&OneClickSigninBubbleGtkTest::OnStartSync, |
| 25 weak_ptr_factory_.GetWeakPtr())), | |
| 26 advanced_callback_( | |
| 27 base::Bind(&OneClickSigninBubbleGtkTest::OnAdvanced, | |
| 28 weak_ptr_factory_.GetWeakPtr())), | 25 weak_ptr_factory_.GetWeakPtr())), |
| 29 bubble_(NULL) {} | 26 bubble_(NULL) {} |
| 30 | 27 |
| 31 virtual OneClickSigninBubbleGtk* MakeBubble() { | 28 virtual OneClickSigninBubbleGtk* MakeBubble() { |
| 32 return new OneClickSigninBubbleGtk( | 29 return new OneClickSigninBubbleGtk( |
| 33 static_cast<BrowserWindowGtk*>(browser()->window()), | 30 static_cast<BrowserWindowGtk*>(browser()->window()), |
| 34 learn_more_callback_, | 31 start_sync_callback_); |
| 35 advanced_callback_); | |
| 36 } | 32 } |
| 37 | 33 |
| 38 MOCK_METHOD0(OnLearnMore, void()); | 34 MOCK_METHOD1(OnStartSync, void(bool)); |
| 39 MOCK_METHOD0(OnAdvanced, void()); | |
| 40 | 35 |
| 41 protected: | 36 protected: |
| 42 base::WeakPtrFactory<OneClickSigninBubbleGtkTest> weak_ptr_factory_; | 37 base::WeakPtrFactory<OneClickSigninBubbleGtkTest> weak_ptr_factory_; |
| 43 base::Closure learn_more_callback_; | 38 OneClickSigninBubbleCallback start_sync_callback_; |
| 44 base::Closure advanced_callback_; | |
| 45 | 39 |
| 46 // Owns itself. | 40 // Owns itself. |
| 47 OneClickSigninBubbleGtk* bubble_; | 41 OneClickSigninBubbleGtk* bubble_; |
| 48 }; | 42 }; |
| 49 | 43 |
| 50 // Test that the dialog doesn't call any callback if the OK button is | 44 // Test that the dialog calls the callback if the OK button is clicked. |
| 51 // clicked. | 45 // Callback should be called to setup sync with default settings. |
| 52 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleGtkTest, ShowAndOK) { | 46 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleGtkTest, ShowAndOK) { |
| 53 EXPECT_CALL(*this, OnLearnMore()).Times(0); | 47 EXPECT_CALL(*this, OnStartSync(true)).Times(1); |
| 54 EXPECT_CALL(*this, OnAdvanced()).Times(0); | |
| 55 | 48 |
| 56 MakeBubble()->ClickOKForTest(); | 49 MakeBubble()->ClickOKForTest(); |
| 57 } | 50 } |
| 58 | 51 |
| 59 // Test that the learn more callback is run if its corresponding | 52 // Test that the dialog doesn't calls the callback if the Undo button is |
| 60 // button is clicked. | 53 // clicked. |
| 61 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleGtkTest, ShowAndClickLearnMore) { | 54 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleGtkTest, ShowAndUndo) { |
| 62 EXPECT_CALL(*this, OnLearnMore()).Times(1); | 55 EXPECT_CALL(*this, OnStartSync(testing::_)).Times(0); |
| 63 EXPECT_CALL(*this, OnAdvanced()).Times(0); | |
| 64 | 56 |
| 65 MakeBubble()->ClickLearnMoreForTest(); | 57 MakeBubble()->ClickUndoForTest(); |
| 66 } | 58 } |
| 67 | 59 |
| 68 // Test that the advanced callback is run if its corresponding button | 60 // Test that the dialog calls the callback if the advanced link is clicked. |
| 69 // is clicked. | 61 // Callback should be called to configure sync before starting. |
| 70 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleGtkTest, ShowAndClickAdvanced) { | 62 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleGtkTest, ShowAndClickAdvanced) { |
| 71 EXPECT_CALL(*this, OnLearnMore()).Times(0); | 63 EXPECT_CALL(*this, OnStartSync(false)).Times(1); |
| 72 EXPECT_CALL(*this, OnAdvanced()).Times(1); | |
| 73 | 64 |
| 74 MakeBubble()->ClickAdvancedForTest(); | 65 MakeBubble()->ClickAdvancedForTest(); |
| 75 } | 66 } |
| 76 | 67 |
| 68 // Test that the dialog calls the callback if the bubble is closed. |
| 69 // Callback should be called to setup sync with default settings. |
| 70 IN_PROC_BROWSER_TEST_F(OneClickSigninBubbleGtkTest, ShowAndClose) { |
| 71 EXPECT_CALL(*this, OnStartSync(true)).Times(1); |
| 72 |
| 73 MakeBubble()->CloseForTest(); |
| 74 } |
| 75 |
| 77 } // namespace | 76 } // namespace |
| OLD | NEW |