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

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: Add render_view_context_menu_test_util to unit_test and browser_tests. 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
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 {
sky 2013/01/14 16:03:37 indent two more
rustema 2013/01/15 07:37:40 Done.
24 public:
25 TestChromeLauncherControllerPerBrowser(
26 Profile* profile, ash::LauncherModel* model)
27 : ChromeLauncherControllerPerBrowser(profile, model) {}
28 virtual bool IsLoggedInAsGuest() {
sky 2013/01/14 16:03:37 OVERRIDE
rustema 2013/01/15 07:37:40 Done.
29 return false;
30 }
31 };
sky 2013/01/14 16:03:37 private: DISALLOW...
rustema 2013/01/15 07:37:40 Done.
32
33 class LauncherContextMenuBrowserTest : public ChromeRenderViewHostTestHarness {
sky 2013/01/14 16:03:37 BrowserTest -> Test
rustema 2013/01/15 07:37:40 Done.
34 protected:
35 static bool IsItemPresentInMenu(LauncherContextMenu* menu, int command_id) {
36 DCHECK(menu);
37 return menu->GetIndexOfCommandId(command_id) != -1;
38 }
39
40 LauncherContextMenuBrowserTest()
41 : ChromeRenderViewHostTestHarness(),
42 browser_thread_(content::BrowserThread::UI, &message_loop_) {}
43
44 virtual void SetUp() {
sky 2013/01/14 16:03:37 OVERRIDE where appropriate
rustema 2013/01/15 07:37:40 Done.
45 ChromeRenderViewHostTestHarness::SetUp();
46 controller_.reset(
47 new TestChromeLauncherControllerPerBrowser(profile(),
48 &launcher_model_));
49 }
50
51 virtual void TearDown() {
52 controller_.reset(NULL);
53 ChromeRenderViewHostTestHarness::TearDown();
54 }
55
56 LauncherContextMenu* CreateLauncherContextMenu(
57 ash::LauncherItemType launcher_item_type) {
58 ash::LauncherItem item;
59 item.id = 1; // dummy id
60 item.type = launcher_item_type;
61 return new LauncherContextMenu(controller_.get(), &item, root_window());
62 }
63 private:
sky 2013/01/14 16:03:37 newline between 62/63.
rustema 2013/01/15 07:37:40 Done.
64 content::TestBrowserThread browser_thread_;
65 ash::LauncherModel launcher_model_;
66 scoped_ptr<ChromeLauncherController> controller_;
67 };
sky 2013/01/14 16:03:37 DISALLOW...
rustema 2013/01/15 07:37:40 Done.
68
69 // Verifies that "New Incognito window" menu item in the launcher context
70 // menu is disabled when Incognito mode is switched off (by a policy).
71 TEST_F(LauncherContextMenuBrowserTest,
72 NewIncognitoWindowMenuIsDisabledWhenIncognitoModeOff) {
73 // Initially, "New Incognito window" should be enabled.
74 scoped_ptr<LauncherContextMenu> menu(
75 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
76 ASSERT_TRUE(IsItemPresentInMenu(
77 menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
78 EXPECT_TRUE(menu->IsCommandIdEnabled(
79 LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
80
81 // Disable Incognito mode.
82 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
83 IncognitoModePrefs::DISABLED);
84 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
85 // The item should be disabled.
86 ASSERT_TRUE(IsItemPresentInMenu(
87 menu.get(), LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
88 EXPECT_FALSE(menu->IsCommandIdEnabled(
89 LauncherContextMenu::MENU_NEW_INCOGNITO_WINDOW));
90 }
91
92 // Verifies that "New window" menu item in the launcher context
93 // menu is disabled when Incognito mode is forced (by a policy).
94 TEST_F(LauncherContextMenuBrowserTest,
95 NewWindowMenuIsDisabledWhenIncognitoModeForced) {
96 // Initially, "New window" should be enabled.
97 scoped_ptr<LauncherContextMenu> menu(
98 CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
99 ASSERT_TRUE(IsItemPresentInMenu(
100 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
101 EXPECT_TRUE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
102
103 // Disable Incognito mode.
104 IncognitoModePrefs::SetAvailability(profile()->GetPrefs(),
105 IncognitoModePrefs::FORCED);
106 menu.reset(CreateLauncherContextMenu(ash::TYPE_BROWSER_SHORTCUT));
107 ASSERT_TRUE(IsItemPresentInMenu(
108 menu.get(), LauncherContextMenu::MENU_NEW_WINDOW));
109 EXPECT_FALSE(menu->IsCommandIdEnabled(LauncherContextMenu::MENU_NEW_WINDOW));
110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698