OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 11 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_commands.h" | 14 #include "chrome/browser/ui/browser_commands.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/ui/browser_navigator.h" | 16 #include "chrome/browser/ui/browser_navigator.h" |
16 #include "chrome/browser/ui/browser_tabstrip.h" | 17 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
18 #include "chrome/browser/ui/chrome_pages.h" | 19 #include "chrome/browser/ui/chrome_pages.h" |
19 #include "chrome/browser/ui/singleton_tabs.h" | 20 #include "chrome/browser/ui/singleton_tabs.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
24 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/notification_types.h" | 27 #include "content/public/browser/notification_types.h" |
27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
28 #include "content/public/browser/web_contents_view.h" | 29 #include "content/public/browser/web_contents_view.h" |
29 #include "ipc/ipc_message.h" | 30 #include "ipc/ipc_message.h" |
30 | 31 |
31 using content::WebContents; | 32 using content::WebContents; |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
| 36 const char kExpectedTitle[] = "PASSED!"; |
| 37 const char kEchoTitleCommand[] = "echotitle"; |
| 38 |
35 GURL GetGoogleURL() { | 39 GURL GetGoogleURL() { |
36 return GURL("http://www.google.com/"); | 40 return GURL("http://www.google.com/"); |
37 } | 41 } |
38 | 42 |
39 GURL GetSettingsURL() { | 43 GURL GetSettingsURL() { |
40 return GURL(chrome::kChromeUISettingsURL); | 44 return GURL(chrome::kChromeUISettingsURL); |
41 } | 45 } |
42 | 46 |
43 GURL GetContentSettingsURL() { | 47 GURL GetContentSettingsURL() { |
44 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage); | 48 return GetSettingsURL().Resolve(chrome::kContentSettingsExceptionsSubPage); |
(...skipping 10 matching lines...) Expand all Loading... |
55 GURL ShortenUberURL(const GURL& url) { | 59 GURL ShortenUberURL(const GURL& url) { |
56 std::string url_string = url.spec(); | 60 std::string url_string = url.spec(); |
57 const std::string long_prefix = "chrome://chrome/"; | 61 const std::string long_prefix = "chrome://chrome/"; |
58 const std::string short_prefix = "chrome://"; | 62 const std::string short_prefix = "chrome://"; |
59 if (url_string.find(long_prefix) != 0) | 63 if (url_string.find(long_prefix) != 0) |
60 return url; | 64 return url; |
61 url_string.replace(0, long_prefix.length(), short_prefix); | 65 url_string.replace(0, long_prefix.length(), short_prefix); |
62 return GURL(url_string); | 66 return GURL(url_string); |
63 } | 67 } |
64 | 68 |
65 } // namespace | 69 } // namespace |
66 | 70 |
67 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const { | 71 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const { |
68 return MakeNavigateParams(browser()); | 72 return MakeNavigateParams(browser()); |
69 } | 73 } |
70 | 74 |
71 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams( | 75 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams( |
72 Browser* browser) const { | 76 Browser* browser) const { |
73 chrome::NavigateParams params(browser, GetGoogleURL(), | 77 chrome::NavigateParams params(browser, GetGoogleURL(), |
74 content::PAGE_TRANSITION_LINK); | 78 content::PAGE_TRANSITION_LINK); |
75 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 79 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
76 return params; | 80 return params; |
77 } | 81 } |
78 | 82 |
| 83 bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle( |
| 84 const GURL& url, const std::string& post_data, bool is_browser_initiated, |
| 85 base::string16* title) { |
| 86 chrome::NavigateParams param(MakeNavigateParams()); |
| 87 param.disposition = NEW_FOREGROUND_TAB; |
| 88 param.url = url; |
| 89 param.is_renderer_initiated = !is_browser_initiated; |
| 90 param.uses_post = true; |
| 91 param.browser_initiated_post_data = new base::RefCountedStaticMemory( |
| 92 reinterpret_cast<const uint8*>(post_data.data()), post_data.size()); |
| 93 |
| 94 ui_test_utils::NavigateToURL(¶m); |
| 95 if (!param.target_contents) |
| 96 return false; |
| 97 |
| 98 // Navigate() should have opened the contents in new foreground tab in the |
| 99 // current Browser. |
| 100 EXPECT_EQ(browser(), param.browser); |
| 101 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(), |
| 102 param.target_contents); |
| 103 // We should have one window, with one tab. |
| 104 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| 105 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| 106 |
| 107 *title = param.target_contents->GetTitle(); |
| 108 return true; |
| 109 } |
| 110 |
79 Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type, | 111 Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type, |
80 Profile* profile) { | 112 Profile* profile) { |
81 Browser* browser = new Browser( | 113 Browser* browser = new Browser( |
82 Browser::CreateParams(type, profile, chrome::GetActiveDesktop())); | 114 Browser::CreateParams(type, profile, chrome::GetActiveDesktop())); |
83 chrome::AddBlankTabAt(browser, -1, true); | 115 chrome::AddBlankTabAt(browser, -1, true); |
84 return browser; | 116 return browser; |
85 } | 117 } |
86 | 118 |
87 Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type, | 119 Browser* BrowserNavigatorTest::CreateEmptyBrowserForApp(Browser::Type type, |
88 Profile* profile) { | 120 Profile* profile) { |
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 content::PAGE_TRANSITION_LINK); | 1316 content::PAGE_TRANSITION_LINK); |
1285 ui_test_utils::NavigateToURL(&viewsource_params); | 1317 ui_test_utils::NavigateToURL(&viewsource_params); |
1286 | 1318 |
1287 chrome::NavigateParams singleton_params(browser(), | 1319 chrome::NavigateParams singleton_params(browser(), |
1288 GURL(chrome::kChromeUIVersionURL), | 1320 GURL(chrome::kChromeUIVersionURL), |
1289 content::PAGE_TRANSITION_LINK); | 1321 content::PAGE_TRANSITION_LINK); |
1290 singleton_params.disposition = SINGLETON_TAB; | 1322 singleton_params.disposition = SINGLETON_TAB; |
1291 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params)); | 1323 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params)); |
1292 } | 1324 } |
1293 | 1325 |
1294 } // namespace | 1326 // This test verifies that browser initiated navigations can send requests |
| 1327 // using POST. |
| 1328 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1329 SendBrowserInitiatedRequestUsingPOST) { |
| 1330 // Uses a test sever to verify POST request. |
| 1331 ASSERT_TRUE(test_server()->Start()); |
| 1332 |
| 1333 // Open a browser initiated POST request in new foreground tab. |
| 1334 string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); |
| 1335 std::string post_data = kExpectedTitle; |
| 1336 string16 title; |
| 1337 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle( |
| 1338 test_server()->GetURL(kEchoTitleCommand), post_data, true, &title)); |
| 1339 EXPECT_EQ(expected_title, title); |
| 1340 } |
| 1341 |
| 1342 // This test verifies that renderer initiated navigations can NOT send requests |
| 1343 // using POST. |
| 1344 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1345 SendRendererInitiatedRequestUsingPOST) { |
| 1346 // Uses a test sever to verify POST request. |
| 1347 ASSERT_TRUE(test_server()->Start()); |
| 1348 |
| 1349 // Open a renderer initiated POST request in new foreground tab. |
| 1350 string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); |
| 1351 std::string post_data = kExpectedTitle; |
| 1352 string16 title; |
| 1353 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle( |
| 1354 test_server()->GetURL(kEchoTitleCommand), post_data, false, &title)); |
| 1355 EXPECT_NE(expected_title, title); |
| 1356 } |
| 1357 |
| 1358 } // namespace |
OLD | NEW |