| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/webui/web_ui_browsertest.h" | 5 #include "content/browser/webui/web_ui_browsertest.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 14 #include "chrome/test/ui_test_utils.h" | 14 #include "chrome/test/ui_test_utils.h" |
| 15 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 | 17 |
| 18 static const FilePath::CharType* kWebUILibraryJS = | 18 static const FilePath::CharType* kWebUILibraryJS = |
| 19 FILE_PATH_LITERAL("test_api.js"); | 19 FILE_PATH_LITERAL("test_api.js"); |
| 20 static const FilePath::CharType* kWebUITestFolder = FILE_PATH_LITERAL("webui"); | 20 static const FilePath::CharType* kWebUITestFolder = FILE_PATH_LITERAL("webui"); |
| 21 static std::vector<std::string> error_messages_; | 21 static std::vector<std::string> error_messages_; |
| 22 | 22 |
| 23 // Intercepts all log messages. | 23 // Intercepts all log messages. |
| 24 bool LogHandler(int severity, | 24 bool LogHandler(int severity, |
| 25 const char* file, | 25 const char* file, |
| 26 int line, | 26 int line, |
| 27 size_t message_start, | 27 size_t message_start, |
| 28 const std::string& str) { | 28 const std::string& str) { |
| 29 if (severity == logging::LOG_ERROR) { | 29 if (severity == logging::LOG_ERROR) |
| 30 error_messages_.push_back(str); | 30 error_messages_.push_back(str); |
| 31 return true; | 31 return true; |
| 32 } else { | |
| 33 // For debugging messages while developing tests. | |
| 34 return false; | |
| 35 } | |
| 36 } | 32 } |
| 37 | 33 |
| 38 WebUIBrowserTest::~WebUIBrowserTest() {} | 34 WebUIBrowserTest::~WebUIBrowserTest() {} |
| 39 | 35 |
| 40 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { | 36 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { |
| 41 return RunJavascriptUsingHandler(function_name, true); | 37 return RunJavascriptUsingHandler(function_name, false); |
| 42 } | 38 } |
| 43 | 39 |
| 44 bool WebUIBrowserTest::RunJavascriptTest(const std::string& test_name) { | 40 bool WebUIBrowserTest::RunJavascriptTest(const std::string& test_name) { |
| 45 return RunJavascriptUsingHandler(test_name, true); | 41 return RunJavascriptUsingHandler(test_name, true); |
| 46 } | 42 } |
| 47 | 43 |
| 48 WebUIBrowserTest::WebUIBrowserTest() | 44 WebUIBrowserTest::WebUIBrowserTest() |
| 49 : test_handler_(new WebUITestHandler()) {} | 45 : test_handler_(new WebUITestHandler()) {} |
| 50 | 46 |
| 51 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { | 47 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 AddLibrary(FILE_PATH_LITERAL("sample_downloads.js")); | 118 AddLibrary(FILE_PATH_LITERAL("sample_downloads.js")); |
| 123 | 119 |
| 124 // Navigate to UI. | 120 // Navigate to UI. |
| 125 // TODO(dtseng): make accessor for subclasses to return? | 121 // TODO(dtseng): make accessor for subclasses to return? |
| 126 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); | 122 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); |
| 127 | 123 |
| 128 ASSERT_TRUE(RunJavascriptTest("testAssertFalse")); | 124 ASSERT_TRUE(RunJavascriptTest("testAssertFalse")); |
| 129 ASSERT_TRUE(RunJavascriptTest("testInitialFocus")); | 125 ASSERT_TRUE(RunJavascriptTest("testInitialFocus")); |
| 130 ASSERT_FALSE(RunJavascriptTest("testConsoleError")); | 126 ASSERT_FALSE(RunJavascriptTest("testConsoleError")); |
| 131 } | 127 } |
| OLD | NEW |