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

Side by Side Diff: chrome/browser/history/android/android_provider_backend_unittest.cc

Issue 2543023003: Fix TestBrowserThread destruction order in Android history tests. (Closed)
Patch Set: undo safe_browsing changes Created 4 years 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
« no previous file with comments | « no previous file | chrome/browser/history/android/bookmark_model_sql_handler_unittest.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 "chrome/browser/history/android/android_provider_backend.h" 5 #include "chrome/browser/history/android/android_provider_backend.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/threading/thread_task_runner_handle.h"
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
16 #include "chrome/browser/history/chrome_history_client.h" 18 #include "chrome/browser/history/chrome_history_client.h"
17 #include "chrome/browser/profiles/profile_manager.h" 19 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/common/chrome_constants.h" 20 #include "chrome/common/chrome_constants.h"
19 #include "chrome/test/base/testing_browser_process.h" 21 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
21 #include "chrome/test/base/testing_profile_manager.h" 23 #include "chrome/test/base/testing_profile_manager.h"
22 #include "components/bookmarks/browser/bookmark_model.h" 24 #include "components/bookmarks/browser/bookmark_model.h"
23 #include "components/bookmarks/test/bookmark_test_helpers.h" 25 #include "components/bookmarks/test/bookmark_test_helpers.h"
24 #include "components/history/core/browser/android/android_time.h" 26 #include "components/history/core/browser/android/android_time.h"
25 #include "components/history/core/browser/history_backend.h" 27 #include "components/history/core/browser/history_backend.h"
26 #include "components/history/core/browser/history_backend_client.h" 28 #include "components/history/core/browser/history_backend_client.h"
27 #include "components/history/core/browser/history_constants.h" 29 #include "components/history/core/browser/history_constants.h"
28 #include "components/history/core/browser/history_database_params.h" 30 #include "components/history/core/browser/history_database_params.h"
29 #include "components/history/core/browser/keyword_search_term.h" 31 #include "components/history/core/browser/keyword_search_term.h"
30 #include "components/history/core/test/test_history_database.h" 32 #include "components/history/core/test/test_history_database.h"
31 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
32 #include "content/public/test/test_browser_thread.h" 34 #include "content/public/test/test_browser_thread_bundle.h"
33 #include "content/public/test/test_utils.h" 35 #include "content/public/test/test_utils.h"
34 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
35 #include "third_party/skia/include/core/SkBitmap.h" 37 #include "third_party/skia/include/core/SkBitmap.h"
36 38
37 using base::Time; 39 using base::Time;
38 using base::TimeDelta; 40 using base::TimeDelta;
39 using base::UTF8ToUTF16; 41 using base::UTF8ToUTF16;
40 using bookmarks::BookmarkModel; 42 using bookmarks::BookmarkModel;
41 using bookmarks::BookmarkNode; 43 using bookmarks::BookmarkNode;
42 using content::BrowserThread; 44 using content::BrowserThread;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 std::unique_ptr<std::set<GURL>> favicon_changed_; 165 std::unique_ptr<std::set<GURL>> favicon_changed_;
164 166
165 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendNotifier); 167 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendNotifier);
166 }; 168 };
167 169
168 class AndroidProviderBackendTest : public testing::Test { 170 class AndroidProviderBackendTest : public testing::Test {
169 public: 171 public:
170 AndroidProviderBackendTest() 172 AndroidProviderBackendTest()
171 : thumbnail_db_(NULL), 173 : thumbnail_db_(NULL),
172 profile_manager_(TestingBrowserProcess::GetGlobal()), 174 profile_manager_(TestingBrowserProcess::GetGlobal()),
173 bookmark_model_(NULL), 175 bookmark_model_(NULL) {}
174 ui_thread_(BrowserThread::UI, &message_loop_), 176
175 file_thread_(BrowserThread::FILE, &message_loop_) {} 177 ~AndroidProviderBackendTest() override {
176 ~AndroidProviderBackendTest() override {} 178 // Avoid use after frees by running any unhandled tasks before freeing this
179 // fixture's members.
180 base::RunLoop().RunUntilIdle();
181 }
177 182
178 protected: 183 protected:
179 void SetUp() override { 184 void SetUp() override {
180 // Setup the testing profile, so the bookmark_model_sql_handler could 185 // Setup the testing profile, so the bookmark_model_sql_handler could
181 // get the bookmark model from it. 186 // get the bookmark model from it.
182 ASSERT_TRUE(profile_manager_.SetUp()); 187 ASSERT_TRUE(profile_manager_.SetUp());
183 // It seems that the name has to be chrome::kInitialProfile, so it 188 // It seems that the name has to be chrome::kInitialProfile, so it
184 // could be found by ProfileManager::GetLastUsedProfile(). 189 // could be found by ProfileManager::GetLastUsedProfile().
185 TestingProfile* testing_profile = profile_manager_.CreateTestingProfile( 190 TestingProfile* testing_profile = profile_manager_.CreateTestingProfile(
186 chrome::kInitialProfile); 191 chrome::kInitialProfile);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 row.create_time_ = FromDatabaseTime(statement.ColumnInt64(0)); 243 row.create_time_ = FromDatabaseTime(statement.ColumnInt64(0));
239 row.last_visit_time_ = FromDatabaseTime(statement.ColumnInt64(1)); 244 row.last_visit_time_ = FromDatabaseTime(statement.ColumnInt64(1));
240 row.url_id_ = statement.ColumnInt64(2); 245 row.url_id_ = statement.ColumnInt64(2);
241 row.bookmark_ = statement.ColumnBool(3); 246 row.bookmark_ = statement.ColumnBool(3);
242 row.favicon_id_ = statement.ColumnInt64(4); 247 row.favicon_id_ = statement.ColumnInt64(4);
243 rows->push_back(row); 248 rows->push_back(row);
244 } 249 }
245 return true; 250 return true;
246 } 251 }
247 252
253 content::TestBrowserThreadBundle thread_bundle_;
254
248 AndroidProviderBackendNotifier notifier_; 255 AndroidProviderBackendNotifier notifier_;
249 scoped_refptr<HistoryBackend> history_backend_; 256 scoped_refptr<HistoryBackend> history_backend_;
250 TestHistoryDatabase history_db_; 257 TestHistoryDatabase history_db_;
251 ThumbnailDatabase thumbnail_db_; 258 ThumbnailDatabase thumbnail_db_;
252 base::ScopedTempDir temp_dir_; 259 base::ScopedTempDir temp_dir_;
253 base::FilePath android_cache_db_name_; 260 base::FilePath android_cache_db_name_;
254 base::FilePath history_db_name_; 261 base::FilePath history_db_name_;
255 base::FilePath thumbnail_db_name_; 262 base::FilePath thumbnail_db_name_;
256 263
257 TestingProfileManager profile_manager_; 264 TestingProfileManager profile_manager_;
258 BookmarkModel* bookmark_model_; 265 BookmarkModel* bookmark_model_;
259 base::MessageLoopForUI message_loop_;
260 content::TestBrowserThread ui_thread_;
261 content::TestBrowserThread file_thread_;
262 std::unique_ptr<history::HistoryClient> history_client_; 266 std::unique_ptr<history::HistoryClient> history_client_;
263 std::unique_ptr<history::HistoryBackendClient> history_backend_client_; 267 std::unique_ptr<history::HistoryBackendClient> history_backend_client_;
264 268
265 private: 269 private:
266 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendTest); 270 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendTest);
267 }; 271 };
268 272
269 TEST_F(AndroidProviderBackendTest, IgnoreAboutBlank) { 273 TEST_F(AndroidProviderBackendTest, IgnoreAboutBlank) {
270 GURL url("about:blank"); 274 GURL url("about:blank");
271 ASSERT_FALSE(history_client_->CanAddURL(url)); 275 ASSERT_FALSE(history_client_->CanAddURL(url));
(...skipping 24 matching lines...) Expand all
296 GURL url3("http://www.bookmark.com"); 300 GURL url3("http://www.bookmark.com");
297 base::string16 title3(UTF8ToUTF16("bookmark")); 301 base::string16 title3(UTF8ToUTF16("bookmark"));
298 ASSERT_TRUE(bookmark_model_->AddURL(bookmark_model_->bookmark_bar_node(), 0, 302 ASSERT_TRUE(bookmark_model_->AddURL(bookmark_model_->bookmark_bar_node(), 0,
299 title3, url3)); 303 title3, url3));
300 // Only use the HistoryBackend to generate the test data. 304 // Only use the HistoryBackend to generate the test data.
301 // HistoryBackend will shutdown after that. 305 // HistoryBackend will shutdown after that.
302 { 306 {
303 scoped_refptr<HistoryBackend> history_backend; 307 scoped_refptr<HistoryBackend> history_backend;
304 history_backend = new HistoryBackend(new AndroidProviderBackendDelegate(), 308 history_backend = new HistoryBackend(new AndroidProviderBackendDelegate(),
305 history_client_->CreateBackendClient(), 309 history_client_->CreateBackendClient(),
306 message_loop_.task_runner()); 310 base::ThreadTaskRunnerHandle::Get());
307 history_backend->Init(false, 311 history_backend->Init(false,
308 TestHistoryDatabaseParamsForPath(temp_dir_.GetPath())); 312 TestHistoryDatabaseParamsForPath(temp_dir_.GetPath()));
309 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED); 313 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED);
310 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 314 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
311 URLRow url_row; 315 URLRow url_row;
312 316
313 ASSERT_TRUE(history_backend->GetURL(url1, &url_row)); 317 ASSERT_TRUE(history_backend->GetURL(url1, &url_row));
314 url_id1 = url_row.id(); 318 url_id1 = url_row.id();
315 ASSERT_TRUE(history_backend->GetURL(url2, &url_row)); 319 ASSERT_TRUE(history_backend->GetURL(url2, &url_row));
316 url_id2 = url_row.id(); 320 url_id2 = url_row.id();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5), 436 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5),
433 ui::PAGE_TRANSITION_LINK)); 437 ui::PAGE_TRANSITION_LINK));
434 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK)); 438 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK));
435 439
436 // Only use the HistoryBackend to generate the test data. 440 // Only use the HistoryBackend to generate the test data.
437 // HistoryBackend will shutdown after that. 441 // HistoryBackend will shutdown after that.
438 { 442 {
439 scoped_refptr<HistoryBackend> history_backend; 443 scoped_refptr<HistoryBackend> history_backend;
440 history_backend = new HistoryBackend(new AndroidProviderBackendDelegate(), 444 history_backend = new HistoryBackend(new AndroidProviderBackendDelegate(),
441 history_client_->CreateBackendClient(), 445 history_client_->CreateBackendClient(),
442 message_loop_.task_runner()); 446 base::ThreadTaskRunnerHandle::Get());
443 history_backend->Init(false, 447 history_backend->Init(false,
444 TestHistoryDatabaseParamsForPath(temp_dir_.GetPath())); 448 TestHistoryDatabaseParamsForPath(temp_dir_.GetPath()));
445 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED); 449 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED);
446 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 450 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
447 451
448 history::URLRows url_rows(2u); 452 history::URLRows url_rows(2u);
449 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0])); 453 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0]));
450 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1])); 454 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1]));
451 url_rows[0].set_title(title1); 455 url_rows[0].set_title(title1);
452 url_rows[1].set_title(title2); 456 url_rows[1].set_title(title2);
(...skipping 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5), 1824 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5),
1821 ui::PAGE_TRANSITION_LINK)); 1825 ui::PAGE_TRANSITION_LINK));
1822 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK)); 1826 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK));
1823 1827
1824 // Only use the HistoryBackend to generate the test data. 1828 // Only use the HistoryBackend to generate the test data.
1825 // HistoryBackend will shutdown after that. 1829 // HistoryBackend will shutdown after that.
1826 { 1830 {
1827 scoped_refptr<HistoryBackend> history_backend; 1831 scoped_refptr<HistoryBackend> history_backend;
1828 history_backend = new HistoryBackend(new AndroidProviderBackendDelegate(), 1832 history_backend = new HistoryBackend(new AndroidProviderBackendDelegate(),
1829 history_client_->CreateBackendClient(), 1833 history_client_->CreateBackendClient(),
1830 message_loop_.task_runner()); 1834 base::ThreadTaskRunnerHandle::Get());
1831 history_backend->Init(false, 1835 history_backend->Init(false,
1832 TestHistoryDatabaseParamsForPath(temp_dir_.GetPath())); 1836 TestHistoryDatabaseParamsForPath(temp_dir_.GetPath()));
1833 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED); 1837 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED);
1834 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 1838 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
1835 URLRow url_row; 1839 URLRow url_row;
1836 1840
1837 history::URLRows url_rows(2u); 1841 history::URLRows url_rows(2u);
1838 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0])); 1842 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0]));
1839 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1])); 1843 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1]));
1840 url_rows[0].set_title(title1); 1844 url_rows[0].set_title(title1);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 update_args, &update_count)); 2097 update_args, &update_count));
2094 // Verify notifications. 2098 // Verify notifications.
2095 EXPECT_FALSE(notifier_.deleted_details()); 2099 EXPECT_FALSE(notifier_.deleted_details());
2096 ASSERT_TRUE(notifier_.modified_details()); 2100 ASSERT_TRUE(notifier_.modified_details());
2097 ASSERT_EQ(1u, notifier_.modified_details()->size()); 2101 ASSERT_EQ(1u, notifier_.modified_details()->size());
2098 // No favicon will be updated as thumbnail database is missing. 2102 // No favicon will be updated as thumbnail database is missing.
2099 EXPECT_FALSE(notifier_.favicon_changed()); 2103 EXPECT_FALSE(notifier_.favicon_changed());
2100 } 2104 }
2101 2105
2102 } // namespace history 2106 } // namespace history
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/history/android/bookmark_model_sql_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698