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

Side by Side Diff: chrome/browser/ui/browser_navigator_browsertest.cc

Issue 6272016: Prevent non-Incognito windows in the Guest session. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser
Patch Set: code review Created 9 years, 10 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/browser_navigator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/profiles/profile.h" 6 #include "chrome/browser/profiles/profile.h"
7 #include "chrome/browser/tab_contents/tab_contents.h" 7 #include "chrome/browser/tab_contents/tab_contents.h"
8 #include "chrome/browser/tab_contents/tab_contents_view.h" 8 #include "chrome/browser/tab_contents/tab_contents_view.h"
9 #include "chrome/browser/tabs/tab_strip_model.h" 9 #include "chrome/browser/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/browser_navigator.h" 12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/in_process_browser_test.h" 16 #include "chrome/test/in_process_browser_test.h"
17 #include "chrome/test/ui_test_utils.h" 17 #include "chrome/test/ui_test_utils.h"
18 #include "ipc/ipc_message.h" 18 #include "ipc/ipc_message.h"
19 19
20 #if defined(OS_CHROMEOS)
21 #include "chrome/browser/chromeos/login/login_utils.h"
22 #endif
23
20 namespace { 24 namespace {
21 25
22 class BrowserNavigatorTest : public InProcessBrowserTest, 26 class BrowserNavigatorTest : public InProcessBrowserTest,
23 public NotificationObserver { 27 public NotificationObserver {
24 protected: 28 protected:
25 GURL GetGoogleURL() const { 29 GURL GetGoogleURL() const {
26 return GURL("http://www.google.com/"); 30 return GURL("http://www.google.com/");
27 } 31 }
28 32
29 browser::NavigateParams MakeNavigateParams() const { 33 browser::NavigateParams MakeNavigateParams() const {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) { 87 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_CurrentTab) {
84 browser::NavigateParams p(MakeNavigateParams()); 88 browser::NavigateParams p(MakeNavigateParams());
85 browser::Navigate(&p); 89 browser::Navigate(&p);
86 ui_test_utils::WaitForNavigationInCurrentTab(browser()); 90 ui_test_utils::WaitForNavigationInCurrentTab(browser());
87 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL()); 91 EXPECT_EQ(GetGoogleURL(), browser()->GetSelectedTabContents()->GetURL());
88 // We should have one window with one tab. 92 // We should have one window with one tab.
89 EXPECT_EQ(1u, BrowserList::size()); 93 EXPECT_EQ(1u, BrowserList::size());
90 EXPECT_EQ(1, browser()->tab_count()); 94 EXPECT_EQ(1, browser()->tab_count());
91 } 95 }
92 96
93 // This test verifies that a singleton tab is refocused if one is already open 97 // This test verifies that a singleton tab is refocused if one is already opened
94 // in another or an existing window, or added if it is not. 98 // in another or an existing window, or added if it is not.
95 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) { 99 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_SingletonTabExisting) {
96 GURL url("http://www.google.com/"); 100 GURL url("http://www.google.com/");
97 GURL singleton_url1("http://maps.google.com/"); 101 GURL singleton_url1("http://maps.google.com/");
98 102
99 // Register for a notification if an additional tab_contents was instantiated. 103 // Register for a notification if an additional tab_contents was instantiated.
100 // Opening a Singleton tab that is already open should not be opening a new 104 // Opening a Singleton tab that is already opened should not be opening a new
101 // tab nor be creating a new TabContents object 105 // tab nor be creating a new TabContents object
102 NotificationRegistrar registrar; 106 NotificationRegistrar registrar;
103 107
104 // As the registrar object goes out of scope, this will get unregistered 108 // As the registrar object goes out of scope, this will get unregistered
105 registrar.Add(this, NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, 109 registrar.Add(this, NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
106 NotificationService::AllSources()); 110 NotificationService::AllSources());
107 111
108 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK); 112 browser()->AddSelectedTabWithURL(singleton_url1, PageTransition::LINK);
109 browser()->AddSelectedTabWithURL(url, PageTransition::LINK); 113 browser()->AddSelectedTabWithURL(url, PageTransition::LINK);
110 114
(...skipping 17 matching lines...) Expand all
128 // No tab contents should have been created 132 // No tab contents should have been created
129 EXPECT_EQ(previous_tab_contents_count, 133 EXPECT_EQ(previous_tab_contents_count,
130 created_tab_contents_count_); 134 created_tab_contents_count_);
131 } 135 }
132 136
133 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, 137 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
134 Disposition_SingletonTabNoneExisting) { 138 Disposition_SingletonTabNoneExisting) {
135 GURL url("http://www.google.com/"); 139 GURL url("http://www.google.com/");
136 GURL singleton_url1("http://maps.google.com/"); 140 GURL singleton_url1("http://maps.google.com/");
137 141
138 // We should have one browser with 3 tabs, the 3rd selected. 142 // We should have one browser with 1 tab.
139 EXPECT_EQ(1u, BrowserList::size()); 143 EXPECT_EQ(1u, BrowserList::size());
140 EXPECT_EQ(0, browser()->selected_index()); 144 EXPECT_EQ(0, browser()->selected_index());
141 145
142 // Navigate to singleton_url1. 146 // Navigate to singleton_url1.
143 browser::NavigateParams p(MakeNavigateParams()); 147 browser::NavigateParams p(MakeNavigateParams());
144 p.disposition = SINGLETON_TAB; 148 p.disposition = SINGLETON_TAB;
145 p.url = singleton_url1; 149 p.url = singleton_url1;
146 browser::Navigate(&p); 150 browser::Navigate(&p);
147 151
148 // We should now have 2 tabs, the 2nd one selected. 152 // We should now have 2 tabs, the 2nd one selected.
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 browser::Navigate(&p); 678 browser::Navigate(&p);
675 679
676 // The second tab should still be selected, but navigated to the new path. 680 // The second tab should still be selected, but navigated to the new path.
677 EXPECT_EQ(browser(), p.browser); 681 EXPECT_EQ(browser(), p.browser);
678 EXPECT_EQ(2, browser()->tab_count()); 682 EXPECT_EQ(2, browser()->tab_count());
679 EXPECT_EQ(1, browser()->selected_index()); 683 EXPECT_EQ(1, browser()->selected_index());
680 EXPECT_EQ(singleton_url_target, 684 EXPECT_EQ(singleton_url_target,
681 browser()->GetSelectedTabContents()->GetURL()); 685 browser()->GetSelectedTabContents()->GetURL());
682 } 686 }
683 687
688 // This test verifies that the settings page isn't opened in the incognito
689 // window.
690 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
691 Disposition_Settings_UseNonIncognitoWindow) {
692 Browser* incognito_browser = CreateIncognitoBrowser();
693
694 EXPECT_EQ(2u, BrowserList::size());
695 EXPECT_EQ(1, browser()->tab_count());
696 EXPECT_EQ(1, incognito_browser->tab_count());
697
698 // Navigate to the settings page.
699 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
700 p.disposition = SINGLETON_TAB;
701 p.url = GURL("chrome://settings");
702 p.show_window = true;
703 p.ignore_path = true;
704 browser::Navigate(&p);
705
706 // The settings page should be opened in browser() window.
707 EXPECT_NE(incognito_browser, p.browser);
708 EXPECT_EQ(browser(), p.browser);
709 EXPECT_EQ(2, browser()->tab_count());
710 EXPECT_EQ(GURL("chrome://settings"),
711 browser()->GetSelectedTabContents()->GetURL());
712 }
713
714 // This test verifies that the bookmarks page isn't opened in the incognito
715 // window.
716 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
717 Disposition_Bookmarks_UseNonIncognitoWindow) {
718 Browser* incognito_browser = CreateIncognitoBrowser();
719
720 EXPECT_EQ(2u, BrowserList::size());
721 EXPECT_EQ(1, browser()->tab_count());
722 EXPECT_EQ(1, incognito_browser->tab_count());
723
724 // Navigate to the settings page.
725 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
726 p.disposition = SINGLETON_TAB;
727 p.url = GURL("chrome://bookmarks");
728 p.show_window = true;
729 p.ignore_path = true;
730 browser::Navigate(&p);
731
732 // The bookmarks page should be opened in browser() window.
733 EXPECT_NE(incognito_browser, p.browser);
734 EXPECT_EQ(browser(), p.browser);
735 EXPECT_EQ(2, browser()->tab_count());
736 EXPECT_EQ(GURL("chrome://bookmarks"),
737 browser()->GetSelectedTabContents()->GetURL());
738 }
739
740 #if defined(OS_CHROMEOS)
Ben Goodger (Google) 2011/02/01 17:59:09 I would rather this live in browser_navigator_brow
Evan Stade 2011/02/01 21:12:35 I actually like this here, because it is logically
741 // Subclass that tests navigation while in the Guest session.
742 class BrowserGuestSessionNavigatorTest: public BrowserNavigatorTest {
743 protected:
744 virtual void SetUpCommandLine(CommandLine* command_line) {
745 CommandLine command_line_copy = *command_line;
746 chromeos::LoginUtils::Get()->GetOffTheRecordCommandLine(GetGoogleURL(),
747 command_line_copy,
748 command_line);
749 }
750 };
751
752 // This test verifies that the settings page is opened in the incognito window
753 // in Guest Session (as well as all other windows in Guest session).
754 IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,
755 Disposition_Settings_UseIncognitoWindow) {
756 Browser* incognito_browser = CreateIncognitoBrowser();
757
758 EXPECT_EQ(2u, BrowserList::size());
759 EXPECT_EQ(1, browser()->tab_count());
760 EXPECT_EQ(1, incognito_browser->tab_count());
761
762 // Navigate to the settings page.
763 browser::NavigateParams p(MakeNavigateParams(incognito_browser));
764 p.disposition = SINGLETON_TAB;
765 p.url = GURL("chrome://settings");
766 p.show_window = true;
767 p.ignore_path = true;
768 browser::Navigate(&p);
769
770 // Settings page should be opened in incognito window.
771 EXPECT_NE(browser(), p.browser);
772 EXPECT_EQ(incognito_browser, p.browser);
773 EXPECT_EQ(2, incognito_browser->tab_count());
774 EXPECT_EQ(GURL("chrome://settings"),
775 incognito_browser->GetSelectedTabContents()->GetURL());
776 }
777 #endif
778
684 } // namespace 779 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_navigator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698