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

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

Issue 11471027: Added more tests for IncognitoModeAvailability. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Style issues. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_context_menu.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
6
7 #include "ash/launcher/launcher.h"
8 #include "ash/launcher/launcher_model.h"
9 #include "ash/launcher/launcher_types.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/prefs/incognito_mode_prefs.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #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_per_browser. h"
16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
17 #include "chrome/test/base/testing_profile.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"
21
22 class TestChromeLauncherControllerPerBrowser :
23 public ChromeLauncherControllerPerBrowser {
24 public:
25 TestChromeLauncherControllerPerBrowser(
26 Profile* profile, ash::LauncherModel* model)
27 : ChromeLauncherControllerPerBrowser(profile, model) {}
28 virtual bool IsLoggedInAsGuest() OVERRIDE {
29 return false;
30 }
31 private:
32 DISALLOW_COPY_AND_ASSIGN(TestChromeLauncherControllerPerBrowser);
33 };
34
35 class LauncherContextMenuTest : public ChromeRenderViewHostTestHarness {
36 protected:
37 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
38 DCHECK(menu);
39 return menu->GetIndexOfCommandId(command_id) != -1;
40 }
41
42 LauncherContextMenuTest()
43 : ChromeRenderViewHostTestHarness(),
44 browser_thread_(content::BrowserThread::UI, &message_loop_) {}
45
46 virtual void SetUp() OVERRIDE {
47 ChromeRenderViewHostTestHarness::SetUp();
48 controller_.reset(
49 new TestChromeLauncherControllerPerBrowser(profile(),
50 &launcher_model_));
51 }
52
53 virtual void TearDown() OVERRIDE {
54 controller_.reset(NULL);
55 ChromeRenderViewHostTestHarness::TearDown();
56 }
57
58 LauncherContextMenu* CreateLauncherContextMenu(
59 ash::LauncherItemType launcher_item_type) {
60 ash::LauncherItem item;
61 item.id = 1; // dummy id
62 item.type = launcher_item_type;
63 return new LauncherContextMenu(controller_.get(), &item, root_window());
64 }
65
66 private:
67 content::TestBrowserThread browser_thread_;
68 ash::LauncherModel launcher_model_;
69 scoped_ptr<ChromeLauncherController> controller_;
70
71 DISALLOW_COPY_AND_ASSIGN(LauncherContextMenuTest);
72 };
73
74 // Verifies that "New Incognito window" menu item in the launcher context
75 // menu is disabled when Incognito mode is switched off (by a policy).
76 TEST_F(LauncherContextMenuTest,
77 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) {
78 // Initially, "New Incognito window" should be enabled.
79 scoped_ptr<LauncherContextMenu> menu(
80 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
81 ASSERT_TRUE(IsItemPresentInMenu(
82 menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
83 EXPECT_TRUE(menu->IsCommandIdEnabled(
84 LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
85
86 // Disable Incognito mode.
87 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
88 IncognitoModePrefs::DISABLED);
89 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
90 // The item should be disabled.
91 ASSERT_TRUE(IsItemPresentInMenu(
92 menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
93 EXPECT_FALSE(menu->IsCommandIdEnabled(
94 LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
95 }
96
97 // Verifies that "New window" menu item in the launcher context
98 // menu is disabled when Incognito mode is forced (by a policy).
99 TEST_F(LauncherContextMenuTest,
100 NewWindowMenuIsDisabledWhenIncognitoModeForced) {
101 // Initially, "New window" should be enabled.
102 scoped_ptr<LauncherContextMenu> menu(
103 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
104 ASSERT_TRUE(IsItemPresentInMenu(
105 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
106 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
107
108 // Disable Incognito mode.
109 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
110 IncognitoModePrefs::FORCED);
111 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
112 ASSERT_TRUE(IsItemPresentInMenu(
113 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
114 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
115 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/launcher_context_menu.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698