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

Side by Side Diff: content/browser/webui/web_ui_browsertest.cc

Issue 6805003: Add a test for checking that refreshing a page does load the same WebUI page. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
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 4
5 #include "content/browser/webui/web_ui_browsertest.h" 5 #include "content/browser/webui/web_ui_browsertest.h"
6 6
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "chrome/test/ui_test_utils.h" 11 #include "chrome/test/ui_test_utils.h"
12 #include "content/browser/tab_contents/tab_contents.h" 12 #include "content/browser/tab_contents/tab_contents.h"
13 #include "ui/base/resource/resource_bundle.h" 13 #include "ui/base/resource/resource_bundle.h"
14 14
15 static const FilePath::CharType* kWebUILibraryJS = 15 static const FilePath::CharType* kWebUILibraryJS =
16 FILE_PATH_LITERAL("test_api.js"); 16 FILE_PATH_LITERAL("test_api.js");
17 static const FilePath::CharType* kWebUITestFolder = FILE_PATH_LITERAL("webui"); 17 static const FilePath::CharType* kWebUITestFolder = FILE_PATH_LITERAL("webui");
18 18
19 WebUIBrowserTest::~WebUIBrowserTest() {} 19 WebUIBrowserTest::~WebUIBrowserTest() {}
20 20
21 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) { 21 bool WebUIBrowserTest::RunJavascriptFunction(const std::string& function_name) {
22 return RunJavascriptUsingHandler(function_name, false); 22 return RunJavascriptUsingHandler(function_name, true);
23 } 23 }
24 24
25 bool WebUIBrowserTest::RunJavascriptTest(const std::string& test_name) { 25 bool WebUIBrowserTest::RunJavascriptTest(const std::string& test_name) {
26 return RunJavascriptUsingHandler(test_name, true); 26 return RunJavascriptUsingHandler(test_name, true);
27 } 27 }
28 28
29 WebUIBrowserTest::WebUIBrowserTest() 29 WebUIBrowserTest::WebUIBrowserTest()
30 : test_handler_(new WebUITestHandler()) {} 30 : test_handler_(new WebUITestHandler()) {}
31 31
32 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { 32 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() {
(...skipping 28 matching lines...) Expand all
61 } 61 }
62 } 62 }
63 63
64 bool WebUIBrowserTest::RunJavascriptUsingHandler( 64 bool WebUIBrowserTest::RunJavascriptUsingHandler(
65 const std::string& function_name, bool is_test) { 65 const std::string& function_name, bool is_test) {
66 std::string content; 66 std::string content;
67 BuildJavascriptLibraries(&content); 67 BuildJavascriptLibraries(&content);
68 68
69 if (!function_name.empty()) { 69 if (!function_name.empty()) {
70 std::string called_function = is_test ? "runTest(" + function_name + ");" : 70 std::string called_function = is_test ? "runTest(" + function_name + ");" :
71 function_name + "()"; 71 function_name + "();";
72 content.append(called_function); 72 content.append(called_function);
73 } 73 }
74 SetupHandlers(); 74 SetupHandlers();
75 return test_handler_->RunJavascript(content, is_test); 75 return test_handler_->RunJavascript(content, is_test);
76 } 76 }
77 77
78 void WebUIBrowserTest::SetupHandlers() { 78 void WebUIBrowserTest::SetupHandlers() {
79 WebUI* web_ui_instance = 79 WebUI* web_ui_instance =
80 browser()->GetSelectedTabContents()->web_ui(); 80 browser()->GetSelectedTabContents()->web_ui();
81 ASSERT_TRUE(web_ui_instance != NULL); 81 ASSERT_TRUE(web_ui_instance != NULL);
(...skipping 11 matching lines...) Expand all
93 IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, TestSamplePass) { 93 IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, TestSamplePass) {
94 AddLibrary(FILE_PATH_LITERAL("sample_downloads.js")); 94 AddLibrary(FILE_PATH_LITERAL("sample_downloads.js"));
95 95
96 // Navigate to UI. 96 // Navigate to UI.
97 // TODO(dtseng): make accessor for subclasses to return? 97 // TODO(dtseng): make accessor for subclasses to return?
98 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); 98 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL));
99 99
100 ASSERT_TRUE(RunJavascriptTest("testAssertFalse")); 100 ASSERT_TRUE(RunJavascriptTest("testAssertFalse"));
101 ASSERT_TRUE(RunJavascriptTest("testInitialFocus")); 101 ASSERT_TRUE(RunJavascriptTest("testInitialFocus"));
102 } 102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698