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 "chrome/browser/dom_ui/dom_ui_browsertest.h" | 5 #include "chrome/browser/dom_ui/web_ui_browsertest.h" |
6 | 6 |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "chrome/test/ui_test_utils.h" | 12 #include "chrome/test/ui_test_utils.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 = | 17 static const FilePath::CharType* kWebUITestFolder = |
18 FILE_PATH_LITERAL("dom_ui"); | 18 FILE_PATH_LITERAL("dom_ui"); |
19 | 19 |
20 DOMUITest::~DOMUITest() {} | 20 WebUIBrowserTest::~WebUIBrowserTest() {} |
21 | 21 |
22 bool DOMUITest::RunDOMUITest(const FilePath::CharType* src_path) { | 22 bool WebUIBrowserTest::RunWebUITest(const FilePath::CharType* src_path) { |
23 std::string content; | 23 std::string content; |
24 BuildJavaScriptTest(FilePath(src_path), &content); | 24 BuildJavaScriptTest(FilePath(src_path), &content); |
25 SetupHandlers(); | 25 SetupHandlers(); |
26 return test_handler_->Execute(content); | 26 return test_handler_->Execute(content); |
27 } | 27 } |
28 | 28 |
29 DOMUITest::DOMUITest() : test_handler_(new DOMUITestHandler()) {} | 29 WebUIBrowserTest::WebUIBrowserTest() |
| 30 : test_handler_(new WebUIHandlerBrowserTest()) {} |
30 | 31 |
31 void DOMUITest::SetUpInProcessBrowserTestFixture() { | 32 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { |
32 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); | 33 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); |
33 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); | 34 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); |
34 | 35 |
35 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. | 36 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. |
36 FilePath resources_pack_path; | 37 FilePath resources_pack_path; |
37 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | 38 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
38 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); | 39 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); |
39 } | 40 } |
40 | 41 |
41 void DOMUITest::BuildJavaScriptTest(const FilePath& src_path, | 42 void WebUIBrowserTest::BuildJavaScriptTest(const FilePath& src_path, |
42 std::string* content) { | 43 std::string* content) { |
43 ASSERT_TRUE(content != NULL); | 44 ASSERT_TRUE(content != NULL); |
44 std::string library_content, src_content; | 45 std::string library_content, src_content; |
45 ASSERT_TRUE(file_util::ReadFileToString( | 46 ASSERT_TRUE(file_util::ReadFileToString( |
46 test_data_directory_.Append(FilePath(kWebUILibraryJS)), | 47 test_data_directory_.Append(FilePath(kWebUILibraryJS)), |
47 &library_content)); | 48 &library_content)); |
48 ASSERT_TRUE(file_util::ReadFileToString( | 49 ASSERT_TRUE(file_util::ReadFileToString( |
49 test_data_directory_.Append(src_path), &src_content)); | 50 test_data_directory_.Append(src_path), &src_content)); |
50 | 51 |
51 content->append(library_content); | 52 content->append(library_content); |
52 content->append(";\n"); | 53 content->append(";\n"); |
53 content->append(src_content); | 54 content->append(src_content); |
54 } | 55 } |
55 | 56 |
56 void DOMUITest::SetupHandlers() { | 57 void WebUIBrowserTest::SetupHandlers() { |
57 WebUI* web_ui_instance = | 58 WebUI* web_ui_instance = |
58 browser()->GetSelectedTabContents()->web_ui(); | 59 browser()->GetSelectedTabContents()->web_ui(); |
59 ASSERT_TRUE(web_ui_instance != NULL); | 60 ASSERT_TRUE(web_ui_instance != NULL); |
60 web_ui_instance->register_callback_overwrites(true); | 61 web_ui_instance->register_callback_overwrites(true); |
61 test_handler_->Attach(web_ui_instance); | 62 test_handler_->Attach(web_ui_instance); |
62 | 63 |
63 if (GetMockMessageHandler()) | 64 if (GetMockMessageHandler()) |
64 GetMockMessageHandler()->Attach(web_ui_instance); | 65 GetMockMessageHandler()->Attach(web_ui_instance); |
65 } | 66 } |
66 | 67 |
67 IN_PROC_BROWSER_TEST_F(DOMUITest, TestSamplePass) { | 68 IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, TestSamplePass) { |
68 // Navigate to UI. | 69 // Navigate to UI. |
69 // TODO(dtseng): make accessor for subclasses to return? | 70 // TODO(dtseng): make accessor for subclasses to return? |
70 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); | 71 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); |
71 | 72 |
72 ASSERT_TRUE(RunDOMUITest(FILE_PATH_LITERAL("sample_downloads.js"))); | 73 ASSERT_TRUE(RunWebUITest(FILE_PATH_LITERAL("sample_downloads.js"))); |
73 } | 74 } |
OLD | NEW |