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 #include "chrome/browser/ui/webui/web_ui_browsertest.h" | 4 #include "chrome/browser/ui/webui/web_ui_browsertest.h" |
5 | 5 |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/ui_test_utils.h" | 15 #include "chrome/test/ui_test_utils.h" |
16 #include "content/browser/tab_contents/tab_contents.h" | 16 #include "content/browser/tab_contents/tab_contents.h" |
17 #include "content/browser/webui/web_ui.h" | 17 #include "content/browser/webui/web_ui.h" |
18 #include "testing/gtest/include/gtest/gtest-spi.h" | |
18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
19 | 20 |
20 static const FilePath::CharType* kWebUILibraryJS = | 21 static const FilePath::CharType* kWebUILibraryJS = |
21 FILE_PATH_LITERAL("test_api.js"); | 22 FILE_PATH_LITERAL("test_api.js"); |
22 static const FilePath::CharType* kWebUITestFolder = FILE_PATH_LITERAL("webui"); | 23 static const FilePath::CharType* kWebUITestFolder = FILE_PATH_LITERAL("webui"); |
23 static std::vector<std::string> error_messages_; | 24 static std::vector<std::string> error_messages_; |
24 | 25 |
25 // Intercepts all log messages. | 26 // Intercepts all log messages. |
26 bool LogHandler(int severity, | 27 bool LogHandler(int severity, |
27 const char* file, | 28 const char* file, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 } | 195 } |
195 | 196 |
196 IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, TestSamplePass) { | 197 IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, TestSamplePass) { |
197 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); | 198 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); |
198 | 199 |
199 // Navigate to UI. | 200 // Navigate to UI. |
200 // TODO(dtseng): make accessor for subclasses to return? | 201 // TODO(dtseng): make accessor for subclasses to return? |
201 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); | 202 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); |
202 | 203 |
203 ASSERT_TRUE(RunJavascriptTest("testAssertFalse")); | 204 ASSERT_TRUE(RunJavascriptTest("testAssertFalse")); |
205 ASSERT_FALSE(RunJavascriptTest("FAILS_testAssertFalse")); | |
204 ASSERT_TRUE(RunJavascriptTest("testInitialFocus")); | 206 ASSERT_TRUE(RunJavascriptTest("testInitialFocus")); |
205 ASSERT_FALSE(RunJavascriptTest("testConsoleError")); | 207 ASSERT_FALSE(RunJavascriptTest("testConsoleError")); |
206 } | 208 } |
209 | |
210 class WebUIBrowserExpectFailTest : public WebUIBrowserTest { | |
211 protected: | |
212 static WebUIBrowserTest* s_test_; | |
Paweł Hajdan Jr.
2011/06/15 17:16:20
Hm, I'm not a fan of this s_test variable. How abo
| |
213 static void RunJavascriptTestNoReturn(const std::string& testname) { | |
214 s_test_->RunJavascriptTest(testname); | |
215 } | |
216 }; | |
217 WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL; | |
218 | |
219 IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) { | |
220 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js"))); | |
221 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); | |
222 | |
223 s_test_ = this; | |
224 EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("FAILS_BogusFunctionName"), | |
225 "WebUITestHandler::Observe"); | |
226 } | |
OLD | NEW |