• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5GEN('#if !defined(OS_CHROMEOS)');
6
7/**
8 * Test fixture for sync setup WebUI testing.
9 * @constructor
10 * @extends {testing.Test}
11 */
12function SyncSetupWebUITest() {}
13
14SyncSetupWebUITest.prototype = {
15  __proto__: testing.Test.prototype,
16
17  /**
18   * Browse to the settings sub-frame.
19   */
20  browsePreload: 'chrome://settings-frame',
21
22  /** @override */
23  preLoad: function() {
24    this.makeAndRegisterMockHandler(['SyncSetupConfigure',
25                                     'SyncSetupShowSetupUI',
26                                     'SyncSetupStartSignIn',
27                                    ]);
28  },
29
30  /**
31   * Verifies starting point is not synced.
32   */
33  verifyUnsynced: function() {
34    assertFalse(BrowserOptions.getInstance().signedIn_);
35  },
36
37  /**
38   * Clicks the "Sign in to Chrome" button.
39   */
40  startSyncing: function() {
41    var startStopSyncButton = BrowserOptions.getStartStopSyncButton();
42    assertNotEquals(null, startStopSyncButton);
43    startStopSyncButton.click();
44  },
45};
46
47/**
48 * Async version of SyncSetupWebUITest.
49 * @extends {SyncSetupWebUITest}
50 * @constructor
51 */
52function SyncSetupWebUITestAsync() {}
53
54SyncSetupWebUITestAsync.prototype = {
55  __proto__: SyncSetupWebUITest.prototype,
56
57  /** @override */
58  isAsync: true,
59};
60
61// Verify that initial state is unsynced, click the sign in button, verify
62// that the sync setup dialog appears, and dismiss it.
63TEST_F('SyncSetupWebUITestAsync', 'VerifySignIn', function() {
64  // Make sure the user is not starting off in the signed in or syncing state.
65  this.verifyUnsynced();
66
67  // Handle SyncSetupShowSetupUI by navigating to chrome://settings/syncSetup.
68  this.mockHandler.expects(once()).SyncSetupShowSetupUI().
69      will(callFunction(function() {
70                          OptionsPage.navigateToPage('syncSetup');
71                        }));
72
73  // Handle SyncSetupStartSignIn by displaying the sync setup dialog, verifying
74  // that a confirmation dialog appears, and clicking OK to dismiss the dialog.
75  // Note that this test doesn't actually do a gaia sign in.
76  this.mockHandler.expects(once()).SyncSetupStartSignIn().
77      will(callFunction(function() {
78                          SyncSetupOverlay.showSyncSetupPage('configure');
79                          var okButton = $('confirm-everything-ok');
80                          assertNotEquals(null, okButton);
81                          okButton.click();
82                        }));
83
84  // The test completes after the sync config is sent out.
85  this.mockHandler.expects(once()).SyncSetupConfigure(ANYTHING).
86      will(callFunction(testDone));
87
88  // For testing, don't wait to execute timeouts.
89  var oldSetTimeout = setTimeout;
90  setTimeout = function(fn, timeout) {
91    oldSetTimeout(fn, 0);
92  };
93
94  // Kick off the test by clicking the "Sign in to Chrome..." button.
95  this.startSyncing();
96});
97
98GEN('#endif  // OS_CHROMEOS');
99