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

Side by Side Diff: chrome/browser/history/history_browsertest.cc

Issue 12066003: Remove TabStripModel wrapper use. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gtk Created 7 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
OLDNEW
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/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/history/history_service.h" 12 #include "chrome/browser/history/history_service.h"
13 #include "chrome/browser/history/history_service_factory.h" 13 #include "chrome/browser/history/history_service_factory.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h" 17 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
22 #include "chrome/common/url_constants.h" 21 #include "chrome/common/url_constants.h"
23 #include "chrome/test/base/in_process_browser_test.h" 22 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
25 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/browser_test_utils.h" 25 #include "content/public/test/browser_test_utils.h"
27 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
28 #include "googleurl/src/gurl.h" 27 #include "googleurl/src/gurl.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 95 }
97 96
98 void ExpectEmptyHistory() { 97 void ExpectEmptyHistory() {
99 std::vector<GURL> urls(GetHistoryContents()); 98 std::vector<GURL> urls(GetHistoryContents());
100 EXPECT_EQ(0U, urls.size()); 99 EXPECT_EQ(0U, urls.size());
101 } 100 }
102 101
103 void LoadAndWaitForURL(const GURL& url) { 102 void LoadAndWaitForURL(const GURL& url) {
104 string16 expected_title(ASCIIToUTF16("OK")); 103 string16 expected_title(ASCIIToUTF16("OK"));
105 content::TitleWatcher title_watcher( 104 content::TitleWatcher title_watcher(
106 chrome::GetActiveWebContents(browser()), expected_title); 105 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
107 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); 106 title_watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL"));
108 ui_test_utils::NavigateToURL(browser(), url); 107 ui_test_utils::NavigateToURL(browser(), url);
109 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 108 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
110 } 109 }
111 110
112 void LoadAndWaitForFile(const char* filename) { 111 void LoadAndWaitForFile(const char* filename) {
113 GURL url = ui_test_utils::GetTestUrl( 112 GURL url = ui_test_utils::GetTestUrl(
114 FilePath().AppendASCII("History"), 113 FilePath().AppendASCII("History"),
115 FilePath().AppendASCII(filename)); 114 FilePath().AppendASCII(filename));
116 LoadAndWaitForURL(url); 115 LoadAndWaitForURL(url);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 ConsiderRedirectAfterGestureAsUserInitiated) { 238 ConsiderRedirectAfterGestureAsUserInitiated) {
240 // Test the history length for the following page transition. 239 // Test the history length for the following page transition.
241 // 240 //
242 // -open-> Page 11 -slow_redirect-> Page 12. 241 // -open-> Page 11 -slow_redirect-> Page 12.
243 // 242 //
244 // If redirect occurs after a user gesture, e.g., mouse click, the 243 // If redirect occurs after a user gesture, e.g., mouse click, the
245 // redirect is more likely to be user-initiated rather than automatic. 244 // redirect is more likely to be user-initiated rather than automatic.
246 // Therefore, Page 11 should be in the history in addition to Page 12. 245 // Therefore, Page 11 should be in the history in addition to Page 12.
247 LoadAndWaitForFile("history_length_test_page_11.html"); 246 LoadAndWaitForFile("history_length_test_page_11.html");
248 247
249 content::SimulateMouseClick(chrome::GetActiveWebContents(browser()), 0, 248 content::SimulateMouseClick(
249 browser()->tab_strip_model()->GetActiveWebContents(), 0,
250 WebKit::WebMouseEvent::ButtonLeft); 250 WebKit::WebMouseEvent::ButtonLeft);
251 LoadAndWaitForFile("history_length_test_page_11.html"); 251 LoadAndWaitForFile("history_length_test_page_11.html");
252 } 252 }
253 253
254 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, 254 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest,
255 ConsiderSlowRedirectAsUserInitiated) { 255 ConsiderSlowRedirectAsUserInitiated) {
256 // Test the history length for the following page transition. 256 // Test the history length for the following page transition.
257 // 257 //
258 // -open-> Page 21 -redirect-> Page 22. 258 // -open-> Page 21 -redirect-> Page 22.
259 // 259 //
(...skipping 10 matching lines...) Expand all
270 #define MAYBE_HistorySearchXSS HistorySearchXSS 270 #define MAYBE_HistorySearchXSS HistorySearchXSS
271 #endif 271 #endif
272 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, MAYBE_HistorySearchXSS) { 272 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, MAYBE_HistorySearchXSS) {
273 GURL url(std::string(chrome::kChromeUIHistoryURL) + 273 GURL url(std::string(chrome::kChromeUIHistoryURL) +
274 "#q=%3Cimg%20src%3Dx%3Ax%20onerror%3D%22document.title%3D'XSS'%22%3E"); 274 "#q=%3Cimg%20src%3Dx%3Ax%20onerror%3D%22document.title%3D'XSS'%22%3E");
275 ui_test_utils::NavigateToURL(browser(), url); 275 ui_test_utils::NavigateToURL(browser(), url);
276 // Mainly, this is to ensure we send a synchronous message to the renderer 276 // Mainly, this is to ensure we send a synchronous message to the renderer
277 // so that we're not susceptible (less susceptible?) to a race condition. 277 // so that we're not susceptible (less susceptible?) to a race condition.
278 // Should a race condition ever trigger, it won't result in flakiness. 278 // Should a race condition ever trigger, it won't result in flakiness.
279 int num = ui_test_utils::FindInPage( 279 int num = ui_test_utils::FindInPage(
280 chrome::GetActiveWebContents(browser()), ASCIIToUTF16("<img"), true, 280 browser()->tab_strip_model()->GetActiveWebContents(),
281 ASCIIToUTF16("<img"), true,
281 true, NULL, NULL); 282 true, NULL, NULL);
282 EXPECT_GT(num, 0); 283 EXPECT_GT(num, 0);
283 EXPECT_EQ(ASCIIToUTF16("History"), 284 EXPECT_EQ(ASCIIToUTF16("History"),
284 chrome::GetActiveWebContents(browser())->GetTitle()); 285 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
285 } 286 }
286 287
287 // Verify that history persists after session restart. 288 // Verify that history persists after session restart.
288 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, PRE_HistoryPersists) { 289 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, PRE_HistoryPersists) {
289 ui_test_utils::NavigateToURL(browser(), GetTestUrl()); 290 ui_test_utils::NavigateToURL(browser(), GetTestUrl());
290 std::vector<GURL> urls(GetHistoryContents()); 291 std::vector<GURL> urls(GetHistoryContents());
291 ASSERT_EQ(1u, urls.size()); 292 ASSERT_EQ(1u, urls.size());
292 ASSERT_EQ(GetTestUrl(), urls[0]); 293 ASSERT_EQ(GetTestUrl(), urls[0]);
293 } 294 }
294 295
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 // HTTP meta-refresh redirects should have separate history entries. 369 // HTTP meta-refresh redirects should have separate history entries.
369 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, RedirectHistory) { 370 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, RedirectHistory) {
370 GURL redirector = ui_test_utils::GetTestUrl( 371 GURL redirector = ui_test_utils::GetTestUrl(
371 FilePath().AppendASCII("History"), 372 FilePath().AppendASCII("History"),
372 FilePath().AppendASCII("redirector.html")); 373 FilePath().AppendASCII("redirector.html"));
373 GURL landing_url = ui_test_utils::GetTestUrl( 374 GURL landing_url = ui_test_utils::GetTestUrl(
374 FilePath().AppendASCII("History"), 375 FilePath().AppendASCII("History"),
375 FilePath().AppendASCII("landing.html")); 376 FilePath().AppendASCII("landing.html"));
376 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 377 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
377 browser(), redirector, 2); 378 browser(), redirector, 2);
378 ASSERT_EQ(landing_url, chrome::GetActiveWebContents(browser())->GetURL()); 379 ASSERT_EQ(landing_url,
380 browser()->tab_strip_model()->GetActiveWebContents()->GetURL());
379 std::vector<GURL> urls(GetHistoryContents()); 381 std::vector<GURL> urls(GetHistoryContents());
380 ASSERT_EQ(2u, urls.size()); 382 ASSERT_EQ(2u, urls.size());
381 ASSERT_EQ(landing_url, urls[0]); 383 ASSERT_EQ(landing_url, urls[0]);
382 ASSERT_EQ(redirector, urls[1]); 384 ASSERT_EQ(redirector, urls[1]);
383 } 385 }
384 386
385 // Verify that navigation brings current page to top of history list. 387 // Verify that navigation brings current page to top of history list.
386 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, NavigateBringPageToTop) { 388 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, NavigateBringPageToTop) {
387 GURL url1 = GetTestUrl(); 389 GURL url1 = GetTestUrl();
388 GURL url2 = ui_test_utils::GetTestUrl( 390 GURL url2 = ui_test_utils::GetTestUrl(
(...skipping 17 matching lines...) Expand all
406 ui_test_utils::NavigateToURL(browser(), url1); 408 ui_test_utils::NavigateToURL(browser(), url1);
407 ui_test_utils::NavigateToURLWithDisposition( 409 ui_test_utils::NavigateToURLWithDisposition(
408 browser(), url2, NEW_BACKGROUND_TAB, 410 browser(), url2, NEW_BACKGROUND_TAB,
409 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 411 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
410 412
411 std::vector<GURL> urls(GetHistoryContents()); 413 std::vector<GURL> urls(GetHistoryContents());
412 ASSERT_EQ(2u, urls.size()); 414 ASSERT_EQ(2u, urls.size());
413 ASSERT_EQ(url2, urls[0]); 415 ASSERT_EQ(url2, urls[0]);
414 ASSERT_EQ(url1, urls[1]); 416 ASSERT_EQ(url1, urls[1]);
415 417
416 content::WebContents* tab = chrome::GetActiveWebContents(browser()); 418 content::WebContents* tab =
419 browser()->tab_strip_model()->GetActiveWebContents();
417 tab->GetController().Reload(false); 420 tab->GetController().Reload(false);
418 content::WaitForLoadStop(tab); 421 content::WaitForLoadStop(tab);
419 422
420 urls = GetHistoryContents(); 423 urls = GetHistoryContents();
421 ASSERT_EQ(2u, urls.size()); 424 ASSERT_EQ(2u, urls.size());
422 ASSERT_EQ(url1, urls[0]); 425 ASSERT_EQ(url1, urls[0]);
423 ASSERT_EQ(url2, urls[1]); 426 ASSERT_EQ(url2, urls[1]);
424 } 427 }
425 428
426 // Verify that back/forward brings current page to top of history list. 429 // Verify that back/forward brings current page to top of history list.
427 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, BackForwardBringPageToTop) { 430 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, BackForwardBringPageToTop) {
428 GURL url1 = GetTestUrl(); 431 GURL url1 = GetTestUrl();
429 GURL url2 = ui_test_utils::GetTestUrl( 432 GURL url2 = ui_test_utils::GetTestUrl(
430 FilePath(), FilePath(FILE_PATH_LITERAL("title3.html"))); 433 FilePath(), FilePath(FILE_PATH_LITERAL("title3.html")));
431 434
432 ui_test_utils::NavigateToURL(browser(), url1); 435 ui_test_utils::NavigateToURL(browser(), url1);
433 ui_test_utils::NavigateToURL(browser(), url2); 436 ui_test_utils::NavigateToURL(browser(), url2);
434 437
435 content::WebContents* tab = chrome::GetActiveWebContents(browser()); 438 content::WebContents* tab =
439 browser()->tab_strip_model()->GetActiveWebContents();
436 chrome::GoBack(browser(), CURRENT_TAB); 440 chrome::GoBack(browser(), CURRENT_TAB);
437 content::WaitForLoadStop(tab); 441 content::WaitForLoadStop(tab);
438 442
439 std::vector<GURL> urls(GetHistoryContents()); 443 std::vector<GURL> urls(GetHistoryContents());
440 ASSERT_EQ(2u, urls.size()); 444 ASSERT_EQ(2u, urls.size());
441 ASSERT_EQ(url1, urls[0]); 445 ASSERT_EQ(url1, urls[0]);
442 ASSERT_EQ(url2, urls[1]); 446 ASSERT_EQ(url2, urls[1]);
443 447
444 chrome::GoForward(browser(), CURRENT_TAB); 448 chrome::GoForward(browser(), CURRENT_TAB);
445 content::WaitForLoadStop(tab); 449 content::WaitForLoadStop(tab);
446 urls = GetHistoryContents(); 450 urls = GetHistoryContents();
447 ASSERT_EQ(2u, urls.size()); 451 ASSERT_EQ(2u, urls.size());
448 ASSERT_EQ(url2, urls[0]); 452 ASSERT_EQ(url2, urls[0]);
449 ASSERT_EQ(url1, urls[1]); 453 ASSERT_EQ(url1, urls[1]);
450 } 454 }
451 455
452 // Verify that submitting form adds target page to history list. 456 // Verify that submitting form adds target page to history list.
453 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SubmitFormAddsTargetPage) { 457 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SubmitFormAddsTargetPage) {
454 GURL form = ui_test_utils::GetTestUrl( 458 GURL form = ui_test_utils::GetTestUrl(
455 FilePath().AppendASCII("History"), 459 FilePath().AppendASCII("History"),
456 FilePath().AppendASCII("form.html")); 460 FilePath().AppendASCII("form.html"));
457 GURL target = ui_test_utils::GetTestUrl( 461 GURL target = ui_test_utils::GetTestUrl(
458 FilePath().AppendASCII("History"), 462 FilePath().AppendASCII("History"),
459 FilePath().AppendASCII("target.html")); 463 FilePath().AppendASCII("target.html"));
460 ui_test_utils::NavigateToURL(browser(), form); 464 ui_test_utils::NavigateToURL(browser(), form);
461 465
462 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 466 content::WebContents* web_contents =
467 browser()->tab_strip_model()->GetActiveWebContents();
463 string16 expected_title(ASCIIToUTF16("Target Page")); 468 string16 expected_title(ASCIIToUTF16("Target Page"));
464 content::TitleWatcher title_watcher( 469 content::TitleWatcher title_watcher(
465 chrome::GetActiveWebContents(browser()), expected_title); 470 browser()->tab_strip_model()->GetActiveWebContents(), expected_title);
466 ASSERT_TRUE(content::ExecuteScript( 471 ASSERT_TRUE(content::ExecuteScript(
467 web_contents, "document.getElementById('form').submit()")); 472 web_contents, "document.getElementById('form').submit()"));
468 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 473 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
469 474
470 std::vector<GURL> urls(GetHistoryContents()); 475 std::vector<GURL> urls(GetHistoryContents());
471 ASSERT_EQ(2u, urls.size()); 476 ASSERT_EQ(2u, urls.size());
472 ASSERT_EQ(target, urls[0]); 477 ASSERT_EQ(target, urls[0]);
473 ASSERT_EQ(form, urls[1]); 478 ASSERT_EQ(form, urls[1]);
474 } 479 }
475 480
476 // Verify history shortcut opens only one history tab per window. Also, make 481 // Verify history shortcut opens only one history tab per window. Also, make
477 // sure that existing history tab is activated. 482 // sure that existing history tab is activated.
478 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, OneHistoryTabPerWindow) { 483 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, OneHistoryTabPerWindow) {
479 GURL history_url(chrome::kChromeUIHistoryURL); 484 GURL history_url(chrome::kChromeUIHistoryURL);
480 485
481 // Even after navigate completes, the currently-active tab title is 486 // Even after navigate completes, the currently-active tab title is
482 // 'Loading...' for a brief time while the history page loads. 487 // 'Loading...' for a brief time while the history page loads.
483 content::WebContents* web_contents = chrome::GetActiveWebContents(browser()); 488 content::WebContents* web_contents =
489 browser()->tab_strip_model()->GetActiveWebContents();
484 string16 expected_title(ASCIIToUTF16("History")); 490 string16 expected_title(ASCIIToUTF16("History"));
485 content::TitleWatcher title_watcher(web_contents, expected_title); 491 content::TitleWatcher title_watcher(web_contents, expected_title);
486 chrome::ExecuteCommand(browser(), IDC_SHOW_HISTORY); 492 chrome::ExecuteCommand(browser(), IDC_SHOW_HISTORY);
487 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); 493 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
488 494
489 ui_test_utils::NavigateToURLWithDisposition( 495 ui_test_utils::NavigateToURLWithDisposition(
490 browser(), GURL(chrome::kAboutBlankURL), NEW_FOREGROUND_TAB, 496 browser(), GURL(chrome::kAboutBlankURL), NEW_FOREGROUND_TAB,
491 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 497 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
492 chrome::ExecuteCommand(browser(), IDC_SHOW_HISTORY); 498 chrome::ExecuteCommand(browser(), IDC_SHOW_HISTORY);
493 499
494 content::WebContents* active_web_contents = 500 content::WebContents* active_web_contents =
495 browser()->tab_strip_model()->GetActiveWebContents(); 501 browser()->tab_strip_model()->GetActiveWebContents();
496 ASSERT_EQ(web_contents, active_web_contents); 502 ASSERT_EQ(web_contents, active_web_contents);
497 ASSERT_EQ(history_url, active_web_contents->GetURL()); 503 ASSERT_EQ(history_url, active_web_contents->GetURL());
498 504
499 content::WebContents* second_tab = 505 content::WebContents* second_tab =
500 browser()->tab_strip_model()->GetWebContentsAt(1); 506 browser()->tab_strip_model()->GetWebContentsAt(1);
501 ASSERT_NE(history_url, second_tab->GetURL()); 507 ASSERT_NE(history_url, second_tab->GetURL());
502 } 508 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/webstore_standalone_install_browsertest.cc ('k') | chrome/browser/history/multipart_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698