summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/webui/sync_setup_browsertest.js
blob: 6614e9bfbfa5685d820390d2a1e3a5364f88513c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

GEN('#if !defined(OS_CHROMEOS)');

/**
 * Test fixture for sync setup WebUI testing.
 * @constructor
 * @extends {testing.Test}
 */
function SyncSetupWebUITest() {}

SyncSetupWebUITest.prototype = {
  __proto__: testing.Test.prototype,

  /**
   * Browse to the settings sub-frame.
   */
  browsePreload: 'chrome://settings-frame',

  /** @inheritDoc */
  preLoad: function() {
    this.makeAndRegisterMockHandler(['SyncSetupConfigure',
                                     'SyncSetupShowSetupUI',
                                     'SyncSetupStartSignIn',
                                    ]);
  },

  /**
   * Verifies starting point is not synced.
   */
  verifyUnsynced: function() {
    assertFalse(BrowserOptions.getInstance().signedIn_);
  },

  /**
   * Clicks the "Sign in to Chrome" button.
   */
  startSyncing: function() {
    var startStopSyncButton = BrowserOptions.getStartStopSyncButton();
    assertNotEquals(null, startStopSyncButton);
    startStopSyncButton.click();
  },
};

/**
 * Async version of SyncSetupWebUITest.
 * @extends {SyncSetupWebUITest}
 * @constructor
 */
function SyncSetupWebUITestAsync() {}

SyncSetupWebUITestAsync.prototype = {
  __proto__: SyncSetupWebUITest.prototype,

  /** @inheritDoc */
  isAsync: true,
};

// Verify that initial state is unsynced, click the sign in button, verify
// that the sync setup dialog appears, and dismiss it.
TEST_F('SyncSetupWebUITestAsync', 'VerifySignIn', function() {
  // Make sure the user is not starting off in the signed in or syncing state.
  this.verifyUnsynced();

  // Handle SyncSetupShowSetupUI by navigating to chrome://settings/syncSetup.
  this.mockHandler.expects(once()).SyncSetupShowSetupUI().
      will(callFunction(function() {
                          OptionsPage.navigateToPage('syncSetup');
                        }));

  // Handle SyncSetupStartSignIn by displaying the sync setup dialog, verifying
  // that a confirmation dialog appears, and clicking OK to dismiss the dialog.
  // Note that this test doesn't actually do a gaia sign in.
  this.mockHandler.expects(once()).SyncSetupStartSignIn().
      will(callFunction(function() {
                          SyncSetupOverlay.showSyncSetupPage('configure');
                          var okButton = $('confirm-everything-ok');
                          assertNotEquals(null, okButton);
                          okButton.click();
                        }));

  // The test completes after the sync config is sent out.
  this.mockHandler.expects(once()).SyncSetupConfigure(ANYTHING).
      will(callFunction(testDone));

  // For testing, don't wait to execute timeouts.
  var oldSetTimeout = setTimeout;
  setTimeout = function(fn, timeout) {
    oldSetTimeout(fn, 0);
  };

  // Kick off the test by clicking the "Sign in to Chrome..." button.
  this.startSyncing();
});

GEN('#endif  // OS_CHROMEOS');