summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/ui/webui/javascript2webui.js3
-rw-r--r--chrome/browser/ui/webui/options/options_browsertest.js121
-rw-r--r--chrome/browser/ui/webui/web_ui_browsertest.cc14
-rw-r--r--chrome/browser/ui/webui/web_ui_browsertest.h3
4 files changed, 137 insertions, 4 deletions
diff --git a/chrome/browser/ui/webui/javascript2webui.js b/chrome/browser/ui/webui/javascript2webui.js
index 731ec72..e1e380f 100644
--- a/chrome/browser/ui/webui/javascript2webui.js
+++ b/chrome/browser/ui/webui/javascript2webui.js
@@ -44,7 +44,8 @@ function TEST_F(testFixture, testFunction, testBody) {
print('IN_PROC_BROWSER_TEST_F(' + testFixture + ', ' + testFunction + ') {');
if (testGenPreamble)
testGenPreamble(testFixture, testFunction);
- print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' + jsFileBase + '")));');
+ print(' AddLibrary(FilePath(FILE_PATH_LITERAL("' +
+ jsFileBase.replace(/\\/g, '/') + '")));');
if (browsePreload) {
print(' BrowsePreload(GURL("' + browsePreload + '"), "' + testFixture +
'", "' + testFunction + '");');
diff --git a/chrome/browser/ui/webui/options/options_browsertest.js b/chrome/browser/ui/webui/options/options_browsertest.js
new file mode 100644
index 0000000..e3ec6ab
--- /dev/null
+++ b/chrome/browser/ui/webui/options/options_browsertest.js
@@ -0,0 +1,121 @@
+// Copyright (c) 2011 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.
+
+/**
+ * TestFixture for OptionsPage WebUI testing.
+ * @extends {testing.Test}
+ * @constructor
+ */
+function OptionsWebUITest() {}
+
+OptionsWebUITest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /**
+ * Browse to the options page & call our preLoad().
+ */
+ browsePreload: 'chrome://settings',
+
+ /**
+ * Register a mock handler to ensure expectations are met and options pages
+ * behave correctly.
+ */
+ preLoad: function() {
+
+ /**
+ * Create handler class with empty methods to allow mocking to register
+ * expectations and for registration of handlers with chrome.send.
+ */
+ function MockOptionsHandler() {}
+
+ MockOptionsHandler.prototype = {
+ coreOptionsInitialize: function() {},
+ fetchPrefs: function() {},
+ observePrefs: function() {},
+ setBooleanPref: function() {},
+ setIntegerPref: function() {},
+ setDoublePref: function() {},
+ setStringPref: function() {},
+ setObjectPref: function() {},
+ clearPref: function() {},
+ coreOptionsUserMetricsAction: function() {},
+ // TODO(scr): Handle this new message:
+ // getInstantFieldTrialStatus: function() {},
+ };
+
+ // Create the actual mock and register stubs for methods expected to be
+ // called before our tests run. Specific expectations can be made in the
+ // tests themselves.
+ var mockHandler = this.mockHandler = mock(MockOptionsHandler);
+ mockHandler.stubs().fetchPrefs(ANYTHING);
+ mockHandler.stubs().observePrefs(ANYTHING);
+ mockHandler.stubs().coreOptionsInitialize();
+
+ // Register our mock as a handler of the chrome.send messages.
+ registerMockMessageCallbacks(mockHandler, MockOptionsHandler);
+ },
+};
+
+// Crashes on Mac only. See http://crbug.com/79181
+GEN('#if defined(OS_MACOSX)');
+GEN('#define MAYBE_testSetBooleanPrefTriggers ' +
+ 'DISABLED_testSetBooleanPrefTriggers');
+GEN('#else');
+GEN('#define MAYBE_testSetBooleanPrefTriggers testSetBooleanPrefTriggers');
+GEN('#endif // defined(OS_MACOSX)');
+
+TEST_F('OptionsWebUITest', 'MAYBE_testSetBooleanPrefTriggers', function() {
+ // TODO(dtseng): make generic to click all buttons.
+ var showHomeButton = $('toolbarShowHomeButton');
+ var trueListValue = [
+ 'browser.show_home_button',
+ true,
+ 'Options_Homepage_HomeButton',
+ ];
+ // Note: this expectation is checked in testing::Test::tearDown.
+ this.mockHandler.expects(once()).setBooleanPref(trueListValue);
+
+ // Cause the handler to be called.
+ showHomeButton.click();
+ showHomeButton.blur();
+});
+
+// Not meant to run on ChromeOS at this time.
+// Not finishing in windows. http://crbug.com/81723
+GEN('#if defined(OS_CHROMEOS) || defined(OS_MACOSX) || defined(OS_WIN) \\');
+GEN(' || defined(TOUCH_UI)');
+GEN('#define MAYBE_testRefreshStaysOnCurrentPage \\');
+GEN(' DISABLED_testRefreshStaysOnCurrentPage');
+GEN('#else');
+GEN('#define MAYBE_testRefreshStaysOnCurrentPage ' +
+ 'testRefreshStaysOnCurrentPage');
+GEN('#endif');
+
+TEST_F('OptionsWebUITest', 'MAYBE_testRefreshStaysOnCurrentPage', function() {
+ var item = $('advancedPageNav');
+ item.onclick();
+ window.location.reload();
+ var pageInstance = AdvancedOptions.getInstance();
+ var topPage = OptionsPage.getTopmostVisiblePage();
+ var expectedTitle = pageInstance.title;
+ var actualTitle = document.title;
+ assertEquals("chrome://settings/advanced", document.location.href);
+ assertEquals(expectedTitle, actualTitle);
+ assertEquals(pageInstance, topPage);
+});
+
+// Test that there are no console errors after opening all registered pages.
+// Crashes on chromium os, flaky on other platforms. See crbug.com/90420.
+// Disabling on Mac OS X since the failure rate is now >50%.
+GEN('#if defined(TOOLKIT_VIEWS) || defined(OS_MACOSX)');
+GEN('#define MAYBE_testOpenAllOptionsPages DISABLED_testOpenAllOptionsPages');
+GEN('#else');
+GEN('#define MAYBE_testOpenAllOptionsPages FLAKY_testOpenAllOptionsPages');
+GEN('#endif // defined(TOOLKIT_VIEWS)');
+TEST_F('OptionsWebUITest', 'MAYBE_testOpenAllOptionsPages', function() {
+ expectTrue(!!OptionsPage.registeredPages);
+ for (var name in OptionsPage.registeredPages) {
+ OptionsPage.showPageByName(name, false);
+ }
+});
diff --git a/chrome/browser/ui/webui/web_ui_browsertest.cc b/chrome/browser/ui/webui/web_ui_browsertest.cc
index e0a058b..2c84f2df 100644
--- a/chrome/browser/ui/webui/web_ui_browsertest.cc
+++ b/chrome/browser/ui/webui/web_ui_browsertest.cc
@@ -251,6 +251,8 @@ void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() {
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_));
test_data_directory_ = test_data_directory_.Append(kWebUITestFolder);
+ ASSERT_TRUE(PathService::Get(chrome::DIR_GEN_TEST_DATA,
+ &gen_test_data_directory_));
// TODO(dtseng): should this be part of every BrowserTest or just WebUI test.
FilePath resources_pack_path;
@@ -307,9 +309,15 @@ void WebUIBrowserTest::BuildJavascriptLibraries(string16* content) {
&library_content))
<< user_libraries_iterator->value();
} else {
- ASSERT_TRUE(file_util::ReadFileToString(
- test_data_directory_.Append(*user_libraries_iterator),
- &library_content)) << user_libraries_iterator->value();
+ bool ok = file_util::ReadFileToString(
+ gen_test_data_directory_.Append(*user_libraries_iterator),
+ &library_content);
+ if (!ok) {
+ ok = file_util::ReadFileToString(
+ test_data_directory_.Append(*user_libraries_iterator),
+ &library_content);
+ }
+ ASSERT_TRUE(ok) << user_libraries_iterator->value();
}
utf8_content.append(library_content);
utf8_content.append(";\n");
diff --git a/chrome/browser/ui/webui/web_ui_browsertest.h b/chrome/browser/ui/webui/web_ui_browsertest.h
index e308a2b..99f086a 100644
--- a/chrome/browser/ui/webui/web_ui_browsertest.h
+++ b/chrome/browser/ui/webui/web_ui_browsertest.h
@@ -174,6 +174,9 @@ class WebUIBrowserTest
// Location of test data (currently test/data/webui).
FilePath test_data_directory_;
+ // Location of generated test data (<(PROGRAM_DIR)/test_data).
+ FilePath gen_test_data_directory_;
+
// User added libraries
std::vector<FilePath> user_libraries_;