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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 14 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
15 #include "chrome/browser/ui/browser_navigator.h" | |
15 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" | 16 #include "chrome/browser/ui/webui/test_chrome_web_ui_factory.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "chrome/test/test_navigation_observer.h" | |
18 #include "chrome/test/ui_test_utils.h" | 20 #include "chrome/test/ui_test_utils.h" |
19 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
20 #include "testing/gtest/include/gtest/gtest-spi.h" | 22 #include "testing/gtest/include/gtest/gtest-spi.h" |
21 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); | 27 const FilePath::CharType kWebUILibraryJS[] = FILE_PATH_LITERAL("test_api.js"); |
26 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); | 28 const FilePath::CharType kWebUITestFolder[] = FILE_PATH_LITERAL("webui"); |
27 base::LazyInstance<std::vector<std::string> > error_messages_( | 29 base::LazyInstance<std::vector<std::string> > error_messages_( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 void WebUIBrowserTest::PreLoadJavascriptLibraries(bool override_chrome_send) { | 100 void WebUIBrowserTest::PreLoadJavascriptLibraries(bool override_chrome_send) { |
99 ASSERT_FALSE(libraries_preloaded_); | 101 ASSERT_FALSE(libraries_preloaded_); |
100 scoped_ptr<Value> override_chrome_send_arg( | 102 scoped_ptr<Value> override_chrome_send_arg( |
101 Value::CreateBooleanValue(override_chrome_send)); | 103 Value::CreateBooleanValue(override_chrome_send)); |
102 RunJavascriptFunction("preloadJavascriptLibraries", | 104 RunJavascriptFunction("preloadJavascriptLibraries", |
103 *override_chrome_send_arg); | 105 *override_chrome_send_arg); |
104 libraries_preloaded_ = true; | 106 libraries_preloaded_ = true; |
105 } | 107 } |
106 | 108 |
107 WebUIBrowserTest::WebUIBrowserTest() | 109 WebUIBrowserTest::WebUIBrowserTest() |
108 : test_handler_(new WebUITestHandler()), | 110 : override_chrome_send_(false), |
111 test_handler_(new WebUITestHandler()), | |
109 libraries_preloaded_(false), | 112 libraries_preloaded_(false), |
110 skip_test_(false) {} | 113 skip_test_(false) {} |
111 | 114 |
115 void WebUIBrowserTest::BrowsePreload(const GURL& browse_to, | |
116 bool override_chrome_send) { | |
117 override_chrome_send_ = override_chrome_send; | |
118 TestNavigationObserver navigation_observer( | |
119 browser()->GetSelectedTabContentsWrapper(), this); | |
120 browser::NavigateParams params( | |
121 browser(), GURL(browse_to), PageTransition::TYPED); | |
122 params.disposition = CURRENT_TAB; | |
123 browser::Navigate(¶ms); | |
124 navigation_observer.WaitForObservation(); | |
125 } | |
126 | |
112 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { | 127 void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { |
113 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); | 128 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); |
114 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); | 129 test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); |
115 | 130 |
116 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. | 131 // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. |
117 FilePath resources_pack_path; | 132 FilePath resources_pack_path; |
118 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); | 133 PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); |
119 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); | 134 ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); |
120 | 135 |
121 AddLibrary(FilePath(kWebUILibraryJS)); | 136 AddLibrary(FilePath(kWebUILibraryJS)); |
(...skipping 11 matching lines...) Expand all Loading... | |
133 GURL WebUIBrowserTest::WebUITestDataPathToURL( | 148 GURL WebUIBrowserTest::WebUITestDataPathToURL( |
134 const FilePath::StringType& path) { | 149 const FilePath::StringType& path) { |
135 FilePath dir_test_data; | 150 FilePath dir_test_data; |
136 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); | 151 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &dir_test_data)); |
137 FilePath test_path(dir_test_data.AppendASCII("webui")); | 152 FilePath test_path(dir_test_data.AppendASCII("webui")); |
138 test_path = test_path.Append(path); | 153 test_path = test_path.Append(path); |
139 EXPECT_TRUE(file_util::PathExists(test_path)); | 154 EXPECT_TRUE(file_util::PathExists(test_path)); |
140 return net::FilePathToFileURL(test_path); | 155 return net::FilePathToFileURL(test_path); |
141 } | 156 } |
142 | 157 |
158 // TestTabStripModelObserver::LoadStartObserver: | |
159 void WebUIBrowserTest::OnLoadStart() OVERRIDE { | |
160 PreLoadJavascriptLibraries(override_chrome_send_); | |
James Hawkins
2011/07/08 00:03:33
When is this ever false?
Sheridan Rawlins
2011/07/08 22:45:49
It wasn't and with the TEST_F-style of generation/
| |
161 } | |
162 | |
143 void WebUIBrowserTest::BuildJavascriptLibraries(std::string* content) { | 163 void WebUIBrowserTest::BuildJavascriptLibraries(std::string* content) { |
144 ASSERT_TRUE(content != NULL); | 164 ASSERT_TRUE(content != NULL); |
145 std::string library_content, src_content; | 165 std::string library_content; |
166 | |
167 #if defined(OS_MACOSX) | |
James Hawkins
2011/07/08 00:03:33
Document this section.
Sheridan Rawlins
2011/07/08 22:45:49
With GEN() method for generation, the test files o
| |
168 content->append("var OS_MACOSX = 1;"); | |
169 #endif | |
170 #if defined(OS_CHROMEOS) | |
171 content->append("var OS_CHROMEOS = 1;"); | |
172 #endif | |
173 #if defined(OS_WIN) | |
174 content->append("var OS_WIN = 1;"); | |
175 #endif | |
176 #if defined(TOUCH_UI) | |
177 content->append("var TOUCH_UI = 1;"); | |
178 #endif | |
146 | 179 |
147 std::vector<FilePath>::iterator user_libraries_iterator; | 180 std::vector<FilePath>::iterator user_libraries_iterator; |
148 for (user_libraries_iterator = user_libraries_.begin(); | 181 for (user_libraries_iterator = user_libraries_.begin(); |
149 user_libraries_iterator != user_libraries_.end(); | 182 user_libraries_iterator != user_libraries_.end(); |
150 ++user_libraries_iterator) { | 183 ++user_libraries_iterator) { |
151 if (user_libraries_iterator->IsAbsolute()) { | 184 if (user_libraries_iterator->IsAbsolute()) { |
152 ASSERT_TRUE(file_util::ReadFileToString(*user_libraries_iterator, | 185 ASSERT_TRUE(file_util::ReadFileToString(*user_libraries_iterator, |
153 &library_content)); | 186 &library_content)); |
154 } else { | 187 } else { |
155 ASSERT_TRUE(file_util::ReadFileToString( | 188 ASSERT_TRUE(file_util::ReadFileToString( |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 | 350 |
318 static const char kChromeTestBrowserTestPass[]; | 351 static const char kChromeTestBrowserTestPass[]; |
319 }; | 352 }; |
320 | 353 |
321 const char WebUIBrowserTestPass::kChromeTestBrowserTestPass[] = | 354 const char WebUIBrowserTestPass::kChromeTestBrowserTestPass[] = |
322 "chrome://WebUIBrowserTestPass"; | 355 "chrome://WebUIBrowserTestPass"; |
323 | 356 |
324 #include "chrome/test/data/webui/sample_pass-inl.h" | 357 #include "chrome/test/data/webui/sample_pass-inl.h" |
325 | 358 |
326 #endif // !defined(ARCH_CPU_ARM_FAMILY) | 359 #endif // !defined(ARCH_CPU_ARM_FAMILY) |
OLD | NEW |