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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/history/history.h" | 11 #include "chrome/browser/history/history.h" |
12 #include "chrome/browser/history/history_service_factory.h" | 12 #include "chrome/browser/history/history_service_factory.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
19 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
20 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
22 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
24 | 25 |
25 using content::BrowserThread; | 26 using content::BrowserThread; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 } | 132 } |
132 | 133 |
133 void ExpectEmptyHistory() { | 134 void ExpectEmptyHistory() { |
134 std::vector<GURL> urls(GetHistoryContents()); | 135 std::vector<GURL> urls(GetHistoryContents()); |
135 EXPECT_EQ(0U, urls.size()); | 136 EXPECT_EQ(0U, urls.size()); |
136 } | 137 } |
137 | 138 |
138 void LoadAndWaitForURL(const GURL& url) { | 139 void LoadAndWaitForURL(const GURL& url) { |
139 string16 expected_title(ASCIIToUTF16("OK")); | 140 string16 expected_title(ASCIIToUTF16("OK")); |
140 ui_test_utils::TitleWatcher title_watcher( | 141 ui_test_utils::TitleWatcher title_watcher( |
141 browser()->GetActiveWebContents(), expected_title); | 142 chrome::GetActiveWebContents(browser()), expected_title); |
142 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 143 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
143 ui_test_utils::NavigateToURL(browser(), url); | 144 ui_test_utils::NavigateToURL(browser(), url); |
144 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 145 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
145 } | 146 } |
146 | 147 |
147 void LoadAndWaitForFile(const char* filename) { | 148 void LoadAndWaitForFile(const char* filename) { |
148 GURL url = ui_test_utils::GetTestUrl( | 149 GURL url = ui_test_utils::GetTestUrl( |
149 FilePath().AppendASCII("History"), | 150 FilePath().AppendASCII("History"), |
150 FilePath().AppendASCII(filename)); | 151 FilePath().AppendASCII(filename)); |
151 LoadAndWaitForURL(url); | 152 LoadAndWaitForURL(url); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 ConsiderRedirectAfterGestureAsUserInitiated) { | 271 ConsiderRedirectAfterGestureAsUserInitiated) { |
271 // Test the history length for the following page transition. | 272 // Test the history length for the following page transition. |
272 // | 273 // |
273 // -open-> Page 11 -slow_redirect-> Page 12. | 274 // -open-> Page 11 -slow_redirect-> Page 12. |
274 // | 275 // |
275 // If redirect occurs after a user gesture, e.g., mouse click, the | 276 // If redirect occurs after a user gesture, e.g., mouse click, the |
276 // redirect is more likely to be user-initiated rather than automatic. | 277 // redirect is more likely to be user-initiated rather than automatic. |
277 // Therefore, Page 11 should be in the history in addition to Page 12. | 278 // Therefore, Page 11 should be in the history in addition to Page 12. |
278 LoadAndWaitForFile("history_length_test_page_11.html"); | 279 LoadAndWaitForFile("history_length_test_page_11.html"); |
279 | 280 |
280 ui_test_utils::SimulateMouseClick(browser()->GetActiveWebContents()); | 281 ui_test_utils::SimulateMouseClick(chrome::GetActiveWebContents(browser())); |
281 LoadAndWaitForFile("history_length_test_page_11.html"); | 282 LoadAndWaitForFile("history_length_test_page_11.html"); |
282 } | 283 } |
283 | 284 |
284 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, | 285 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, |
285 ConsiderSlowRedirectAsUserInitiated) { | 286 ConsiderSlowRedirectAsUserInitiated) { |
286 // Test the history length for the following page transition. | 287 // Test the history length for the following page transition. |
287 // | 288 // |
288 // -open-> Page 21 -redirect-> Page 22. | 289 // -open-> Page 21 -redirect-> Page 22. |
289 // | 290 // |
290 // If redirect occurs more than 5 seconds later after the page is loaded, | 291 // If redirect occurs more than 5 seconds later after the page is loaded, |
291 // the redirect is likely to be user-initiated. | 292 // the redirect is likely to be user-initiated. |
292 // Therefore, Page 21 should be in the history in addition to Page 22. | 293 // Therefore, Page 21 should be in the history in addition to Page 22. |
293 LoadAndWaitForFile("history_length_test_page_21.html"); | 294 LoadAndWaitForFile("history_length_test_page_21.html"); |
294 } | 295 } |
295 | 296 |
296 // If this test flakes, use bug 22111. | 297 // If this test flakes, use bug 22111. |
297 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, HistorySearchXSS) { | 298 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, HistorySearchXSS) { |
298 GURL url(std::string(chrome::kChromeUIHistoryURL) + | 299 GURL url(std::string(chrome::kChromeUIHistoryURL) + |
299 "#q=%3Cimg%20src%3Dx%3Ax%20onerror%3D%22document.title%3D'XSS'%22%3E"); | 300 "#q=%3Cimg%20src%3Dx%3Ax%20onerror%3D%22document.title%3D'XSS'%22%3E"); |
300 ui_test_utils::NavigateToURL(browser(), url); | 301 ui_test_utils::NavigateToURL(browser(), url); |
301 // Mainly, this is to ensure we send a synchronous message to the renderer | 302 // Mainly, this is to ensure we send a synchronous message to the renderer |
302 // so that we're not susceptible (less susceptible?) to a race condition. | 303 // so that we're not susceptible (less susceptible?) to a race condition. |
303 // Should a race condition ever trigger, it won't result in flakiness. | 304 // Should a race condition ever trigger, it won't result in flakiness. |
304 int num = ui_test_utils::FindInPage( | 305 int num = ui_test_utils::FindInPage( |
305 browser()->GetActiveTabContents(), ASCIIToUTF16("<img"), true, | 306 chrome::GetActiveTabContents(browser()), ASCIIToUTF16("<img"), true, |
306 true, NULL); | 307 true, NULL); |
307 EXPECT_GT(num, 0); | 308 EXPECT_GT(num, 0); |
308 EXPECT_EQ(ASCIIToUTF16("History"), | 309 EXPECT_EQ(ASCIIToUTF16("History"), |
309 browser()->GetActiveWebContents()->GetTitle()); | 310 chrome::GetActiveWebContents(browser())->GetTitle()); |
310 } | 311 } |
OLD | NEW |