OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 OptionsPage WebUI testing. |
| 7 * @extends {testing.Test} |
| 8 * @constructor |
| 9 **/ |
| 10 function OptionsWebUITest() {} |
| 11 |
| 12 OptionsWebUITest.prototype = { |
| 13 __proto__: testing.Test.prototype, |
| 14 |
| 15 /** |
| 16 * Browse to the options page & call our PreLoad(). |
| 17 **/ |
| 18 browsePreload: 'chrome://settings', |
| 19 |
| 20 /** |
| 21 * Register a mock handler to ensure expectations are met and options pages |
| 22 * behave correctly. |
| 23 **/ |
| 24 PreLoad: function() { |
| 25 |
| 26 /** |
| 27 * Create handler class with empty methods to allow mocking to register |
| 28 * expectations and for registration of handlers with chrome.send. |
| 29 **/ |
| 30 function MockOptionsHandler() {} |
| 31 |
| 32 MockOptionsHandler.prototype = { |
| 33 coreOptionsInitialize: function() {}, |
| 34 fetchPrefs: function() {}, |
| 35 observePrefs: function() {}, |
| 36 setBooleanPref: function() {}, |
| 37 setIntegerPref: function() {}, |
| 38 setDoublePref: function() {}, |
| 39 setStringPref: function() {}, |
| 40 setObjectPref: function() {}, |
| 41 clearPref: function() {}, |
| 42 coreOptionsUserMetricsAction: function() {}, |
| 43 }; |
| 44 |
| 45 // Create the actual mock and register stubs for methods expected to be |
| 46 // called before our tests run. Specific expectations can be made in the |
| 47 // tests themselves. |
| 48 var mockHandler = this.mockHandler = mock(MockOptionsHandler); |
| 49 mockHandler.stubs().fetchPrefs(ANYTHING); |
| 50 mockHandler.stubs().observePrefs(ANYTHING); |
| 51 mockHandler.stubs().coreOptionsInitialize(); |
| 52 |
| 53 // Register our mock as a handler of the chrome.send messages. |
| 54 registerMockMessageCallbacks(mockHandler, MockOptionsHandler); |
| 55 }, |
| 56 }; |
| 57 |
| 58 // Crashes on Mac only. See http://crbug.com/79181 |
| 59 GEN('#if defined(OS_MACOSX)'); |
| 60 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + |
| 61 'DISABLED_testSetBooleanPrefTriggers'); |
| 62 GEN('#else'); |
| 63 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); |
| 64 GEN('#endif // defined(OS_MACOSX)'); |
| 65 |
| 66 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { |
| 67 // TODO(dtseng): make generic to click all buttons. |
| 68 var showHomeButton = $('toolbarShowHomeButton'); |
| 69 var trueListValue = [ |
| 70 'browser.show_home_button', |
| 71 true, |
| 72 'Options_Homepage_HomeButton', |
| 73 ]; |
| 74 // Note: this expectation is checked in testing::Test::TearDown. |
| 75 this.mockHandler.expects(once()).setBooleanPref(trueListValue); |
| 76 |
| 77 // Cause the handler to be called. |
| 78 showHomeButton.click(); |
| 79 showHomeButton.blur(); |
| 80 }); |
| 81 |
| 82 // Not meant to run on ChromeOS at this time. |
| 83 // Not finishing in windows. http://crbug.com/81723 |
| 84 GEN('#if defined(OS_CHROMEOS) || defined(OS_MACOSX) || defined(OS_WIN) \\'); |
| 85 GEN(' || defined(TOUCH_UI)'); |
| 86 GEN('#define MAYBE_testRefreshStaysOnCurrentPage \\'); |
| 87 GEN(' DISABLED_testRefreshStaysOnCurrentPage'); |
| 88 GEN('#else'); |
| 89 GEN('#define MAYBE_testRefreshStaysOnCurrentPage ' + |
| 90 'testRefreshStaysOnCurrentPage'); |
| 91 GEN('#endif'); |
| 92 |
| 93 TEST_F('OptionsWebUITest', 'MAYBE_testRefreshStaysOnCurrentPage', function() { |
| 94 var item = $('advancedPageNav'); |
| 95 item.onclick(); |
| 96 window.location.reload(); |
| 97 var pageInstance = AdvancedOptions.getInstance(); |
| 98 var topPage = OptionsPage.getTopmostVisiblePage(); |
| 99 var expectedTitle = pageInstance.title; |
| 100 var actualTitle = document.title; |
| 101 assertEquals("chrome://settings/advanced", document.location.href); |
| 102 assertEquals(expectedTitle, actualTitle); |
| 103 assertEquals(pageInstance, topPage); |
| 104 }); |
OLD | NEW |