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

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

Issue 14579006: Start app shim when app launched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 7 years, 6 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/extension_app_shim_handler_mac.cc ('k') | chrome/app/chrome_main_app_mode_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "apps/app_shim/extension_app_shim_handler_mac.h" 5 #include "apps/app_shim/extension_app_shim_handler_mac.h"
6 6
7 #include "apps/app_shim/app_shim_host_mac.h" 7 #include "apps/app_shim/app_shim_host_mac.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/common/chrome_notification_types.h" 9 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 13 matching lines...) Expand all
24 24
25 AppShimHandler::Host* FindHost(Profile* profile, 25 AppShimHandler::Host* FindHost(Profile* profile,
26 const std::string& app_id) { 26 const std::string& app_id) {
27 HostMap::const_iterator it = hosts().find(make_pair(profile, app_id)); 27 HostMap::const_iterator it = hosts().find(make_pair(profile, app_id));
28 return it == hosts().end() ? NULL : it->second; 28 return it == hosts().end() ? NULL : it->second;
29 } 29 }
30 30
31 content::NotificationRegistrar& GetRegistrar() { return registrar(); } 31 content::NotificationRegistrar& GetRegistrar() { return registrar(); }
32 32
33 protected: 33 protected:
34 virtual bool LaunchApp(Profile* profile, const std::string& app_id) OVERRIDE { 34 virtual bool LaunchApp(Profile* profile,
35 const std::string& app_id,
36 AppShimLaunchType launch_type) OVERRIDE {
35 return !fails_launch_; 37 return !fails_launch_;
36 } 38 }
37 39
38 private: 40 private:
39 bool fails_launch_; 41 bool fails_launch_;
40 42
41 DISALLOW_COPY_AND_ASSIGN(TestingExtensionAppShimHandler); 43 DISALLOW_COPY_AND_ASSIGN(TestingExtensionAppShimHandler);
42 }; 44 };
43 45
44 const char kTestAppIdA[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 46 const char kTestAppIdA[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 FakeHost host_bb_; 91 FakeHost host_bb_;
90 FakeHost host_aa_duplicate_; 92 FakeHost host_aa_duplicate_;
91 93
92 private: 94 private:
93 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest); 95 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest);
94 }; 96 };
95 97
96 TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) { 98 TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) {
97 // If launch fails, the host is not added to the map. 99 // If launch fails, the host is not added to the map.
98 handler_->set_fails_launch(true); 100 handler_->set_fails_launch(true);
99 EXPECT_EQ(false, handler_->OnShimLaunch(&host_aa_)); 101 EXPECT_EQ(false, handler_->OnShimLaunch(&host_aa_, APP_SHIM_LAUNCH_NORMAL));
100 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA)); 102 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA));
101 103
102 // Normal startup. 104 // Normal startup.
103 handler_->set_fails_launch(false); 105 handler_->set_fails_launch(false);
104 EXPECT_EQ(true, handler_->OnShimLaunch(&host_aa_)); 106 EXPECT_EQ(true, handler_->OnShimLaunch(&host_aa_, APP_SHIM_LAUNCH_NORMAL));
105 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); 107 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA));
106 EXPECT_TRUE(handler_->GetRegistrar().IsRegistered( 108 EXPECT_TRUE(handler_->GetRegistrar().IsRegistered(
107 handler_.get(), 109 handler_.get(),
108 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 110 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
109 content::Source<Profile>(&profile_a_))); 111 content::Source<Profile>(&profile_a_)));
110 EXPECT_EQ(true, handler_->OnShimLaunch(&host_ab_)); 112 EXPECT_EQ(true, handler_->OnShimLaunch(&host_ab_, APP_SHIM_LAUNCH_NORMAL));
111 EXPECT_EQ(&host_ab_, handler_->FindHost(&profile_a_, kTestAppIdB)); 113 EXPECT_EQ(&host_ab_, handler_->FindHost(&profile_a_, kTestAppIdB));
112 EXPECT_EQ(true, handler_->OnShimLaunch(&host_bb_)); 114 EXPECT_EQ(true, handler_->OnShimLaunch(&host_bb_, APP_SHIM_LAUNCH_NORMAL));
113 EXPECT_EQ(&host_bb_, handler_->FindHost(&profile_b_, kTestAppIdB)); 115 EXPECT_EQ(&host_bb_, handler_->FindHost(&profile_b_, kTestAppIdB));
114 EXPECT_TRUE(handler_->GetRegistrar().IsRegistered( 116 EXPECT_TRUE(handler_->GetRegistrar().IsRegistered(
115 handler_.get(), 117 handler_.get(),
116 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, 118 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
117 content::Source<Profile>(&profile_b_))); 119 content::Source<Profile>(&profile_b_)));
118 120
119 // Starting and closing a second host does nothing. 121 // Starting and closing a second host does nothing.
120 EXPECT_EQ(false, handler_->OnShimLaunch(&host_aa_duplicate_)); 122 EXPECT_EQ(false, handler_->OnShimLaunch(&host_aa_duplicate_,
123 APP_SHIM_LAUNCH_NORMAL));
121 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); 124 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA));
122 handler_->OnShimClose(&host_aa_duplicate_); 125 handler_->OnShimClose(&host_aa_duplicate_);
123 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); 126 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA));
124 127
125 // Normal close. 128 // Normal close.
126 handler_->OnShimClose(&host_aa_); 129 handler_->OnShimClose(&host_aa_);
127 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA)); 130 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA));
128 131
129 // Closing the second host afterward does nothing. 132 // Closing the second host afterward does nothing.
130 handler_->OnShimClose(&host_aa_duplicate_); 133 handler_->OnShimClose(&host_aa_duplicate_);
131 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA)); 134 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA));
132 135
133 // Destruction sends OnAppClose to remaining hosts. 136 // Destruction sends OnAppClose to remaining hosts.
134 handler_.reset(); 137 handler_.reset();
135 EXPECT_EQ(1, host_ab_.close_count()); 138 EXPECT_EQ(1, host_ab_.close_count());
136 EXPECT_EQ(1, host_bb_.close_count()); 139 EXPECT_EQ(1, host_bb_.close_count());
137 } 140 }
138 141
139 } // namespace apps 142 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_shim/extension_app_shim_handler_mac.cc ('k') | chrome/app/chrome_main_app_mode_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698