summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-20 11:42:34 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-20 11:42:34 +0000
commiteab691be5f7c0a54e41c9ff758675c07c373e463 (patch)
tree503b197647054527b10f37240086c1bf23d9a049 /apps
parent0a1ca8f44cdd738cbea1c12361cd6adcb638091a (diff)
downloadchromium_src-eab691be5f7c0a54e41c9ff758675c07c373e463.zip
chromium_src-eab691be5f7c0a54e41c9ff758675c07c373e463.tar.gz
chromium_src-eab691be5f7c0a54e41c9ff758675c07c373e463.tar.bz2
Move FetchProfileForDirectory to ExtensionAppShimHandler.
AppShimHandler now identifies profiles with the profile path. ExtensionAppShimHandler is responsible for looking up and storing the Profile*. This allows app shims to have no associated profile, and be handled by an appropriate handler. BUG=168080 Review URL: https://chromiumcodereview.appspot.com/17366002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207401 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r--apps/app_shim/app_shim_handler_mac.h3
-rw-r--r--apps/app_shim/app_shim_host_mac.cc39
-rw-r--r--apps/app_shim/app_shim_host_mac.h10
-rw-r--r--apps/app_shim/app_shim_host_mac_unittest.cc35
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac.cc64
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac.h14
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac_unittest.cc87
7 files changed, 142 insertions, 110 deletions
diff --git a/apps/app_shim/app_shim_handler_mac.h b/apps/app_shim/app_shim_handler_mac.h
index c24b340..bf08b19 100644
--- a/apps/app_shim/app_shim_handler_mac.h
+++ b/apps/app_shim/app_shim_handler_mac.h
@@ -8,6 +8,7 @@
#include <string>
#include "apps/app_shim/app_shim_launch.h"
+#include "base/files/file_path.h"
class Profile;
@@ -23,7 +24,7 @@ class AppShimHandler {
virtual void OnAppClosed() = 0;
// Allows the handler to determine which app this host corresponds to.
- virtual Profile* GetProfile() const = 0;
+ virtual base::FilePath GetProfilePath() const = 0;
virtual std::string GetAppId() const = 0;
protected:
diff --git a/apps/app_shim/app_shim_host_mac.cc b/apps/app_shim/app_shim_host_mac.cc
index 097cb2f..5c4fefc 100644
--- a/apps/app_shim/app_shim_host_mac.cc
+++ b/apps/app_shim/app_shim_host_mac.cc
@@ -9,12 +9,10 @@
#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/logging.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "content/public/browser/browser_thread.h"
#include "ipc/ipc_channel_proxy.h"
-AppShimHost::AppShimHost() : profile_(NULL) {}
+AppShimHost::AppShimHost() {}
AppShimHost::~AppShimHost() {
DCHECK(CalledOnValidThread());
@@ -34,8 +32,8 @@ void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) {
content::BrowserThread::IO).get()));
}
-Profile* AppShimHost::GetProfile() const {
- return profile_;
+base::FilePath AppShimHost::GetProfilePath() const {
+ return profile_path_;
}
std::string AppShimHost::GetAppId() const {
@@ -68,18 +66,14 @@ void AppShimHost::OnLaunchApp(base::FilePath profile_dir,
std::string app_id,
apps::AppShimLaunchType launch_type) {
DCHECK(CalledOnValidThread());
- DCHECK(!profile_);
- if (profile_) {
+ DCHECK(profile_path_.empty());
+ if (!profile_path_.empty()) {
// Only one app launch message per channel.
Send(new AppShimMsg_LaunchApp_Done(false));
return;
}
- if (!(profile_ = FetchProfileForDirectory(profile_dir))) {
- Send(new AppShimMsg_LaunchApp_Done(false));
- return;
- }
-
+ profile_path_ = profile_dir;
app_id_ = app_id;
apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
@@ -101,27 +95,6 @@ void AppShimHost::OnQuit() {
handler->OnShimQuit(this);
}
-Profile* AppShimHost::FetchProfileForDirectory(
- const base::FilePath& profile_dir) {
- ProfileManager* profileManager = g_browser_process->profile_manager();
- // Check for the profile name in the profile info cache to ensure that we
- // never access any directory that isn't a known profile.
- base::FilePath path = profileManager->user_data_dir().Append(profile_dir);
- ProfileInfoCache& cache = profileManager->GetProfileInfoCache();
- if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) {
- LOG(ERROR) << "Requested directory is not a known profile '"
- << profile_dir.value() << "'.";
- return NULL;
- }
- Profile* profile = profileManager->GetProfile(path);
- if (!profile) {
- LOG(ERROR) << "Couldn't get profile for directory '"
- << profile_dir.value() << "'.";
- return NULL;
- }
- return profile;
-}
-
void AppShimHost::OnAppClosed() {
Close();
}
diff --git a/apps/app_shim/app_shim_host_mac.h b/apps/app_shim/app_shim_host_mac.h
index ce5ce5b..c119d238 100644
--- a/apps/app_shim/app_shim_host_mac.h
+++ b/apps/app_shim/app_shim_host_mac.h
@@ -14,8 +14,6 @@
#include "ipc/ipc_listener.h"
#include "ipc/ipc_sender.h"
-class Profile;
-
namespace IPC {
struct ChannelHandle;
class ChannelProxy;
@@ -40,10 +38,6 @@ class AppShimHost : public IPC::Listener,
void ServeChannel(const IPC::ChannelHandle& handle);
protected:
-
- // Used internally; virtual so they can be mocked for testing.
- virtual Profile* FetchProfileForDirectory(const base::FilePath& profile_dir);
-
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void OnChannelError() OVERRIDE;
@@ -70,7 +64,7 @@ class AppShimHost : public IPC::Listener,
// apps::AppShimHandler::Host overrides:
virtual void OnAppClosed() OVERRIDE;
- virtual Profile* GetProfile() const OVERRIDE;
+ virtual base::FilePath GetProfilePath() const OVERRIDE;
virtual std::string GetAppId() const OVERRIDE;
// Closes the channel and destroys the AppShimHost.
@@ -78,7 +72,7 @@ class AppShimHost : public IPC::Listener,
scoped_ptr<IPC::ChannelProxy> channel_;
std::string app_id_;
- Profile* profile_;
+ base::FilePath profile_path_;
};
#endif // CHROME_BROWSER_WEB_APPLICATIONS_APP_SHIM_HOST_MAC_H_
diff --git a/apps/app_shim/app_shim_host_mac_unittest.cc b/apps/app_shim/app_shim_host_mac_unittest.cc
index 6b1d049..5589485 100644
--- a/apps/app_shim/app_shim_host_mac_unittest.cc
+++ b/apps/app_shim/app_shim_host_mac_unittest.cc
@@ -7,7 +7,6 @@
#include "apps/app_shim/app_shim_messages.h"
#include "base/basictypes.h"
#include "base/memory/scoped_vector.h"
-#include "chrome/test/base/testing_profile.h"
#include "ipc/ipc_message.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,7 +14,7 @@ namespace {
class TestingAppShimHost : public AppShimHost {
public:
- explicit TestingAppShimHost(Profile* profile);
+ TestingAppShimHost() {}
virtual ~TestingAppShimHost() {}
bool ReceiveMessage(IPC::Message* message);
@@ -24,29 +23,15 @@ class TestingAppShimHost : public AppShimHost {
return sent_messages_.get();
}
- void set_fails_profile(bool fails_profile) {
- fails_profile_ = fails_profile;
- }
-
protected:
- virtual Profile* FetchProfileForDirectory(const base::FilePath& profile_dir)
- OVERRIDE;
virtual bool Send(IPC::Message* message) OVERRIDE;
private:
- Profile* test_profile_;
- bool fails_profile_;
-
ScopedVector<IPC::Message> sent_messages_;
DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost);
};
-TestingAppShimHost::TestingAppShimHost(Profile* profile)
- : test_profile_(profile),
- fails_profile_(false) {
-}
-
bool TestingAppShimHost::ReceiveMessage(IPC::Message* message) {
bool handled = OnMessageReceived(*message);
delete message;
@@ -58,13 +43,8 @@ bool TestingAppShimHost::Send(IPC::Message* message) {
return true;
}
-Profile* TestingAppShimHost::FetchProfileForDirectory(
- const base::FilePath& profile_dir) {
- return fails_profile_ ? NULL : test_profile_;
-}
-
const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
-const char kTestProfileDir[] = "Default";
+const char kTestProfileDir[] = "Profile 1";
class AppShimHostTest : public testing::Test,
public apps::AppShimHandler {
@@ -77,7 +57,6 @@ class AppShimHostTest : public testing::Test,
quit_count_(0) {}
TestingAppShimHost* host() { return host_.get(); }
- TestingProfile* profile() { return profile_.get(); }
void LaunchApp(bool launch_now) {
EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_LaunchApp(
@@ -122,12 +101,10 @@ class AppShimHostTest : public testing::Test,
private:
virtual void SetUp() OVERRIDE {
testing::Test::SetUp();
- profile_.reset(new TestingProfile);
- host_.reset(new TestingAppShimHost(profile()));
+ host_.reset(new TestingAppShimHost());
}
scoped_ptr<TestingAppShimHost> host_;
- scoped_ptr<TestingProfile> profile_;
DISALLOW_COPY_AND_ASSIGN(AppShimHostTest);
};
@@ -170,12 +147,6 @@ TEST_F(AppShimHostTest, TestNoLaunchNow) {
apps::AppShimHandler::RemoveHandler(kTestAppId);
}
-TEST_F(AppShimHostTest, TestFailProfile) {
- host()->set_fails_profile(true);
- LaunchApp(true);
- ASSERT_FALSE(LaunchWasSuccessful());
-}
-
TEST_F(AppShimHostTest, TestFailLaunch) {
apps::AppShimHandler::RegisterHandler(kTestAppId, this);
fail_launch_ = true;
diff --git a/apps/app_shim/extension_app_shim_handler_mac.cc b/apps/app_shim/extension_app_shim_handler_mac.cc
index 396184b..2ba950f 100644
--- a/apps/app_shim/extension_app_shim_handler_mac.cc
+++ b/apps/app_shim/extension_app_shim_handler_mac.cc
@@ -7,10 +7,12 @@
#include "apps/app_shim/app_shim_messages.h"
#include "base/files/file_path.h"
#include "base/logging.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_host.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/shell_window_registry.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/extensions/native_app_window.h"
#include "chrome/browser/ui/extensions/shell_window.h"
@@ -24,7 +26,23 @@
namespace apps {
-ExtensionAppShimHandler::ExtensionAppShimHandler() {
+bool ExtensionAppShimHandler::ProfileManagerFacade::ProfileExistsForPath(
+ const base::FilePath& path) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ // Check for the profile name in the profile info cache to ensure that we
+ // never access any directory that isn't a known profile.
+ base::FilePath full_path = profile_manager->user_data_dir().Append(path);
+ ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
+ return cache.GetIndexOfProfileWithPath(full_path) != std::string::npos;
+}
+
+Profile* ExtensionAppShimHandler::ProfileManagerFacade::ProfileForPath(
+ const base::FilePath& path) {
+ return g_browser_process->profile_manager()->GetProfile(path);
+}
+
+ExtensionAppShimHandler::ExtensionAppShimHandler()
+ : profile_manager_facade_(new ProfileManagerFacade) {
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
content::NotificationService::AllBrowserContextsAndSources());
}
@@ -39,8 +57,18 @@ ExtensionAppShimHandler::~ExtensionAppShimHandler() {
bool ExtensionAppShimHandler::OnShimLaunch(Host* host,
AppShimLaunchType launch_type) {
- Profile* profile = host->GetProfile();
- DCHECK(profile);
+ const base::FilePath& profile_path = host->GetProfilePath();
+ DCHECK(!profile_path.empty());
+
+ if (!profile_manager_facade_->ProfileExistsForPath(profile_path)) {
+ // User may have deleted the profile this shim was originally created for.
+ // TODO(jackhou): Add some UI for this case and remove the LOG.
+ LOG(ERROR) << "Requested directory is not a known profile '"
+ << profile_path.value() << "'.";
+ return false;
+ }
+
+ Profile* profile = profile_manager_facade_->ProfileForPath(profile_path);
const std::string& app_id = host->GetAppId();
if (!extensions::Extension::IdIsValid(app_id)) {
@@ -48,6 +76,7 @@ bool ExtensionAppShimHandler::OnShimLaunch(Host* host,
return false;
}
+ // TODO(jackhou): Add some UI for this case and remove the LOG.
if (!LaunchApp(profile, app_id, launch_type))
return false;
@@ -69,8 +98,12 @@ bool ExtensionAppShimHandler::OnShimLaunch(Host* host,
}
void ExtensionAppShimHandler::OnShimClose(Host* host) {
- HostMap::iterator it = hosts_.find(make_pair(host->GetProfile(),
- host->GetAppId()));
+ DCHECK(profile_manager_facade_->ProfileExistsForPath(
+ host->GetProfilePath()));
+ Profile* profile =
+ profile_manager_facade_->ProfileForPath(host->GetProfilePath());
+
+ HostMap::iterator it = hosts_.find(make_pair(profile, host->GetAppId()));
// Any hosts other than the main host will still call OnShimClose, so ignore
// them.
if (it != hosts_.end() && it->second == host)
@@ -78,11 +111,13 @@ void ExtensionAppShimHandler::OnShimClose(Host* host) {
}
void ExtensionAppShimHandler::OnShimFocus(Host* host) {
- if (!host->GetProfile())
- return;
+ DCHECK(profile_manager_facade_->ProfileExistsForPath(
+ host->GetProfilePath()));
+ Profile* profile =
+ profile_manager_facade_->ProfileForPath(host->GetProfilePath());
extensions::ShellWindowRegistry* registry =
- extensions::ShellWindowRegistry::Get(host->GetProfile());
+ extensions::ShellWindowRegistry::Get(profile);
const extensions::ShellWindowRegistry::ShellWindowList windows =
registry->GetShellWindowsForApp(host->GetAppId());
std::set<gfx::NativeWindow> native_windows;
@@ -94,11 +129,13 @@ void ExtensionAppShimHandler::OnShimFocus(Host* host) {
}
void ExtensionAppShimHandler::OnShimQuit(Host* host) {
- if (!host->GetProfile())
- return;
+ DCHECK(profile_manager_facade_->ProfileExistsForPath(
+ host->GetProfilePath()));
+ Profile* profile =
+ profile_manager_facade_->ProfileForPath(host->GetProfilePath());
extensions::ShellWindowRegistry::ShellWindowList windows =
- extensions::ShellWindowRegistry::Get(host->GetProfile())->
+ extensions::ShellWindowRegistry::Get(profile)->
GetShellWindowsForApp(host->GetAppId());
for (extensions::ShellWindowRegistry::const_iterator it = windows.begin();
it != windows.end(); ++it) {
@@ -106,6 +143,11 @@ void ExtensionAppShimHandler::OnShimQuit(Host* host) {
}
}
+void ExtensionAppShimHandler::set_profile_manager_facade(
+ ProfileManagerFacade* profile_manager_facade) {
+ profile_manager_facade_.reset(profile_manager_facade);
+}
+
bool ExtensionAppShimHandler::LaunchApp(Profile* profile,
const std::string& app_id,
AppShimLaunchType launch_type) {
diff --git a/apps/app_shim/extension_app_shim_handler_mac.h b/apps/app_shim/extension_app_shim_handler_mac.h
index f5a7d66..1be556a 100644
--- a/apps/app_shim/extension_app_shim_handler_mac.h
+++ b/apps/app_shim/extension_app_shim_handler_mac.h
@@ -9,11 +9,16 @@
#include <string>
#include "apps/app_shim/app_shim_handler_mac.h"
+#include "base/memory/scoped_ptr.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
+namespace base {
+class FilePath;
+}
+
namespace extensions {
class Extension;
}
@@ -25,6 +30,13 @@ namespace apps {
class ExtensionAppShimHandler : public AppShimHandler,
public content::NotificationObserver {
public:
+ class ProfileManagerFacade {
+ public:
+ virtual ~ProfileManagerFacade() {}
+ virtual bool ProfileExistsForPath(const base::FilePath& path);
+ virtual Profile* ProfileForPath(const base::FilePath& path);
+ };
+
ExtensionAppShimHandler();
virtual ~ExtensionAppShimHandler();
@@ -39,6 +51,7 @@ class ExtensionAppShimHandler : public AppShimHandler,
HostMap;
// Exposed for testing.
+ void set_profile_manager_facade(ProfileManagerFacade* profile_manager_facade);
HostMap& hosts() { return hosts_; }
content::NotificationRegistrar& registrar() { return registrar_; }
@@ -59,6 +72,7 @@ class ExtensionAppShimHandler : public AppShimHandler,
void CloseShim(Profile* profile, const std::string& app_id);
+ scoped_ptr<ProfileManagerFacade> profile_manager_facade_;
HostMap hosts_;
content::NotificationRegistrar registrar_;
diff --git a/apps/app_shim/extension_app_shim_handler_mac_unittest.cc b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc
index 651d597..d440555 100644
--- a/apps/app_shim/extension_app_shim_handler_mac_unittest.cc
+++ b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc
@@ -9,18 +9,32 @@
#include "chrome/common/chrome_notification_types.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_service.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace apps {
+using ::testing::Return;
+
+class MockProfileManagerFacade
+ : public ExtensionAppShimHandler::ProfileManagerFacade {
+ public:
+ virtual ~MockProfileManagerFacade() {}
+
+ MOCK_METHOD1(ProfileExistsForPath, bool(const base::FilePath& path));
+ MOCK_METHOD1(ProfileForPath, Profile*(const base::FilePath& path));
+};
+
class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
public:
- explicit TestingExtensionAppShimHandler() : fails_launch_(false) {}
+ TestingExtensionAppShimHandler(ProfileManagerFacade* profile_manager_facade) {
+ set_profile_manager_facade(profile_manager_facade);
+ }
virtual ~TestingExtensionAppShimHandler() {}
- void set_fails_launch(bool fails_launch) {
- fails_launch_ = fails_launch;
- }
+ MOCK_METHOD3(LaunchApp, bool(Profile*,
+ const std::string&,
+ AppShimLaunchType));
AppShimHandler::Host* FindHost(Profile* profile,
const std::string& app_id) {
@@ -30,16 +44,7 @@ class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
content::NotificationRegistrar& GetRegistrar() { return registrar(); }
- protected:
- virtual bool LaunchApp(Profile* profile,
- const std::string& app_id,
- AppShimLaunchType launch_type) OVERRIDE {
- return !fails_launch_;
- }
-
private:
- bool fails_launch_;
-
DISALLOW_COPY_AND_ASSIGN(TestingExtensionAppShimHandler);
};
@@ -48,10 +53,10 @@ const char kTestAppIdB[] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
class FakeHost : public apps::AppShimHandler::Host {
public:
- FakeHost(Profile* profile,
- std::string app_id,
+ FakeHost(const base::FilePath& profile_path,
+ const std::string& app_id,
TestingExtensionAppShimHandler* handler)
- : profile_(profile),
+ : profile_path_(profile_path),
app_id_(app_id),
handler_(handler),
close_count_(0) {}
@@ -60,13 +65,15 @@ class FakeHost : public apps::AppShimHandler::Host {
handler_->OnShimClose(this);
++close_count_;
}
- virtual Profile* GetProfile() const OVERRIDE { return profile_; }
+ virtual base::FilePath GetProfilePath() const OVERRIDE {
+ return profile_path_;
+ }
virtual std::string GetAppId() const OVERRIDE { return app_id_; }
int close_count() { return close_count_; }
private:
- Profile* profile_;
+ base::FilePath profile_path_;
std::string app_id_;
TestingExtensionAppShimHandler* handler_;
int close_count_;
@@ -77,13 +84,28 @@ class FakeHost : public apps::AppShimHandler::Host {
class ExtensionAppShimHandlerTest : public testing::Test {
protected:
ExtensionAppShimHandlerTest()
- : handler_(new TestingExtensionAppShimHandler),
- host_aa_(&profile_a_, kTestAppIdA, handler_.get()),
- host_ab_(&profile_a_, kTestAppIdB, handler_.get()),
- host_bb_(&profile_b_, kTestAppIdB, handler_.get()),
- host_aa_duplicate_(&profile_a_, kTestAppIdA, handler_.get()) {}
+ : profile_manager_facade_(new MockProfileManagerFacade),
+ handler_(new TestingExtensionAppShimHandler(profile_manager_facade_)),
+ profile_path_a_("Profile A"),
+ profile_path_b_("Profile B"),
+ host_aa_(profile_path_a_, kTestAppIdA, handler_.get()),
+ host_ab_(profile_path_a_, kTestAppIdB, handler_.get()),
+ host_bb_(profile_path_b_, kTestAppIdB, handler_.get()),
+ host_aa_duplicate_(profile_path_a_, kTestAppIdA, handler_.get()) {
+ EXPECT_CALL(*profile_manager_facade_, ProfileExistsForPath(profile_path_a_))
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(*profile_manager_facade_, ProfileForPath(profile_path_a_))
+ .WillRepeatedly(Return(&profile_a_));
+ EXPECT_CALL(*profile_manager_facade_, ProfileExistsForPath(profile_path_b_))
+ .WillRepeatedly(Return(true));
+ EXPECT_CALL(*profile_manager_facade_, ProfileForPath(profile_path_b_))
+ .WillRepeatedly(Return(&profile_b_));
+ }
+ MockProfileManagerFacade* profile_manager_facade_;
scoped_ptr<TestingExtensionAppShimHandler> handler_;
+ base::FilePath profile_path_a_;
+ base::FilePath profile_path_b_;
TestingProfile profile_a_;
TestingProfile profile_b_;
FakeHost host_aa_;
@@ -97,20 +119,32 @@ class ExtensionAppShimHandlerTest : public testing::Test {
TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) {
// If launch fails, the host is not added to the map.
- handler_->set_fails_launch(true);
+ EXPECT_CALL(*handler_,
+ LaunchApp(&profile_a_, kTestAppIdA, APP_SHIM_LAUNCH_NORMAL))
+ .WillOnce(Return(false));
EXPECT_EQ(false, handler_->OnShimLaunch(&host_aa_, APP_SHIM_LAUNCH_NORMAL));
EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA));
// Normal startup.
- handler_->set_fails_launch(false);
+ EXPECT_CALL(*handler_,
+ LaunchApp(&profile_a_, kTestAppIdA, APP_SHIM_LAUNCH_NORMAL))
+ .WillOnce(Return(true));
EXPECT_EQ(true, handler_->OnShimLaunch(&host_aa_, APP_SHIM_LAUNCH_NORMAL));
EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA));
EXPECT_TRUE(handler_->GetRegistrar().IsRegistered(
handler_.get(),
chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
content::Source<Profile>(&profile_a_)));
+
+ EXPECT_CALL(*handler_,
+ LaunchApp(&profile_a_, kTestAppIdB, APP_SHIM_LAUNCH_NORMAL))
+ .WillOnce(Return(true));
EXPECT_EQ(true, handler_->OnShimLaunch(&host_ab_, APP_SHIM_LAUNCH_NORMAL));
EXPECT_EQ(&host_ab_, handler_->FindHost(&profile_a_, kTestAppIdB));
+
+ EXPECT_CALL(*handler_,
+ LaunchApp(&profile_b_, kTestAppIdB, APP_SHIM_LAUNCH_NORMAL))
+ .WillOnce(Return(true));
EXPECT_EQ(true, handler_->OnShimLaunch(&host_bb_, APP_SHIM_LAUNCH_NORMAL));
EXPECT_EQ(&host_bb_, handler_->FindHost(&profile_b_, kTestAppIdB));
EXPECT_TRUE(handler_->GetRegistrar().IsRegistered(
@@ -119,6 +153,9 @@ TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) {
content::Source<Profile>(&profile_b_)));
// Starting and closing a second host does nothing.
+ EXPECT_CALL(*handler_,
+ LaunchApp(&profile_a_, kTestAppIdA, APP_SHIM_LAUNCH_NORMAL))
+ .WillOnce(Return(false));
EXPECT_EQ(false, handler_->OnShimLaunch(&host_aa_duplicate_,
APP_SHIM_LAUNCH_NORMAL));
EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA));