Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: apps/app_shim/extension_app_shim_handler_mac_unittest.cc

Issue 15269003: Refactor extension handling code from AppShimHost into ExtensionAppShimHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Instantiate ExtensionAppShimHandler in AppShimHostManager. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "apps/app_shim/extension_app_shim_handler_mac.h"
6
7 #include "apps/app_shim/app_shim_host_mac.h"
8 #include "base/memory/scoped_ptr.h"
tapted 2013/05/23 02:29:39 unused?
jackhou1 2013/05/23 06:10:19 Done.
9 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/test/base/testing_profile.h"
11 #include "content/public/browser/notification_service.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace apps {
15
16 class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
17 public:
18 explicit TestingExtensionAppShimHandler() : fails_launch_(false) {}
19 virtual ~TestingExtensionAppShimHandler() {}
20
21 void set_fails_launch(bool fails_launch) {
22 fails_launch_ = fails_launch;
23 }
24
25 HostMap::mapped_type FindObserverList(Profile* profile,
26 const std::string& app_id) {
27 return ExtensionAppShimHandler::FindObserverList(profile, app_id);
28 }
29
30 content::NotificationRegistrar* GetRegistrar() { return registrar(); }
31
32 protected:
33 virtual bool LaunchApp(Profile* profile, const std::string& app_id) OVERRIDE {
34 return !fails_launch_;
35 }
36
37 private:
38 bool fails_launch_;
39
40 DISALLOW_COPY_AND_ASSIGN(TestingExtensionAppShimHandler);
41 };
42
43 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
44
45 class FakeHost : public apps::AppShimHandler::Host {
46 public:
47 FakeHost(Profile* profile, std::string app_id)
48 : profile_(profile),
49 app_id_(app_id) {}
50
51 virtual void OnAppClosed() OVERRIDE {}
52 virtual Profile* GetProfile() const OVERRIDE { return profile_; }
53 virtual std::string GetAppId() const OVERRIDE { return app_id_; }
54
55 private:
56 Profile* profile_;
57 std::string app_id_;
58 };
tapted 2013/05/23 02:29:39 DISALLOW_COPY_AND_ASSIGN ?
jackhou1 2013/05/23 06:10:19 Done.
59
60 class ExtensionAppShimHandlerTest : public testing::Test {
61 protected:
62 ExtensionAppShimHandlerTest() : host_(&profile_, kTestAppId) {}
63
64 TestingExtensionAppShimHandler handler_;
65 TestingProfile profile_;
66 FakeHost host_;
67
68 private:
69 virtual void SetUp() OVERRIDE {
70 testing::Test::SetUp();
71 }
72
73 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest);
74 };
75
76 TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) {
77 handler_.set_fails_launch(true);
78 EXPECT_EQ(false, handler_.OnShimLaunch(&host_));
79 EXPECT_FALSE(handler_.FindObserverList(&profile_, kTestAppId));
80
81 handler_.set_fails_launch(false);
82 EXPECT_EQ(true, handler_.OnShimLaunch(&host_));
83 EXPECT_TRUE(handler_.FindObserverList(&profile_, kTestAppId)->
84 HasObserver(&host_));
85 EXPECT_TRUE(handler_.GetRegistrar()->IsRegistered(
86 &handler_,
87 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
88 content::Source<Profile>(&profile_)));
89
90 handler_.OnShimClose(&host_);
91 EXPECT_FALSE(handler_.FindObserverList(&profile_, kTestAppId));
92 }
93
94 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698