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

Side by Side Diff: content/browser/session_history_browsertest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
9 #include "chrome/test/base/in_process_browser_test.h" 10 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 11 #include "chrome/test/base/ui_test_utils.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
15 #include "net/test/test_server.h" 16 #include "net/test/test_server.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 class SessionHistoryTest : public InProcessBrowserTest { 19 class SessionHistoryTest : public InProcessBrowserTest {
(...skipping 29 matching lines...) Expand all
48 ui_test_utils::NavigateToURL(browser(), url); 49 ui_test_utils::NavigateToURL(browser(), url);
49 } 50 }
50 51
51 // Navigate session history using history.go(distance). 52 // Navigate session history using history.go(distance).
52 void JavascriptGo(std::string distance) { 53 void JavascriptGo(std::string distance) {
53 GURL url("javascript:history.go('" + distance + "')"); 54 GURL url("javascript:history.go('" + distance + "')");
54 ui_test_utils::NavigateToURL(browser(), url); 55 ui_test_utils::NavigateToURL(browser(), url);
55 } 56 }
56 57
57 std::string GetTabTitle() { 58 std::string GetTabTitle() {
58 return UTF16ToASCII(browser()->GetActiveWebContents()->GetTitle()); 59 return UTF16ToASCII(chrome::GetActiveWebContents(browser())->GetTitle());
59 } 60 }
60 61
61 GURL GetTabURL() { 62 GURL GetTabURL() {
62 return browser()->GetActiveWebContents()->GetURL(); 63 return chrome::GetActiveWebContents(browser())->GetURL();
63 } 64 }
64 65
65 GURL GetURL(const std::string file) { 66 GURL GetURL(const std::string file) {
66 return test_server()->GetURL(std::string("files/session_history/") + file); 67 return test_server()->GetURL(std::string("files/session_history/") + file);
67 } 68 }
68 69
69 void NavigateAndCheckTitle(const char* filename, 70 void NavigateAndCheckTitle(const char* filename,
70 const std::string& expected_title) { 71 const std::string& expected_title) {
71 string16 expected_title16(ASCIIToUTF16(expected_title)); 72 string16 expected_title16(ASCIIToUTF16(expected_title));
72 ui_test_utils::TitleWatcher title_watcher( 73 ui_test_utils::TitleWatcher title_watcher(
73 browser()->GetActiveWebContents(), expected_title16); 74 chrome::GetActiveWebContents(browser()), expected_title16);
74 ui_test_utils::NavigateToURL(browser(), GetURL(filename)); 75 ui_test_utils::NavigateToURL(browser(), GetURL(filename));
75 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); 76 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
76 } 77 }
77 78
78 void GoBack() { 79 void GoBack() {
79 ui_test_utils::WindowedNotificationObserver load_stop_observer( 80 ui_test_utils::WindowedNotificationObserver load_stop_observer(
80 content::NOTIFICATION_LOAD_STOP, 81 content::NOTIFICATION_LOAD_STOP,
81 content::NotificationService::AllSources()); 82 content::NotificationService::AllSources());
82 chrome::GoBack(browser(), CURRENT_TAB); 83 chrome::GoBack(browser(), CURRENT_TAB);
83 load_stop_observer.Wait(); 84 load_stop_observer.Wait();
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 EXPECT_EQ("foo", GetTabTitle()); 429 EXPECT_EQ("foo", GetTabTitle());
429 430
430 GoBack(); 431 GoBack();
431 EXPECT_EQ("Default Title", GetTabTitle()); 432 EXPECT_EQ("Default Title", GetTabTitle());
432 } 433 }
433 434
434 // http://code.google.com/p/chromium/issues/detail?id=56267 435 // http://code.google.com/p/chromium/issues/detail?id=56267
435 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { 436 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) {
436 int length; 437 int length;
437 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( 438 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
438 browser()->GetActiveWebContents()->GetRenderViewHost(), 439 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
439 L"", L"domAutomationController.send(history.length)", &length)); 440 L"", L"domAutomationController.send(history.length)", &length));
440 EXPECT_EQ(1, length); 441 EXPECT_EQ(1, length);
441 442
442 ui_test_utils::NavigateToURL(browser(), GetURL("title1.html")); 443 ui_test_utils::NavigateToURL(browser(), GetURL("title1.html"));
443 444
444 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( 445 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
445 browser()->GetActiveWebContents()->GetRenderViewHost(), 446 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
446 L"", L"domAutomationController.send(history.length)", &length)); 447 L"", L"domAutomationController.send(history.length)", &length));
447 EXPECT_EQ(2, length); 448 EXPECT_EQ(2, length);
448 449
449 // Now test that history.length is updated when the navigation is committed. 450 // Now test that history.length is updated when the navigation is committed.
450 ui_test_utils::NavigateToURL(browser(), GetURL("record_length.html")); 451 ui_test_utils::NavigateToURL(browser(), GetURL("record_length.html"));
451 452
452 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( 453 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
453 browser()->GetActiveWebContents()->GetRenderViewHost(), 454 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
454 L"", L"domAutomationController.send(history.length)", &length)); 455 L"", L"domAutomationController.send(history.length)", &length));
455 EXPECT_EQ(3, length); 456 EXPECT_EQ(3, length);
456 457
457 GoBack(); 458 GoBack();
458 GoBack(); 459 GoBack();
459 460
460 // Ensure history.length is properly truncated. 461 // Ensure history.length is properly truncated.
461 ui_test_utils::NavigateToURL(browser(), GetURL("title2.html")); 462 ui_test_utils::NavigateToURL(browser(), GetURL("title2.html"));
462 463
463 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( 464 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
464 browser()->GetActiveWebContents()->GetRenderViewHost(), 465 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
465 L"", L"domAutomationController.send(history.length)", &length)); 466 L"", L"domAutomationController.send(history.length)", &length));
466 EXPECT_EQ(2, length); 467 EXPECT_EQ(2, length);
467 } 468 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698