Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: chrome/browser/ui/webui/web_ui_browsertest.cc

Issue 7146024: Use ExecuteJavascriptInWebFrameNotifyResult to return results even in error condition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't check against |this| in the destructor, which doesn't compile on Win. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/webui/web_ui_test_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // According to the interface for EXPECT_FATAL_FAILURE
211 // (http://code.google.com/p/googletest/wiki/AdvancedGuide#Catching_Failures)
212 // the statement must be statically available. Therefore, we make a static
213 // global s_test_ which should point to |this| for the duration of the test run
214 // and be cleared afterward.
215 class WebUIBrowserExpectFailTest : public WebUIBrowserTest {
216 public:
217 WebUIBrowserExpectFailTest() {
218 EXPECT_FALSE(s_test_);
219 s_test_ = this;
220 }
221
222 protected:
223 virtual ~WebUIBrowserExpectFailTest() {
224 EXPECT_TRUE(s_test_);
225 s_test_ = NULL;
226 }
227
228 static void RunJavascriptTestNoReturn(const std::string& testname) {
229 EXPECT_TRUE(s_test_);
230 s_test_->RunJavascriptTest(testname);
231 }
232
233 private:
234 static WebUIBrowserTest* s_test_;
235 };
236 WebUIBrowserTest* WebUIBrowserExpectFailTest::s_test_ = NULL;
237
238 IN_PROC_BROWSER_TEST_F(WebUIBrowserExpectFailTest, TestFailsFast) {
239 AddLibrary(FilePath(FILE_PATH_LITERAL("sample_downloads.js")));
240 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL));
241 EXPECT_FATAL_FAILURE(RunJavascriptTestNoReturn("FAILS_BogusFunctionName"),
242 "WebUITestHandler::Observe");
243 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/web_ui_test_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698