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

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: Add default handler to AppShimHandler. Fix test. 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 "apps/app_shim/app_shim_messages.h"
9 #include "base/memory/scoped_vector.h"
10 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/browser/notification_service.h"
13 #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.
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace {
17
18 class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
19 public:
20 explicit TestingExtensionAppShimHandler() : fails_launch_(false) {}
21 virtual ~TestingExtensionAppShimHandler() {}
22
23 void set_fails_launch(bool fails_launch) {
24 fails_launch_ = fails_launch;
25 }
26
27 HostMap::mapped_type PublicGetObserverList(Profile* profile,
28 const std::string& app_id) {
29 return GetObserverList(profile, app_id, false);
30 }
31
32 content::NotificationRegistrar* GetRegistrar() { return &registrar_; }
33
34 protected:
35 virtual bool LaunchApp(Profile* profile, const std::string& app_id) OVERRIDE {
36 return !fails_launch_;
37 }
38
39 private:
40 bool fails_launch_;
41
42 DISALLOW_COPY_AND_ASSIGN(TestingExtensionAppShimHandler);
43 };
44
45 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
46
47 class FakeAppShimHost : public AppShimHost {
48 public:
49 FakeAppShimHost() : profile_(new TestingProfile),
50 app_id_(kTestAppId) {}
51
52 virtual void OnAppClosed() OVERRIDE { }
tapted 2013/05/21 06:15:37 nit: no space between curlies
jackhou1 2013/05/22 23:54:44 Done.
53 virtual Profile* profile() const OVERRIDE { return profile_.get(); }
54 virtual const std::string& app_id() const OVERRIDE { return app_id_; }
55
56 private:
57 scoped_ptr<TestingProfile> profile_;
58 std::string app_id_;
59 };
tapted 2013/05/21 06:15:37 nit: DISALLOW_COPY_AND_ASSIGN(..)
jackhou1 2013/05/22 23:54:44 Done.
60
61 class ExtensionAppShimHandlerTest : public testing::Test {
62 protected:
63 ExtensionAppShimHandlerTest() {}
64
65 TestingExtensionAppShimHandler* handler() { return handler_.get(); }
66 FakeAppShimHost* host() { return host_.get(); }
67
68 private:
69 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.
70 handler_.reset(new TestingExtensionAppShimHandler());
71 host_.reset(new FakeAppShimHost());
72 }
73
74 scoped_ptr<TestingExtensionAppShimHandler> handler_;
75 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.
76
77 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest);
78 };
79
80 } // namespace
81
82 TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) {
83 handler()->set_fails_launch(true);
84 EXPECT_EQ(false, handler()->OnShimLaunch(host()));
85 EXPECT_FALSE(handler()->PublicGetObserverList(host()->profile(),
86 host()->app_id()));
87
88 handler()->set_fails_launch(false);
89 EXPECT_EQ(true, handler()->OnShimLaunch(host()));
90 EXPECT_TRUE(handler()->PublicGetObserverList(
91 host()->profile(), host()->app_id())->HasObserver(host()));
92 EXPECT_TRUE(handler()->GetRegistrar()->IsRegistered(
93 handler(),
94 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
95 content::Source<Profile>(host()->profile())));
96
97 handler()->OnShimClose(host());
98 EXPECT_FALSE(handler()->PublicGetObserverList(
99 host()->profile(), host()->app_id())->HasObserver(host()));
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698