OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
-> chrome_launcher_controller_unittest.cc
simonhong_
2013/08/19 05:26:11
Done.
| |
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/ash/launcher/chrome_launcher_controller_per_app.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
26 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_commands.h" | 27 #include "chrome/browser/ui/browser_commands.h" |
28 #include "chrome/browser/ui/browser_finder.h" | 28 #include "chrome/browser/ui/browser_finder.h" |
29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/host_desktop.h" | 30 #include "chrome/browser/ui/host_desktop.h" |
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
32 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
33 #include "chrome/common/extensions/extension_constants.h" | 33 #include "chrome/common/extensions/extension_constants.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "chrome/test/base/browser_with_test_window_test.h" | 35 #include "chrome/test/base/browser_with_test_window_test.h" |
36 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
36 #include "chrome/test/base/testing_pref_service_syncable.h" | 37 #include "chrome/test/base/testing_pref_service_syncable.h" |
37 #include "chrome/test/base/testing_profile.h" | 38 #include "chrome/test/base/testing_profile.h" |
39 #include "content/public/browser/web_contents.h" | |
38 #include "content/public/test/test_browser_thread.h" | 40 #include "content/public/test/test_browser_thread.h" |
39 #include "extensions/common/manifest_constants.h" | 41 #include "extensions/common/manifest_constants.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "ui/base/models/menu_model.h" | 43 #include "ui/base/models/menu_model.h" |
42 | 44 |
43 using extensions::Extension; | 45 using extensions::Extension; |
44 using extensions::Manifest; | 46 using extensions::Manifest; |
45 | 47 |
46 namespace { | 48 namespace { |
47 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; | 49 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 | 102 |
101 private: | 103 private: |
102 int added_; | 104 int added_; |
103 int removed_; | 105 int removed_; |
104 int changed_; | 106 int changed_; |
105 int last_index_; | 107 int last_index_; |
106 | 108 |
107 DISALLOW_COPY_AND_ASSIGN(TestLauncherModelObserver); | 109 DISALLOW_COPY_AND_ASSIGN(TestLauncherModelObserver); |
108 }; | 110 }; |
109 | 111 |
112 // Test implementation of AppTabHelper. | |
113 class TestAppTabHelperImpl : public ChromeLauncherController::AppTabHelper { | |
114 public: | |
115 TestAppTabHelperImpl() {} | |
116 virtual ~TestAppTabHelperImpl() {} | |
117 | |
118 // Sets the id for the specified tab. The id is removed if Remove() is | |
119 // invoked. | |
120 void SetAppID(content::WebContents* tab, const std::string& id) { | |
121 tab_id_map_[tab] = id; | |
122 } | |
123 | |
124 // Returns true if there is an id registered for |tab|. | |
125 bool HasAppID(content::WebContents* tab) const { | |
126 return tab_id_map_.find(tab) != tab_id_map_.end(); | |
127 } | |
128 | |
129 // AppTabHelper implementation: | |
130 virtual std::string GetAppID(content::WebContents* tab) OVERRIDE { | |
131 return tab_id_map_.find(tab) != tab_id_map_.end() ? tab_id_map_[tab] : | |
132 std::string(); | |
133 } | |
134 | |
135 virtual bool IsValidID(const std::string& id) OVERRIDE { | |
136 for (TabToStringMap::const_iterator i = tab_id_map_.begin(); | |
137 i != tab_id_map_.end(); ++i) { | |
138 if (i->second == id) | |
139 return true; | |
140 } | |
141 return false; | |
142 } | |
143 | |
144 private: | |
145 typedef std::map<content::WebContents*, std::string> TabToStringMap; | |
146 | |
147 TabToStringMap tab_id_map_; | |
148 | |
149 DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); | |
150 }; | |
151 | |
110 // Test implementation of AppIconLoader. | 152 // Test implementation of AppIconLoader. |
111 class TestAppIconLoaderImpl : public extensions::AppIconLoader { | 153 class TestAppIconLoaderImpl : public extensions::AppIconLoader { |
112 public: | 154 public: |
113 TestAppIconLoaderImpl() : fetch_count_(0) { | 155 TestAppIconLoaderImpl() : fetch_count_(0) { |
114 } | 156 } |
115 | 157 |
116 virtual ~TestAppIconLoaderImpl() { | 158 virtual ~TestAppIconLoaderImpl() { |
117 } | 159 } |
118 | 160 |
119 // AppIconLoader implementation: | 161 // AppIconLoader implementation: |
(...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1378 ash::LauncherID gmail_id = model_->next_id(); | 1420 ash::LauncherID gmail_id = model_->next_id(); |
1379 extension_service_->AddExtension(extension3_.get()); | 1421 extension_service_->AddExtension(extension3_.get()); |
1380 EXPECT_EQ(3, model_->item_count()); | 1422 EXPECT_EQ(3, model_->item_count()); |
1381 int gmail_index = model_->ItemIndexByID(gmail_id); | 1423 int gmail_index = model_->ItemIndexByID(gmail_id); |
1382 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); | 1424 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); |
1383 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); | 1425 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
1384 | 1426 |
1385 // The content should not be able to be handled by the app. | 1427 // The content should not be able to be handled by the app. |
1386 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); | 1428 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); |
1387 } | 1429 } |
1430 | |
Mr4D (OOO till 08-26)
2013/08/16 22:43:22
How did this all end up here?
simonhong_
2013/08/19 05:26:11
Most of unit tests in browser_launcher_item_contro
| |
1431 class LauncherItemControllerPerAppTest | |
1432 : public ChromeRenderViewHostTestHarness { | |
1433 public: | |
1434 LauncherItemControllerPerAppTest() {} | |
1435 virtual ~LauncherItemControllerPerAppTest() {} | |
1436 | |
1437 virtual void SetUp() OVERRIDE { | |
1438 ChromeRenderViewHostTestHarness::SetUp(); | |
1439 | |
1440 launcher_model_.reset(new ash::LauncherModel); | |
1441 launcher_delegate_.reset( | |
1442 ChromeLauncherController::CreateInstance(profile(), | |
1443 launcher_model_.get())); | |
1444 app_tab_helper_ = new TestAppTabHelperImpl; | |
1445 app_icon_loader_ = new TestAppIconLoaderImpl; | |
1446 launcher_delegate_->SetAppTabHelperForTest(app_tab_helper_); | |
1447 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); | |
1448 launcher_delegate_->Init(); | |
1449 } | |
1450 | |
1451 virtual void TearDown() OVERRIDE { | |
1452 launcher_delegate_.reset(); | |
1453 ChromeRenderViewHostTestHarness::TearDown(); | |
1454 } | |
1455 | |
1456 protected: | |
1457 const std::string& GetAppID(ash::LauncherID id) const { | |
1458 return launcher_delegate_->GetAppIdFromLauncherIdForTest(id); | |
1459 } | |
1460 | |
1461 void ResetAppTabHelper() { | |
1462 launcher_delegate_->SetAppTabHelperForTest(app_tab_helper_); | |
1463 } | |
1464 | |
1465 void ResetAppIconLoader() { | |
1466 launcher_delegate_->SetAppIconLoaderForTest(app_icon_loader_); | |
1467 } | |
1468 | |
1469 void UnpinAppsWithID(const std::string& app_id) { | |
1470 launcher_delegate_->UnpinAppsWithID(app_id); | |
1471 } | |
1472 | |
1473 scoped_ptr<ash::LauncherModel> launcher_model_; | |
1474 scoped_ptr<ChromeLauncherController> launcher_delegate_; | |
1475 | |
1476 // Owned by BrowserLauncherItemController. | |
1477 TestAppTabHelperImpl* app_tab_helper_; | |
1478 TestAppIconLoaderImpl* app_icon_loader_; | |
1479 | |
1480 private: | |
1481 DISALLOW_COPY_AND_ASSIGN(LauncherItemControllerPerAppTest); | |
1482 }; | |
1483 | |
1484 // Verify that the launcher item positions are persisted and restored. | |
1485 TEST_F(LauncherItemControllerPerAppTest, PersistLauncherItemPositions) { | |
1486 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | |
1487 launcher_model_->items()[0].type); | |
1488 EXPECT_EQ(ash::TYPE_APP_LIST, | |
1489 launcher_model_->items()[1].type); | |
1490 scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); | |
1491 scoped_ptr<content::WebContents> tab2(CreateTestWebContents()); | |
1492 app_tab_helper_->SetAppID(tab1.get(), "1"); | |
1493 app_tab_helper_->SetAppID(tab1.get(), "2"); | |
1494 | |
1495 EXPECT_FALSE(launcher_delegate_->IsAppPinned("1")); | |
1496 launcher_delegate_->PinAppWithID("1"); | |
1497 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); | |
1498 launcher_delegate_->PinAppWithID("2"); | |
1499 | |
1500 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | |
1501 launcher_model_->items()[0].type); | |
1502 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1503 launcher_model_->items()[1].type); | |
1504 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1505 launcher_model_->items()[2].type); | |
1506 EXPECT_EQ(ash::TYPE_APP_LIST, | |
1507 launcher_model_->items()[3].type); | |
1508 | |
1509 launcher_model_->Move(0, 2); | |
1510 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1511 launcher_model_->items()[0].type); | |
1512 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1513 launcher_model_->items()[1].type); | |
1514 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | |
1515 launcher_model_->items()[2].type); | |
1516 EXPECT_EQ(ash::TYPE_APP_LIST, | |
1517 launcher_model_->items()[3].type); | |
1518 | |
1519 launcher_delegate_.reset(); | |
1520 launcher_model_.reset(new ash::LauncherModel); | |
1521 launcher_delegate_.reset( | |
1522 ChromeLauncherController::CreateInstance(profile(), | |
1523 launcher_model_.get())); | |
1524 app_tab_helper_ = new TestAppTabHelperImpl; | |
1525 app_tab_helper_->SetAppID(tab1.get(), "1"); | |
1526 app_tab_helper_->SetAppID(tab2.get(), "2"); | |
1527 ResetAppTabHelper(); | |
1528 | |
1529 launcher_delegate_->Init(); | |
1530 | |
1531 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1532 launcher_model_->items()[0].type); | |
1533 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1534 launcher_model_->items()[1].type); | |
1535 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, | |
1536 launcher_model_->items()[2].type); | |
1537 EXPECT_EQ(ash::TYPE_APP_LIST, | |
1538 launcher_model_->items()[3].type); | |
1539 } | |
1540 | |
1541 // Verifies pinned apps are persisted and restored. | |
1542 TEST_F(LauncherItemControllerPerAppTest, PersistPinned) { | |
1543 size_t initial_size = launcher_model_->items().size(); | |
1544 scoped_ptr<content::WebContents> tab1(CreateTestWebContents()); | |
1545 | |
1546 app_tab_helper_->SetAppID(tab1.get(), "1"); | |
1547 | |
1548 EXPECT_EQ(0, app_icon_loader_->fetch_count()); | |
1549 launcher_delegate_->PinAppWithID("1"); | |
1550 ash::LauncherID id = launcher_delegate_->GetLauncherIDForAppID("1"); | |
1551 int app_index = launcher_model_->ItemIndexByID(id); | |
1552 EXPECT_EQ(1, app_icon_loader_->fetch_count()); | |
1553 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1554 launcher_model_->items()[app_index].type); | |
1555 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); | |
1556 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); | |
1557 EXPECT_EQ(initial_size + 1, launcher_model_->items().size()); | |
1558 | |
1559 launcher_delegate_.reset(); | |
1560 launcher_model_.reset(new ash::LauncherModel); | |
1561 launcher_delegate_.reset( | |
1562 ChromeLauncherController::CreateInstance(profile(), | |
1563 launcher_model_.get())); | |
1564 app_tab_helper_ = new TestAppTabHelperImpl; | |
1565 app_tab_helper_->SetAppID(tab1.get(), "1"); | |
1566 ResetAppTabHelper(); | |
1567 app_icon_loader_ = new TestAppIconLoaderImpl; | |
1568 ResetAppIconLoader(); | |
1569 launcher_delegate_->Init(); | |
1570 EXPECT_EQ(1, app_icon_loader_->fetch_count()); | |
1571 ASSERT_EQ(initial_size + 1, launcher_model_->items().size()); | |
1572 EXPECT_TRUE(launcher_delegate_->IsAppPinned("1")); | |
1573 EXPECT_FALSE(launcher_delegate_->IsAppPinned("0")); | |
1574 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, | |
1575 launcher_model_->items()[app_index].type); | |
1576 | |
1577 UnpinAppsWithID("1"); | |
1578 ASSERT_EQ(initial_size, launcher_model_->items().size()); | |
1579 } | |
1580 | |
OLD | NEW |