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

Side by Side Diff: chrome/browser/ui/views/ash/launcher/launcher_updater_unittest.cc

Issue 9702054: Revert 126764 - Added notion of currently active app / browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/ash/launcher/launcher_updater.h" 5 #include "chrome/browser/ui/views/ash/launcher/launcher_updater.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/launcher/launcher_model.h" 10 #include "ash/launcher/launcher_model.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
13 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h" 13 #include "chrome/browser/ui/views/ash/launcher/chrome_launcher_delegate.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 14 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/tabs/test_tab_strip_model_delegate.h" 15 #include "chrome/browser/tabs/test_tab_strip_model_delegate.h"
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "content/browser/tab_contents/test_tab_contents.h" 18 #include "content/browser/tab_contents/test_tab_contents.h"
19 #include "content/test/test_browser_thread.h" 19 #include "content/test/test_browser_thread.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/aura/client/activation_delegate.h"
23 #include "ui/aura/test/test_activation_client.h"
24 #include "ui/aura/test/test_window_delegate.h"
25 #include "ui/aura/root_window.h"
26 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
27 #include "ui/aura/window_delegate.h"
28 23
29 namespace { 24 namespace {
30 25
31 // Test implementation of AppIconLoader. 26 // Test implementation of AppIconLoader.
32 class AppIconLoaderImpl : public ChromeLauncherDelegate::AppIconLoader { 27 class AppIconLoaderImpl : public ChromeLauncherDelegate::AppIconLoader {
33 public: 28 public:
34 AppIconLoaderImpl() : fetch_count_(0) {} 29 AppIconLoaderImpl() : fetch_count_(0) {}
35 virtual ~AppIconLoaderImpl() {} 30 virtual ~AppIconLoaderImpl() {}
36 31
37 // Sets the id for the specified tab. The id is removed if Remove() is 32 // Sets the id for the specified tab. The id is removed if Remove() is
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 private: 70 private:
76 typedef std::map<TabContentsWrapper*, std::string> TabToStringMap; 71 typedef std::map<TabContentsWrapper*, std::string> TabToStringMap;
77 72
78 TabToStringMap tab_id_map_; 73 TabToStringMap tab_id_map_;
79 74
80 int fetch_count_; 75 int fetch_count_;
81 76
82 DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl); 77 DISALLOW_COPY_AND_ASSIGN(AppIconLoaderImpl);
83 }; 78 };
84 79
80 // Contains all the objects needed to create a LauncherUpdater.
81 struct State {
82 State(Profile* profile,
83 ChromeLauncherDelegate* launcher_delegate,
84 const std::string& app_id,
85 LauncherUpdater::Type launcher_type)
86 : window(NULL),
87 tab_strip(&tab_strip_delegate, profile),
88 updater(&window, &tab_strip, launcher_delegate, launcher_type,
89 app_id) {
90 updater.Init();
91 }
92
93 aura::Window window;
94 TestTabStripModelDelegate tab_strip_delegate;
95 TabStripModel tab_strip;
96 LauncherUpdater updater;
97
98 private:
99 DISALLOW_COPY_AND_ASSIGN(State);
100 };
101
85 } // namespace 102 } // namespace
86 103
87 class LauncherUpdaterTest : public ChromeRenderViewHostTestHarness { 104 class LauncherUpdaterTest : public ChromeRenderViewHostTestHarness {
88 public: 105 public:
89 LauncherUpdaterTest() 106 LauncherUpdaterTest()
90 : browser_thread_(content::BrowserThread::UI, &message_loop_) { 107 : browser_thread_(content::BrowserThread::UI, &message_loop_) {
91 } 108 }
92 109
93 virtual void SetUp() OVERRIDE { 110 virtual void SetUp() OVERRIDE {
94 ChromeRenderViewHostTestHarness::SetUp(); 111 ChromeRenderViewHostTestHarness::SetUp();
95
96 activation_client_.reset(
97 new aura::test::TestActivationClient(root_window()));
98 launcher_model_.reset(new ash::LauncherModel); 112 launcher_model_.reset(new ash::LauncherModel);
99 launcher_delegate_.reset( 113 launcher_delegate_.reset(
100 new ChromeLauncherDelegate(profile(), launcher_model_.get())); 114 new ChromeLauncherDelegate(profile(), launcher_model_.get()));
101 app_icon_loader_ = new AppIconLoaderImpl; 115 app_icon_loader_ = new AppIconLoaderImpl;
102 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); 116 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_);
103 launcher_delegate_->Init(); 117 launcher_delegate_->Init();
104 } 118 }
105 119
106 protected: 120 protected:
107 // Contains all the objects needed to create a LauncherUpdater.
108 struct State : public aura::client::ActivationDelegate {
109 public:
110 State(LauncherUpdaterTest* test,
111 const std::string& app_id,
112 LauncherUpdater::Type launcher_type)
113 : launcher_test(test),
114 window(NULL),
115 tab_strip(&tab_strip_delegate, test->profile()),
116 updater(&window,
117 &tab_strip,
118 test->launcher_delegate_.get(),
119 launcher_type,
120 app_id) {
121 window.Init(ui::Layer::LAYER_NOT_DRAWN);
122 launcher_test->root_window()->AddChild(&window);
123 launcher_test->activation_client_->ActivateWindow(&window);
124 updater.Init();
125 aura::client::SetActivationDelegate(&window, this);
126 }
127
128 ash::LauncherItem GetUpdaterItem() {
129 ash::LauncherID launcher_id =
130 LauncherUpdater::TestApi(&updater).item_id();
131 int index = launcher_test->launcher_model_->ItemIndexByID(launcher_id);
132 return launcher_test->launcher_model_->items()[index];
133 }
134
135 // aura::client::ActivationDelegate overrides.
136 virtual bool ShouldActivate(aura::Event* event) { return true; }
137 virtual void OnActivated() {
138 updater.BrowserActivationStateChanged();
139 }
140 virtual void OnLostActive() {
141 updater.BrowserActivationStateChanged();
142 }
143
144 LauncherUpdaterTest* launcher_test;
145 aura::Window window;
146 TestTabStripModelDelegate tab_strip_delegate;
147 TabStripModel tab_strip;
148 LauncherUpdater updater;
149
150 private:
151 DISALLOW_COPY_AND_ASSIGN(State);
152 };
153
154 LauncherUpdater* GetUpdaterByID(ash::LauncherID id) const { 121 LauncherUpdater* GetUpdaterByID(ash::LauncherID id) const {
155 return launcher_delegate_->id_to_item_map_[id].updater; 122 return launcher_delegate_->id_to_item_map_[id].updater;
156 } 123 }
157 124
158 const std::string& GetAppID(ash::LauncherID id) const { 125 const std::string& GetAppID(ash::LauncherID id) const {
159 return launcher_delegate_->id_to_item_map_[id].app_id; 126 return launcher_delegate_->id_to_item_map_[id].app_id;
160 } 127 }
161 128
162 void ResetAppIconLoader() { 129 void ResetAppIconLoader() {
163 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); 130 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_);
164 } 131 }
165 132
166 void UnpinAppsWithID(const std::string& app_id) { 133 void UnpinAppsWithID(const std::string& app_id) {
167 launcher_delegate_->UnpinAppsWithID(app_id); 134 launcher_delegate_->UnpinAppsWithID(app_id);
168 } 135 }
169 136
170 ash::LauncherItem GetItem(LauncherUpdater& updater,
171 TabContentsWrapper* tab) {
172 LauncherUpdater::TestApi test_api(&updater);
173 ash::LauncherID launcher_id = test_api.GetLauncherID(tab);
174 int index = launcher_model_->ItemIndexByID(launcher_id);
175 return launcher_model_->items()[index];
176 }
177
178 scoped_ptr<ash::LauncherModel> launcher_model_; 137 scoped_ptr<ash::LauncherModel> launcher_model_;
179 scoped_ptr<ChromeLauncherDelegate> launcher_delegate_; 138 scoped_ptr<ChromeLauncherDelegate> launcher_delegate_;
180 139
181 // Owned by LauncherUpdater. 140 // Owned by LauncherUpdater.
182 AppIconLoaderImpl* app_icon_loader_; 141 AppIconLoaderImpl* app_icon_loader_;
183 142
184 scoped_ptr<aura::test::TestActivationClient> activation_client_;
185
186 private: 143 private:
187 content::TestBrowserThread browser_thread_; 144 content::TestBrowserThread browser_thread_;
188 std::vector<State*> states;
189 145
190 DISALLOW_COPY_AND_ASSIGN(LauncherUpdaterTest); 146 DISALLOW_COPY_AND_ASSIGN(LauncherUpdaterTest);
191 }; 147 };
192 148
193 // Verifies a new launcher item is added for TYPE_TABBED. 149 // Verifies a new launcher item is added for TYPE_TABBED.
194 TEST_F(LauncherUpdaterTest, TabbedSetup) { 150 TEST_F(LauncherUpdaterTest, TabbedSetup) {
195 size_t initial_size = launcher_model_->items().size(); 151 size_t initial_size = launcher_model_->items().size();
196 { 152 {
197 TabContentsWrapper wrapper(CreateTestTabContents()); 153 TabContentsWrapper wrapper(CreateTestTabContents());
198 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 154 State state(profile(), launcher_delegate_.get(), std::string(),
199 155 LauncherUpdater::TYPE_TABBED);
200 // Since the type is tabbed and there is nothing in the tabstrip an item 156 // Since the type is tabbed and there is nothing in the tabstrip an item
201 // should not have been added. 157 // should not have been added.
202 EXPECT_EQ(initial_size, launcher_model_->items().size()); 158 EXPECT_EQ(initial_size, launcher_model_->items().size());
203 159
204 // Add a tab. 160 // Add a tab.
205 state.tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE); 161 state.tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_NONE);
206 162
207 // There should be one more item. 163 // There should be one more item.
208 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 164 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
209 // New item should be added at the end. 165 // New item should be added at the end.
210 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 166 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
211 } 167 }
212 // Deleting the LauncherUpdater should have removed the item. 168 // Deleting the LauncherUpdater should have removed the item.
213 ASSERT_EQ(initial_size, launcher_model_->items().size()); 169 ASSERT_EQ(initial_size, launcher_model_->items().size());
214 170
215 // Do the same, but this time add the tab first. 171 // Do the same, but this time add the tab first.
216 { 172 {
217 TabContentsWrapper wrapper(CreateTestTabContents()); 173 TabContentsWrapper wrapper(CreateTestTabContents());
218 174
219 TestTabStripModelDelegate tab_strip_delegate; 175 TestTabStripModelDelegate tab_strip_delegate;
220 TabStripModel tab_strip(&tab_strip_delegate, profile()); 176 TabStripModel tab_strip(&tab_strip_delegate, profile());
221 tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE); 177 tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_NONE);
222 aura::Window window(NULL); 178 LauncherUpdater updater(NULL, &tab_strip, launcher_delegate_.get(),
223 window.Init(ui::Layer::LAYER_NOT_DRAWN);
224 root_window()->AddChild(&window);
225 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(),
226 LauncherUpdater::TYPE_TABBED, std::string()); 179 LauncherUpdater::TYPE_TABBED, std::string());
227 updater.Init(); 180 updater.Init();
228 181
229 // There should be one more item. 182 // There should be one more item.
230 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 183 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
231 // New item should be added at the end. 184 // New item should be added at the end.
232 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 185 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
233 } 186 }
234 } 187 }
235 188
236 // Verifies a new launcher item is added for TYPE_APP. 189 // Verifies a new launcher item is added for TYPE_APP.
237 TEST_F(LauncherUpdaterTest, AppSetup) { 190 TEST_F(LauncherUpdaterTest, AppSetup) {
238 size_t initial_size = launcher_model_->items().size(); 191 size_t initial_size = launcher_model_->items().size();
239 { 192 {
240 State state(this, std::string(), LauncherUpdater::TYPE_APP); 193 State state(profile(), launcher_delegate_.get(), std::string(),
194 LauncherUpdater::TYPE_APP);
241 // There should be one more item. 195 // There should be one more item.
242 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 196 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
243 // New item should be added at the end. 197 // New item should be added at the end.
244 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 198 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
245 } 199 }
246 // Deleting the LauncherUpdater should have removed the item. 200 // Deleting the LauncherUpdater should have removed the item.
247 ASSERT_EQ(initial_size, launcher_model_->items().size()); 201 ASSERT_EQ(initial_size, launcher_model_->items().size());
248 } 202 }
249 203
250 // Various assertions when adding/removing a tab that has an app associated with 204 // Various assertions when adding/removing a tab that has an app associated with
251 // it. 205 // it.
252 TEST_F(LauncherUpdaterTest, TabbedWithApp) { 206 TEST_F(LauncherUpdaterTest, TabbedWithApp) {
253 size_t initial_size = launcher_model_->items().size(); 207 size_t initial_size = launcher_model_->items().size();
254 { 208 {
255 TabContentsWrapper initial_tab(CreateTestTabContents()); 209 TabContentsWrapper initial_tab(CreateTestTabContents());
256 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 210 State state(profile(), launcher_delegate_.get(), std::string(),
211 LauncherUpdater::TYPE_TABBED);
257 // Add a tab. 212 // Add a tab.
258 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 213 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
259 TabStripModel::ADD_ACTIVE); 214 TabStripModel::ADD_NONE);
260 215
261 // There should be one more item. 216 // There should be one more item.
262 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 217 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
263 // New item should be added at the end. 218 // New item should be added at the end.
264 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 219 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
265 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; 220 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id;
266 221
267 // Add another tab, configure it so that the launcher thinks it's an app. 222 // Add another tab, configure it so that the launcher thinks it's an app.
268 TabContentsWrapper app_tab(CreateTestTabContents()); 223 TabContentsWrapper app_tab(CreateTestTabContents());
269 app_icon_loader_->SetAppID(&app_tab, "1"); 224 app_icon_loader_->SetAppID(&app_tab, "1");
(...skipping 18 matching lines...) Expand all
288 launcher_model_->items()[initial_size].type); 243 launcher_model_->items()[initial_size].type);
289 244
290 } 245 }
291 // Deleting the LauncherUpdater should have removed the item. 246 // Deleting the LauncherUpdater should have removed the item.
292 ASSERT_EQ(initial_size, launcher_model_->items().size()); 247 ASSERT_EQ(initial_size, launcher_model_->items().size());
293 } 248 }
294 249
295 TEST_F(LauncherUpdaterTest, TabbedWithAppOnCreate) { 250 TEST_F(LauncherUpdaterTest, TabbedWithAppOnCreate) {
296 size_t initial_size = launcher_model_->items().size(); 251 size_t initial_size = launcher_model_->items().size();
297 aura::Window window(NULL); 252 aura::Window window(NULL);
298 window.Init(ui::Layer::LAYER_NOT_DRAWN);
299 root_window()->AddChild(&window);
300 TestTabStripModelDelegate tab_strip_delegate; 253 TestTabStripModelDelegate tab_strip_delegate;
301 TabStripModel tab_strip(&tab_strip_delegate, profile()); 254 TabStripModel tab_strip(&tab_strip_delegate, profile());
302 TabContentsWrapper app_tab(CreateTestTabContents()); 255 TabContentsWrapper app_tab(CreateTestTabContents());
303 app_icon_loader_->SetAppID(&app_tab, "1"); 256 app_icon_loader_->SetAppID(&app_tab, "1");
304 tab_strip.InsertTabContentsAt(0, &app_tab, TabStripModel::ADD_ACTIVE); 257 tab_strip.InsertTabContentsAt(0, &app_tab, TabStripModel::ADD_NONE);
305 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(), 258 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(),
306 LauncherUpdater::TYPE_TABBED, std::string()); 259 LauncherUpdater::TYPE_TABBED, std::string());
307 updater.Init(); 260 updater.Init();
308 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 261 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
309 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 262 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
310 } 263 }
311 264
312 // Verifies transitioning from a normal tab to app tab and back works. 265 // Verifies transitioning from a normal tab to app tab and back works.
313 TEST_F(LauncherUpdaterTest, ChangeToApp) { 266 TEST_F(LauncherUpdaterTest, ChangeToApp) {
314 size_t initial_size = launcher_model_->items().size(); 267 size_t initial_size = launcher_model_->items().size();
315 { 268 {
316 TabContentsWrapper initial_tab(CreateTestTabContents()); 269 TabContentsWrapper initial_tab(CreateTestTabContents());
317 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 270 State state(profile(), launcher_delegate_.get(), std::string(),
271 LauncherUpdater::TYPE_TABBED);
318 // Add a tab. 272 // Add a tab.
319 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 273 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
320 TabStripModel::ADD_ACTIVE); 274 TabStripModel::ADD_NONE);
321 275
322 // There should be one more item. 276 // There should be one more item.
323 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 277 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
324 // New item should be added at the end. 278 // New item should be added at the end.
325 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 279 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
326 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; 280 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id;
327 281
328 app_icon_loader_->SetAppID(&initial_tab, "1"); 282 app_icon_loader_->SetAppID(&initial_tab, "1");
329 // Triggers LauncherUpdater seeing the tab changed to an app. 283 // Triggers LauncherUpdater seeing the tab changed to an app.
330 state.updater.TabChangedAt(&initial_tab, 0, TabStripModelObserver::ALL); 284 state.updater.TabChangedAt(&initial_tab, 0, TabStripModelObserver::ALL);
(...skipping 10 matching lines...) Expand all
341 } 295 }
342 // Deleting the LauncherUpdater should have removed the item. 296 // Deleting the LauncherUpdater should have removed the item.
343 ASSERT_EQ(initial_size, launcher_model_->items().size()); 297 ASSERT_EQ(initial_size, launcher_model_->items().size());
344 } 298 }
345 299
346 // Verifies AppIconLoader is queried appropriately. 300 // Verifies AppIconLoader is queried appropriately.
347 TEST_F(LauncherUpdaterTest, QueryAppIconLoader) { 301 TEST_F(LauncherUpdaterTest, QueryAppIconLoader) {
348 size_t initial_size = launcher_model_->items().size(); 302 size_t initial_size = launcher_model_->items().size();
349 { 303 {
350 TabContentsWrapper initial_tab(CreateTestTabContents()); 304 TabContentsWrapper initial_tab(CreateTestTabContents());
351 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 305 State state(profile(), launcher_delegate_.get(), std::string(),
306 LauncherUpdater::TYPE_TABBED);
352 // Configure the tab as an app. 307 // Configure the tab as an app.
353 app_icon_loader_->SetAppID(&initial_tab, "1"); 308 app_icon_loader_->SetAppID(&initial_tab, "1");
354 // Add a tab. 309 // Add a tab.
355 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 310 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
356 TabStripModel::ADD_ACTIVE); 311 TabStripModel::ADD_NONE);
357 // AppIconLoader should have been queried. 312 // AppIconLoader should have been queried.
358 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); 313 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0);
359 // Remove the tab. 314 // Remove the tab.
360 state.tab_strip.DetachTabContentsAt(0); 315 state.tab_strip.DetachTabContentsAt(0);
361 } 316 }
362 // Deleting the LauncherUpdater should have removed the item. 317 // Deleting the LauncherUpdater should have removed the item.
363 ASSERT_EQ(initial_size, launcher_model_->items().size()); 318 ASSERT_EQ(initial_size, launcher_model_->items().size());
364 } 319 }
365 320
366 // Verifies SetAppImage works. 321 // Verifies SetAppImage works.
367 TEST_F(LauncherUpdaterTest, SetAppImage) { 322 TEST_F(LauncherUpdaterTest, SetAppImage) {
368 size_t initial_size = launcher_model_->items().size(); 323 size_t initial_size = launcher_model_->items().size();
369 TabContentsWrapper initial_tab(CreateTestTabContents()); 324 TabContentsWrapper initial_tab(CreateTestTabContents());
370 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 325 State state(profile(), launcher_delegate_.get(), std::string(),
326 LauncherUpdater::TYPE_TABBED);
371 // Configure the tab as an app. 327 // Configure the tab as an app.
372 app_icon_loader_->SetAppID(&initial_tab, "1"); 328 app_icon_loader_->SetAppID(&initial_tab, "1");
373 // Add a tab. 329 // Add a tab.
374 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 330 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
375 TabStripModel::ADD_ACTIVE); 331 TabStripModel::ADD_NONE);
376 SkBitmap image; 332 SkBitmap image;
377 image.setConfig(SkBitmap::kARGB_8888_Config, 2, 3); 333 image.setConfig(SkBitmap::kARGB_8888_Config, 2, 3);
378 image.allocPixels(); 334 image.allocPixels();
379 launcher_delegate_->SetAppImage("1", &image); 335 launcher_delegate_->SetAppImage("1", &image);
380 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 336 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
381 EXPECT_EQ(2, launcher_model_->items()[initial_size].image.width()); 337 EXPECT_EQ(2, launcher_model_->items()[initial_size].image.width());
382 EXPECT_EQ(3, launcher_model_->items()[initial_size].image.height()); 338 EXPECT_EQ(3, launcher_model_->items()[initial_size].image.height());
383 } 339 }
384 340
385 // Verifies app tabs are added right after the existing tabbed item. 341 // Verifies app tabs are added right after the existing tabbed item.
386 TEST_F(LauncherUpdaterTest, AddAppAfterTabbed) { 342 TEST_F(LauncherUpdaterTest, AddAppAfterTabbed) {
387 size_t initial_size = launcher_model_->items().size(); 343 size_t initial_size = launcher_model_->items().size();
388 TabContentsWrapper tab1(CreateTestTabContents()); 344 TabContentsWrapper tab1(CreateTestTabContents());
389 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 345 State state1(profile(), launcher_delegate_.get(), std::string(),
346 LauncherUpdater::TYPE_TABBED);
390 // Add a tab. 347 // Add a tab.
391 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 348 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
392 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 349 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
393 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; 350 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id;
394 351
395 // Create another LauncherUpdater. 352 // Create another LauncherUpdater.
396 State state2(this, std::string(), LauncherUpdater::TYPE_APP); 353 State state2(profile(), launcher_delegate_.get(), std::string(),
354 LauncherUpdater::TYPE_APP);
397 355
398 // Should be two extra items. 356 // Should be two extra items.
399 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); 357 EXPECT_EQ(initial_size + 2, launcher_model_->items().size());
400 358
401 // Add an app tab to state1, it should go after the item for state1 but 359 // Add an app tab to state1, it should go after the item for state1 but
402 // before the item for state2. 360 // before the item for state2.
403 int next_id = launcher_model_->next_id(); 361 int next_id = launcher_model_->next_id();
404 TabContentsWrapper app_tab(CreateTestTabContents()); 362 TabContentsWrapper app_tab(CreateTestTabContents());
405 app_icon_loader_->SetAppID(&app_tab, "1"); 363 app_icon_loader_->SetAppID(&app_tab, "1");
406 state1.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_ACTIVE); 364 state1.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_NONE);
407 365
408 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); 366 ASSERT_EQ(initial_size + 3, launcher_model_->items().size());
409 EXPECT_EQ(next_id, launcher_model_->items()[initial_size + 1].id); 367 EXPECT_EQ(next_id, launcher_model_->items()[initial_size + 1].id);
410 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); 368 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type);
411 369
412 // Remove the non-app tab. 370 // Remove the non-app tab.
413 state1.tab_strip.DetachTabContentsAt(0); 371 state1.tab_strip.DetachTabContentsAt(0);
414 // Should have removed one item. 372 // Should have removed one item.
415 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); 373 EXPECT_EQ(initial_size + 2, launcher_model_->items().size());
416 EXPECT_EQ(-1, launcher_model_->ItemIndexByID(tabbed_id)); 374 EXPECT_EQ(-1, launcher_model_->ItemIndexByID(tabbed_id));
417 next_id = launcher_model_->next_id(); 375 next_id = launcher_model_->next_id();
418 // Add the non-app tab back. It should go to the original position (but get a 376 // Add the non-app tab back. It should go to the original position (but get a
419 // new id). 377 // new id).
420 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); 378 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
421 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); 379 ASSERT_EQ(initial_size + 3, launcher_model_->items().size());
422 EXPECT_EQ(next_id, launcher_model_->items()[initial_size].id); 380 EXPECT_EQ(next_id, launcher_model_->items()[initial_size].id);
423 } 381 }
424 382
425 // Verifies GetWindowAndTabByID works. 383 // Verifies GetWindowAndTabByID works.
426 TEST_F(LauncherUpdaterTest, GetUpdaterByID) { 384 TEST_F(LauncherUpdaterTest, GetUpdaterByID) {
427 size_t initial_size = launcher_model_->items().size(); 385 size_t initial_size = launcher_model_->items().size();
428 TabContentsWrapper tab1(CreateTestTabContents()); 386 TabContentsWrapper tab1(CreateTestTabContents());
429 TabContentsWrapper tab2(CreateTestTabContents()); 387 TabContentsWrapper tab2(CreateTestTabContents());
430 TabContentsWrapper tab3(CreateTestTabContents()); 388 TabContentsWrapper tab3(CreateTestTabContents());
431 389
432 // Create 3 states: 390 // Create 3 states:
433 // . tabbed with an app tab and normal tab. 391 // . tabbed with an app tab and normal tab.
434 // . tabbed with a normal tab. 392 // . tabbed with a normal tab.
435 // . app. 393 // . app.
436 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 394 State state1(profile(), launcher_delegate_.get(), std::string(),
437 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 395 LauncherUpdater::TYPE_TABBED);
396 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
438 app_icon_loader_->SetAppID(&tab2, "1"); 397 app_icon_loader_->SetAppID(&tab2, "1");
439 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE); 398 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE);
440 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED); 399 State state2(profile(), launcher_delegate_.get(), std::string(),
400 LauncherUpdater::TYPE_TABBED);
441 state2.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE); 401 state2.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE);
442 State state3(this, std::string(), LauncherUpdater::TYPE_APP); 402 State state3(profile(), launcher_delegate_.get(), std::string(),
403 LauncherUpdater::TYPE_APP);
443 ASSERT_EQ(initial_size + 4, launcher_model_->items().size()); 404 ASSERT_EQ(initial_size + 4, launcher_model_->items().size());
444 405
445 // Tabbed item from first state. 406 // Tabbed item from first state.
446 ash::LauncherID id = launcher_model_->items()[initial_size].id; 407 ash::LauncherID id = launcher_model_->items()[initial_size].id;
447 LauncherUpdater* updater = GetUpdaterByID(id); 408 LauncherUpdater* updater = GetUpdaterByID(id);
448 EXPECT_EQ(&(state1.updater), updater); 409 EXPECT_EQ(&(state1.updater), updater);
449 ASSERT_TRUE(updater); 410 ASSERT_TRUE(updater);
450 EXPECT_TRUE(updater->GetTab(id) == NULL); 411 EXPECT_TRUE(updater->GetTab(id) == NULL);
451 412
452 // App item from first state. 413 // App item from first state.
(...skipping 21 matching lines...) Expand all
474 // Various assertions around pinning. In particular verifies destroying a 435 // Various assertions around pinning. In particular verifies destroying a
475 // LauncherUpdater doesn't remove the entry for a pinned app. 436 // LauncherUpdater doesn't remove the entry for a pinned app.
476 TEST_F(LauncherUpdaterTest, Pin) { 437 TEST_F(LauncherUpdaterTest, Pin) {
477 size_t initial_size = launcher_model_->items().size(); 438 size_t initial_size = launcher_model_->items().size();
478 TabContentsWrapper tab1(CreateTestTabContents()); 439 TabContentsWrapper tab1(CreateTestTabContents());
479 TabContentsWrapper tab2(CreateTestTabContents()); 440 TabContentsWrapper tab2(CreateTestTabContents());
480 TabContentsWrapper tab3(CreateTestTabContents()); 441 TabContentsWrapper tab3(CreateTestTabContents());
481 442
482 ash::LauncherID id; 443 ash::LauncherID id;
483 { 444 {
484 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 445 State state1(profile(), launcher_delegate_.get(), std::string(),
446 LauncherUpdater::TYPE_TABBED);
485 app_icon_loader_->SetAppID(&tab1, "1"); 447 app_icon_loader_->SetAppID(&tab1, "1");
486 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 448 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
487 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 449 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
488 id = launcher_model_->items()[initial_size].id; 450 id = launcher_model_->items()[initial_size].id;
489 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 451 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
490 // Shouldn't be pinned. 452 // Shouldn't be pinned.
491 EXPECT_FALSE(launcher_delegate_->IsPinned(id)); 453 EXPECT_FALSE(launcher_delegate_->IsPinned(id));
492 launcher_delegate_->Pin(id); 454 launcher_delegate_->Pin(id);
493 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); 455 EXPECT_TRUE(launcher_delegate_->IsPinned(id));
494 EXPECT_EQ(ash::STATUS_ACTIVE, 456 EXPECT_EQ(ash::STATUS_RUNNING,
495 launcher_model_->items()[initial_size].status); 457 launcher_model_->items()[initial_size].status);
496 } 458 }
497 459
498 // Should still have the item. 460 // Should still have the item.
499 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 461 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
500 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); 462 EXPECT_TRUE(launcher_delegate_->IsPinned(id));
501 EXPECT_TRUE(GetUpdaterByID(id) == NULL); 463 EXPECT_TRUE(GetUpdaterByID(id) == NULL);
502 EXPECT_EQ(ash::STATUS_CLOSED, launcher_model_->items()[initial_size].status); 464 EXPECT_EQ(ash::STATUS_CLOSED, launcher_model_->items()[initial_size].status);
503 465
504 // Create another app tab, it shouldn't get the same id. 466 // Create another app tab, it shouldn't get the same id.
505 { 467 {
506 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 468 State state1(profile(), launcher_delegate_.get(), std::string(),
469 LauncherUpdater::TYPE_TABBED);
507 app_icon_loader_->SetAppID(&tab2, "2"); 470 app_icon_loader_->SetAppID(&tab2, "2");
508 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_ACTIVE); 471 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE);
509 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); 472 ASSERT_EQ(initial_size + 2, launcher_model_->items().size());
510 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id; 473 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id;
511 EXPECT_NE(id, new_id); 474 EXPECT_NE(id, new_id);
512 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); 475 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type);
513 // Shouldn't be pinned. 476 // Shouldn't be pinned.
514 EXPECT_FALSE(launcher_delegate_->IsPinned(new_id)); 477 EXPECT_FALSE(launcher_delegate_->IsPinned(new_id));
515 // But existing one should still be pinned. 478 // But existing one should still be pinned.
516 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); 479 EXPECT_TRUE(launcher_delegate_->IsPinned(id));
517 } 480 }
518 481
519 // Add it back and make sure we don't get another entry. 482 // Add it back and make sure we don't get another entry.
520 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 483 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
521 { 484 {
522 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 485 State state1(profile(), launcher_delegate_.get(), std::string(),
486 LauncherUpdater::TYPE_TABBED);
523 app_icon_loader_->SetAppID(&tab1, "1"); 487 app_icon_loader_->SetAppID(&tab1, "1");
524 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 488 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
525 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 489 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
526 ash::LauncherID new_id = launcher_model_->items()[initial_size].id; 490 ash::LauncherID new_id = launcher_model_->items()[initial_size].id;
527 EXPECT_EQ(id, new_id); 491 EXPECT_EQ(id, new_id);
528 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 492 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
529 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); 493 EXPECT_TRUE(launcher_delegate_->IsPinned(id));
530 EXPECT_EQ(&(state1.updater), GetUpdaterByID(id)); 494 EXPECT_EQ(&(state1.updater), GetUpdaterByID(id));
531 495
532 // Add another tab. 496 // Add another tab.
533 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE); 497 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE);
534 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); 498 ASSERT_EQ(initial_size + 2, launcher_model_->items().size());
535 new_id = launcher_model_->items()[initial_size].id; 499 new_id = launcher_model_->items()[initial_size].id;
536 EXPECT_NE(id, new_id); 500 EXPECT_NE(id, new_id);
537 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 501 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
538 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); 502 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id));
539 } 503 }
540 504
541 // Add it back and make sure we don't get another entry. 505 // Add it back and make sure we don't get another entry.
542 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 506 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
543 { 507 {
544 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 508 State state1(profile(), launcher_delegate_.get(), std::string(),
545 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_ACTIVE); 509 LauncherUpdater::TYPE_TABBED);
510 state1.tab_strip.InsertTabContentsAt(0, &tab3, TabStripModel::ADD_NONE);
546 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); 511 ASSERT_EQ(initial_size + 2, launcher_model_->items().size());
547 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id; 512 ash::LauncherID new_id = launcher_model_->items()[initial_size + 1].id;
548 EXPECT_NE(id, new_id); 513 EXPECT_NE(id, new_id);
549 EXPECT_EQ(ash::TYPE_TABBED, 514 EXPECT_EQ(ash::TYPE_TABBED,
550 launcher_model_->items()[initial_size + 1].type); 515 launcher_model_->items()[initial_size + 1].type);
551 EXPECT_TRUE(GetUpdaterByID(id) == NULL); 516 EXPECT_TRUE(GetUpdaterByID(id) == NULL);
552 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); 517 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id));
553 518
554 // Add the app tab. 519 // Add the app tab.
555 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); 520 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
556 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); 521 ASSERT_EQ(initial_size + 2, launcher_model_->items().size());
557 new_id = launcher_model_->items()[initial_size].id; 522 new_id = launcher_model_->items()[initial_size].id;
558 EXPECT_EQ(id, new_id); 523 EXPECT_EQ(id, new_id);
559 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 524 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
560 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); 525 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id));
561 } 526 }
562 } 527 }
563 528
564 // Verifies pinned apps are persisted and restored. 529 // Verifies pinned apps are persisted and restored.
565 TEST_F(LauncherUpdaterTest, PersistPinned) { 530 TEST_F(LauncherUpdaterTest, PersistPinned) {
566 size_t initial_size = launcher_model_->items().size(); 531 size_t initial_size = launcher_model_->items().size();
567 TabContentsWrapper tab1(CreateTestTabContents()); 532 TabContentsWrapper tab1(CreateTestTabContents());
568 533
569 app_icon_loader_->SetAppID(&tab1, "1"); 534 app_icon_loader_->SetAppID(&tab1, "1");
570 app_icon_loader_->SetAppID(NULL, "2"); 535 app_icon_loader_->SetAppID(NULL, "2");
571 { 536 {
572 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 537 State state1(profile(), launcher_delegate_.get(), std::string(),
573 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 538 LauncherUpdater::TYPE_TABBED);
539 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
574 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 540 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
575 ash::LauncherID id = launcher_model_->items()[initial_size].id; 541 ash::LauncherID id = launcher_model_->items()[initial_size].id;
576 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 542 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
577 // Shouldn't be pinned. 543 // Shouldn't be pinned.
578 EXPECT_FALSE(launcher_delegate_->IsPinned(id)); 544 EXPECT_FALSE(launcher_delegate_->IsPinned(id));
579 launcher_delegate_->Pin(id); 545 launcher_delegate_->Pin(id);
580 EXPECT_TRUE(launcher_delegate_->IsPinned(id)); 546 EXPECT_TRUE(launcher_delegate_->IsPinned(id));
581 547
582 // Create an app window. 548 // Create an app window.
583 State state2(this, "2", LauncherUpdater::TYPE_APP); 549 State state2(profile(), launcher_delegate_.get(), "2",
550 LauncherUpdater::TYPE_APP);
584 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); 551 ASSERT_EQ(initial_size + 2, launcher_model_->items().size());
585 ash::LauncherID id2 = launcher_model_->items()[initial_size + 1].id; 552 ash::LauncherID id2 = launcher_model_->items()[initial_size + 1].id;
586 EXPECT_NE(id, id2); 553 EXPECT_NE(id, id2);
587 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); 554 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type);
588 launcher_delegate_->Pin(id2); 555 launcher_delegate_->Pin(id2);
589 EXPECT_TRUE(launcher_delegate_->IsPinned(id2)); 556 EXPECT_TRUE(launcher_delegate_->IsPinned(id2));
590 } 557 }
591 558
592 launcher_delegate_.reset(NULL); 559 launcher_delegate_.reset(NULL);
593 ASSERT_EQ(initial_size, launcher_model_->items().size()); 560 ASSERT_EQ(initial_size, launcher_model_->items().size());
(...skipping 17 matching lines...) Expand all
611 EXPECT_EQ("2", GetAppID(id2)); 578 EXPECT_EQ("2", GetAppID(id2));
612 EXPECT_EQ(ChromeLauncherDelegate::APP_TYPE_WINDOW, 579 EXPECT_EQ(ChromeLauncherDelegate::APP_TYPE_WINDOW,
613 launcher_delegate_->GetAppType(id2)); 580 launcher_delegate_->GetAppType(id2));
614 EXPECT_TRUE(launcher_delegate_->IsPinned(id2)); 581 EXPECT_TRUE(launcher_delegate_->IsPinned(id2));
615 582
616 UnpinAppsWithID("1"); 583 UnpinAppsWithID("1");
617 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 584 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
618 ash::LauncherID id3 = launcher_model_->items()[initial_size].id; 585 ash::LauncherID id3 = launcher_model_->items()[initial_size].id;
619 EXPECT_EQ(id2, id3); 586 EXPECT_EQ(id2, id3);
620 } 587 }
621
622 // Confirm that tabbed browsers with apps handle activation correctly.
623 TEST_F(LauncherUpdaterTest, ActivateAppsInBrowser) {
624 State state(this, std::string(), LauncherUpdater::TYPE_TABBED);
625 TabContentsWrapper app_tab1(CreateTestTabContents());
626 app_icon_loader_->SetAppID(&app_tab1, "1");
627 TabContentsWrapper app_tab2(CreateTestTabContents());
628 app_icon_loader_->SetAppID(&app_tab2, "2");
629 TabContentsWrapper app_tab3(CreateTestTabContents());
630 app_icon_loader_->SetAppID(&app_tab3, "3");
631
632 // Insert an app tab.
633 state.tab_strip.InsertTabContentsAt(0, &app_tab1, TabStripModel::ADD_ACTIVE);
634 ASSERT_EQ(0, state.tab_strip.active_index());
635 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status);
636
637 // Add a second, inactive tab.
638 state.tab_strip.InsertTabContentsAt(1, &app_tab2, TabStripModel::ADD_NONE);
639 ASSERT_EQ(0, state.tab_strip.active_index());
640 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status);
641 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
642
643 // Add a third, and make it active.
644 state.tab_strip.InsertTabContentsAt(2, &app_tab3, TabStripModel::ADD_ACTIVE);
645 ASSERT_EQ(2, state.tab_strip.active_index());
646 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status);
647 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
648 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status);
649
650 // Make the first active
651 state.tab_strip.ActivateTabAt(0, false);
652 ASSERT_EQ(0, state.tab_strip.active_index());
653 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status);
654 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
655 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status);
656
657 {
658 // Add a 4th tab.
659 TabContentsWrapper app_tab4(CreateTestTabContents());
660 app_icon_loader_->SetAppID(&app_tab3, "4");
661 state.tab_strip.InsertTabContentsAt(
662 4, &app_tab4, TabStripModel::ADD_ACTIVE);
663 ASSERT_EQ(3, state.tab_strip.active_index());
664 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status);
665 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
666 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status);
667 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab4).status);
668 }
669
670 // After the 4th is closed the third becomes active.
671 ASSERT_EQ(2, state.tab_strip.active_index());
672 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status);
673 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
674 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status);
675 }
676
677 // Confirm that tabbed browsers handle activation correctly.
678 TEST_F(LauncherUpdaterTest, ActivateBrowsers) {
679 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED);
680 TabContentsWrapper tab1(CreateTestTabContents());
681 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
682
683 // First browser is active.
684 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
685
686 {
687 // Second browser is active and first is inactive.
688 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED);
689 TabContentsWrapper tab2(CreateTestTabContents());
690 state2.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
691 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status);
692 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status);
693
694 // Make first browser active again.
695 activation_client_->ActivateWindow(&state1.window);
696 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
697 EXPECT_EQ(ash::STATUS_RUNNING, state2.GetUpdaterItem().status);
698
699 // And back to second.
700 activation_client_->ActivateWindow(&state2.window);
701 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status);
702 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status);
703 }
704
705 // First browser should be active again after second is closed.
706 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
707 }
708
709 // Confirm that applications handle activation correctly.
710 TEST_F(LauncherUpdaterTest, ActivateApps) {
711 State state1(this, "1", LauncherUpdater::TYPE_APP);
712
713 // First app is active.
714 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
715
716 {
717 // Second app is active and first is inactive.
718 State state2(this, "2", LauncherUpdater::TYPE_APP);
719 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status);
720 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status);
721
722 // Make first app active again.
723 activation_client_->ActivateWindow(&state1.window);
724 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
725 EXPECT_EQ(ash::STATUS_RUNNING, state2.GetUpdaterItem().status);
726
727 // And back to second.
728 activation_client_->ActivateWindow(&state2.window);
729 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status);
730 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status);
731 }
732
733 // First app should be active again after second is closed.
734 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
735 }
736
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/ash/launcher/launcher_updater.cc ('k') | chrome/browser/ui/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698