diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-23 15:41:02 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-23 15:41:02 +0000 |
commit | f947bc1b3b2941ff136a3cffbf2d91e4a6465f0f (patch) | |
tree | a95c93db55cbe012001723dd05c0b56123e61a7b /ash | |
parent | 77d0fa87ddab5e40b0eefef3b5c5d48dce2ed7d1 (diff) | |
download | chromium_src-f947bc1b3b2941ff136a3cffbf2d91e4a6465f0f.zip chromium_src-f947bc1b3b2941ff136a3cffbf2d91e4a6465f0f.tar.gz chromium_src-f947bc1b3b2941ff136a3cffbf2d91e4a6465f0f.tar.bz2 |
Create MetroViewerProcessHost as a common base for TestMetroViewerProcessHost and ChromeMetroViewerProcessHost
Bringing LaunchViewerAndWaitForConnection() to the common base so that ChromeMetroViewerProcessHost can also benefit from it (required for ash browser tests).
BUG=179830
Review URL: https://chromiumcodereview.appspot.com/14629025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 5 | ||||
-rw-r--r-- | ash/test/DEPS | 1 | ||||
-rw-r--r-- | ash/test/ash_test_base.cc | 9 | ||||
-rw-r--r-- | ash/test/ash_test_base.h | 4 | ||||
-rw-r--r-- | ash/test/test_metro_viewer_process_host.cc | 74 | ||||
-rw-r--r-- | ash/test/test_metro_viewer_process_host.h | 58 |
6 files changed, 26 insertions, 125 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 1e13f7c..09fa925 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -571,9 +571,10 @@ ['OS=="win"', { 'dependencies': [ '../ipc/ipc.gyp:ipc', - '../ui/metro_viewer/metro_viewer.gyp:metro_viewer', - '../win8/win8_tests.gyp:test_registrar', + '../ui/metro_viewer/metro_viewer.gyp:metro_viewer_messages', + '../win8/win8.gyp:metro_viewer', '../win8/win8.gyp:test_support_win8', + '../win8/win8_tests.gyp:test_registrar', ], 'sources': [ 'test/test_metro_viewer_process_host.cc', diff --git a/ash/test/DEPS b/ash/test/DEPS index ace334c..8bc7896 100644 --- a/ash/test/DEPS +++ b/ash/test/DEPS @@ -1,4 +1,5 @@ include_rules = [ "+content/public/test", "+content/test", + "+win8/viewer", ] diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index 99105e1..87f2243 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -119,7 +119,14 @@ void AshTestBase::SetUp() { if (base::win::GetVersion() >= base::win::VERSION_WIN8 && !CommandLine::ForCurrentProcess()->HasSwitch( ash::switches::kForceAshToDesktop)) { - metro_viewer_host_.reset(new TestMetroViewerProcessHost("viewer")); + ipc_thread_.reset(new base::Thread("test_metro_viewer_ipc_thread")); + base::Thread::Options options; + options.message_loop_type = base::MessageLoop::TYPE_IO; + ipc_thread_->StartWithOptions(options); + + metro_viewer_host_.reset( + new TestMetroViewerProcessHost("viewer", + ipc_thread_->message_loop_proxy())); CHECK(metro_viewer_host_->LaunchViewerAndWaitForConnection( win8::test::kDefaultTestAppUserModelId)); aura::RemoteRootWindowHostWin* root_window_host = diff --git a/ash/test/ash_test_base.h b/ash/test/ash_test_base.h index dd65bf4..2d9f717 100644 --- a/ash/test/ash_test_base.h +++ b/ash/test/ash_test_base.h @@ -9,6 +9,7 @@ #include "base/compiler_specific.h" #include "base/message_loop.h" +#include "base/threading/thread.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/aura/client/window_types.h" @@ -109,6 +110,9 @@ class AshTestBase : public testing::Test { scoped_ptr<AshTestHelper> ash_test_helper_; scoped_ptr<aura::test::EventGenerator> event_generator_; #if defined(OS_WIN) + // Note that the order is important here as ipc_thread_ should be destroyed + // after metro_viewer_host_->channel_. + scoped_ptr<base::Thread> ipc_thread_; scoped_ptr<TestMetroViewerProcessHost> metro_viewer_host_; ui::ScopedOleInitializer ole_initializer_; #endif diff --git a/ash/test/test_metro_viewer_process_host.cc b/ash/test/test_metro_viewer_process_host.cc index 277864f..63725f7 100644 --- a/ash/test/test_metro_viewer_process_host.cc +++ b/ash/test/test_metro_viewer_process_host.cc @@ -23,81 +23,13 @@ namespace ash { namespace test { -TestMetroViewerProcessHost::InternalMessageFilter::InternalMessageFilter( - TestMetroViewerProcessHost* owner) - : owner_(owner) { -} - -void TestMetroViewerProcessHost::InternalMessageFilter::OnChannelConnected( - int32 peer_pid) { - owner_->NotifyChannelConnected(); -} - TestMetroViewerProcessHost::TestMetroViewerProcessHost( - const std::string& ipc_channel_name) - : ipc_thread_("test_metro_viewer_ipc_thread"), - channel_connected_event_(false, false), - closed_unexpectedly_(false) { - - base::Thread::Options options; - options.message_loop_type = base::MessageLoop::TYPE_IO; - ipc_thread_.StartWithOptions(options); - - channel_.reset(new IPC::ChannelProxy( - ipc_channel_name.c_str(), - IPC::Channel::MODE_NAMED_SERVER, - this, - ipc_thread_.message_loop_proxy())); - - channel_->AddFilter(new InternalMessageFilter(this)); + const std::string& ipc_channel_name, + base::SingleThreadTaskRunner* ipc_task_runner) + : MetroViewerProcessHost(ipc_channel_name, ipc_task_runner) { } TestMetroViewerProcessHost::~TestMetroViewerProcessHost() { - channel_.reset(); - ipc_thread_.Stop(); -} - -void TestMetroViewerProcessHost::NotifyChannelConnected() { - channel_connected_event_.Signal(); -} - -bool TestMetroViewerProcessHost::LaunchViewerAndWaitForConnection( - const base::string16& app_user_model_id) { - // Activate the viewer process. NOTE: This assumes that the viewer process is - // registered as the default browser using the provided |app_user_model_id|. - - // TODO(robertshield): Initialize COM at test suite startup. - base::win::ScopedCOMInitializer com_initializer; - - base::win::ScopedComPtr<IApplicationActivationManager> activator; - HRESULT hr = activator.CreateInstance(CLSID_ApplicationActivationManager); - if (SUCCEEDED(hr)) { - DWORD pid = 0; - hr = activator->ActivateApplication( - app_user_model_id.c_str(), L"open", AO_NONE, &pid); - } - - LOG_IF(ERROR, FAILED(hr)) << "Tried and failed to launch Metro Chrome. " - << "hr=" << std::hex << hr; - - // Having launched the viewer process, now we wait for it to connect. - return channel_connected_event_.TimedWait(base::TimeDelta::FromSeconds(60)); -} - -bool TestMetroViewerProcessHost::Send(IPC::Message* msg) { - return channel_->Send(msg); -} - -bool TestMetroViewerProcessHost::OnMessageReceived( - const IPC::Message& message) { - DCHECK(CalledOnValidThread()); - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(TestMetroViewerProcessHost, message) - IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled ? true : - aura::RemoteRootWindowHostWin::Instance()->OnMessageReceived(message); } void TestMetroViewerProcessHost::OnChannelError() { diff --git a/ash/test/test_metro_viewer_process_host.h b/ash/test/test_metro_viewer_process_host.h index f52230b..0f24169 100644 --- a/ash/test/test_metro_viewer_process_host.h +++ b/ash/test/test_metro_viewer_process_host.h @@ -7,69 +7,25 @@ #include <string> -#include "base/memory/scoped_ptr.h" -#include "base/synchronization/waitable_event.h" -#include "base/threading/non_thread_safe.h" -#include "base/threading/thread.h" -#include "ipc/ipc_channel_proxy.h" -#include "ipc/ipc_listener.h" -#include "ipc/ipc_sender.h" -#include "ui/gfx/native_widget_types.h" +#include "win8/viewer/metro_viewer_process_host.h" class AcceleratedSurface; namespace ash { namespace test { -class TestMetroViewerProcessHost : public IPC::Listener, - public IPC::Sender, - public base::NonThreadSafe { +class TestMetroViewerProcessHost : public win8::MetroViewerProcessHost { public: - explicit TestMetroViewerProcessHost(const std::string& ipc_channel_name); + TestMetroViewerProcessHost(const std::string& ipc_channel_name, + base::SingleThreadTaskRunner* ipc_task_runner); virtual ~TestMetroViewerProcessHost(); - // Launches the viewer process associated with the given |app_user_model_id| - // and blocks until that viewer process connects or until a timeout is - // reached. Returns true if the viewer process connects before the timeout is - // reached. - bool LaunchViewerAndWaitForConnection( - const base::string16& app_user_model_id); - - // IPC::Sender implementation: - virtual bool Send(IPC::Message* msg) OVERRIDE; - - // IPC::Listener implementation: - virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - virtual void OnChannelError() OVERRIDE; - bool closed_unexpectedly() { return closed_unexpectedly_; } private: - void OnSetTargetSurface(gfx::NativeViewId target_surface); - - void NotifyChannelConnected(); - - // Inner message filter used to handle connection event on the IPC channel - // proxy's background thread. This prevents consumers of - // TestMetroViewerProcessHost from having to pump messages on their own - // message loop. - class InternalMessageFilter : public IPC::ChannelProxy::MessageFilter { - public: - InternalMessageFilter(TestMetroViewerProcessHost* owner); - - // IPC::ChannelProxy::MessageFilter implementation. - virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; - - private: - TestMetroViewerProcessHost* owner_; - DISALLOW_COPY_AND_ASSIGN(InternalMessageFilter); - }; - - // Members related to the IPC channel. Note that the order is important - // here as ipc_thread_ should be destroyed after channel_. - base::Thread ipc_thread_; - scoped_ptr<IPC::ChannelProxy> channel_; - base::WaitableEvent channel_connected_event_; + // win8::MetroViewerProcessHost implementation + virtual void OnChannelError() OVERRIDE; + virtual void OnSetTargetSurface(gfx::NativeViewId target_surface) OVERRIDE; scoped_ptr<AcceleratedSurface> backing_surface; |