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

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

Issue 12623005: [mac] App shims (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: -> _mac Created 7 years, 9 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
« no previous file with comments | « apps/app_shim/app_shim_host_mac.cc ('k') | apps/app_shim/app_shim_host_manager_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/app_shim_host_mac.h"
6
7 #include "apps/app_shim/app_shim_messages.h"
8 #include "base/memory/scoped_vector.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "ipc/ipc_message.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 class TestingAppShimHost : public AppShimHost {
14 public:
15 explicit TestingAppShimHost(Profile* profile);
16 virtual ~TestingAppShimHost() {}
17
18 bool ReceiveMessage(IPC::Message* message);
19
20 const std::vector<IPC::Message*>& sent_messages() {
21 return sent_messages_.get();
22 }
23
24 void set_fails_profile(bool fails_profile) {
25 fails_profile_ = fails_profile;
26 }
27
28 void set_fails_launch(bool fails_launch) {
29 fails_launch_ = fails_launch;
30 }
31
32 protected:
33 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir)
34 OVERRIDE;
35 virtual bool LaunchApp(Profile* profile, const std::string& app_id) OVERRIDE;
36
37 virtual bool Send(IPC::Message* message) OVERRIDE;
38
39 Profile* test_profile_;
40 bool fails_profile_;
41 bool fails_launch_;
42
43 ScopedVector<IPC::Message> sent_messages_;
44
45 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost);
46 };
47
48 TestingAppShimHost::TestingAppShimHost(Profile* profile)
49 : test_profile_(profile),
50 fails_profile_(false),
51 fails_launch_(false) {
52 }
53
54 bool TestingAppShimHost::ReceiveMessage(IPC::Message* message) {
55 bool handled = OnMessageReceived(*message);
56 delete message;
57 return handled;
58 }
59
60 bool TestingAppShimHost::Send(IPC::Message* message) {
61 sent_messages_.push_back(message);
62 return true;
63 }
64
65 Profile* TestingAppShimHost::FetchProfileForDirectory(
66 const std::string& profile_dir) {
67 return fails_profile_ ? NULL : test_profile_;
68 }
69
70 bool TestingAppShimHost::LaunchApp(
71 Profile* profile, const std::string& app_id) {
72 return !fails_launch_;
73 }
74
75 class AppShimHostTest : public testing::Test {
76 public:
77 TestingAppShimHost* host() { return host_.get(); }
78 TestingProfile* profile() { return profile_.get(); }
79
80 bool LaunchWasSuccessful() {
81 EXPECT_EQ(1u, host()->sent_messages().size());
82 IPC::Message* message = host()->sent_messages()[0];
83 EXPECT_EQ(AppShimMsg_LaunchApp_Done::ID, message->type());
84 AppShimMsg_LaunchApp_Done::Param param;
85 AppShimMsg_LaunchApp_Done::Read(message, &param);
86 return param.a;
87 }
88
89 private:
90 virtual void SetUp() OVERRIDE {
91 profile_.reset(new TestingProfile);
92 host_.reset(new TestingAppShimHost(profile()));
93 }
94
95 scoped_ptr<TestingAppShimHost> host_;
96 scoped_ptr<TestingProfile> profile_;
97 };
98
99 static const std::string kTestAppId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
100 static const std::string kTestProfileDir = "Default";
101
102 TEST_F(AppShimHostTest, TestLaunchApp) {
103 host()->ReceiveMessage(
104 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId));
105 ASSERT_EQ(kTestAppId, host()->app_id());
106 ASSERT_EQ(profile(), host()->profile());
107 ASSERT_TRUE(LaunchWasSuccessful());
108 }
109
110 TEST_F(AppShimHostTest, TestFailProfile) {
111 host()->set_fails_profile(true);
112 host()->ReceiveMessage(
113 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId));
114 ASSERT_TRUE(host()->app_id().empty());
115 ASSERT_FALSE(LaunchWasSuccessful());
116 }
117
118 TEST_F(AppShimHostTest, TestFailLaunch) {
119 host()->set_fails_launch(true);
120 host()->ReceiveMessage(
121 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId));
122 ASSERT_TRUE(host()->app_id().empty());
123 ASSERT_FALSE(LaunchWasSuccessful());
124 }
OLDNEW
« no previous file with comments | « apps/app_shim/app_shim_host_mac.cc ('k') | apps/app_shim/app_shim_host_manager_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698