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 }, | |
35 'fetchPrefs': function() { | |
Evan Stade
2011/07/08 23:04:46
I think the closing curly might as well be on the
Sheridan Rawlins
2011/07/08 23:47:24
Done.
| |
36 }, | |
37 'observePrefs': function() { | |
38 }, | |
39 'setBooleanPref': function() { | |
40 }, | |
41 'setIntegerPref': function() { | |
42 }, | |
43 'setDoublePref': function() { | |
44 }, | |
45 'setStringPref': function() { | |
46 }, | |
47 'setObjectPref': function() { | |
48 }, | |
49 'clearPref': function() { | |
50 }, | |
51 'coreOptionsUserMetricsAction': function() { | |
52 }, | |
53 }; | |
54 | |
55 // Create the actual mock and register stubs for methods expected to be | |
56 // called before our tests run. Specific expectations can be made in the | |
57 // tests themselves. | |
58 var mockHandler = this.mockHandler = mock(MockOptionsHandler); | |
59 mockHandler.stubs().fetchPrefs(ANYTHING); | |
60 mockHandler.stubs().observePrefs(ANYTHING); | |
61 mockHandler.stubs().coreOptionsInitialize(); | |
62 | |
63 // Register our mock as a handler of the chrome.send messages. | |
64 registerMockMessageCallbacks(mockHandler, MockOptionsHandler); | |
65 }, | |
66 }; | |
67 | |
68 GEN('#include "chrome/browser/ui/webui/web_ui_browsertest.h"'); | |
69 GEN('#include "googleurl/src/gurl.h"'); | |
70 GEN('#include "testing/gtest/include/gtest/gtest.h"'); | |
71 GEN(''); | |
72 GEN('typedef WebUIBrowserTest OptionsWebUITest;'); | |
73 | |
74 // Crashes on Mac only. See http://crbug.com/79181 | |
75 GEN('#if defined(OS_MACOSX)'); | |
76 GEN('#define MAYBE_testSetBooleanPrefTriggers ' + | |
77 'DISABLED_testSetBooleanPrefTriggers'); | |
78 GEN('#else'); | |
79 GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers'); | |
80 GEN('#endif // defined(OS_MACOSX)'); | |
81 | |
82 TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() { | |
83 // TODO(dtseng): make generic to click all buttons. | |
84 var showHomeButton = $('toolbarShowHomeButton'); | |
85 var trueListValue = ['browser.show_home_button', | |
86 true, | |
87 'Options_Homepage_HomeButton']; | |
88 // Note: this expectation is checked in testing::Test::TearDown. | |
89 this.mockHandler.expects(once()).setBooleanPref(trueListValue); | |
90 | |
91 // Cause the handler to be called. | |
92 showHomeButton.click(); | |
93 showHomeButton.blur(); | |
94 }); | |
95 | |
96 // Not meant to run on ChromeOS at this time. | |
97 // Not finishing in windows. http://crbug.com/81723 | |
98 GEN('#if defined(OS_CHROMEOS) || defined(OS_MACOSX) || defined(OS_WIN) \\'); | |
99 GEN(' || defined(TOUCH_UI)'); | |
100 GEN('#define MAYBE_testRefreshStaysOnCurrentPage \\'); | |
101 GEN(' DISABLED_testRefreshStaysOnCurrentPage'); | |
102 GEN('#else'); | |
103 GEN('#define MAYBE_testRefreshStaysOnCurrentPage ' + | |
104 'testRefreshStaysOnCurrentPage'); | |
105 GEN('#endif'); | |
106 | |
107 TEST_F('OptionsWebUITest', 'MAYBE_testRefreshStaysOnCurrentPage', function() { | |
108 var item = $('advancedPageNav'); | |
109 item.onclick(); | |
110 window.location.reload(); | |
111 var pageInstance = AdvancedOptions.getInstance(); | |
112 var topPage = OptionsPage.getTopmostVisiblePage(); | |
113 var expectedTitle = pageInstance.title; | |
114 var actualTitle = document.title; | |
115 assertEquals("chrome://settings/advanced", document.location.href); | |
116 assertEquals(expectedTitle, actualTitle); | |
117 assertEquals(pageInstance, topPage); | |
118 }); | |
OLD | NEW |