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

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

Issue 409743003: Use content::RunBlockingPoolTask() in tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/sessions/persistent_tab_restore_service.h" 5 #include "chrome/browser/sessions/persistent_tab_restore_service.h"
6 6
7 #include <string>
8
7 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
8 #include "base/run_loop.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/sessions/session_service.h" 14 #include "chrome/browser/sessions/session_service.h"
14 #include "chrome/browser/sessions/session_service_factory.h" 15 #include "chrome/browser/sessions/session_service_factory.h"
15 #include "chrome/browser/sessions/session_types.h" 16 #include "chrome/browser/sessions/session_types.h"
16 #include "chrome/browser/sessions/tab_restore_service_factory.h" 17 #include "chrome/browser/sessions/tab_restore_service_factory.h"
17 #include "chrome/browser/sessions/tab_restore_service_observer.h" 18 #include "chrome/browser/sessions/tab_restore_service_observer.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
20 #include "chrome/test/base/chrome_render_view_test.h" 21 #include "chrome/test/base/chrome_render_view_test.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
22 #include "components/sessions/serialized_navigation_entry_test_helper.h" 23 #include "components/sessions/serialized_navigation_entry_test_helper.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/navigation_controller.h" 25 #include "content/public/browser/navigation_controller.h"
25 #include "content/public/browser/navigation_entry.h" 26 #include "content/public/browser/navigation_entry.h"
26 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/notification_types.h" 28 #include "content/public/browser/notification_types.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "content/public/test/render_view_test.h" 30 #include "content/public/test/render_view_test.h"
31 #include "content/public/test/test_utils.h"
30 #include "content/public/test/web_contents_tester.h" 32 #include "content/public/test/web_contents_tester.h"
31 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
32 34
33 typedef TabRestoreService::Tab Tab; 35 typedef TabRestoreService::Tab Tab;
34 typedef TabRestoreService::Window Window; 36 typedef TabRestoreService::Window Window;
35 37
36 using content::NavigationEntry; 38 using content::NavigationEntry;
37 using content::WebContentsTester; 39 using content::WebContentsTester;
38 using sessions::SerializedNavigationEntry; 40 using sessions::SerializedNavigationEntry;
39 using sessions::SerializedNavigationEntryTestHelper; 41 using sessions::SerializedNavigationEntryTestHelper;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Navigate back. We have to do this song and dance as NavigationController 109 // Navigate back. We have to do this song and dance as NavigationController
108 // isn't happy if you navigate immediately while going back. 110 // isn't happy if you navigate immediately while going back.
109 controller().GoToIndex(index); 111 controller().GoToIndex(index);
110 WebContentsTester::For(web_contents())->CommitPendingNavigation(); 112 WebContentsTester::For(web_contents())->CommitPendingNavigation();
111 } 113 }
112 114
113 void RecreateService() { 115 void RecreateService() {
114 // Must set service to null first so that it is destroyed before the new 116 // Must set service to null first so that it is destroyed before the new
115 // one is created. 117 // one is created.
116 service_->Shutdown(); 118 service_->Shutdown();
117 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 119 content::RunAllBlockingPoolTasksUntilIdle();
118 service_.reset(); 120 service_.reset();
119 service_.reset(new PersistentTabRestoreService(profile(), time_factory_)); 121 service_.reset(new PersistentTabRestoreService(profile(), time_factory_));
120 SynchronousLoadTabsFromLastSession(); 122 SynchronousLoadTabsFromLastSession();
121 } 123 }
122 124
123 // Adds a window with one tab and url to the profile's session service. 125 // Adds a window with one tab and url to the profile's session service.
124 // If |pinned| is true, the tab is marked as pinned in the session service. 126 // If |pinned| is true, the tab is marked as pinned in the session service.
125 void AddWindowWithOneTabToSessionService(bool pinned) { 127 void AddWindowWithOneTabToSessionService(bool pinned) {
126 SessionService* session_service = 128 SessionService* session_service =
127 SessionServiceFactory::GetForProfile(profile()); 129 SessionServiceFactory::GetForProfile(profile());
(...skipping 23 matching lines...) Expand all
151 153
152 AddWindowWithOneTabToSessionService(pinned); 154 AddWindowWithOneTabToSessionService(pinned);
153 155
154 // Set this, otherwise previous session won't be loaded. 156 // Set this, otherwise previous session won't be loaded.
155 profile()->set_last_session_exited_cleanly(false); 157 profile()->set_last_session_exited_cleanly(false);
156 } 158 }
157 159
158 void SynchronousLoadTabsFromLastSession() { 160 void SynchronousLoadTabsFromLastSession() {
159 // Ensures that the load is complete before continuing. 161 // Ensures that the load is complete before continuing.
160 service_->LoadTabsFromLastSession(); 162 service_->LoadTabsFromLastSession();
161 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 163 content::RunAllBlockingPoolTasksUntilIdle();
162 base::RunLoop().RunUntilIdle();
163 content::BrowserThread::GetBlockingPool()->FlushForTesting();
164 } 164 }
165 165
166 GURL url1_; 166 GURL url1_;
167 GURL url2_; 167 GURL url2_;
168 GURL url3_; 168 GURL url3_;
169 std::string user_agent_override_; 169 std::string user_agent_override_;
170 scoped_ptr<PersistentTabRestoreService> service_; 170 scoped_ptr<PersistentTabRestoreService> service_;
171 PersistentTabRestoreTimeFactory* time_factory_; 171 PersistentTabRestoreTimeFactory* time_factory_;
172 }; 172 };
173 173
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 758
759 EXPECT_FALSE(service_->IsLoaded()); 759 EXPECT_FALSE(service_->IsLoaded());
760 TestTabRestoreServiceObserver observer; 760 TestTabRestoreServiceObserver observer;
761 service_->AddObserver(&observer); 761 service_->AddObserver(&observer);
762 EXPECT_EQ(max_entries, service_->entries().size()); 762 EXPECT_EQ(max_entries, service_->entries().size());
763 SynchronousLoadTabsFromLastSession(); 763 SynchronousLoadTabsFromLastSession();
764 EXPECT_TRUE(observer.got_loaded()); 764 EXPECT_TRUE(observer.got_loaded());
765 EXPECT_TRUE(service_->IsLoaded()); 765 EXPECT_TRUE(service_->IsLoaded());
766 service_->RemoveObserver(&observer); 766 service_->RemoveObserver(&observer);
767 } 767 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698