Extensions cleanup: Merge IsSyncableApp+Extension, ShouldSyncApp+Extension
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / one_click_signin_dialog_controller_browsertest.mm
blob4047e3af9d77febbbf341e7906aefa7321d16c00
1 // Copyright (c) 2013 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_dialog_controller.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #import "testing/gtest_mac.h"
14 class OneClickSigninDialogControllerTest : public InProcessBrowserTest {
15  public:
16   OneClickSigninDialogControllerTest()
17     : controller_(NULL),
18       sync_mode_(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS),
19       callback_count_(0) {
20   }
22  protected:
23   void SetUpOnMainThread() override {
24     content::WebContents* web_contents =
25         browser()->tab_strip_model()->GetWebContentsAt(0);
26     BrowserWindow::StartSyncCallback callback = base::Bind(
27         &OneClickSigninDialogControllerTest::OnStartSyncCallback,
28         base::Unretained(this));
29     controller_ = new OneClickSigninDialogController(
30         web_contents, callback, base::string16());
31     EXPECT_NSEQ(@"OneClickSigninDialog",
32                 [controller_->view_controller() nibName]);
33   }
35   // Weak pointer. Will delete itself when dialog closes.
36   OneClickSigninDialogController* controller_;
37   OneClickSigninSyncStarter::StartSyncMode sync_mode_;
38   int callback_count_;
40  private:
41   void OnStartSyncCallback(OneClickSigninSyncStarter::StartSyncMode mode) {
42     sync_mode_ = mode;
43     ++callback_count_;
44   }
46   DISALLOW_COPY_AND_ASSIGN(OneClickSigninDialogControllerTest);
49 // Test that the dialog calls the callback if the OK button is clicked.
50 // Callback should be called to setup sync with default settings.
51 IN_PROC_BROWSER_TEST_F(OneClickSigninDialogControllerTest, OK) {
52   [controller_->view_controller() ok:nil];
53   EXPECT_EQ(OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS, sync_mode_);
54   EXPECT_EQ(1, callback_count_);
57 // Test that the dialog does call the callback if the Undo button
58 // is clicked. Callback should be called to abort the sync.
59 IN_PROC_BROWSER_TEST_F(OneClickSigninDialogControllerTest, Undo) {
60   [controller_->view_controller() onClickUndo:nil];
61   EXPECT_EQ(OneClickSigninSyncStarter::UNDO_SYNC, sync_mode_);
62   EXPECT_EQ(1, callback_count_);
65 // Test that the advanced callback is run if its corresponding button
66 // is clicked.
67 IN_PROC_BROWSER_TEST_F(OneClickSigninDialogControllerTest, Advanced) {
68   [controller_->view_controller() onClickAdvancedLink:nil];
69   EXPECT_EQ(OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST, sync_mode_);
70   EXPECT_EQ(1, callback_count_);
73 // Test that the dialog calls the callback if the bubble is closed.
74 // Callback should be called to setup sync with default settings.
75 IN_PROC_BROWSER_TEST_F(OneClickSigninDialogControllerTest, Close) {
76   controller_->constrained_window()->CloseWebContentsModalDialog();
77   EXPECT_EQ(OneClickSigninSyncStarter::UNDO_SYNC, sync_mode_);
78   EXPECT_EQ(1, callback_count_);
81 // Test that clicking the learn more link opens a new window.
82 IN_PROC_BROWSER_TEST_F(OneClickSigninDialogControllerTest, LearnMore) {
83   EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
84   [controller_->view_controller() textView:nil
85                              clickedOnLink:nil
86                                    atIndex:0];
87   EXPECT_EQ(2u, chrome::GetTotalBrowserCount());