diff options
author | oshima <oshima@chromium.org> | 2014-11-07 14:17:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-07 22:17:34 +0000 |
commit | 153fc11c88cc94409b1ef8f08a175e0931b35c07 (patch) | |
tree | 496c5f4b9c41d6f88132c367fd84b73bf4a7ed6a /athena | |
parent | 0510d2d5ee3c9a9153741cdf53061932e4f0bedf (diff) | |
download | chromium_src-153fc11c88cc94409b1ef8f08a175e0931b35c07.zip chromium_src-153fc11c88cc94409b1ef8f08a175e0931b35c07.tar.gz chromium_src-153fc11c88cc94409b1ef8f08a175e0931b35c07.tar.bz2 |
Add AthenaBrowserTest framework
This allow us to run tests that depends on content/extensions without chrome/.
* extract AthenaMainDelegate from athena_main.cc to use it in browser tests.
* renamed existing AthenaBrowserTest for chrome to AthenaChromeBrowserTset
* Renamed athena_xxx_brosertest.{h|cc} to xxx_browser_test.{h|cc} to match the patter used for other base test class for browser tests.
BUG=None
TBR=davidben@chromium.org, jamescook@chromium.org
Review URL: https://codereview.chromium.org/689163003
Cr-Commit-Position: refs/heads/master@{#303307}
Diffstat (limited to 'athena')
24 files changed, 496 insertions, 260 deletions
diff --git a/athena/athena.gyp b/athena/athena.gyp index e4e1455..b5ffcf6 100644 --- a/athena/athena.gyp +++ b/athena/athena.gyp @@ -282,11 +282,49 @@ 'test/base/test_resource_manager_delegate.cc', 'test/base/test_windows.cc', 'test/base/test_windows.h', + 'test/base/test_util.cc', + 'test/base/test_util.h', 'wm/test/window_manager_impl_test_api.cc', 'wm/test/window_manager_impl_test_api.h', ], }, { + 'target_name': 'athena_browsertest_support', + 'type': 'static_library', + 'dependencies': [ + '../testing/gtest.gyp:gtest', + 'athena_test_support', + 'main/athena_main.gyp:athena_main_lib', + 'resources/athena_resources.gyp:athena_pak', + ], + 'sources': [ + 'test/base/activity_lifetime_tracker.h', + 'test/base/activity_lifetime_tracker.cc', + 'test/base/athena_browser_test.h', + 'test/base/athena_browser_test.cc', + 'test/base/athena_browser_test.h', + 'test/base/athena_test_launcher_delegate.cc', + 'test/base/athena_test_launcher_delegate.h', + ], + }, + { + 'target_name': 'athena_browsertests', + 'type': 'executable', + 'dependencies': [ + '../testing/gtest.gyp:gtest', + '../skia/skia.gyp:skia', + 'athena_browsertest_support', + 'athena_app_shell_lib', + 'athena_lib', + ], + 'defines': [ + 'HAS_OUT_OF_PROC_TEST_RUNNER', + ], + 'sources': [ + 'test/base/athena_browser_test_main.cc', + ], + }, + { 'target_name': 'athena_unittests', 'type': 'executable', 'dependencies': [ diff --git a/athena/content/app_activity_browsertest.cc b/athena/content/app_activity_browsertest.cc index 17cc893..2c954ef 100644 --- a/athena/content/app_activity_browsertest.cc +++ b/athena/content/app_activity_browsertest.cc @@ -5,8 +5,8 @@ #include "athena/activity/public/activity.h" #include "athena/resource_manager/public/resource_manager.h" #include "athena/test/base/activity_lifetime_tracker.h" -#include "athena/test/chrome/athena_app_browsertest.h" -#include "athena/test/chrome/test_util.h" +#include "athena/test/base/test_util.h" +#include "athena/test/chrome/athena_app_browser_test.h" #include "athena/wm/public/window_list_provider.h" #include "athena/wm/public/window_manager.h" #include "base/strings/utf_string_conversions.h" @@ -72,9 +72,7 @@ class AppActivityBrowserTest : public AthenaAppBrowserTest { // Then a web activity (which will then be in front of the app). *web_activity = test_util::CreateTestWebActivity( - test_util::GetBrowserContext(), - base::UTF8ToUTF16("App1"), - GURL(kTestUrl)); + GetBrowserContext(), base::UTF8ToUTF16("App1"), GURL(kTestUrl)); ASSERT_TRUE(*web_activity); EXPECT_EQ(*web_activity, tracker_->GetNewActivityAndReset()); EXPECT_EQ(nullptr, tracker_->GetDeletedActivityAndReset()); @@ -124,10 +122,8 @@ IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, StartApplication) { // Test that creating an application (without a particular activity order // location) should activate it initially. IN_PROC_BROWSER_TEST_F(AppActivityBrowserTest, CreatedAppGetsFocus) { - Activity* web_activity = - test_util::CreateTestWebActivity(test_util::GetBrowserContext(), - base::UTF8ToUTF16("App1"), - GURL(kTestUrl)); + Activity* web_activity = test_util::CreateTestWebActivity( + GetBrowserContext(), base::UTF8ToUTF16("App1"), GURL(kTestUrl)); EXPECT_TRUE(IsActivityActive(web_activity)); Activity* app_activity = CreateTestAppActivity(GetTestAppID()); diff --git a/athena/content/chrome/web_activity_browsertest.cc b/athena/content/chrome/web_activity_browsertest.cc index 42f6d13..aabe449 100644 --- a/athena/content/chrome/web_activity_browsertest.cc +++ b/athena/content/chrome/web_activity_browsertest.cc @@ -4,8 +4,8 @@ #include "athena/activity/public/activity.h" #include "athena/resource_manager/public/resource_manager.h" -#include "athena/test/chrome/athena_browsertest.h" -#include "athena/test/chrome/test_util.h" +#include "athena/test/base/test_util.h" +#include "athena/test/chrome/athena_chrome_browser_test.h" #include "athena/wm/public/window_list_provider.h" #include "athena/wm/public/window_manager.h" #include "base/strings/utf_string_conversions.h" @@ -21,16 +21,14 @@ namespace { const char kTestUrl[] = "chrome:about"; } -typedef AthenaBrowserTest WebActivityBrowserTest; +typedef AthenaChromeBrowserTest WebActivityBrowserTest; // A simple test to create web content. IN_PROC_BROWSER_TEST_F(WebActivityBrowserTest, SimpleCreate) { const GURL target_url(kTestUrl); // Create an activity, wait until it is loaded and check that it was created. Activity* activity = test_util::CreateTestWebActivity( - test_util::GetBrowserContext(), - base::UTF8ToUTF16("App"), - target_url); + GetBrowserContext(), base::UTF8ToUTF16("App"), target_url); ASSERT_TRUE(activity); EXPECT_NE(Activity::ACTIVITY_UNLOADED, activity->GetCurrentState()); // The activity manager should take care of destroying the activity upon @@ -47,16 +45,12 @@ IN_PROC_BROWSER_TEST_F(WebActivityBrowserTest, LoadUnloadReload) { // Create an activity (and wait until it is loaded). // The size of its overview image should be empty since it is visible. Activity* activity2 = test_util::CreateTestWebActivity( - test_util::GetBrowserContext(), - base::UTF8ToUTF16("App2"), - target_url); + GetBrowserContext(), base::UTF8ToUTF16("App2"), target_url); EXPECT_TRUE(activity2); EXPECT_EQ(list[0], activity2->GetWindow()); EXPECT_NE(Activity::ACTIVITY_UNLOADED, activity2->GetCurrentState()); Activity* activity1 = test_util::CreateTestWebActivity( - test_util::GetBrowserContext(), - base::UTF8ToUTF16("App1"), - target_url); + GetBrowserContext(), base::UTF8ToUTF16("App1"), target_url); EXPECT_TRUE(activity1); // |activity2| should now be the second activity. Both activities should have diff --git a/athena/content/chrome/web_activity_helpers_browsertest.cc b/athena/content/chrome/web_activity_helpers_browsertest.cc index 4dd8bee..9dfdb01 100644 --- a/athena/content/chrome/web_activity_helpers_browsertest.cc +++ b/athena/content/chrome/web_activity_helpers_browsertest.cc @@ -3,8 +3,8 @@ // found in the LICENSE file. #include "athena/activity/public/activity.h" -#include "athena/test/chrome/athena_browsertest.h" -#include "athena/test/chrome/test_util.h" +#include "athena/test/base/test_util.h" +#include "athena/test/chrome/athena_chrome_browser_test.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/extensions/tab_helper.h" #include "content/public/browser/notification_observer.h" @@ -58,7 +58,7 @@ class HelpersCreatedChecker : public content::NotificationObserver { DISALLOW_COPY_AND_ASSIGN(HelpersCreatedChecker); }; -typedef AthenaBrowserTest WebActivityHelpersBrowserTest; +typedef AthenaChromeBrowserTest WebActivityHelpersBrowserTest; // Test that the WebActivity helpers are attached to the web contents prior to // the RenderView view being created. This is important because some of the @@ -70,10 +70,8 @@ IN_PROC_BROWSER_TEST_F(WebActivityHelpersBrowserTest, CreationTime) { HelpersCreatedChecker checker; GURL url("http://www.google.com"); - athena::Activity* activity = - test_util::CreateTestWebActivity(test_util::GetBrowserContext(), - base::UTF8ToUTF16("App"), - url); + athena::Activity* activity = test_util::CreateTestWebActivity( + GetBrowserContext(), base::UTF8ToUTF16("App"), url); content::WebContents* web_contents1 = activity->GetWebContents(); EXPECT_NE(Activity::ACTIVITY_UNLOADED, activity->GetCurrentState()); EXPECT_TRUE(web_contents1->GetRenderViewHost()->IsRenderViewLive()); diff --git a/athena/content/content_proxy_browsertest.cc b/athena/content/content_proxy_browsertest.cc index c962837..f48eed5 100644 --- a/athena/content/content_proxy_browsertest.cc +++ b/athena/content/content_proxy_browsertest.cc @@ -5,8 +5,8 @@ #include "athena/activity/public/activity.h" #include "athena/activity/public/activity_view_model.h" #include "athena/resource_manager/public/resource_manager.h" -#include "athena/test/chrome/athena_browsertest.h" -#include "athena/test/chrome/test_util.h" +#include "athena/test/base/test_util.h" +#include "athena/test/chrome/athena_chrome_browser_test.h" #include "base/command_line.h" #include "base/strings/utf_string_conversions.h" #include "ui/compositor/compositor_switches.h" @@ -22,7 +22,7 @@ const char kTestUrl[] = "chrome:about"; } // Need to override the test class to make the test always draw its content. -class ContentProxyBrowserTest : public AthenaBrowserTest { +class ContentProxyBrowserTest : public AthenaChromeBrowserTest { public: ContentProxyBrowserTest() {} ~ContentProxyBrowserTest() override {} @@ -31,7 +31,7 @@ class ContentProxyBrowserTest : public AthenaBrowserTest { void SetUpCommandLine(base::CommandLine* command_line) override { // Make sure that we draw the output - it's required for this test. command_line->AppendSwitch(switches::kEnablePixelOutputInTests); - AthenaBrowserTest::SetUpCommandLine(command_line); + AthenaChromeBrowserTest::SetUpCommandLine(command_line); } private: @@ -42,7 +42,7 @@ IN_PROC_BROWSER_TEST_F(ContentProxyBrowserTest, CreateContent) { const int kTimeoutMS = 12000; // The timeout: 2 seconds. const int kIterationSleepMS = 5; // The wait time in ms per iteration. const GURL gurl(kTestUrl); - content::BrowserContext* context = test_util::GetBrowserContext(); + content::BrowserContext* context = GetBrowserContext(); // Create an activity (and wait until it is loaded). // The size of its overview image should be empty since it is visible. Activity* activity1 = diff --git a/athena/main/DEPS b/athena/main/DEPS index d0ff633..2724d27 100644 --- a/athena/main/DEPS +++ b/athena/main/DEPS @@ -31,7 +31,7 @@ include_rules = [ ] specific_include_rules = { - "athena_main\.cc": [ + "athena_main_delegate.*": [ "+content/public/app", "+extensions/browser/app_window", "+extensions/shell/app", diff --git a/athena/main/athena_frame_view.h b/athena/main/athena_frame_view.h index c385ed9..b3829a8 100644 --- a/athena/main/athena_frame_view.h +++ b/athena/main/athena_frame_view.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ATHENA_COMMON_ATHENA_FRAME_VIEW_H_ -#define ATHENA_COMMON_ATHENA_FRAME_VIEW_H_ +#ifndef ATHENA_MAIN_ATHENA_FRAME_VIEW_H_ +#define ATHENA_MAIN_ATHENA_FRAME_VIEW_H_ #include "ui/views/window/non_client_view.h" @@ -54,4 +54,4 @@ class AthenaFrameView : public views::NonClientFrameView { } // namespace athena -#endif // ATHENA_COMMON_ATHENA_FRAME_VIEW_H_ +#endif // ATHENA_MAIN_ATHENA_FRAME_VIEW_H_ diff --git a/athena/main/athena_main.cc b/athena/main/athena_main.cc index 98fe171..1eab128 100644 --- a/athena/main/athena_main.cc +++ b/athena/main/athena_main.cc @@ -2,196 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "athena/activity/public/activity_factory.h" -#include "athena/activity/public/activity_manager.h" -#include "athena/content/public/web_contents_view_delegate_creator.h" -#include "athena/env/public/athena_env.h" -#include "athena/extensions/public/extensions_delegate.h" -#include "athena/main/athena_content_client.h" -#include "athena/main/athena_renderer_pdf_helper.h" -#include "athena/main/public/athena_launcher.h" -#include "athena/screen/public/screen_manager.h" -#include "base/command_line.h" -#include "base/files/file_util.h" -#include "base/path_service.h" -#include "components/pdf/renderer/ppb_pdf_impl.h" +#include "athena/main/athena_main_delegate.h" #include "content/public/app/content_main.h" -#include "content/public/browser/browser_thread.h" -#include "extensions/browser/app_window/app_window.h" -#include "extensions/browser/app_window/app_window_client.h" -#include "extensions/shell/app/shell_main_delegate.h" -#include "extensions/shell/browser/desktop_controller.h" -#include "extensions/shell/browser/shell_app_delegate.h" -#include "extensions/shell/browser/shell_browser_main_delegate.h" -#include "extensions/shell/browser/shell_content_browser_client.h" -#include "extensions/shell/browser/shell_extension_system.h" -#include "extensions/shell/browser/shell_native_app_window.h" -#include "extensions/shell/common/shell_content_client.h" -#include "extensions/shell/common/switches.h" -#include "extensions/shell/renderer/shell_content_renderer_client.h" -#include "ppapi/c/private/ppb_pdf.h" -#include "ui/aura/window_tree_host.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/wm/core/visibility_controller.h" - -namespace { - -// We want to load the sample calculator app by default, for a while. Expecting -// to run athena_main at src/ -const char kDefaultAppPath[] = - "chrome/common/extensions/docs/examples/apps/calculator/app"; - -} // namespace - -class AthenaDesktopController : public extensions::DesktopController { - public: - AthenaDesktopController() {} - ~AthenaDesktopController() override {} - - private: - // extensions::DesktopController: - virtual aura::WindowTreeHost* GetHost() override { - return athena::AthenaEnv::Get()->GetHost(); - } - - // Creates a new app window and adds it to the desktop. The desktop maintains - // ownership of the window. - // TODO(jamescook|oshima): Is this function needed? - virtual extensions::AppWindow* CreateAppWindow( - content::BrowserContext* context, - const extensions::Extension* extension) override { - NOTIMPLEMENTED(); - return nullptr; - } - - // Adds the window to the desktop. - virtual void AddAppWindow(aura::Window* window) override { - NOTIMPLEMENTED(); - } - - virtual void RemoveAppWindow(extensions::AppWindow* window) override {} - - // Closes and destroys the app windows. - virtual void CloseAppWindows() override {} - - DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController); -}; - -class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate { - public: - AthenaBrowserMainDelegate() {} - ~AthenaBrowserMainDelegate() override {} - - // extensions::ShellBrowserMainDelegate: - virtual void Start(content::BrowserContext* context) override { - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - - base::FilePath app_dir = base::FilePath::FromUTF8Unsafe( - command_line->HasSwitch(extensions::switches::kAppShellAppPath) - ? command_line->GetSwitchValueNative( - extensions::switches::kAppShellAppPath) - : kDefaultAppPath); - - base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir); - if (base::DirectoryExists(app_absolute_dir)) { - extensions::ShellExtensionSystem* extension_system = - static_cast<extensions::ShellExtensionSystem*>( - extensions::ExtensionSystem::Get(context)); - extension_system->LoadApp(app_absolute_dir); - } - - athena::StartAthenaEnv(content::BrowserThread::GetBlockingPool()-> - GetTaskRunnerWithShutdownBehavior( - base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); - athena::CreateVirtualKeyboardWithContext(context); - athena::StartAthenaSessionWithContext(context); - } - - virtual void Shutdown() override { - athena::AthenaEnv::Get()->OnTerminating(); - athena::ShutdownAthena(); - } - - virtual extensions::DesktopController* CreateDesktopController() override { - return new AthenaDesktopController(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); -}; - -class AthenaContentBrowserClient - : public extensions::ShellContentBrowserClient { - public: - AthenaContentBrowserClient() - : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) { - } - ~AthenaContentBrowserClient() override {} - - // content::ContentBrowserClient: - virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( - content::WebContents* web_contents) override { - return athena::CreateWebContentsViewDelegate(web_contents); - } - - private: - DISALLOW_COPY_AND_ASSIGN(AthenaContentBrowserClient); -}; - -class AthenaContentRendererClient - : public extensions::ShellContentRendererClient { - public: - AthenaContentRendererClient() {} - ~AthenaContentRendererClient() override {} - - // content::ContentRendererClient: - virtual void RenderFrameCreated(content::RenderFrame* render_frame) override { - new athena::AthenaRendererPDFHelper(render_frame); - extensions::ShellContentRendererClient::RenderFrameCreated(render_frame); - } - - virtual const void* CreatePPAPIInterface( - const std::string& interface_name) override { - if (interface_name == PPB_PDF_INTERFACE) - return pdf::PPB_PDF_Impl::GetInterface(); - return extensions::ShellContentRendererClient::CreatePPAPIInterface( - interface_name); - } -}; - -class AthenaMainDelegate : public extensions::ShellMainDelegate { - public: - AthenaMainDelegate() {} - ~AthenaMainDelegate() override {} - - private: - // extensions::ShellMainDelegate: - virtual content::ContentClient* CreateContentClient() override { - return new athena::AthenaContentClient(); - } - virtual content::ContentBrowserClient* CreateShellContentBrowserClient() - override { - return new AthenaContentBrowserClient(); - } - - virtual content::ContentRendererClient* CreateShellContentRendererClient() - override { - return new AthenaContentRendererClient(); - } - - virtual void InitializeResourceBundle() override { - base::FilePath pak_dir; - PathService::Get(base::DIR_MODULE, &pak_dir); - base::FilePath pak_file = - pak_dir.Append(FILE_PATH_LITERAL("athena_resources.pak")); - ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); - } - - DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate); -}; int main(int argc, const char** argv) { - AthenaMainDelegate delegate; + athena::AthenaMainDelegate delegate; content::ContentMainParams params(&delegate); params.argc = argc; diff --git a/athena/main/athena_main.gyp b/athena/main/athena_main.gyp index c829ad6..a14df37 100644 --- a/athena/main/athena_main.gyp +++ b/athena/main/athena_main.gyp @@ -39,6 +39,8 @@ 'athena_frame_view.cc', 'athena_frame_view.h', 'athena_launcher.cc', + 'athena_main_delegate.cc', + 'athena_main_delegate.h', 'athena_renderer_pdf_helper.cc', 'athena_renderer_pdf_helper.h', 'athena_views_delegate.cc', diff --git a/athena/main/athena_main_delegate.cc b/athena/main/athena_main_delegate.cc new file mode 100644 index 0000000..59c6c42 --- /dev/null +++ b/athena/main/athena_main_delegate.cc @@ -0,0 +1,175 @@ +// 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 "athena/main/athena_main_delegate.h" + +#include "athena/content/public/web_contents_view_delegate_creator.h" +#include "athena/env/public/athena_env.h" +#include "athena/main/athena_content_client.h" +#include "athena/main/athena_renderer_pdf_helper.h" +#include "athena/main/public/athena_launcher.h" +#include "base/command_line.h" +#include "base/files/file_util.h" +#include "base/path_service.h" +#include "components/pdf/renderer/ppb_pdf_impl.h" +#include "content/public/app/content_main.h" +#include "content/public/browser/browser_thread.h" +#include "extensions/shell/browser/desktop_controller.h" +#include "extensions/shell/browser/shell_browser_main_delegate.h" +#include "extensions/shell/browser/shell_content_browser_client.h" +#include "extensions/shell/browser/shell_extension_system.h" +#include "extensions/shell/common/shell_content_client.h" +#include "extensions/shell/common/switches.h" +#include "extensions/shell/renderer/shell_content_renderer_client.h" +#include "ppapi/c/private/ppb_pdf.h" +#include "ui/base/resource/resource_bundle.h" + +namespace athena { +namespace { + +// We want to load the sample calculator app by default, for a while. Expecting +// to run athena_main at src/ +const char kDefaultAppPath[] = + "chrome/common/extensions/docs/examples/apps/calculator/app"; + +class AthenaDesktopController : public extensions::DesktopController { + public: + AthenaDesktopController() {} + ~AthenaDesktopController() override {} + + private: + // extensions::DesktopController: + virtual aura::WindowTreeHost* GetHost() override { + return athena::AthenaEnv::Get()->GetHost(); + } + + // Creates a new app window and adds it to the desktop. The desktop maintains + // ownership of the window. + // TODO(jamescook|oshima): Is this function needed? + virtual extensions::AppWindow* CreateAppWindow( + content::BrowserContext* context, + const extensions::Extension* extension) override { + NOTIMPLEMENTED(); + return nullptr; + } + + // Adds the window to the desktop. + virtual void AddAppWindow(aura::Window* window) override { NOTIMPLEMENTED(); } + + virtual void RemoveAppWindow(extensions::AppWindow* window) override {} + + // Closes and destroys the app windows. + virtual void CloseAppWindows() override {} + + DISALLOW_COPY_AND_ASSIGN(AthenaDesktopController); +}; + +class AthenaBrowserMainDelegate : public extensions::ShellBrowserMainDelegate { + public: + AthenaBrowserMainDelegate() {} + ~AthenaBrowserMainDelegate() override {} + + // extensions::ShellBrowserMainDelegate: + virtual void Start(content::BrowserContext* context) override { + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + + base::FilePath app_dir = base::FilePath::FromUTF8Unsafe( + command_line->HasSwitch(extensions::switches::kAppShellAppPath) + ? command_line->GetSwitchValueNative( + extensions::switches::kAppShellAppPath) + : kDefaultAppPath); + + base::FilePath app_absolute_dir = base::MakeAbsoluteFilePath(app_dir); + if (base::DirectoryExists(app_absolute_dir)) { + extensions::ShellExtensionSystem* extension_system = + static_cast<extensions::ShellExtensionSystem*>( + extensions::ExtensionSystem::Get(context)); + extension_system->LoadApp(app_absolute_dir); + } + + athena::StartAthenaEnv( + content::BrowserThread::GetBlockingPool() + ->GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); + athena::CreateVirtualKeyboardWithContext(context); + athena::StartAthenaSessionWithContext(context); + } + + virtual void Shutdown() override { + athena::AthenaEnv::Get()->OnTerminating(); + athena::ShutdownAthena(); + } + + virtual extensions::DesktopController* CreateDesktopController() override { + return new AthenaDesktopController(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(AthenaBrowserMainDelegate); +}; + +class AthenaContentBrowserClient + : public extensions::ShellContentBrowserClient { + public: + AthenaContentBrowserClient() + : extensions::ShellContentBrowserClient(new AthenaBrowserMainDelegate()) { + } + ~AthenaContentBrowserClient() override {} + + // content::ContentBrowserClient: + virtual content::WebContentsViewDelegate* GetWebContentsViewDelegate( + content::WebContents* web_contents) override { + return athena::CreateWebContentsViewDelegate(web_contents); + } + + private: + DISALLOW_COPY_AND_ASSIGN(AthenaContentBrowserClient); +}; + +class AthenaContentRendererClient + : public extensions::ShellContentRendererClient { + public: + AthenaContentRendererClient() {} + ~AthenaContentRendererClient() override {} + + // content::ContentRendererClient: + virtual void RenderFrameCreated(content::RenderFrame* render_frame) override { + new athena::AthenaRendererPDFHelper(render_frame); + extensions::ShellContentRendererClient::RenderFrameCreated(render_frame); + } + + virtual const void* CreatePPAPIInterface( + const std::string& interface_name) override { + if (interface_name == PPB_PDF_INTERFACE) + return pdf::PPB_PDF_Impl::GetInterface(); + return extensions::ShellContentRendererClient::CreatePPAPIInterface( + interface_name); + } +}; + +} // namespace + +content::ContentClient* AthenaMainDelegate::CreateContentClient() { + return new athena::AthenaContentClient(); +} + +content::ContentBrowserClient* +AthenaMainDelegate::CreateShellContentBrowserClient() { + return new AthenaContentBrowserClient(); +} + +content::ContentRendererClient* +AthenaMainDelegate::CreateShellContentRendererClient() { + return new AthenaContentRendererClient(); +} + +void AthenaMainDelegate::InitializeResourceBundle() { + base::FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + base::FilePath pak_file = + pak_dir.Append(FILE_PATH_LITERAL("athena_resources.pak")); + ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); +} + +} // namespace athena diff --git a/athena/main/athena_main_delegate.h b/athena/main/athena_main_delegate.h new file mode 100644 index 0000000..14ce081 --- /dev/null +++ b/athena/main/athena_main_delegate.h @@ -0,0 +1,29 @@ +// 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 ATHENA_MAIN_ATHENA_MAIN_DELEGATE_H_ +#define ATHENA_MAIN_ATHENA_MAIN_DELEGATE_H_ + +#include "extensions/shell/app/shell_main_delegate.h" + +namespace athena { + +class AthenaMainDelegate : public extensions::ShellMainDelegate { + public: + AthenaMainDelegate() {} + ~AthenaMainDelegate() override {} + + private: + // extensions::ShellMainDelegate: + content::ContentClient* CreateContentClient() override; + content::ContentBrowserClient* CreateShellContentBrowserClient() override; + content::ContentRendererClient* CreateShellContentRendererClient() override; + void InitializeResourceBundle() override; + + DISALLOW_COPY_AND_ASSIGN(AthenaMainDelegate); +}; + +} // namespace + +#endif // ATHENA_MAIN_ATHENA_MAIN_DELEGATE_H_ diff --git a/athena/test/base/DEPS b/athena/test/base/DEPS new file mode 100644 index 0000000..abfd99b --- /dev/null +++ b/athena/test/base/DEPS @@ -0,0 +1,6 @@ +include_rules = [ + "+athena/main", + "+content/public", + "+extensions/browser", + "+extensions/shell", +] diff --git a/athena/test/base/athena_browser_test.cc b/athena/test/base/athena_browser_test.cc new file mode 100644 index 0000000..1348647 --- /dev/null +++ b/athena/test/base/athena_browser_test.cc @@ -0,0 +1,61 @@ +// 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 "athena/test/base/athena_browser_test.h" + +#include "athena/activity/public/activity_manager.h" +#include "athena/content/public/web_contents_view_delegate_creator.h" +#include "athena/env/public/athena_env.h" +#include "athena/main/athena_content_client.h" +#include "athena/main/athena_renderer_pdf_helper.h" +#include "athena/main/public/athena_launcher.h" +#include "athena/test/base/test_util.h" +#include "base/command_line.h" +#include "base/logging.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/common/content_switches.h" +#include "extensions/shell/browser/shell_content_browser_client.h" + +namespace athena { +namespace test { + +AthenaBrowserTest::AthenaBrowserTest() { +} + +AthenaBrowserTest::~AthenaBrowserTest() { +} + +content::BrowserContext* AthenaBrowserTest::GetBrowserContext() { + return extensions::ShellContentBrowserClient::Get()->GetBrowserContext(); +} + +void AthenaBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { + command_line->AppendSwitchASCII(switches::kTestType, "athena"); + // The NaCl sandbox won't work in our browser tests. + command_line->AppendSwitch(switches::kNoSandbox); + content::BrowserTestBase::SetUpCommandLine(command_line); +} + +void AthenaBrowserTest::SetUpOnMainThread() { + content::BrowserContext* context = GetBrowserContext(); + athena::StartAthenaEnv(content::BrowserThread::GetBlockingPool() + ->GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); + athena::CreateVirtualKeyboardWithContext(context); + athena::StartAthenaSessionWithContext(context); + + // Set the memory pressure to low and turning off undeterministic resource + // observer events. + test_util::SendTestMemoryPressureEvent(ResourceManager::MEMORY_PRESSURE_LOW); +} + +void AthenaBrowserTest::RunTestOnMainThreadLoop() { + base::MessageLoopForUI::current()->RunUntilIdle(); + SetUpOnMainThread(); + RunTestOnMainThread(); + TearDownOnMainThread(); +} + +} // namespace test +} // namespace athena diff --git a/athena/test/base/athena_browser_test.h b/athena/test/base/athena_browser_test.h new file mode 100644 index 0000000..4ed6d21 --- /dev/null +++ b/athena/test/base/athena_browser_test.h @@ -0,0 +1,45 @@ +// 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 ATHENA_TEST_BASE_ATHENA_BROWSER_TEST_H_ +#define ATHENA_TEST_BASE_ATHENA_BROWSER_TEST_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/public/test/browser_test.h" +#include "content/public/test/browser_test_base.h" + +namespace base { +class CommandLine; +} + +namespace content { +class BrowserContext; +} + +namespace athena { +namespace test { + +// Base class for athena browser tests. +class AthenaBrowserTest : public content::BrowserTestBase { + public: + AthenaBrowserTest(); + ~AthenaBrowserTest() override; + + protected: + // Returns the browser context used by the test. + content::BrowserContext* GetBrowserContext(); + + private: + // content::BrowserTestBase implementation. + void SetUpCommandLine(base::CommandLine* command_line) override; + void SetUpOnMainThread() override; + void RunTestOnMainThreadLoop() override; + + DISALLOW_COPY_AND_ASSIGN(AthenaBrowserTest); +}; + +} // namespace test +} // namespace athena + +#endif // ATHENA_TEST_BASE_ATHENA_BROWSER_TEST_H_ diff --git a/athena/test/base/athena_browser_test_main.cc b/athena/test/base/athena_browser_test_main.cc new file mode 100644 index 0000000..a6258fe --- /dev/null +++ b/athena/test/base/athena_browser_test_main.cc @@ -0,0 +1,15 @@ +// 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 <algorithm> + +#include "athena/test/base/athena_test_launcher_delegate.h" +#include "base/sys_info.h" +#include "testing/gtest/include/gtest/gtest.h" + +int main(int argc, char** argv) { + int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2); + athena::test::AthenaTestLauncherDelegate launcher_delegate; + return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv); +} diff --git a/athena/test/base/athena_test_launcher_delegate.cc b/athena/test/base/athena_test_launcher_delegate.cc new file mode 100644 index 0000000..0e800c9 --- /dev/null +++ b/athena/test/base/athena_test_launcher_delegate.cc @@ -0,0 +1,29 @@ +// 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 "athena/test/base/athena_test_launcher_delegate.h" + +#include "athena/main/athena_main_delegate.h" +#include "base/test/test_suite.h" + +namespace athena { +namespace test { + +int AthenaTestLauncherDelegate::RunTestSuite(int argc, char** argv) { + return base::TestSuite(argc, argv).Run(); +} + +bool AthenaTestLauncherDelegate::AdjustChildProcessCommandLine( + base::CommandLine* command_line, + const base::FilePath& temp_data_dir) { + return true; +} + +content::ContentMainDelegate* +AthenaTestLauncherDelegate::CreateContentMainDelegate() { + return new AthenaMainDelegate(); +} + +} // namespace test +} // namespace extensions diff --git a/athena/test/base/athena_test_launcher_delegate.h b/athena/test/base/athena_test_launcher_delegate.h new file mode 100644 index 0000000..c3d621f --- /dev/null +++ b/athena/test/base/athena_test_launcher_delegate.h @@ -0,0 +1,25 @@ +// 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 ATHENA_TEST_BASE_ATHENA_TEST_LAUNCHER_DELEGATE_H_ +#define ATHENA_TEST_BASE_ATHENA_TEST_LAUNCHER_DELEGATE_H_ + +#include "content/public/test/test_launcher.h" + +namespace athena { +namespace test { + +class AthenaTestLauncherDelegate : public content::TestLauncherDelegate { + public: + int RunTestSuite(int argc, char** argv) override; + bool AdjustChildProcessCommandLine( + base::CommandLine* command_line, + const base::FilePath& temp_data_dir) override; + content::ContentMainDelegate* CreateContentMainDelegate() override; +}; + +} // namespace test +} // namespace athena + +#endif // ATHENA_TEST_BASE_ATHENA_TEST_LAUNCHER_DELEGATE_H_ diff --git a/athena/test/chrome/test_util.cc b/athena/test/base/test_util.cc index c7af619..7e88e10 100644 --- a/athena/test/chrome/test_util.cc +++ b/athena/test/base/test_util.cc @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "athena/test/chrome/test_util.h" +#include "athena/test/base/test_util.h" #include "athena/activity/public/activity.h" #include "athena/activity/public/activity_factory.h" #include "athena/resource_manager/public/resource_manager.h" -#include "chrome/browser/profiles/profile_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/test/test_utils.h" #include "extensions/browser/notification_types.h" @@ -38,9 +37,5 @@ void WaitUntilIdle() { base::MessageLoopForUI::current()->RunUntilIdle(); } -content::BrowserContext* GetBrowserContext() { - return ProfileManager::GetActiveUserProfile(); -} - } // namespace test_util } // namespace athena diff --git a/athena/test/chrome/test_util.h b/athena/test/base/test_util.h index 067548a..1b2430f 100644 --- a/athena/test/chrome/test_util.h +++ b/athena/test/base/test_util.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ATHENA_TEST_CHROME_TEST_UTIL_H_ -#define ATHENA_TEST_CHROME_TEST_UTIL_H_ +#ifndef ATHENA_TEST_BASE_TEST_UTIL_H_ +#define ATHENA_TEST_BASE_TEST_UTIL_H_ #include "athena/resource_manager/public/resource_manager.h" #include "base/strings/string16.h" @@ -30,12 +30,8 @@ Activity* CreateTestWebActivity(content::BrowserContext* context, // Wait until the system is idle. void WaitUntilIdle(); -// Returns a |BrowserContext| which can be used by tests. -content::BrowserContext* GetBrowserContext(); - } // namespace test_util } // namespace athena -#endif // ATHENA_TEST_CHROME_TEST_UTIL_H_ - +#endif // ATHENA_TEST_BASE_TEST_UTIL_H_ diff --git a/athena/test/chrome/DEPS b/athena/test/chrome/DEPS index 3fd16ab..76f3b44 100644 --- a/athena/test/chrome/DEPS +++ b/athena/test/chrome/DEPS @@ -3,6 +3,4 @@ include_rules = [ "+chrome/browser/profiles", "+chrome/test/base", "+content/public", - "+extensions/browser", ] - diff --git a/athena/test/chrome/athena_app_browsertest.cc b/athena/test/chrome/athena_app_browser_test.cc index 5b2ddeb..4ade37a 100644 --- a/athena/test/chrome/athena_app_browsertest.cc +++ b/athena/test/chrome/athena_app_browser_test.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "athena/test/chrome/athena_app_browsertest.h" +#include "athena/test/chrome/athena_app_browser_test.h" #include "athena/extensions/public/extensions_delegate.h" #include "athena/test/base/activity_lifetime_tracker.h" -#include "athena/test/chrome/test_util.h" +#include "athena/test/base/test_util.h" +#include "chrome/browser/profiles/profile_manager.h" #include "content/public/browser/notification_service.h" #include "content/public/common/content_switches.h" #include "content/public/test/test_utils.h" @@ -34,7 +35,7 @@ Activity* AthenaAppBrowserTest::CreateTestAppActivity( content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, content::NotificationService::AllSources()); - ExtensionsDelegate::Get(test_util::GetBrowserContext())->LaunchApp(app_id); + ExtensionsDelegate::Get(GetBrowserContext())->LaunchApp(app_id); observer.Wait(); return tracker.GetNewActivityAndReset(); @@ -58,4 +59,8 @@ void AthenaAppBrowserTest::SetUpOnMainThread() { test_util::SendTestMemoryPressureEvent(ResourceManager::MEMORY_PRESSURE_LOW); } +content::BrowserContext* AthenaAppBrowserTest::GetBrowserContext() { + return ProfileManager::GetActiveUserProfile(); +} + } // namespace athena diff --git a/athena/test/chrome/athena_app_browsertest.h b/athena/test/chrome/athena_app_browser_test.h index 8aa9f27..87ae3c9 100644 --- a/athena/test/chrome/athena_app_browsertest.h +++ b/athena/test/chrome/athena_app_browser_test.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ATHENA_TEST_CHROME_ATHENA_APP_BROWSERTEST_H_ -#define ATHENA_TEST_CHROME_ATHENA_APP_BROWSERTEST_H_ +#ifndef ATHENA_TEST_CHROME_ATHENA_APP_BROWSER_TEST_H_ +#define ATHENA_TEST_CHROME_ATHENA_APP_BROWSER_TEST_H_ #include "chrome/browser/apps/app_browsertest_util.h" @@ -32,6 +32,9 @@ class AthenaAppBrowserTest : public extensions::PlatformAppBrowserTest { // BrowserTestBase: void SetUpOnMainThread() override; + // Returns the browser context used by the test. + content::BrowserContext* GetBrowserContext(); + private: // Our created app id - after it got created and installed. std::string app_id_; @@ -41,5 +44,4 @@ class AthenaAppBrowserTest : public extensions::PlatformAppBrowserTest { } // namespace athena -#endif // ATHENA_TEST_CHROME_ATHENA_APP_BROWSERTEST_H_ - +#endif // ATHENA_TEST_CHROME_ATHENA_APP_BROWSER_TEST_H_ diff --git a/athena/test/chrome/athena_browsertest.cc b/athena/test/chrome/athena_chrome_browser_test.cc index c9e8965..c619b0a 100644 --- a/athena/test/chrome/athena_browsertest.cc +++ b/athena/test/chrome/athena_chrome_browser_test.cc @@ -2,30 +2,36 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "athena/test/chrome/athena_browsertest.h" +#include "athena/test/chrome/athena_chrome_browser_test.h" -#include "athena/test/chrome/test_util.h" +#include "athena/test/base/test_util.h" #include "base/command_line.h" +#include "chrome/browser/profiles/profile_manager.h" #include "content/public/common/content_switches.h" namespace athena { -AthenaBrowserTest::AthenaBrowserTest() { +AthenaChromeBrowserTest::AthenaChromeBrowserTest() { } -AthenaBrowserTest::~AthenaBrowserTest() { +AthenaChromeBrowserTest::~AthenaChromeBrowserTest() { } -void AthenaBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { +void AthenaChromeBrowserTest::SetUpCommandLine( + base::CommandLine* command_line) { // The NaCl sandbox won't work in our browser tests. command_line->AppendSwitch(switches::kNoSandbox); InProcessBrowserTest::SetUpCommandLine(command_line); } -void AthenaBrowserTest::SetUpOnMainThread() { +void AthenaChromeBrowserTest::SetUpOnMainThread() { // Set the memory pressure to low and turning off undeterministic resource // observer events. test_util::SendTestMemoryPressureEvent(ResourceManager::MEMORY_PRESSURE_LOW); } +content::BrowserContext* AthenaChromeBrowserTest::GetBrowserContext() { + return ProfileManager::GetActiveUserProfile(); +} + } // namespace athena diff --git a/athena/test/chrome/athena_browsertest.h b/athena/test/chrome/athena_chrome_browser_test.h index 85917e1..a16844a 100644 --- a/athena/test/chrome/athena_browsertest.h +++ b/athena/test/chrome/athena_chrome_browser_test.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ATHENA_TEST_CHROME_ATHENA_BROWSERTEST_H_ -#define ATHENA_TEST_CHROME_ATHENA_BROWSERTEST_H_ +#ifndef ATHENA_TEST_CHROME_ATHENA_CHROME_BROWSER_TEST_H_ +#define ATHENA_TEST_CHROME_ATHENA_CHROME_BROWSER_TEST_H_ #include "chrome/test/base/in_process_browser_test.h" @@ -11,27 +11,33 @@ namespace base { class CommandLine; } +namespace content { +class BrowserContext; +} + namespace athena { // Base class for athena tests which allows to use WebActivities. // // Note: To avoid asynchronous resource manager events, the memory pressure // callback gets turned off at the beginning to a low memory pressure. -class AthenaBrowserTest : public InProcessBrowserTest { +class AthenaChromeBrowserTest : public InProcessBrowserTest { public: - AthenaBrowserTest(); - ~AthenaBrowserTest() override; + AthenaChromeBrowserTest(); + ~AthenaChromeBrowserTest() override; protected: // BrowserTestBase: void SetUpCommandLine(base::CommandLine* command_line) override; void SetUpOnMainThread() override; + // Returns the browser context used by the test. + content::BrowserContext* GetBrowserContext(); + private: - DISALLOW_COPY_AND_ASSIGN(AthenaBrowserTest); + DISALLOW_COPY_AND_ASSIGN(AthenaChromeBrowserTest); }; } // namespace athena -#endif // ATHENA_TEST_CHROME_ATHENA_BROWSERTEST_H_ - +#endif // ATHENA_TEST_CHROME_ATHENA_CHROME_BROWSER_TEST_H_ |