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
5/**
6 * TestFixture for testing messages of dictionary download progress in language
7 * options WebUI.
8 * @extends {testing.Test}
9 * @constructor
10 */
11function LanguagesOptionsDictionaryDownloadWebUITest() {}
12
13LanguagesOptionsDictionaryDownloadWebUITest.prototype = {
14  __proto__: testing.Test.prototype,
15
16  /**
17   * Browse to languages options.
18   */
19  browsePreload: 'chrome://settings-frame/languages',
20
21  /**
22   * Register a mock dictionary handler.
23   */
24  preLoad: function() {
25    this.makeAndRegisterMockHandler(['retryDictionaryDownload']);
26    this.mockHandler.stubs().retryDictionaryDownload().
27        will(callFunction(function() {
28          options.LanguageOptions.onDictionaryDownloadBegin('en-US');
29        }));
30  },
31};
32
33// Verify that dictionary download success shows 'This language is used for
34// spellchecking' message.
35TEST_F('LanguagesOptionsDictionaryDownloadWebUITest',
36       'testdictionaryDownloadSuccess',
37       function() {
38  options.LanguageOptions.onDictionaryDownloadSuccess('en-US');
39  expectFalse($('language-options-spell-check-language-message').hidden);
40  expectTrue($('language-options-dictionary-downloading-message').hidden);
41  expectTrue($('language-options-dictionary-download-failed-message').hidden);
42  expectTrue(
43      $('language-options-dictionary-download-fail-help-message').hidden);
44});
45
46// Verify that dictionary download in progress shows 'Downloading spell check
47// language' message.
48TEST_F('LanguagesOptionsDictionaryDownloadWebUITest',
49       'testdictionaryDownloadProgress',
50       function() {
51  options.LanguageOptions.onDictionaryDownloadBegin('en-US');
52  expectTrue($('language-options-spell-check-language-message').hidden);
53  expectFalse($('language-options-dictionary-downloading-message').hidden);
54  expectTrue($('language-options-dictionary-download-failed-message').hidden);
55  expectTrue(
56      $('language-options-dictionary-download-fail-help-message').hidden);
57});
58
59// Verify that failure in dictionary download shows 'Dictionary download failed'
60// message.
61TEST_F('LanguagesOptionsDictionaryDownloadWebUITest',
62       'testdictionaryDownloadFailed',
63       function() {
64  // Clear the failure counter:
65  options.LanguageOptions.onDictionaryDownloadSuccess('en-US');
66
67  // First failure shows a short error message.
68  options.LanguageOptions.onDictionaryDownloadFailure('en-US');
69  expectTrue($('language-options-spell-check-language-message').hidden);
70  expectTrue($('language-options-dictionary-downloading-message').hidden);
71  expectFalse($('language-options-dictionary-download-failed-message').hidden);
72  expectTrue(
73      $('language-options-dictionary-download-fail-help-message').hidden);
74
75  // Second and all following failures show a longer error message.
76  options.LanguageOptions.onDictionaryDownloadFailure('en-US');
77  expectTrue($('language-options-spell-check-language-message').hidden);
78  expectTrue($('language-options-dictionary-downloading-message').hidden);
79  expectFalse($('language-options-dictionary-download-failed-message').hidden);
80  expectFalse(
81      $('language-options-dictionary-download-fail-help-message').hidden);
82
83  options.LanguageOptions.onDictionaryDownloadFailure('en-US');
84  expectTrue($('language-options-spell-check-language-message').hidden);
85  expectTrue($('language-options-dictionary-downloading-message').hidden);
86  expectFalse($('language-options-dictionary-download-failed-message').hidden);
87  expectFalse(
88      $('language-options-dictionary-download-fail-help-message').hidden);
89});
90
91// Verify that clicking the retry button calls the handler.
92TEST_F('LanguagesOptionsDictionaryDownloadWebUITest',
93       'testdictionaryDownloadRetry',
94       function() {
95  this.mockHandler.expects(once()).retryDictionaryDownload().
96      will(callFunction(function() {
97        options.LanguageOptions.onDictionaryDownloadBegin('en-US');
98      }));
99  options.LanguageOptions.onDictionaryDownloadFailure('en-US');
100  $('dictionary-download-retry-button').click();
101});
102