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

Side by Side Diff: chrome/browser/sessions/tab_restore_service_browsertest.cc

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 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/stringprintf.h" 5 #include "base/stringprintf.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/sessions/session_service_factory.h" 7 #include "chrome/browser/sessions/session_service_factory.h"
8 #include "chrome/browser/sessions/session_service.h" 8 #include "chrome/browser/sessions/session_service.h"
9 #include "chrome/browser/sessions/session_types.h" 9 #include "chrome/browser/sessions/session_types.h"
10 #include "chrome/browser/sessions/tab_restore_service.h" 10 #include "chrome/browser/sessions/tab_restore_service.h"
11 #include "chrome/browser/sessions/tab_restore_service_factory.h" 11 #include "chrome/browser/sessions/tab_restore_service_factory.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "chrome/test/base/chrome_render_view_test.h" 16 #include "chrome/test/base/chrome_render_view_test.h"
17 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/testing_profile.h" 18 #include "chrome/test/base/testing_profile.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/browser/tab_contents/test_tab_contents.h"
21 #include "content/public/browser/navigation_controller.h" 20 #include "content/public/browser/navigation_controller.h"
22 #include "content/public/browser/navigation_entry.h" 21 #include "content/public/browser/navigation_entry.h"
23 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
25 #include "content/test/render_view_test.h" 24 #include "content/test/render_view_test.h"
25 #include "content/test/web_contents_tester.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
28 28
29 typedef TabRestoreService::Tab Tab; 29 typedef TabRestoreService::Tab Tab;
30 typedef TabRestoreService::Window Window; 30 typedef TabRestoreService::Window Window;
31 using content::WebContentsTester;
31 32
32 using content::NavigationEntry; 33 using content::NavigationEntry;
33 34
34 // Create subclass that overrides TimeNow so that we can control the time used 35 // Create subclass that overrides TimeNow so that we can control the time used
35 // for closed tabs and windows. 36 // for closed tabs and windows.
36 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory { 37 class TabRestoreTimeFactory : public TabRestoreService::TimeFactory {
37 public: 38 public:
38 TabRestoreTimeFactory() : time_(base::Time::Now()) {} 39 TabRestoreTimeFactory() : time_(base::Time::Now()) {}
39 40
40 virtual ~TabRestoreTimeFactory() {} 41 virtual ~TabRestoreTimeFactory() {}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Navigate to three URLs. 80 // Navigate to three URLs.
80 NavigateAndCommit(url1_); 81 NavigateAndCommit(url1_);
81 NavigateAndCommit(url2_); 82 NavigateAndCommit(url2_);
82 NavigateAndCommit(url3_); 83 NavigateAndCommit(url3_);
83 } 84 }
84 85
85 void NavigateToIndex(int index) { 86 void NavigateToIndex(int index) {
86 // Navigate back. We have to do this song and dance as NavigationController 87 // Navigate back. We have to do this song and dance as NavigationController
87 // isn't happy if you navigate immediately while going back. 88 // isn't happy if you navigate immediately while going back.
88 controller().GoToIndex(index); 89 controller().GoToIndex(index);
89 contents()->CommitPendingNavigation(); 90 WebContentsTester::For(contents())->CommitPendingNavigation();
90 } 91 }
91 92
92 void RecreateService() { 93 void RecreateService() {
93 // Must set service to null first so that it is destroyed before the new 94 // Must set service to null first so that it is destroyed before the new
94 // one is created. 95 // one is created.
95 service_->Shutdown(); 96 service_->Shutdown();
96 service_.reset(); 97 service_.reset();
97 service_.reset(new TabRestoreService(profile(), time_factory_)); 98 service_.reset(new TabRestoreService(profile(), time_factory_));
98 service_->LoadTabsFromLastSession(); 99 service_->LoadTabsFromLastSession();
99 } 100 }
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 for (size_t i = 0; i < max_entries + 5; i++) { 640 for (size_t i = 0; i < max_entries + 5; i++) {
640 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i)))); 641 NavigateAndCommit(GURL(StringPrintf("http://%d", static_cast<int>(i))));
641 service_->CreateHistoricalTab(&controller(), -1); 642 service_->CreateHistoricalTab(&controller(), -1);
642 } 643 }
643 644
644 EXPECT_EQ(max_entries, service_->entries_.size()); 645 EXPECT_EQ(max_entries, service_->entries_.size());
645 // This should not crash. 646 // This should not crash.
646 service_->LoadTabsFromLastSession(); 647 service_->LoadTabsFromLastSession();
647 EXPECT_EQ(max_entries, service_->entries_.size()); 648 EXPECT_EQ(max_entries, service_->entries_.size());
648 } 649 }
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_blocking_page_unittest.cc ('k') | chrome/browser/tabs/tab_strip_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698