| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 6 | 6 |
| 7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
| 8 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
| 9 #include "ash/launcher/launcher_types.h" | 9 #include "ash/launcher/launcher_types.h" |
| 10 #include "ash/test/ash_test_base.h" |
| 10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 12 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.
h" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.
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/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | |
| 20 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
| 21 | 20 |
| 22 class TestChromeLauncherControllerPerBrowser : | 21 class TestChromeLauncherControllerPerBrowser : |
| 23 public ChromeLauncherControllerPerBrowser { | 22 public ChromeLauncherControllerPerBrowser { |
| 24 public: | 23 public: |
| 25 TestChromeLauncherControllerPerBrowser( | 24 TestChromeLauncherControllerPerBrowser( |
| 26 Profile* profile, ash::LauncherModel* model) | 25 Profile* profile, ash::LauncherModel* model) |
| 27 : ChromeLauncherControllerPerBrowser(profile, model) {} | 26 : ChromeLauncherControllerPerBrowser(profile, model) {} |
| 28 virtual bool IsLoggedInAsGuest() OVERRIDE { | 27 virtual bool IsLoggedInAsGuest() OVERRIDE { |
| 29 return false; | 28 return false; |
| 30 } | 29 } |
| 31 private: | 30 private: |
| 32 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerPerBrowser); | 31 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerPerBrowser); |
| 33 }; | 32 }; |
| 34 | 33 |
| 35 class LauncherContextMenuTest : public ChromeRenderViewHostTestHarness { | 34 class LauncherContextMenuTest : public ash::test::AshTestBase { |
| 36 protected: | 35 protected: |
| 37 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { | 36 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) { |
| 38 DCHECK(menu); | 37 DCHECK(menu); |
| 39 return menu->GetIndexOfCommandId(command_id) != -1; | 38 return menu->GetIndexOfCommandId(command_id) != -1; |
| 40 } | 39 } |
| 41 | 40 |
| 42 LauncherContextMenuTest() | 41 LauncherContextMenuTest() |
| 43 : ChromeRenderViewHostTestHarness(), | 42 : ash::test::AshTestBase(), |
| 44 browser_thread_(content::BrowserThread::UI, &message_loop_) {} | 43 profile_(new TestingProfile()), |
| 44 browser_thread_(content::BrowserThread::UI, message_loop()) {} |
| 45 | 45 |
| 46 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
| 47 ChromeRenderViewHostTestHarness::SetUp(); | 47 ash::test::AshTestBase::SetUp(); |
| 48 controller_.reset( | 48 controller_.reset( |
| 49 new TestChromeLauncherControllerPerBrowser(profile(), | 49 new TestChromeLauncherControllerPerBrowser(profile(), |
| 50 &launcher_model_)); | 50 &launcher_model_)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual void TearDown() OVERRIDE { | 53 virtual void TearDown() OVERRIDE { |
| 54 controller_.reset(NULL); | 54 controller_.reset(NULL); |
| 55 ChromeRenderViewHostTestHarness::TearDown(); | 55 ash::test::AshTestBase::TearDown(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 LauncherContextMenu* CreateLauncherContextMenu( | 58 LauncherContextMenu* CreateLauncherContextMenu( |
| 59 ash::LauncherItemType launcher_item_type) { | 59 ash::LauncherItemType launcher_item_type) { |
| 60 ash::LauncherItem item; | 60 ash::LauncherItem item; |
| 61 item.id = 1; // dummy id | 61 item.id = 1; // dummy id |
| 62 item.type = launcher_item_type; | 62 item.type = launcher_item_type; |
| 63 return new LauncherContextMenu(controller_.get(), &item, root_window()); | 63 return new LauncherContextMenu(controller_.get(), &item, CurrentContext()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 Profile* profile() { return profile_.get(); } |
| 67 |
| 66 private: | 68 private: |
| 69 scoped_ptr<TestingProfile> profile_; |
| 67 content::TestBrowserThread browser_thread_; | 70 content::TestBrowserThread browser_thread_; |
| 68 ash::LauncherModel launcher_model_; | 71 ash::LauncherModel launcher_model_; |
| 69 scoped_ptr<ChromeLauncherController> controller_; | 72 scoped_ptr<ChromeLauncherController> controller_; |
| 70 | 73 |
| 71 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); | 74 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest); |
| 72 }; | 75 }; |
| 73 | 76 |
| 74 // Verifies that "New Incognito window" menu item in the launcher context | 77 // Verifies that "New Incognito window" menu item in the launcher context |
| 75 // menu is disabled when Incognito mode is switched off (by a policy). | 78 // menu is disabled when Incognito mode is switched off (by a policy). |
| 76 TEST_F(LauncherContextMenuTest, | 79 TEST_F(LauncherContextMenuTest, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 106 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 109 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
| 107 | 110 |
| 108 // Disable Incognito mode. | 111 // Disable Incognito mode. |
| 109 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), | 112 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(), |
| 110 IncognitoModePrefs::FORCED); | 113 IncognitoModePrefs::FORCED); |
| 111 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); | 114 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT)); |
| 112 ASSERT_TRUE(IsItemPresentInMenu( | 115 ASSERT_TRUE(IsItemPresentInMenu( |
| 113 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); | 116 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW)); |
| 114 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); | 117 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW)); |
| 115 } | 118 } |
| OLD | NEW |