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