diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 02:56:57 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-25 02:56:57 +0000 |
commit | 67fc03984940b07daa38970e6876fcec1fce0e8e (patch) | |
tree | cc4df6d037ecc5e0a479305856fa84137d62af93 /content/browser/webui/web_ui_browsertest.cc | |
parent | 31de2b56d10626c2328f43531931bc08348ebad2 (diff) | |
download | chromium_src-67fc03984940b07daa38970e6876fcec1fce0e8e.zip chromium_src-67fc03984940b07daa38970e6876fcec1fce0e8e.tar.gz chromium_src-67fc03984940b07daa38970e6876fcec1fce0e8e.tar.bz2 |
WebUI: Move the core files of WebUI from chrome/browser/webui to content/browser/webui.
BUG=59946
TEST=trybots
Review URL: http://codereview.chromium.org/6575054
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/webui/web_ui_browsertest.cc')
-rw-r--r-- | content/browser/webui/web_ui_browsertest.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/content/browser/webui/web_ui_browsertest.cc b/content/browser/webui/web_ui_browsertest.cc new file mode 100644 index 0000000..18836c3 --- /dev/null +++ b/content/browser/webui/web_ui_browsertest.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/webui/web_ui_browsertest.h" + +#include "base/path_service.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_paths.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/ui_test_utils.h" +#include "ui/base/resource/resource_bundle.h" + +static const FilePath::CharType* kWebUILibraryJS = + FILE_PATH_LITERAL("test_api.js"); +static const FilePath::CharType* kWebUITestFolder = FILE_PATH_LITERAL("webui"); + +WebUIBrowserTest::~WebUIBrowserTest() {} + +bool WebUIBrowserTest::RunWebUITest(const FilePath::CharType* src_path) { + std::string content; + BuildJavaScriptTest(FilePath(src_path), &content); + SetupHandlers(); + return test_handler_->Execute(content); +} + +WebUIBrowserTest::WebUIBrowserTest() + : test_handler_(new WebUIHandlerBrowserTest()) {} + +void WebUIBrowserTest::SetUpInProcessBrowserTestFixture() { + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_)); + test_data_directory_ = test_data_directory_.Append(kWebUITestFolder); + + // TODO(dtseng): should this be part of every BrowserTest or just WebUI test. + FilePath resources_pack_path; + PathService::Get(chrome::FILE_RESOURCES_PACK, &resources_pack_path); + ResourceBundle::AddDataPackToSharedInstance(resources_pack_path); +} + +WebUIMessageHandler* WebUIBrowserTest::GetMockMessageHandler() { + return NULL; +} + +void WebUIBrowserTest::BuildJavaScriptTest(const FilePath& src_path, + std::string* content) { + ASSERT_TRUE(content != NULL); + std::string library_content, src_content; + ASSERT_TRUE(file_util::ReadFileToString( + test_data_directory_.Append(FilePath(kWebUILibraryJS)), + &library_content)); + ASSERT_TRUE(file_util::ReadFileToString( + test_data_directory_.Append(src_path), &src_content)); + + content->append(library_content); + content->append(";\n"); + content->append(src_content); +} + +void WebUIBrowserTest::SetupHandlers() { + WebUI* web_ui_instance = + browser()->GetSelectedTabContents()->web_ui(); + ASSERT_TRUE(web_ui_instance != NULL); + web_ui_instance->register_callback_overwrites(true); + test_handler_->Attach(web_ui_instance); + + if (GetMockMessageHandler()) + GetMockMessageHandler()->Attach(web_ui_instance); +} + +IN_PROC_BROWSER_TEST_F(WebUIBrowserTest, TestSamplePass) { + // Navigate to UI. + // TODO(dtseng): make accessor for subclasses to return? + ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIDownloadsURL)); + + ASSERT_TRUE(RunWebUITest(FILE_PATH_LITERAL("sample_downloads.js"))); +} |