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..d0d0a866091efd97e9b4109a8ce5090664858682 |
--- /dev/null |
+++ b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc |
@@ -0,0 +1,94 @@ |
+// 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 "base/memory/scoped_ptr.h" |
tapted
2013/05/23 02:29:39
unused?
jackhou1
2013/05/23 06:10:19
Done.
|
+#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/test/base/testing_profile.h" |
+#include "content/public/browser/notification_service.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace apps { |
+ |
+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 FindObserverList(Profile* profile, |
+ const std::string& app_id) { |
+ return ExtensionAppShimHandler::FindObserverList(profile, app_id); |
+ } |
+ |
+ content::NotificationRegistrar* GetRegistrar() { return registrar(); } |
+ |
+ 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 FakeHost : public apps::AppShimHandler::Host { |
+ public: |
+ FakeHost(Profile* profile, std::string app_id) |
+ : profile_(profile), |
+ app_id_(app_id) {} |
+ |
+ virtual void OnAppClosed() OVERRIDE {} |
+ virtual Profile* GetProfile() const OVERRIDE { return profile_; } |
+ virtual std::string GetAppId() const OVERRIDE { return app_id_; } |
+ |
+ private: |
+ Profile* profile_; |
+ std::string app_id_; |
+}; |
tapted
2013/05/23 02:29:39
DISALLOW_COPY_AND_ASSIGN ?
jackhou1
2013/05/23 06:10:19
Done.
|
+ |
+class ExtensionAppShimHandlerTest : public testing::Test { |
+ protected: |
+ ExtensionAppShimHandlerTest() : host_(&profile_, kTestAppId) {} |
+ |
+ TestingExtensionAppShimHandler handler_; |
+ TestingProfile profile_; |
+ FakeHost host_; |
+ |
+ private: |
+ virtual void SetUp() OVERRIDE { |
+ testing::Test::SetUp(); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest); |
+}; |
+ |
+TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) { |
+ handler_.set_fails_launch(true); |
+ EXPECT_EQ(false, handler_.OnShimLaunch(&host_)); |
+ EXPECT_FALSE(handler_.FindObserverList(&profile_, kTestAppId)); |
+ |
+ handler_.set_fails_launch(false); |
+ EXPECT_EQ(true, handler_.OnShimLaunch(&host_)); |
+ EXPECT_TRUE(handler_.FindObserverList(&profile_, kTestAppId)-> |
+ HasObserver(&host_)); |
+ EXPECT_TRUE(handler_.GetRegistrar()->IsRegistered( |
+ &handler_, |
+ chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
+ content::Source<Profile>(&profile_))); |
+ |
+ handler_.OnShimClose(&host_); |
+ EXPECT_FALSE(handler_.FindObserverList(&profile_, kTestAppId)); |
+} |
+ |
+} // namespace apps |