Commit 3c2a1733 authored by gunsch's avatar gunsch Committed by Commit bot

Chromecast: end-to-end browser test based on content::BrowserTest.

R=lcwu@chromium.org,byungchul@chromium.org,phajdan.jr@chromium.org
BUG=409163

Review URL: https://codereview.chromium.org/518773003

Cr-Commit-Position: refs/heads/master@{#294523}
parent 88e3114d
......@@ -394,19 +394,18 @@
], # end of targets
}, { # OS != "android"
'targets': [
# This target includes all dependencies that cannot be built on Android.
# This target contains all of the primary code of |cast_shell|, except
# for |main|. This allows end-to-end tests using |cast_shell|.
# This also includes all targets that cannot be built on Android.
{
'target_name': 'cast_shell',
'type': 'executable',
'target_name': 'cast_shell_core',
'type': '<(component)',
'dependencies': [
'cast_net',
'cast_shell_common',
'media/media.gyp:cast_media',
'../ui/aura/aura.gyp:aura_test_support',
],
'sources': [
'shell/app/cast_main.cc',
],
'conditions': [
['chromecast_branding=="Chrome"', {
'dependencies': [
......@@ -419,6 +418,47 @@
}],
],
},
{
'target_name': 'cast_shell',
'type': 'executable',
'dependencies': [
'cast_shell_core',
],
'sources': [
'shell/app/cast_main.cc',
],
},
{
'target_name': 'cast_shell_browser_test',
'type': '<(gtest_target_type)',
'dependencies': [
'cast_shell_test_support',
'../testing/gtest.gyp:gtest',
],
'defines': [
'HAS_OUT_OF_PROC_TEST_RUNNER',
],
'sources': [
'shell/browser/test/chromecast_shell_browser_test.cc',
],
},
{
'target_name': 'cast_shell_test_support',
'type': '<(component)',
'defines': [
'HAS_OUT_OF_PROC_TEST_RUNNER',
],
'dependencies': [
'cast_shell_core',
'../content/content_shell_and_tests.gyp:content_browser_test_support',
'../testing/gtest.gyp:gtest',
],
'sources': [
'shell/browser/test/chromecast_browser_test.cc',
'shell/browser/test/chromecast_browser_test.h',
'shell/browser/test/chromecast_browser_test_runner.cc',
],
},
], # end of targets
}],
], # end of conditions
......
......@@ -4,28 +4,16 @@
#include "chromecast/net/network_change_notifier_factory_cast.h"
#include "base/lazy_instance.h"
#include "chromecast/net/network_change_notifier_cast.h"
namespace chromecast {
namespace {
base::LazyInstance<NetworkChangeNotifierCast> g_network_change_notifier_cast =
LAZY_INSTANCE_INITIALIZER;
} // namespace
net::NetworkChangeNotifier* NetworkChangeNotifierFactoryCast::CreateInstance() {
return g_network_change_notifier_cast.Pointer();
// Caller assumes ownership.
return new NetworkChangeNotifierCast();
}
NetworkChangeNotifierFactoryCast::~NetworkChangeNotifierFactoryCast() {
}
// static
NetworkChangeNotifierCast* NetworkChangeNotifierFactoryCast::GetInstance() {
return g_network_change_notifier_cast.Pointer();
}
} // namespace chromecast
......@@ -52,6 +52,10 @@ CastBrowserContext::CastBrowserContext(
}
CastBrowserContext::~CastBrowserContext() {
content::BrowserThread::DeleteSoon(
content::BrowserThread::IO,
FROM_HERE,
resource_context_.release());
}
void CastBrowserContext::InitWhileIOAllowed() {
......
......@@ -56,6 +56,7 @@ CastBrowserMainParts::CastBrowserMainParts(
URLRequestContextFactory* url_request_context_factory)
: BrowserMainParts(),
cast_browser_process_(new CastBrowserProcess()),
parameters_(parameters),
url_request_context_factory_(url_request_context_factory) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
AddDefaultCommandLineSwitches(command_line);
......@@ -104,7 +105,13 @@ void CastBrowserMainParts::PreMainMessageLoopRun() {
}
bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) {
base::MessageLoopForUI::current()->Run();
// If parameters_.ui_task is not NULL, we are running browser tests. In this
// case, the browser's main message loop will not run.
if (parameters_.ui_task) {
parameters_.ui_task->Run();
} else {
base::MessageLoopForUI::current()->Run();
}
return true;
}
......
......@@ -9,10 +9,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_main_parts.h"
namespace content {
struct MainFunctionParams;
}
#include "content/public/common/main_function_params.h"
namespace chromecast {
namespace shell {
......@@ -36,7 +33,7 @@ class CastBrowserMainParts : public content::BrowserMainParts {
private:
scoped_ptr<CastBrowserProcess> cast_browser_process_;
const content::MainFunctionParams parameters_; // For running browser tests.
URLRequestContextFactory* const url_request_context_factory_;
DISALLOW_COPY_AND_ASSIGN(CastBrowserMainParts);
......
......@@ -14,6 +14,7 @@
#include "chromecast/shell/browser/cast_browser_process.h"
#include "chromecast/shell/browser/geolocation/cast_access_token_store.h"
#include "chromecast/shell/browser/url_request_context_factory.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/certificate_request_result_type.h"
#include "content/public/browser/file_descriptor_info.h"
#include "content/public/browser/render_process_host.h"
......@@ -30,6 +31,10 @@ CastContentBrowserClient::CastContentBrowserClient()
}
CastContentBrowserClient::~CastContentBrowserClient() {
content::BrowserThread::DeleteSoon(
content::BrowserThread::IO,
FROM_HERE,
url_request_context_factory_.release());
}
content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts(
......
include_rules = [
"+content/public/test",
]
# content/public/test OWNERS for review of Chromecast browser test code
jcivelli@chromium.org
phajdan.jr@chromium.org
sky@chromium.org
// Copyright 2014 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 "chromecast/shell/browser/test/chromecast_browser_test.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "chromecast/shell/browser/cast_browser_context.h"
#include "chromecast/shell/browser/cast_browser_process.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
namespace chromecast {
namespace shell {
ChromecastBrowserTest::ChromecastBrowserTest()
: setup_called_(false) {
}
ChromecastBrowserTest::~ChromecastBrowserTest() {
CHECK(setup_called_) << "Overridden SetUp() did not call parent "
<< "implementation, so test not run.";
}
void ChromecastBrowserTest::SetUp() {
SetUpCommandLine(CommandLine::ForCurrentProcess());
setup_called_ = true;
BrowserTestBase::SetUp();
}
void ChromecastBrowserTest::RunTestOnMainThreadLoop() {
// Pump startup related events.
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
base::RunLoop().RunUntilIdle();
SetUpOnMainThread();
RunTestOnMainThread();
TearDownOnMainThread();
for (content::RenderProcessHost::iterator i(
content::RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) {
i.GetCurrentValue()->FastShutdownIfPossible();
}
web_contents_.reset();
}
void ChromecastBrowserTest::NavigateToURL(content::WebContents* window,
const GURL& url) {
content::WaitForLoadStop(window);
content::TestNavigationObserver same_tab_observer(window, 1);
content::NavigationController::LoadURLParams params(url);
params.transition_type = content::PageTransitionFromInt(
content::PAGE_TRANSITION_TYPED |
content::PAGE_TRANSITION_FROM_ADDRESS_BAR);
window->GetController().LoadURLWithParams(params);
same_tab_observer.Wait();
}
content::WebContents* ChromecastBrowserTest::CreateBrowser() {
content::WebContents::CreateParams create_params(
CastBrowserProcess::GetInstance()->browser_context(),
NULL);
create_params.routing_id = MSG_ROUTING_NONE;
create_params.initial_size = gfx::Size(1280, 720);
web_contents_.reset(content::WebContents::Create(create_params));
return web_contents_.get();
}
} // namespace shell
} // namespace chromecast
// Copyright 2014 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.
#ifndef CHROMECAST_SHELL_BROWSER_TEST_CHROMECAST_BROWSER_TEST_H_
#define CHROMECAST_SHELL_BROWSER_TEST_CHROMECAST_BROWSER_TEST_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_base.h"
namespace content {
class WebContents;
}
namespace chromecast {
namespace shell {
// This test allows for running an entire browser-process lifecycle per unit
// test, using Chromecast's cast_shell. This starts up the shell, runs a test
// case, then shuts down the entire shell.
// Note that this process takes 7-10 seconds per test case on Chromecast, so
// fewer test cases with more assertions are preferable.
class ChromecastBrowserTest : public content::BrowserTestBase {
protected:
ChromecastBrowserTest();
virtual ~ChromecastBrowserTest();
// testing::Test implementation:
virtual void SetUp() OVERRIDE;
// BrowserTestBase implementation:
virtual void RunTestOnMainThreadLoop() OVERRIDE;
protected:
void NavigateToURL(content::WebContents* window, const GURL& gurl);
// Creates a new window and loads about:blank.
content::WebContents* CreateBrowser();
// Returns the window for the test.
content::WebContents* web_contents() const { return web_contents_.get(); }
private:
scoped_ptr<content::WebContents> web_contents_;
bool setup_called_;
DISALLOW_COPY_AND_ASSIGN(ChromecastBrowserTest);
};
} // namespace shell
} // namespace chromecast
#endif // CHROMECAST_SHELL_BROWSER_TEST_CHROMECAST_BROWSER_TEST_H_
// Copyright 2014 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 "base/command_line.h"
#include "base/macros.h"
#include "base/sys_info.h"
#include "chromecast/shell/app/cast_main_delegate.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/content_test_suite_base.h"
#include "content/public/test/test_launcher.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromecast {
namespace shell {
namespace {
const char kTestTypeBrowser[] = "browser";
class BrowserTestSuite : public content::ContentTestSuiteBase {
public:
BrowserTestSuite(int argc, char** argv)
: content::ContentTestSuiteBase(argc, argv) {
}
virtual ~BrowserTestSuite() {
}
private:
DISALLOW_COPY_AND_ASSIGN(BrowserTestSuite);
};
class ChromecastTestLauncherDelegate : public content::TestLauncherDelegate {
public:
ChromecastTestLauncherDelegate() {}
virtual ~ChromecastTestLauncherDelegate() {}
virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
return BrowserTestSuite(argc, argv).Run();
}
virtual bool AdjustChildProcessCommandLine(
base::CommandLine* command_line,
const base::FilePath& temp_data_dir) OVERRIDE {
// TODO(gunsch): handle temp_data_dir
command_line->AppendSwitchASCII(switches::kTestType, kTestTypeBrowser);
return true;
}
protected:
virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
return new CastMainDelegate();
}
private:
DISALLOW_COPY_AND_ASSIGN(ChromecastTestLauncherDelegate);
};
} // namespace
} // namespace shell
} // namespace chromecast
int main(int argc, char** argv) {
int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
chromecast::shell::ChromecastTestLauncherDelegate launcher_delegate;
return LaunchTests(&launcher_delegate, default_jobs, argc, argv);
}
// Copyright 2014 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 "base/macros.h"
#include "chromecast/shell/browser/test/chromecast_browser_test.h"
#include "url/gurl.h"
#include "url/url_constants.h"
namespace chromecast {
namespace shell {
class ChromecastShellBrowserTest : public ChromecastBrowserTest {
public:
ChromecastShellBrowserTest() : url_(url::kAboutBlankURL) {}
virtual void SetUpOnMainThread() OVERRIDE {
CreateBrowser();
NavigateToURL(web_contents(), url_);
}
private:
const GURL url_;
DISALLOW_COPY_AND_ASSIGN(ChromecastShellBrowserTest);
};
IN_PROC_BROWSER_TEST_F(ChromecastShellBrowserTest, EmptyTest) {
// Run an entire browser lifecycle to ensure nothing breaks.
// TODO(gunsch): Remove this test case once there are actual assertions to
// test in a ChromecastBrowserTest instance.
EXPECT_TRUE(true);
}
} // namespace shell
} // namespace chromecast
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment