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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 <algorithm> 5 #include <algorithm>
6 #include <fstream> 6 #include <fstream>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // Note that only lines whose first character is an upper-case letter are 47 // Note that only lines whose first character is an upper-case letter are
48 // processed when creating the test database. 48 // processed when creating the test database.
49 49
50 namespace history { 50 namespace history {
51 51
52 // ----------------------------------------------------------------------------- 52 // -----------------------------------------------------------------------------
53 53
54 // Observer class so the unit tests can wait while the cache is being saved. 54 // Observer class so the unit tests can wait while the cache is being saved.
55 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver { 55 class CacheFileSaverObserver : public InMemoryURLIndex::SaveCacheObserver {
56 public: 56 public:
57 explicit CacheFileSaverObserver(MessageLoop* loop); 57 explicit CacheFileSaverObserver(base::MessageLoop* loop);
58 virtual void OnCacheSaveFinished(bool succeeded) OVERRIDE; 58 virtual void OnCacheSaveFinished(bool succeeded) OVERRIDE;
59 59
60 MessageLoop* loop_; 60 base::MessageLoop* loop_;
61 bool succeeded_; 61 bool succeeded_;
62 DISALLOW_COPY_AND_ASSIGN(CacheFileSaverObserver); 62 DISALLOW_COPY_AND_ASSIGN(CacheFileSaverObserver);
63 }; 63 };
64 64
65 CacheFileSaverObserver::CacheFileSaverObserver(MessageLoop* loop) 65 CacheFileSaverObserver::CacheFileSaverObserver(base::MessageLoop* loop)
66 : loop_(loop), 66 : loop_(loop), succeeded_(false) {
67 succeeded_(false) {
68 DCHECK(loop); 67 DCHECK(loop);
69 } 68 }
70 69
71 void CacheFileSaverObserver::OnCacheSaveFinished(bool succeeded) { 70 void CacheFileSaverObserver::OnCacheSaveFinished(bool succeeded) {
72 succeeded_ = succeeded; 71 succeeded_ = succeeded;
73 loop_->Quit(); 72 loop_->Quit();
74 } 73 }
75 74
76 // ----------------------------------------------------------------------------- 75 // -----------------------------------------------------------------------------
77 76
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Pass-through functions to simplify our friendship with URLIndexPrivateData. 110 // Pass-through functions to simplify our friendship with URLIndexPrivateData.
112 bool UpdateURL(const URLRow& row); 111 bool UpdateURL(const URLRow& row);
113 bool DeleteURL(const GURL& url); 112 bool DeleteURL(const GURL& url);
114 113
115 // Data verification helper functions. 114 // Data verification helper functions.
116 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data); 115 void ExpectPrivateDataNotEmpty(const URLIndexPrivateData& data);
117 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data); 116 void ExpectPrivateDataEmpty(const URLIndexPrivateData& data);
118 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected, 117 void ExpectPrivateDataEqual(const URLIndexPrivateData& expected,
119 const URLIndexPrivateData& actual); 118 const URLIndexPrivateData& actual);
120 119
121 MessageLoopForUI message_loop_; 120 base::MessageLoopForUI message_loop_;
122 content::TestBrowserThread ui_thread_; 121 content::TestBrowserThread ui_thread_;
123 content::TestBrowserThread file_thread_; 122 content::TestBrowserThread file_thread_;
124 TestingProfile profile_; 123 TestingProfile profile_;
125 HistoryService* history_service_; 124 HistoryService* history_service_;
126 125
127 scoped_ptr<InMemoryURLIndex> url_index_; 126 scoped_ptr<InMemoryURLIndex> url_index_;
128 HistoryDatabase* history_database_; 127 HistoryDatabase* history_database_;
129 }; 128 };
130 129
131 InMemoryURLIndexTest::InMemoryURLIndexTest() 130 InMemoryURLIndexTest::InMemoryURLIndexTest()
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 EXPECT_TRUE(private_data.word_list_.empty()); 1030 EXPECT_TRUE(private_data.word_list_.empty());
1032 EXPECT_TRUE(private_data.available_words_.empty()); 1031 EXPECT_TRUE(private_data.available_words_.empty());
1033 EXPECT_TRUE(private_data.word_map_.empty()); 1032 EXPECT_TRUE(private_data.word_map_.empty());
1034 EXPECT_TRUE(private_data.char_word_map_.empty()); 1033 EXPECT_TRUE(private_data.char_word_map_.empty());
1035 EXPECT_TRUE(private_data.word_id_history_map_.empty()); 1034 EXPECT_TRUE(private_data.word_id_history_map_.empty());
1036 EXPECT_TRUE(private_data.history_id_word_map_.empty()); 1035 EXPECT_TRUE(private_data.history_id_word_map_.empty());
1037 EXPECT_TRUE(private_data.history_info_map_.empty()); 1036 EXPECT_TRUE(private_data.history_info_map_.empty());
1038 EXPECT_TRUE(private_data.word_starts_map_.empty()); 1037 EXPECT_TRUE(private_data.word_starts_map_.empty());
1039 1038
1040 HistoryIndexRestoreObserver restore_observer( 1039 HistoryIndexRestoreObserver restore_observer(
1041 base::Bind(&MessageLoop::Quit, base::Unretained(&message_loop_))); 1040 base::Bind(&base::MessageLoop::Quit, base::Unretained(&message_loop_)));
1042 url_index_->set_restore_cache_observer(&restore_observer); 1041 url_index_->set_restore_cache_observer(&restore_observer);
1043 PostRestoreFromCacheFileTask(); 1042 PostRestoreFromCacheFileTask();
1044 message_loop_.Run(); 1043 message_loop_.Run();
1045 EXPECT_TRUE(restore_observer.succeeded()); 1044 EXPECT_TRUE(restore_observer.succeeded());
1046 1045
1047 URLIndexPrivateData& new_data(*GetPrivateData()); 1046 URLIndexPrivateData& new_data(*GetPrivateData());
1048 1047
1049 // Make sure the data we have was reloaded from cache. (Version 0 1048 // Make sure the data we have was reloaded from cache. (Version 0
1050 // means rebuilt from history; anything else means restored from 1049 // means rebuilt from history; anything else means restored from
1051 // a cache version.) 1050 // a cache version.)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 full_file_path.GetComponents(&actual_parts); 1098 full_file_path.GetComponents(&actual_parts);
1100 ASSERT_EQ(expected_parts.size(), actual_parts.size()); 1099 ASSERT_EQ(expected_parts.size(), actual_parts.size());
1101 size_t count = expected_parts.size(); 1100 size_t count = expected_parts.size();
1102 for (size_t i = 0; i < count; ++i) 1101 for (size_t i = 0; i < count; ++i)
1103 EXPECT_EQ(expected_parts[i], actual_parts[i]); 1102 EXPECT_EQ(expected_parts[i], actual_parts[i]);
1104 // Must clear the history_dir_ to satisfy the dtor's DCHECK. 1103 // Must clear the history_dir_ to satisfy the dtor's DCHECK.
1105 set_history_dir(base::FilePath()); 1104 set_history_dir(base::FilePath());
1106 } 1105 }
1107 1106
1108 } // namespace history 1107 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698