Index: apps/app_shim/extension_app_shim_handler_mac_unittest.cc |
diff --git a/apps/app_shim/extension_app_shim_handler_mac_unittest.cc b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d9f0c2e2c7f09bf2048bc8d77a09a8742e7c7527 |
--- /dev/null |
+++ b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc |
@@ -0,0 +1,100 @@ |
+// Copyright 2013 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 "apps/app_shim/extension_app_shim_handler_mac.h" |
+ |
+#include "apps/app_shim/app_shim_host_mac.h" |
+#include "apps/app_shim/app_shim_messages.h" |
+#include "base/memory/scoped_vector.h" |
+#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "content/public/browser/notification_service.h" |
+#include "ipc/ipc_message.h" |
tapted
2013/05/21 06:15:37
is this used here?
jackhou1
2013/05/22 23:54:44
Nope, removed.
|
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+class TestingExtensionAppShimHandler : public ExtensionAppShimHandler { |
+ public: |
+ explicit TestingExtensionAppShimHandler() : fails_launch_(false) {} |
+ virtual ~TestingExtensionAppShimHandler() {} |
+ |
+ void set_fails_launch(bool fails_launch) { |
+ fails_launch_ = fails_launch; |
+ } |
+ |
+ HostMap::mapped_type PublicGetObserverList(Profile* profile, |
+ const std::string& app_id) { |
+ return GetObserverList(profile, app_id, false); |
+ } |
+ |
+ content::NotificationRegistrar* GetRegistrar() { return ®istrar_; } |
+ |
+ protected: |
+ virtual bool LaunchApp(Profile* profile, const std::string& app_id) OVERRIDE { |
+ return !fails_launch_; |
+ } |
+ |
+ private: |
+ bool fails_launch_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(TestingExtensionAppShimHandler); |
+}; |
+ |
+const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
+ |
+class FakeAppShimHost : public AppShimHost { |
+ public: |
+ FakeAppShimHost() : profile_(new TestingProfile), |
+ app_id_(kTestAppId) {} |
+ |
+ virtual void OnAppClosed() OVERRIDE { } |
tapted
2013/05/21 06:15:37
nit: no space between curlies
jackhou1
2013/05/22 23:54:44
Done.
|
+ virtual Profile* profile() const OVERRIDE { return profile_.get(); } |
+ virtual const std::string& app_id() const OVERRIDE { return app_id_; } |
+ |
+ private: |
+ scoped_ptr<TestingProfile> profile_; |
+ std::string app_id_; |
+}; |
tapted
2013/05/21 06:15:37
nit: DISALLOW_COPY_AND_ASSIGN(..)
jackhou1
2013/05/22 23:54:44
Done.
|
+ |
+class ExtensionAppShimHandlerTest : public testing::Test { |
+ protected: |
+ ExtensionAppShimHandlerTest() {} |
+ |
+ TestingExtensionAppShimHandler* handler() { return handler_.get(); } |
+ FakeAppShimHost* host() { return host_.get(); } |
+ |
+ private: |
+ virtual void SetUp() OVERRIDE { |
tapted
2013/05/21 06:15:37
Maybe not an issue for unittests as much as it is
jackhou1
2013/05/22 23:54:44
Done.
|
+ handler_.reset(new TestingExtensionAppShimHandler()); |
+ host_.reset(new FakeAppShimHost()); |
+ } |
+ |
+ scoped_ptr<TestingExtensionAppShimHandler> handler_; |
+ scoped_ptr<FakeAppShimHost> host_; |
tapted
2013/05/21 06:15:37
can these be regular members, rather than scoped_p
jackhou1
2013/05/22 23:54:44
Done.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest); |
+}; |
+ |
+} // namespace |
+ |
+TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) { |
+ handler()->set_fails_launch(true); |
+ EXPECT_EQ(false, handler()->OnShimLaunch(host())); |
+ EXPECT_FALSE(handler()->PublicGetObserverList(host()->profile(), |
+ host()->app_id())); |
+ |
+ handler()->set_fails_launch(false); |
+ EXPECT_EQ(true, handler()->OnShimLaunch(host())); |
+ EXPECT_TRUE(handler()->PublicGetObserverList( |
+ host()->profile(), host()->app_id())->HasObserver(host())); |
+ EXPECT_TRUE(handler()->GetRegistrar()->IsRegistered( |
+ handler(), |
+ chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
+ content::Source<Profile>(host()->profile()))); |
+ |
+ handler()->OnShimClose(host()); |
+ EXPECT_FALSE(handler()->PublicGetObserverList( |
+ host()->profile(), host()->app_id())->HasObserver(host())); |
+} |