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

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

Issue 10915002: Convert the history pyauto tests to a browser_tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: make DEPS clearer/cleaner after discussion with erikwright Created 8 years, 3 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
« no previous file with comments | « chrome/browser/history/DEPS ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser/history/history.h" 12 #include "chrome/browser/history/history.h"
12 #include "chrome/browser/history/history_service_factory.h" 13 #include "chrome/browser/history/history_service_factory.h"
13 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_tabstrip.h" 18 #include "chrome/browser/ui/browser_tabstrip.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents.h"
17 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
19 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
20 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
22 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
25 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
26 30
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 68 }
65 69
66 PrefService* GetPrefs() { 70 PrefService* GetPrefs() {
67 return GetProfile()->GetPrefs(); 71 return GetProfile()->GetPrefs();
68 } 72 }
69 73
70 Profile* GetProfile() { 74 Profile* GetProfile() {
71 return browser()->profile(); 75 return browser()->profile();
72 } 76 }
73 77
74 HistoryService* GetHistoryService() {
75 return HistoryServiceFactory::GetForProfile(GetProfile(),
76 Profile::EXPLICIT_ACCESS);
77 }
78
79 std::vector<GURL> GetHistoryContents() { 78 std::vector<GURL> GetHistoryContents() {
80 ui_test_utils::HistoryEnumerator enumerator(GetHistoryService()); 79 ui_test_utils::HistoryEnumerator enumerator(GetProfile());
81 return enumerator.urls(); 80 return enumerator.urls();
82 } 81 }
83 82
84 GURL GetTestUrl() { 83 GURL GetTestUrl() {
85 return ui_test_utils::GetTestUrl( 84 return ui_test_utils::GetTestUrl(
86 FilePath(FilePath::kCurrentDirectory), 85 FilePath(FilePath::kCurrentDirectory),
87 FilePath(FILE_PATH_LITERAL("title2.html"))); 86 FilePath(FILE_PATH_LITERAL("title2.html")));
88 } 87 }
89 88
90 void WaitForHistoryBackendToRun() { 89 void WaitForHistoryBackendToRun() {
91 CancelableRequestConsumerTSimple<int> request_consumer; 90 CancelableRequestConsumerTSimple<int> request_consumer;
92 scoped_refptr<HistoryDBTask> task(new WaitForHistoryTask()); 91 scoped_refptr<HistoryDBTask> task(new WaitForHistoryTask());
93 HistoryService* history = GetHistoryService(); 92 HistoryService* history =
93 HistoryServiceFactory::GetForProfile(GetProfile(),
94 Profile::EXPLICIT_ACCESS);
94 BrowserThread::PostTask(BrowserThread::UI, 95 BrowserThread::PostTask(BrowserThread::UI,
95 FROM_HERE, 96 FROM_HERE,
96 base::Bind(&HistoryService::ScheduleDBTask, 97 base::Bind(&HistoryService::ScheduleDBTask,
97 history, task, &request_consumer)); 98 history, task, &request_consumer));
98 content::RunMessageLoop(); 99 content::RunMessageLoop();
99 } 100 }
100 101
101 void ExpectEmptyHistory() { 102 void ExpectEmptyHistory() {
102 std::vector<GURL> urls(GetHistoryContents()); 103 std::vector<GURL> urls(GetHistoryContents());
103 EXPECT_EQ(0U, urls.size()); 104 EXPECT_EQ(0U, urls.size());
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // Mainly, this is to ensure we send a synchronous message to the renderer 274 // Mainly, this is to ensure we send a synchronous message to the renderer
274 // so that we're not susceptible (less susceptible?) to a race condition. 275 // so that we're not susceptible (less susceptible?) to a race condition.
275 // Should a race condition ever trigger, it won't result in flakiness. 276 // Should a race condition ever trigger, it won't result in flakiness.
276 int num = ui_test_utils::FindInPage( 277 int num = ui_test_utils::FindInPage(
277 chrome::GetActiveTabContents(browser()), ASCIIToUTF16("<img"), true, 278 chrome::GetActiveTabContents(browser()), ASCIIToUTF16("<img"), true,
278 true, NULL, NULL); 279 true, NULL, NULL);
279 EXPECT_GT(num, 0); 280 EXPECT_GT(num, 0);
280 EXPECT_EQ(ASCIIToUTF16("History"), 281 EXPECT_EQ(ASCIIToUTF16("History"),
281 chrome::GetActiveWebContents(browser())->GetTitle()); 282 chrome::GetActiveWebContents(browser())->GetTitle());
282 } 283 }
284
285 // Verify that history persists after session restart.
286 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, PRE_HistoryPersists) {
287 ui_test_utils::NavigateToURL(browser(), GetTestUrl());
288 std::vector<GURL> urls(GetHistoryContents());
289 ASSERT_EQ(1u, urls.size());
290 ASSERT_EQ(GetTestUrl(), urls[0]);
291 }
292
293 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, HistoryPersists) {
294 std::vector<GURL> urls(GetHistoryContents());
295 ASSERT_EQ(1u, urls.size());
296 ASSERT_EQ(GetTestUrl(), urls[0]);
297 }
298
299 // Invalid URLs should not go in history.
300 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, InvalidURLNoHistory) {
301 GURL non_existant = ui_test_utils::GetTestUrl(
302 FilePath().AppendASCII("History"),
303 FilePath().AppendASCII("non_existant_file.html"));
304 ui_test_utils::NavigateToURL(browser(), non_existant);
305 ExpectEmptyHistory();
306 }
307
308 // New tab page should not show up in history.
309 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, NewTabNoHistory) {
310 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUINewTabURL));
311 ExpectEmptyHistory();
312 }
313
314 // Incognito browsing should not show up in history.
315 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, IncognitoNoHistory) {
316 ui_test_utils::NavigateToURL(CreateIncognitoBrowser(), GetTestUrl());
317 ExpectEmptyHistory();
318 }
319
320 // Multiple navigations to the same url should have a single history.
321 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, NavigateMultiTimes) {
322 ui_test_utils::NavigateToURL(browser(), GetTestUrl());
323 ui_test_utils::NavigateToURL(browser(), GetTestUrl());
324 std::vector<GURL> urls(GetHistoryContents());
325 ASSERT_EQ(1u, urls.size());
326 ASSERT_EQ(GetTestUrl(), urls[0]);
327 }
328
329 // Verify history with multiple windows and tabs.
330 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, MultiTabsWindowsHistory) {
331 GURL url1 = GetTestUrl();
332 GURL url2 = ui_test_utils::GetTestUrl(
333 FilePath(), FilePath(FILE_PATH_LITERAL("title1.html")));
334 GURL url3 = ui_test_utils::GetTestUrl(
335 FilePath(), FilePath(FILE_PATH_LITERAL("title3.html")));
336 GURL url4 = ui_test_utils::GetTestUrl(
337 FilePath(), FilePath(FILE_PATH_LITERAL("simple.html")));
338
339 ui_test_utils::NavigateToURL(browser(), url1);
340 Browser* browser2 = CreateBrowser(browser()->profile());
341 ui_test_utils::NavigateToURL(browser2, url2);
342 ui_test_utils::NavigateToURLWithDisposition(
343 browser2, url3, NEW_FOREGROUND_TAB,
344 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
345 ui_test_utils::NavigateToURLWithDisposition(
346 browser2, url4, NEW_FOREGROUND_TAB,
347 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
348
349 std::vector<GURL> urls(GetHistoryContents());
350 ASSERT_EQ(4u, urls.size());
351 ASSERT_EQ(url4, urls[0]);
352 ASSERT_EQ(url3, urls[1]);
353 ASSERT_EQ(url2, urls[2]);
354 ASSERT_EQ(url1, urls[3]);
355 }
356
357 // Downloaded URLs should not show up in history.
358 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, DownloadNoHistory) {
359 GURL download_url = ui_test_utils::GetTestUrl(
360 FilePath().AppendASCII("downloads"),
361 FilePath().AppendASCII("a_zip_file.zip"));
362 ui_test_utils::DownloadURL(browser(), download_url);
363 ExpectEmptyHistory();
364 }
365
366 // HTTP meta-refresh redirects should have separate history entries.
367 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, RedirectHistory) {
368 GURL redirector = ui_test_utils::GetTestUrl(
369 FilePath().AppendASCII("History"),
370 FilePath().AppendASCII("redirector.html"));
371 GURL landing_url = ui_test_utils::GetTestUrl(
372 FilePath().AppendASCII("History"),
373 FilePath().AppendASCII("landing.html"));
374 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
375 browser(), redirector, 2);
376 ASSERT_EQ(landing_url, chrome::GetActiveWebContents(browser())->GetURL());
377 std::vector<GURL> urls(GetHistoryContents());
378 ASSERT_EQ(2u, urls.size());
379 ASSERT_EQ(landing_url, urls[0]);
380 ASSERT_EQ(redirector, urls[1]);
381 }
382
383 // Verify that navigation brings current page to top of history list.
384 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, NavigateBringPageToTop) {
385 GURL url1 = GetTestUrl();
386 GURL url2 = ui_test_utils::GetTestUrl(
387 FilePath(), FilePath(FILE_PATH_LITERAL("title3.html")));
388
389 ui_test_utils::NavigateToURL(browser(), url1);
390 ui_test_utils::NavigateToURL(browser(), url2);
391
392 std::vector<GURL> urls(GetHistoryContents());
393 ASSERT_EQ(2u, urls.size());
394 ASSERT_EQ(url2, urls[0]);
395 ASSERT_EQ(url1, urls[1]);
396 }
397
398 // Verify that reloading a page brings it to top of history list.
399 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, ReloadBringPageToTop) {
400 GURL url1 = GetTestUrl();
401 GURL url2 = ui_test_utils::GetTestUrl(
402 FilePath(), FilePath(FILE_PATH_LITERAL("title3.html")));
403
404 ui_test_utils::NavigateToURL(browser(), url1);
405 ui_test_utils::NavigateToURLWithDisposition(
406 browser(), url2, NEW_BACKGROUND_TAB,
407 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
408
409 std::vector<GURL> urls(GetHistoryContents());
410 ASSERT_EQ(2u, urls.size());
411 ASSERT_EQ(url2, urls[0]);
412 ASSERT_EQ(url1, urls[1]);
413
414 content::WebContents* tab = chrome::GetActiveWebContents(browser());
415 tab->GetController().Reload(false);
416 content::WaitForLoadStop(tab);
417
418 urls = GetHistoryContents();
419 ASSERT_EQ(2u, urls.size());
420 ASSERT_EQ(url1, urls[0]);
421 ASSERT_EQ(url2, urls[1]);
422 }
423
424 // Verify that back/forward brings current page to top of history list.
425 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, BackForwardBringPageToTop) {
426 GURL url1 = GetTestUrl();
427 GURL url2 = ui_test_utils::GetTestUrl(
428 FilePath(), FilePath(FILE_PATH_LITERAL("title3.html")));
429
430 ui_test_utils::NavigateToURL(browser(), url1);
431 ui_test_utils::NavigateToURL(browser(), url2);
432
433 content::WebContents* tab = chrome::GetActiveWebContents(browser());
434 chrome::GoBack(browser(), CURRENT_TAB);
435 content::WaitForLoadStop(tab);
436
437 std::vector<GURL> urls(GetHistoryContents());
438 ASSERT_EQ(2u, urls.size());
439 ASSERT_EQ(url1, urls[0]);
440 ASSERT_EQ(url2, urls[1]);
441
442 chrome::GoForward(browser(), CURRENT_TAB);
443 content::WaitForLoadStop(tab);
444 urls = GetHistoryContents();
445 ASSERT_EQ(2u, urls.size());
446 ASSERT_EQ(url2, urls[0]);
447 ASSERT_EQ(url1, urls[1]);
448 }
449
450 // Verify that submitting form adds target page to history list.
451 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SubmitFormAddsTargetPage) {
452 GURL form = ui_test_utils::GetTestUrl(
453 FilePath().AppendASCII("History"),
454 FilePath().AppendASCII("form.html"));
455 GURL target = ui_test_utils::GetTestUrl(
456 FilePath().AppendASCII("History"),
457 FilePath().AppendASCII("target.html"));
458 ui_test_utils::NavigateToURL(browser(), form);
459
460 content::WebContents* web_contents = chrome::GetActiveWebContents(browser());
461 string16 expected_title(ASCIIToUTF16("Target Page"));
462 content::TitleWatcher title_watcher(
463 chrome::GetActiveWebContents(browser()), expected_title);
464 ASSERT_TRUE(content::ExecuteJavaScript(
465 web_contents->GetRenderViewHost(),
466 L"",
467 ASCIIToWide("document.getElementById('form').submit()")));
468 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
469
470 std::vector<GURL> urls(GetHistoryContents());
471 ASSERT_EQ(2u, urls.size());
472 ASSERT_EQ(target, urls[0]);
473 ASSERT_EQ(form, urls[1]);
474 }
475
476 // Verify history shortcut opens only one history tab per window. Also, make
477 // sure that existing history tab is activated.
478 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, OneHistoryTabPerWindow) {
479 GURL history_url("chrome://chrome/history/");
480
481 // Even after navigate completes, the currently-active tab title is
482 // 'Loading...' for a brief time while the history page loads.
483 content::WebContents* web_contents = chrome::GetActiveWebContents(browser());
484 string16 expected_title(ASCIIToUTF16("History"));
485 content::TitleWatcher title_watcher(web_contents, expected_title);
486 chrome::ExecuteCommand(browser(), IDC_SHOW_HISTORY);
487 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
488
489 ui_test_utils::NavigateToURLWithDisposition(
490 browser(), GURL(chrome::kAboutBlankURL), NEW_FOREGROUND_TAB,
491 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
492 chrome::ExecuteCommand(browser(), IDC_SHOW_HISTORY);
493
494 content::WebContents* active_web_contents =
495 chrome::GetActiveWebContents(browser());
496 ASSERT_EQ(web_contents, active_web_contents);
497 ASSERT_EQ(history_url, active_web_contents->GetURL());
498
499 TabContents* second_tab = browser()->tab_strip_model()->GetTabContentsAt(1);
500 ASSERT_NE(history_url, second_tab->web_contents()->GetURL());
501 }
OLDNEW
« no previous file with comments | « chrome/browser/history/DEPS ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698