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

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

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. 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"
19 #include "content/test/test_browser_thread.h" 18 #include "content/test/test_browser_thread.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/aura/client/activation_delegate.h" 21 #include "ui/aura/client/activation_delegate.h"
23 #include "ui/aura/test/test_activation_client.h" 22 #include "ui/aura/test/test_activation_client.h"
24 #include "ui/aura/test/test_window_delegate.h" 23 #include "ui/aura/test/test_window_delegate.h"
25 #include "ui/aura/root_window.h" 24 #include "ui/aura/root_window.h"
26 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
27 #include "ui/aura/window_delegate.h" 26 #include "ui/aura/window_delegate.h"
28 27
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 content::TestBrowserThread browser_thread_; 188 content::TestBrowserThread browser_thread_;
190 std::vector<State*> states; 189 std::vector<State*> states;
191 190
192 DISALLOW_COPY_AND_ASSIGN(LauncherUpdaterTest); 191 DISALLOW_COPY_AND_ASSIGN(LauncherUpdaterTest);
193 }; 192 };
194 193
195 // Verifies a new launcher item is added for TYPE_TABBED. 194 // Verifies a new launcher item is added for TYPE_TABBED.
196 TEST_F(LauncherUpdaterTest, TabbedSetup) { 195 TEST_F(LauncherUpdaterTest, TabbedSetup) {
197 size_t initial_size = launcher_model_->items().size(); 196 size_t initial_size = launcher_model_->items().size();
198 { 197 {
199 TabContentsWrapper wrapper(CreateTestTabContents()); 198 TabContentsWrapper wrapper(CreateTestWebContents());
200 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 199 State state(this, std::string(), LauncherUpdater::TYPE_TABBED);
201 200
202 // Since the type is tabbed and there is nothing in the tabstrip an item 201 // Since the type is tabbed and there is nothing in the tabstrip an item
203 // should not have been added. 202 // should not have been added.
204 EXPECT_EQ(initial_size, launcher_model_->items().size()); 203 EXPECT_EQ(initial_size, launcher_model_->items().size());
205 204
206 // Add a tab. 205 // Add a tab.
207 state.tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE); 206 state.tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE);
208 207
209 // There should be one more item. 208 // There should be one more item.
210 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 209 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
211 // New item should be added at the end. 210 // New item should be added at the end.
212 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 211 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
213 } 212 }
214 // Deleting the LauncherUpdater should have removed the item. 213 // Deleting the LauncherUpdater should have removed the item.
215 ASSERT_EQ(initial_size, launcher_model_->items().size()); 214 ASSERT_EQ(initial_size, launcher_model_->items().size());
216 215
217 // Do the same, but this time add the tab first. 216 // Do the same, but this time add the tab first.
218 { 217 {
219 TabContentsWrapper wrapper(CreateTestTabContents()); 218 TabContentsWrapper wrapper(CreateTestWebContents());
220 219
221 TestTabStripModelDelegate tab_strip_delegate; 220 TestTabStripModelDelegate tab_strip_delegate;
222 TabStripModel tab_strip(&tab_strip_delegate, profile()); 221 TabStripModel tab_strip(&tab_strip_delegate, profile());
223 tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE); 222 tab_strip.InsertTabContentsAt(0, &wrapper, TabStripModel::ADD_ACTIVE);
224 aura::Window window(NULL); 223 aura::Window window(NULL);
225 window.Init(ui::Layer::LAYER_NOT_DRAWN); 224 window.Init(ui::Layer::LAYER_NOT_DRAWN);
226 root_window()->AddChild(&window); 225 root_window()->AddChild(&window);
227 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(), 226 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(),
228 LauncherUpdater::TYPE_TABBED, std::string()); 227 LauncherUpdater::TYPE_TABBED, std::string());
229 updater.Init(); 228 updater.Init();
(...skipping 17 matching lines...) Expand all
247 } 246 }
248 // Deleting the LauncherUpdater should have removed the item. 247 // Deleting the LauncherUpdater should have removed the item.
249 ASSERT_EQ(initial_size, launcher_model_->items().size()); 248 ASSERT_EQ(initial_size, launcher_model_->items().size());
250 } 249 }
251 250
252 // Various assertions when adding/removing a tab that has an app associated with 251 // Various assertions when adding/removing a tab that has an app associated with
253 // it. 252 // it.
254 TEST_F(LauncherUpdaterTest, TabbedWithApp) { 253 TEST_F(LauncherUpdaterTest, TabbedWithApp) {
255 size_t initial_size = launcher_model_->items().size(); 254 size_t initial_size = launcher_model_->items().size();
256 { 255 {
257 TabContentsWrapper initial_tab(CreateTestTabContents()); 256 TabContentsWrapper initial_tab(CreateTestWebContents());
258 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 257 State state(this, std::string(), LauncherUpdater::TYPE_TABBED);
259 // Add a tab. 258 // Add a tab.
260 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 259 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
261 TabStripModel::ADD_ACTIVE); 260 TabStripModel::ADD_ACTIVE);
262 261
263 // There should be one more item. 262 // There should be one more item.
264 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 263 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
265 // New item should be added at the end. 264 // New item should be added at the end.
266 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 265 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
267 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; 266 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id;
268 267
269 // Add another tab, configure it so that the launcher thinks it's an app. 268 // Add another tab, configure it so that the launcher thinks it's an app.
270 TabContentsWrapper app_tab(CreateTestTabContents()); 269 TabContentsWrapper app_tab(CreateTestWebContents());
271 app_icon_loader_->SetAppID(&app_tab, "1"); 270 app_icon_loader_->SetAppID(&app_tab, "1");
272 state.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_NONE); 271 state.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_NONE);
273 272
274 // There should be one more item. 273 // There should be one more item.
275 ASSERT_EQ(initial_size + 2, launcher_model_->items().size()); 274 ASSERT_EQ(initial_size + 2, launcher_model_->items().size());
276 // New item should be added at the end. 275 // New item should be added at the end.
277 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); 276 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type);
278 277
279 // Remove the first tab, this should trigger removing the tabbed item. 278 // Remove the first tab, this should trigger removing the tabbed item.
280 state.tab_strip.DetachTabContentsAt(0); 279 state.tab_strip.DetachTabContentsAt(0);
(...skipping 13 matching lines...) Expand all
294 ASSERT_EQ(initial_size, launcher_model_->items().size()); 293 ASSERT_EQ(initial_size, launcher_model_->items().size());
295 } 294 }
296 295
297 TEST_F(LauncherUpdaterTest, TabbedWithAppOnCreate) { 296 TEST_F(LauncherUpdaterTest, TabbedWithAppOnCreate) {
298 size_t initial_size = launcher_model_->items().size(); 297 size_t initial_size = launcher_model_->items().size();
299 aura::Window window(NULL); 298 aura::Window window(NULL);
300 window.Init(ui::Layer::LAYER_NOT_DRAWN); 299 window.Init(ui::Layer::LAYER_NOT_DRAWN);
301 root_window()->AddChild(&window); 300 root_window()->AddChild(&window);
302 TestTabStripModelDelegate tab_strip_delegate; 301 TestTabStripModelDelegate tab_strip_delegate;
303 TabStripModel tab_strip(&tab_strip_delegate, profile()); 302 TabStripModel tab_strip(&tab_strip_delegate, profile());
304 TabContentsWrapper app_tab(CreateTestTabContents()); 303 TabContentsWrapper app_tab(CreateTestWebContents());
305 app_icon_loader_->SetAppID(&app_tab, "1"); 304 app_icon_loader_->SetAppID(&app_tab, "1");
306 tab_strip.InsertTabContentsAt(0, &app_tab, TabStripModel::ADD_ACTIVE); 305 tab_strip.InsertTabContentsAt(0, &app_tab, TabStripModel::ADD_ACTIVE);
307 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(), 306 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(),
308 LauncherUpdater::TYPE_TABBED, std::string()); 307 LauncherUpdater::TYPE_TABBED, std::string());
309 updater.Init(); 308 updater.Init();
310 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 309 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
311 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 310 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
312 } 311 }
313 312
314 // Verifies transitioning from a normal tab to app tab and back works. 313 // Verifies transitioning from a normal tab to app tab and back works.
315 TEST_F(LauncherUpdaterTest, ChangeToApp) { 314 TEST_F(LauncherUpdaterTest, ChangeToApp) {
316 size_t initial_size = launcher_model_->items().size(); 315 size_t initial_size = launcher_model_->items().size();
317 { 316 {
318 TabContentsWrapper initial_tab(CreateTestTabContents()); 317 TabContentsWrapper initial_tab(CreateTestWebContents());
319 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 318 State state(this, std::string(), LauncherUpdater::TYPE_TABBED);
320 // Add a tab. 319 // Add a tab.
321 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 320 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
322 TabStripModel::ADD_ACTIVE); 321 TabStripModel::ADD_ACTIVE);
323 322
324 // There should be one more item. 323 // There should be one more item.
325 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 324 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
326 // New item should be added at the end. 325 // New item should be added at the end.
327 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type); 326 EXPECT_EQ(ash::TYPE_TABBED, launcher_model_->items()[initial_size].type);
328 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; 327 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id;
(...skipping 13 matching lines...) Expand all
342 EXPECT_EQ(tabbed_id, launcher_model_->items()[initial_size].id); 341 EXPECT_EQ(tabbed_id, launcher_model_->items()[initial_size].id);
343 } 342 }
344 // Deleting the LauncherUpdater should have removed the item. 343 // Deleting the LauncherUpdater should have removed the item.
345 ASSERT_EQ(initial_size, launcher_model_->items().size()); 344 ASSERT_EQ(initial_size, launcher_model_->items().size());
346 } 345 }
347 346
348 // Verifies AppIconLoader is queried appropriately. 347 // Verifies AppIconLoader is queried appropriately.
349 TEST_F(LauncherUpdaterTest, QueryAppIconLoader) { 348 TEST_F(LauncherUpdaterTest, QueryAppIconLoader) {
350 size_t initial_size = launcher_model_->items().size(); 349 size_t initial_size = launcher_model_->items().size();
351 { 350 {
352 TabContentsWrapper initial_tab(CreateTestTabContents()); 351 TabContentsWrapper initial_tab(CreateTestWebContents());
353 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 352 State state(this, std::string(), LauncherUpdater::TYPE_TABBED);
354 // Configure the tab as an app. 353 // Configure the tab as an app.
355 app_icon_loader_->SetAppID(&initial_tab, "1"); 354 app_icon_loader_->SetAppID(&initial_tab, "1");
356 // Add a tab. 355 // Add a tab.
357 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 356 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
358 TabStripModel::ADD_ACTIVE); 357 TabStripModel::ADD_ACTIVE);
359 // AppIconLoader should have been queried. 358 // AppIconLoader should have been queried.
360 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0); 359 EXPECT_GT(app_icon_loader_->GetAndClearFetchCount(), 0);
361 // Remove the tab. 360 // Remove the tab.
362 state.tab_strip.DetachTabContentsAt(0); 361 state.tab_strip.DetachTabContentsAt(0);
363 } 362 }
364 // Deleting the LauncherUpdater should have removed the item. 363 // Deleting the LauncherUpdater should have removed the item.
365 ASSERT_EQ(initial_size, launcher_model_->items().size()); 364 ASSERT_EQ(initial_size, launcher_model_->items().size());
366 } 365 }
367 366
368 // Verifies SetAppImage works. 367 // Verifies SetAppImage works.
369 TEST_F(LauncherUpdaterTest, SetAppImage) { 368 TEST_F(LauncherUpdaterTest, SetAppImage) {
370 size_t initial_size = launcher_model_->items().size(); 369 size_t initial_size = launcher_model_->items().size();
371 TabContentsWrapper initial_tab(CreateTestTabContents()); 370 TabContentsWrapper initial_tab(CreateTestWebContents());
372 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 371 State state(this, std::string(), LauncherUpdater::TYPE_TABBED);
373 // Configure the tab as an app. 372 // Configure the tab as an app.
374 app_icon_loader_->SetAppID(&initial_tab, "1"); 373 app_icon_loader_->SetAppID(&initial_tab, "1");
375 // Add a tab. 374 // Add a tab.
376 state.tab_strip.InsertTabContentsAt(0, &initial_tab, 375 state.tab_strip.InsertTabContentsAt(0, &initial_tab,
377 TabStripModel::ADD_ACTIVE); 376 TabStripModel::ADD_ACTIVE);
378 SkBitmap image; 377 SkBitmap image;
379 image.setConfig(SkBitmap::kARGB_8888_Config, 2, 3); 378 image.setConfig(SkBitmap::kARGB_8888_Config, 2, 3);
380 image.allocPixels(); 379 image.allocPixels();
381 launcher_delegate_->SetAppImage("1", &image); 380 launcher_delegate_->SetAppImage("1", &image);
382 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 381 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
383 EXPECT_EQ(2, launcher_model_->items()[initial_size].image.width()); 382 EXPECT_EQ(2, launcher_model_->items()[initial_size].image.width());
384 EXPECT_EQ(3, launcher_model_->items()[initial_size].image.height()); 383 EXPECT_EQ(3, launcher_model_->items()[initial_size].image.height());
385 } 384 }
386 385
387 // Verifies Panels items work. 386 // Verifies Panels items work.
388 TEST_F(LauncherUpdaterTest, PanelItem) { 387 TEST_F(LauncherUpdaterTest, PanelItem) {
389 size_t initial_size = launcher_model_->items().size(); 388 size_t initial_size = launcher_model_->items().size();
390 aura::Window window(NULL); 389 aura::Window window(NULL);
391 TestTabStripModelDelegate tab_strip_delegate; 390 TestTabStripModelDelegate tab_strip_delegate;
392 TabStripModel tab_strip(&tab_strip_delegate, profile()); 391 TabStripModel tab_strip(&tab_strip_delegate, profile());
393 TabContentsWrapper panel_tab(CreateTestTabContents()); 392 TabContentsWrapper panel_tab(CreateTestWebContents());
394 app_icon_loader_->SetAppID(&panel_tab, "1"); // Panels are apps. 393 app_icon_loader_->SetAppID(&panel_tab, "1"); // Panels are apps.
395 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE); 394 tab_strip.InsertTabContentsAt(0, &panel_tab, TabStripModel::ADD_ACTIVE);
396 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(), 395 LauncherUpdater updater(&window, &tab_strip, launcher_delegate_.get(),
397 LauncherUpdater::TYPE_PANEL, std::string()); 396 LauncherUpdater::TYPE_PANEL, std::string());
398 updater.Init(); 397 updater.Init();
399 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 398 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
400 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 399 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
401 EXPECT_NE(static_cast<void*>(NULL), updater.favicon_loader_.get()); 400 EXPECT_NE(static_cast<void*>(NULL), updater.favicon_loader_.get());
402 } 401 }
403 402
404 // Verifies app tabs are added right after the existing tabbed item. 403 // Verifies app tabs are added right after the existing tabbed item.
405 TEST_F(LauncherUpdaterTest, AddAppAfterTabbed) { 404 TEST_F(LauncherUpdaterTest, AddAppAfterTabbed) {
406 size_t initial_size = launcher_model_->items().size(); 405 size_t initial_size = launcher_model_->items().size();
407 TabContentsWrapper tab1(CreateTestTabContents()); 406 TabContentsWrapper tab1(CreateTestWebContents());
408 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 407 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED);
409 // Add a tab. 408 // Add a tab.
410 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 409 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
411 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 410 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
412 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id; 411 ash::LauncherID tabbed_id = launcher_model_->items()[initial_size].id;
413 412
414 // Create another LauncherUpdater. 413 // Create another LauncherUpdater.
415 State state2(this, std::string(), LauncherUpdater::TYPE_APP); 414 State state2(this, std::string(), LauncherUpdater::TYPE_APP);
416 415
417 // Should be two extra items. 416 // Should be two extra items.
418 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); 417 EXPECT_EQ(initial_size + 2, launcher_model_->items().size());
419 418
420 // Add an app tab to state1, it should go after the item for state1 but 419 // Add an app tab to state1, it should go after the item for state1 but
421 // before the item for state2. 420 // before the item for state2.
422 int next_id = launcher_model_->next_id(); 421 int next_id = launcher_model_->next_id();
423 TabContentsWrapper app_tab(CreateTestTabContents()); 422 TabContentsWrapper app_tab(CreateTestWebContents());
424 app_icon_loader_->SetAppID(&app_tab, "1"); 423 app_icon_loader_->SetAppID(&app_tab, "1");
425 state1.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_ACTIVE); 424 state1.tab_strip.InsertTabContentsAt(1, &app_tab, TabStripModel::ADD_ACTIVE);
426 425
427 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); 426 ASSERT_EQ(initial_size + 3, launcher_model_->items().size());
428 EXPECT_EQ(next_id, launcher_model_->items()[initial_size + 1].id); 427 EXPECT_EQ(next_id, launcher_model_->items()[initial_size + 1].id);
429 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type); 428 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size + 1].type);
430 429
431 // Remove the non-app tab. 430 // Remove the non-app tab.
432 state1.tab_strip.DetachTabContentsAt(0); 431 state1.tab_strip.DetachTabContentsAt(0);
433 // Should have removed one item. 432 // Should have removed one item.
434 EXPECT_EQ(initial_size + 2, launcher_model_->items().size()); 433 EXPECT_EQ(initial_size + 2, launcher_model_->items().size());
435 EXPECT_EQ(-1, launcher_model_->ItemIndexByID(tabbed_id)); 434 EXPECT_EQ(-1, launcher_model_->ItemIndexByID(tabbed_id));
436 next_id = launcher_model_->next_id(); 435 next_id = launcher_model_->next_id();
437 // Add the non-app tab back. It should go to the original position (but get a 436 // Add the non-app tab back. It should go to the original position (but get a
438 // new id). 437 // new id).
439 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE); 438 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_NONE);
440 ASSERT_EQ(initial_size + 3, launcher_model_->items().size()); 439 ASSERT_EQ(initial_size + 3, launcher_model_->items().size());
441 EXPECT_EQ(next_id, launcher_model_->items()[initial_size].id); 440 EXPECT_EQ(next_id, launcher_model_->items()[initial_size].id);
442 } 441 }
443 442
444 // Verifies GetWindowAndTabByID works. 443 // Verifies GetWindowAndTabByID works.
445 TEST_F(LauncherUpdaterTest, GetUpdaterByID) { 444 TEST_F(LauncherUpdaterTest, GetUpdaterByID) {
446 size_t initial_size = launcher_model_->items().size(); 445 size_t initial_size = launcher_model_->items().size();
447 TabContentsWrapper tab1(CreateTestTabContents()); 446 TabContentsWrapper tab1(CreateTestWebContents());
448 TabContentsWrapper tab2(CreateTestTabContents()); 447 TabContentsWrapper tab2(CreateTestWebContents());
449 TabContentsWrapper tab3(CreateTestTabContents()); 448 TabContentsWrapper tab3(CreateTestWebContents());
450 449
451 // Create 3 states: 450 // Create 3 states:
452 // . tabbed with an app tab and normal tab. 451 // . tabbed with an app tab and normal tab.
453 // . tabbed with a normal tab. 452 // . tabbed with a normal tab.
454 // . app. 453 // . app.
455 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 454 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED);
456 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 455 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
457 app_icon_loader_->SetAppID(&tab2, "1"); 456 app_icon_loader_->SetAppID(&tab2, "1");
458 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE); 457 state1.tab_strip.InsertTabContentsAt(0, &tab2, TabStripModel::ADD_NONE);
459 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED); 458 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED);
(...skipping 27 matching lines...) Expand all
487 updater = GetUpdaterByID(id); 486 updater = GetUpdaterByID(id);
488 EXPECT_EQ(&(state3.updater), updater); 487 EXPECT_EQ(&(state3.updater), updater);
489 ASSERT_TRUE(updater); 488 ASSERT_TRUE(updater);
490 EXPECT_TRUE(updater->GetTab(id) == NULL); 489 EXPECT_TRUE(updater->GetTab(id) == NULL);
491 } 490 }
492 491
493 // Various assertions around pinning. In particular verifies destroying a 492 // Various assertions around pinning. In particular verifies destroying a
494 // LauncherUpdater doesn't remove the entry for a pinned app. 493 // LauncherUpdater doesn't remove the entry for a pinned app.
495 TEST_F(LauncherUpdaterTest, Pin) { 494 TEST_F(LauncherUpdaterTest, Pin) {
496 size_t initial_size = launcher_model_->items().size(); 495 size_t initial_size = launcher_model_->items().size();
497 TabContentsWrapper tab1(CreateTestTabContents()); 496 TabContentsWrapper tab1(CreateTestWebContents());
498 TabContentsWrapper tab2(CreateTestTabContents()); 497 TabContentsWrapper tab2(CreateTestWebContents());
499 TabContentsWrapper tab3(CreateTestTabContents()); 498 TabContentsWrapper tab3(CreateTestWebContents());
500 499
501 ash::LauncherID id; 500 ash::LauncherID id;
502 { 501 {
503 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 502 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED);
504 app_icon_loader_->SetAppID(&tab1, "1"); 503 app_icon_loader_->SetAppID(&tab1, "1");
505 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 504 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
506 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 505 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
507 id = launcher_model_->items()[initial_size].id; 506 id = launcher_model_->items()[initial_size].id;
508 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 507 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
509 // Shouldn't be pinned. 508 // Shouldn't be pinned.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 new_id = launcher_model_->items()[initial_size].id; 575 new_id = launcher_model_->items()[initial_size].id;
577 EXPECT_EQ(id, new_id); 576 EXPECT_EQ(id, new_id);
578 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 577 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
579 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id)); 578 EXPECT_EQ(&(state1.updater), GetUpdaterByID(new_id));
580 } 579 }
581 } 580 }
582 581
583 // Verifies pinned apps are persisted and restored. 582 // Verifies pinned apps are persisted and restored.
584 TEST_F(LauncherUpdaterTest, PersistPinned) { 583 TEST_F(LauncherUpdaterTest, PersistPinned) {
585 size_t initial_size = launcher_model_->items().size(); 584 size_t initial_size = launcher_model_->items().size();
586 TabContentsWrapper tab1(CreateTestTabContents()); 585 TabContentsWrapper tab1(CreateTestWebContents());
587 586
588 app_icon_loader_->SetAppID(&tab1, "1"); 587 app_icon_loader_->SetAppID(&tab1, "1");
589 app_icon_loader_->SetAppID(NULL, "2"); 588 app_icon_loader_->SetAppID(NULL, "2");
590 { 589 {
591 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 590 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED);
592 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 591 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
593 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 592 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
594 ash::LauncherID id = launcher_model_->items()[initial_size].id; 593 ash::LauncherID id = launcher_model_->items()[initial_size].id;
595 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type); 594 EXPECT_EQ(ash::TYPE_APP, launcher_model_->items()[initial_size].type);
596 // Shouldn't be pinned. 595 // Shouldn't be pinned.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 633
635 UnpinAppsWithID("1"); 634 UnpinAppsWithID("1");
636 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); 635 ASSERT_EQ(initial_size + 1, launcher_model_->items().size());
637 ash::LauncherID id3 = launcher_model_->items()[initial_size].id; 636 ash::LauncherID id3 = launcher_model_->items()[initial_size].id;
638 EXPECT_EQ(id2, id3); 637 EXPECT_EQ(id2, id3);
639 } 638 }
640 639
641 // Confirm that tabbed browsers with apps handle activation correctly. 640 // Confirm that tabbed browsers with apps handle activation correctly.
642 TEST_F(LauncherUpdaterTest, ActivateAppsInBrowser) { 641 TEST_F(LauncherUpdaterTest, ActivateAppsInBrowser) {
643 State state(this, std::string(), LauncherUpdater::TYPE_TABBED); 642 State state(this, std::string(), LauncherUpdater::TYPE_TABBED);
644 TabContentsWrapper app_tab1(CreateTestTabContents()); 643 TabContentsWrapper app_tab1(CreateTestWebContents());
645 app_icon_loader_->SetAppID(&app_tab1, "1"); 644 app_icon_loader_->SetAppID(&app_tab1, "1");
646 TabContentsWrapper app_tab2(CreateTestTabContents()); 645 TabContentsWrapper app_tab2(CreateTestWebContents());
647 app_icon_loader_->SetAppID(&app_tab2, "2"); 646 app_icon_loader_->SetAppID(&app_tab2, "2");
648 TabContentsWrapper app_tab3(CreateTestTabContents()); 647 TabContentsWrapper app_tab3(CreateTestWebContents());
649 app_icon_loader_->SetAppID(&app_tab3, "3"); 648 app_icon_loader_->SetAppID(&app_tab3, "3");
650 649
651 // Insert an app tab. 650 // Insert an app tab.
652 state.tab_strip.InsertTabContentsAt(0, &app_tab1, TabStripModel::ADD_ACTIVE); 651 state.tab_strip.InsertTabContentsAt(0, &app_tab1, TabStripModel::ADD_ACTIVE);
653 ASSERT_EQ(0, state.tab_strip.active_index()); 652 ASSERT_EQ(0, state.tab_strip.active_index());
654 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status); 653 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status);
655 654
656 // Add a second, inactive tab. 655 // Add a second, inactive tab.
657 state.tab_strip.InsertTabContentsAt(1, &app_tab2, TabStripModel::ADD_NONE); 656 state.tab_strip.InsertTabContentsAt(1, &app_tab2, TabStripModel::ADD_NONE);
658 ASSERT_EQ(0, state.tab_strip.active_index()); 657 ASSERT_EQ(0, state.tab_strip.active_index());
659 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status); 658 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status);
660 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); 659 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
661 660
662 // Add a third, and make it active. 661 // Add a third, and make it active.
663 state.tab_strip.InsertTabContentsAt(2, &app_tab3, TabStripModel::ADD_ACTIVE); 662 state.tab_strip.InsertTabContentsAt(2, &app_tab3, TabStripModel::ADD_ACTIVE);
664 ASSERT_EQ(2, state.tab_strip.active_index()); 663 ASSERT_EQ(2, state.tab_strip.active_index());
665 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status); 664 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status);
666 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); 665 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
667 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status); 666 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status);
668 667
669 // Make the first active 668 // Make the first active
670 state.tab_strip.ActivateTabAt(0, false); 669 state.tab_strip.ActivateTabAt(0, false);
671 ASSERT_EQ(0, state.tab_strip.active_index()); 670 ASSERT_EQ(0, state.tab_strip.active_index());
672 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status); 671 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab1).status);
673 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); 672 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
674 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status); 673 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status);
675 674
676 { 675 {
677 // Add a 4th tab. 676 // Add a 4th tab.
678 TabContentsWrapper app_tab4(CreateTestTabContents()); 677 TabContentsWrapper app_tab4(CreateTestWebContents());
679 app_icon_loader_->SetAppID(&app_tab3, "4"); 678 app_icon_loader_->SetAppID(&app_tab3, "4");
680 state.tab_strip.InsertTabContentsAt( 679 state.tab_strip.InsertTabContentsAt(
681 4, &app_tab4, TabStripModel::ADD_ACTIVE); 680 4, &app_tab4, TabStripModel::ADD_ACTIVE);
682 ASSERT_EQ(3, state.tab_strip.active_index()); 681 ASSERT_EQ(3, state.tab_strip.active_index());
683 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status); 682 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status);
684 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); 683 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
685 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status); 684 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab3).status);
686 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab4).status); 685 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab4).status);
687 } 686 }
688 687
689 // After the 4th is closed the third becomes active. 688 // After the 4th is closed the third becomes active.
690 ASSERT_EQ(2, state.tab_strip.active_index()); 689 ASSERT_EQ(2, state.tab_strip.active_index());
691 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status); 690 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab1).status);
692 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status); 691 EXPECT_EQ(ash::STATUS_RUNNING, GetItem(state.updater, &app_tab2).status);
693 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status); 692 EXPECT_EQ(ash::STATUS_ACTIVE, GetItem(state.updater, &app_tab3).status);
694 } 693 }
695 694
696 // Confirm that tabbed browsers handle activation correctly. 695 // Confirm that tabbed browsers handle activation correctly.
697 TEST_F(LauncherUpdaterTest, ActivateBrowsers) { 696 TEST_F(LauncherUpdaterTest, ActivateBrowsers) {
698 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED); 697 State state1(this, std::string(), LauncherUpdater::TYPE_TABBED);
699 TabContentsWrapper tab1(CreateTestTabContents()); 698 TabContentsWrapper tab1(CreateTestWebContents());
700 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 699 state1.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
701 700
702 // First browser is active. 701 // First browser is active.
703 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); 702 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
704 703
705 { 704 {
706 // Second browser is active and first is inactive. 705 // Second browser is active and first is inactive.
707 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED); 706 State state2(this, std::string(), LauncherUpdater::TYPE_TABBED);
708 TabContentsWrapper tab2(CreateTestTabContents()); 707 TabContentsWrapper tab2(CreateTestWebContents());
709 state2.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE); 708 state2.tab_strip.InsertTabContentsAt(0, &tab1, TabStripModel::ADD_ACTIVE);
710 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status); 709 EXPECT_EQ(ash::STATUS_ACTIVE, state2.GetUpdaterItem().status);
711 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status); 710 EXPECT_EQ(ash::STATUS_RUNNING, state1.GetUpdaterItem().status);
712 711
713 // Make first browser active again. 712 // Make first browser active again.
714 activation_client_->ActivateWindow(&state1.window); 713 activation_client_->ActivateWindow(&state1.window);
715 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status); 714 EXPECT_EQ(ash::STATUS_ACTIVE, state1.GetUpdaterItem().status);
716 EXPECT_EQ(ash::STATUS_RUNNING, state2.GetUpdaterItem().status); 715 EXPECT_EQ(ash::STATUS_RUNNING, state2.GetUpdaterItem().status);
717 716
718 // And back to second. 717 // And back to second.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 775
777 // And to the second item active. 776 // And to the second item active.
778 ash::LauncherItem new_item2(launcher_model_->items()[index2]); 777 ash::LauncherItem new_item2(launcher_model_->items()[index2]);
779 new_item2.status = ash::STATUS_ACTIVE; 778 new_item2.status = ash::STATUS_ACTIVE;
780 launcher_model_->Set(index2, new_item2); 779 launcher_model_->Set(index2, new_item2);
781 EXPECT_EQ(ash::STATUS_RUNNING, launcher_model_->items()[index1].status); 780 EXPECT_EQ(ash::STATUS_RUNNING, launcher_model_->items()[index1].status);
782 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model_->items()[index2].status); 781 EXPECT_EQ(ash::STATUS_ACTIVE, launcher_model_->items()[index2].status);
783 EXPECT_EQ(&state2.window, activation_client_->GetActiveWindow()); 782 EXPECT_EQ(&state2.window, activation_client_->GetActiveWindow());
784 } 783 }
785 784
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc ('k') | chrome/browser/ui/views/browser_dialogs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698