Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_navigator_browsertest.h" | 5 #include "chrome/browser/ui/browser_navigator_browsertest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 browser::NavigateParams p(MakeNavigateParams()); | 95 browser::NavigateParams p(MakeNavigateParams()); |
| 96 p.disposition = disposition; | 96 p.disposition = disposition; |
| 97 browser::Navigate(&p); | 97 browser::Navigate(&p); |
| 98 | 98 |
| 99 // Nothing should have happened as a result of Navigate(); | 99 // Nothing should have happened as a result of Navigate(); |
| 100 EXPECT_EQ(1, browser()->tab_count()); | 100 EXPECT_EQ(1, browser()->tab_count()); |
| 101 EXPECT_EQ(1u, BrowserList::size()); | 101 EXPECT_EQ(1u, BrowserList::size()); |
| 102 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL()); | 102 EXPECT_EQ(old_url, browser()->GetSelectedTabContents()->GetURL()); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void BrowserNavigatorTest::RunUseNonIncognitoWindowTest(const GURL& url) { | |
| 106 Browser* incognito_browser = CreateIncognitoBrowser(); | |
| 107 | |
| 108 EXPECT_EQ(2u, BrowserList::size()); | |
| 109 EXPECT_EQ(1, browser()->tab_count()); | |
| 110 EXPECT_EQ(1, incognito_browser->tab_count()); | |
| 111 | |
| 112 // Navigate to the page. | |
| 113 browser::NavigateParams p(MakeNavigateParams(incognito_browser)); | |
| 114 p.disposition = SINGLETON_TAB; | |
| 115 p.url = url; | |
| 116 p.window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 117 browser::Navigate(&p); | |
| 118 | |
| 119 // This page should be opened in browser() window. | |
| 120 EXPECT_NE(incognito_browser, p.browser); | |
| 121 EXPECT_EQ(browser(), p.browser); | |
| 122 EXPECT_EQ(2, browser()->tab_count()); | |
| 123 EXPECT_EQ(url, browser()->GetSelectedTabContents()->GetURL()); | |
| 124 } | |
| 125 | |
| 126 void BrowserNavigatorTest::RunDoNothingIfIncognitoIsForcedTest( | |
| 127 const GURL& url) { | |
| 128 Browser* browser = CreateIncognitoBrowser(); | |
| 129 | |
| 130 // Set kIncognitoModeAvailability to FORCED. | |
| 131 PrefService* prefs1 = browser->profile()->GetPrefs(); | |
| 132 prefs1->SetInteger(prefs::kIncognitoModeAvailability, | |
| 133 IncognitoModePrefs::FORCED); | |
| 134 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs(); | |
| 135 prefs2->SetInteger(prefs::kIncognitoModeAvailability, | |
| 136 IncognitoModePrefs::FORCED); | |
| 137 | |
| 138 // Navigate to the page. | |
| 139 browser::NavigateParams p(MakeNavigateParams(browser)); | |
| 140 p.disposition = OFF_THE_RECORD; | |
| 141 p.url = url; | |
| 142 p.window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 143 browser::Navigate(&p); | |
| 144 | |
| 145 // The page should not be opened. | |
| 146 EXPECT_EQ(browser, p.browser); | |
| 147 EXPECT_EQ(1, browser->tab_count()); | |
| 148 EXPECT_EQ(GURL(chrome::kAboutBlankURL), | |
| 149 browser->GetSelectedTabContents()->GetURL()); | |
| 150 } | |
| 151 | |
| 105 void BrowserNavigatorTest::Observe( | 152 void BrowserNavigatorTest::Observe( |
| 106 int type, | 153 int type, |
| 107 const content::NotificationSource& source, | 154 const content::NotificationSource& source, |
| 108 const content::NotificationDetails& details) { | 155 const content::NotificationDetails& details) { |
| 109 switch (type) { | 156 switch (type) { |
| 110 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { | 157 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
| 111 ++this->created_tab_contents_count_; | 158 ++this->created_tab_contents_count_; |
| 112 break; | 159 break; |
| 113 } | 160 } |
| 114 default: | 161 default: |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 // Last tab should still be selected. | 936 // Last tab should still be selected. |
| 890 EXPECT_EQ(browser(), p.browser); | 937 EXPECT_EQ(browser(), p.browser); |
| 891 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count()); | 938 EXPECT_EQ(initial_tab_count + 1, browser()->tab_count()); |
| 892 EXPECT_EQ(initial_tab_count, browser()->active_index()); | 939 EXPECT_EQ(initial_tab_count, browser()->active_index()); |
| 893 } | 940 } |
| 894 | 941 |
| 895 // This test verifies that the settings page isn't opened in the incognito | 942 // This test verifies that the settings page isn't opened in the incognito |
| 896 // window. | 943 // window. |
| 897 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 944 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 898 Disposition_Settings_UseNonIncognitoWindow) { | 945 Disposition_Settings_UseNonIncognitoWindow) { |
| 899 Browser* incognito_browser = CreateIncognitoBrowser(); | 946 RunUseNonIncognitoWindowTest(GetSettingsURL()); |
|
binji
2011/11/17 21:02:09
Is there a better way to group all of these simila
| |
| 900 | |
| 901 EXPECT_EQ(2u, BrowserList::size()); | |
| 902 EXPECT_EQ(1, browser()->tab_count()); | |
| 903 EXPECT_EQ(1, incognito_browser->tab_count()); | |
| 904 | |
| 905 // Navigate to the settings page. | |
| 906 browser::NavigateParams p(MakeNavigateParams(incognito_browser)); | |
| 907 p.disposition = SINGLETON_TAB; | |
| 908 p.url = GetSettingsURL(); | |
| 909 p.window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 910 browser::Navigate(&p); | |
| 911 | |
| 912 // The settings page should be opened in browser() window. | |
| 913 EXPECT_NE(incognito_browser, p.browser); | |
| 914 EXPECT_EQ(browser(), p.browser); | |
| 915 EXPECT_EQ(2, browser()->tab_count()); | |
| 916 EXPECT_EQ(GetSettingsURL(), | |
| 917 browser()->GetSelectedTabContents()->GetURL()); | |
| 918 } | 947 } |
| 919 | 948 |
| 920 // This test verifies that the settings page isn't opened in the incognito | 949 // This test verifies that the settings page isn't opened in the incognito |
| 921 // window from a non-incognito window (bookmark open-in-incognito trigger). | 950 // window from a non-incognito window (bookmark open-in-incognito trigger). |
| 922 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 951 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 923 Disposition_Settings_UseNonIncognitoWindowForBookmark) { | 952 Disposition_Settings_UseNonIncognitoWindowForBookmark) { |
| 924 browser::NavigateParams params(browser(), GURL("chrome://settings"), | 953 browser::NavigateParams params(browser(), GURL("chrome://settings"), |
| 925 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 954 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 926 params.disposition = OFF_THE_RECORD; | 955 params.disposition = OFF_THE_RECORD; |
| 927 { | 956 { |
| 928 ui_test_utils::WindowedNotificationObserver observer( | 957 ui_test_utils::WindowedNotificationObserver observer( |
| 929 content::NOTIFICATION_LOAD_STOP, | 958 content::NOTIFICATION_LOAD_STOP, |
| 930 content::NotificationService::AllSources()); | 959 content::NotificationService::AllSources()); |
| 931 browser::Navigate(¶ms); | 960 browser::Navigate(¶ms); |
| 932 observer.Wait(); | 961 observer.Wait(); |
| 933 } | 962 } |
| 934 | 963 |
| 935 EXPECT_EQ(1u, BrowserList::size()); | 964 EXPECT_EQ(1u, BrowserList::size()); |
| 936 EXPECT_EQ(GURL("chrome://settings"), | 965 EXPECT_EQ(GURL("chrome://settings"), |
| 937 browser()->GetSelectedTabContents()->GetURL().GetOrigin()); | 966 browser()->GetSelectedTabContents()->GetURL().GetOrigin()); |
| 938 } | 967 } |
| 939 | 968 |
| 940 // Settings page is expected to always open in normal mode regardless | 969 // Settings page is expected to always open in normal mode regardless |
| 941 // of whether the user is trying to open it in incognito mode or not. | 970 // of whether the user is trying to open it in incognito mode or not. |
| 942 // This test verifies that if incognito mode is forced (by policy), settings | 971 // This test verifies that if incognito mode is forced (by policy), settings |
| 943 // page doesn't open at all. | 972 // page doesn't open at all. |
| 944 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 973 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 945 Disposition_Settings_DoNothingIfIncognitoIsForced) { | 974 Disposition_Settings_DoNothingIfIncognitoIsForced) { |
| 946 Browser* browser = CreateIncognitoBrowser(); | 975 RunDoNothingIfIncognitoIsForcedTest(GetSettingsURL()); |
| 947 | |
| 948 // Set kIncognitoModeAvailability to FORCED. | |
| 949 PrefService* prefs1 = browser->profile()->GetPrefs(); | |
| 950 prefs1->SetInteger(prefs::kIncognitoModeAvailability, | |
| 951 IncognitoModePrefs::FORCED); | |
| 952 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs(); | |
| 953 prefs2->SetInteger(prefs::kIncognitoModeAvailability, | |
| 954 IncognitoModePrefs::FORCED); | |
| 955 | |
| 956 // Navigate to the settings page. | |
| 957 browser::NavigateParams p(MakeNavigateParams(browser)); | |
| 958 p.disposition = OFF_THE_RECORD; | |
| 959 p.url = GURL(chrome::kChromeUISettingsURL); | |
| 960 p.window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 961 browser::Navigate(&p); | |
| 962 | |
| 963 // The bookmarks page should be opened in browser() window. | |
| 964 EXPECT_EQ(browser, p.browser); | |
| 965 EXPECT_EQ(1, browser->tab_count()); | |
| 966 EXPECT_EQ(GURL(chrome::kAboutBlankURL), | |
| 967 browser->GetSelectedTabContents()->GetURL()); | |
| 968 } | 976 } |
| 969 | 977 |
| 970 // This test verifies that the bookmarks page isn't opened in the incognito | 978 // This test verifies that the bookmarks page isn't opened in the incognito |
| 971 // window. | 979 // window. |
| 972 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 980 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 973 Disposition_Bookmarks_UseNonIncognitoWindow) { | 981 Disposition_Bookmarks_UseNonIncognitoWindow) { |
| 974 Browser* incognito_browser = CreateIncognitoBrowser(); | 982 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUIBookmarksURL)); |
| 975 | |
| 976 EXPECT_EQ(2u, BrowserList::size()); | |
| 977 EXPECT_EQ(1, browser()->tab_count()); | |
| 978 EXPECT_EQ(1, incognito_browser->tab_count()); | |
| 979 | |
| 980 // Navigate to the settings page. | |
| 981 browser::NavigateParams p(MakeNavigateParams(incognito_browser)); | |
| 982 p.disposition = SINGLETON_TAB; | |
| 983 p.url = GURL(chrome::kChromeUIBookmarksURL); | |
| 984 p.window_action = browser::NavigateParams::SHOW_WINDOW; | |
| 985 browser::Navigate(&p); | |
| 986 | |
| 987 // The bookmarks page should be opened in browser() window. | |
| 988 EXPECT_NE(incognito_browser, p.browser); | |
| 989 EXPECT_EQ(browser(), p.browser); | |
| 990 EXPECT_EQ(2, browser()->tab_count()); | |
| 991 EXPECT_EQ(GURL(chrome::kChromeUIBookmarksURL), | |
| 992 browser()->GetSelectedTabContents()->GetURL()); | |
| 993 } | 983 } |
| 994 | 984 |
| 995 // Bookmark manager is expected to always open in normal mode regardless | 985 // Bookmark manager is expected to always open in normal mode regardless |
| 996 // of whether the user is trying to open it in incognito mode or not. | 986 // of whether the user is trying to open it in incognito mode or not. |
| 997 // This test verifies that if incognito mode is forced (by policy), bookmark | 987 // This test verifies that if incognito mode is forced (by policy), bookmark |
| 998 // manager doesn't open at all. | 988 // manager doesn't open at all. |
| 999 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 989 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1000 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) { | 990 Disposition_Bookmarks_DoNothingIfIncognitoIsForced) { |
| 1001 Browser* browser = CreateIncognitoBrowser(); | 991 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUIBookmarksURL)); |
| 992 } | |
| 1002 | 993 |
| 1003 // Set kIncognitoModeAvailability to FORCED. | 994 // This test verifies that the sync promo page isn't opened in the incognito |
| 1004 PrefService* prefs1 = browser->profile()->GetPrefs(); | 995 // window. |
| 1005 prefs1->SetInteger(prefs::kIncognitoModeAvailability, | 996 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1006 IncognitoModePrefs::FORCED); | 997 Disposition_SyncPromo_UseNonIncognitoWindow) { |
| 1007 PrefService* prefs2 = browser->profile()->GetOriginalProfile()->GetPrefs(); | 998 RunUseNonIncognitoWindowTest(GURL(chrome::kChromeUISyncPromoURL)); |
| 1008 prefs2->SetInteger(prefs::kIncognitoModeAvailability, | 999 } |
| 1009 IncognitoModePrefs::FORCED); | |
| 1010 | 1000 |
| 1011 // Navigate to the settings page. | 1001 // The Sync promo page is expected to always open in normal mode regardless of |
| 1012 browser::NavigateParams p(MakeNavigateParams(browser)); | 1002 // whether the user is trying to open it in incognito mode or not. This test |
| 1013 p.disposition = SINGLETON_TAB; | 1003 // verifies that if incognito mode is forced (by policy), the sync promo page |
| 1014 p.url = GURL(chrome::kChromeUISettingsURL); | 1004 // doesn't open at all. |
| 1015 p.window_action = browser::NavigateParams::SHOW_WINDOW; | 1005 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1016 browser::Navigate(&p); | 1006 Disposition_SyncPromo_DoNothingIfIncognitoIsForced) { |
| 1017 | 1007 RunDoNothingIfIncognitoIsForcedTest(GURL(chrome::kChromeUISyncPromoURL)); |
| 1018 // The bookmarks page should be opened in browser() window. | |
| 1019 EXPECT_EQ(browser, p.browser); | |
| 1020 EXPECT_EQ(1, browser->tab_count()); | |
| 1021 EXPECT_EQ(GURL(chrome::kAboutBlankURL), | |
| 1022 browser->GetSelectedTabContents()->GetURL()); | |
| 1023 } | 1008 } |
| 1024 | 1009 |
| 1025 // This test makes sure a crashed singleton tab reloads from a new navigation. | 1010 // This test makes sure a crashed singleton tab reloads from a new navigation. |
| 1026 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 1011 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1027 NavigateToCrashedSingletonTab) { | 1012 NavigateToCrashedSingletonTab) { |
| 1028 GURL singleton_url(GetSettingsAdvancedURL()); | 1013 GURL singleton_url(GetSettingsAdvancedURL()); |
| 1029 TabContentsWrapper* wrapper = browser()->AddSelectedTabWithURL( | 1014 TabContentsWrapper* wrapper = browser()->AddSelectedTabWithURL( |
| 1030 singleton_url, content::PAGE_TRANSITION_LINK); | 1015 singleton_url, content::PAGE_TRANSITION_LINK); |
| 1031 TabContents* tab_contents = wrapper->tab_contents(); | 1016 TabContents* tab_contents = wrapper->tab_contents(); |
| 1032 | 1017 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1281 content::NotificationService::AllSources()); | 1266 content::NotificationService::AllSources()); |
| 1282 browser()->ShowDownloadsTab(); | 1267 browser()->ShowDownloadsTab(); |
| 1283 observer.Wait(); | 1268 observer.Wait(); |
| 1284 } | 1269 } |
| 1285 EXPECT_EQ(1, browser()->tab_count()); | 1270 EXPECT_EQ(1, browser()->tab_count()); |
| 1286 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), | 1271 EXPECT_EQ(GURL(chrome::kChromeUIDownloadsURL), |
| 1287 browser()->GetSelectedTabContents()->GetURL()); | 1272 browser()->GetSelectedTabContents()->GetURL()); |
| 1288 } | 1273 } |
| 1289 | 1274 |
| 1290 } // namespace | 1275 } // namespace |
| OLD | NEW |