| OLD | NEW |
| 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/sync/test/integration/bookmarks_helper.h" | 5 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <stack> | 11 #include <stack> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 18 #include "base/rand_util.h" | 19 #include "base/rand_util.h" |
| 19 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/synchronization/waitable_event.h" | 25 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/task/cancelable_task_tracker.h" | 26 #include "base/task/cancelable_task_tracker.h" |
| 26 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 27 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 49 #include "testing/gtest/include/gtest/gtest.h" | 50 #include "testing/gtest/include/gtest/gtest.h" |
| 50 #include "third_party/skia/include/core/SkBitmap.h" | 51 #include "third_party/skia/include/core/SkBitmap.h" |
| 51 #include "ui/base/models/tree_node_iterator.h" | 52 #include "ui/base/models/tree_node_iterator.h" |
| 52 #include "ui/gfx/image/image_skia.h" | 53 #include "ui/gfx/image/image_skia.h" |
| 53 | 54 |
| 54 using bookmarks::BookmarkModel; | 55 using bookmarks::BookmarkModel; |
| 55 using bookmarks::BookmarkNode; | 56 using bookmarks::BookmarkNode; |
| 56 | 57 |
| 57 namespace { | 58 namespace { |
| 58 | 59 |
| 59 // History task which runs all pending tasks on the history thread and | 60 // History task which signals an event. |
| 60 // signals when the tasks have completed. | 61 class SignalEventTask : public history::HistoryDBTask { |
| 61 class HistoryEmptyTask : public history::HistoryDBTask { | |
| 62 public: | 62 public: |
| 63 explicit HistoryEmptyTask(base::WaitableEvent* done) : done_(done) {} | 63 explicit SignalEventTask(base::WaitableEvent* done) : done_(done) {} |
| 64 | 64 |
| 65 bool RunOnDBThread(history::HistoryBackend* backend, | 65 bool RunOnDBThread(history::HistoryBackend* backend, |
| 66 history::HistoryDatabase* db) override { | 66 history::HistoryDatabase* db) override { |
| 67 content::RunAllPendingInMessageLoop(); | |
| 68 done_->Signal(); | 67 done_->Signal(); |
| 69 return true; | 68 return true; |
| 70 } | 69 } |
| 71 | 70 |
| 72 void DoneRunOnMainThread() override {} | 71 void DoneRunOnMainThread() override {} |
| 73 | 72 |
| 74 private: | 73 private: |
| 75 base::WaitableEvent* done_; | 74 base::WaitableEvent* done_; |
| 76 }; | 75 }; |
| 77 | 76 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 profiles_which_need_to_wait.push_back( | 305 profiles_which_need_to_wait.push_back( |
| 307 sync_datatype_helper::test()->GetProfile(i)); | 306 sync_datatype_helper::test()->GetProfile(i)); |
| 308 | 307 |
| 309 for (size_t i = 0; i < profiles_which_need_to_wait.size(); ++i) { | 308 for (size_t i = 0; i < profiles_which_need_to_wait.size(); ++i) { |
| 310 Profile* profile = profiles_which_need_to_wait[i]; | 309 Profile* profile = profiles_which_need_to_wait[i]; |
| 311 history::HistoryService* history_service = | 310 history::HistoryService* history_service = |
| 312 HistoryServiceFactory::GetForProfileWithoutCreating(profile); | 311 HistoryServiceFactory::GetForProfileWithoutCreating(profile); |
| 313 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 312 base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 314 base::WaitableEvent::InitialState::NOT_SIGNALED); | 313 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 315 base::CancelableTaskTracker task_tracker; | 314 base::CancelableTaskTracker task_tracker; |
| 316 history_service->ScheduleDBTask( | 315 // Post a task that signals |done|. Since tasks run in posting order, all |
| 317 std::unique_ptr<history::HistoryDBTask>(new HistoryEmptyTask(&done)), | 316 // previously posted tasks have run when |done| is signaled. |
| 318 &task_tracker); | 317 history_service->ScheduleDBTask(base::MakeUnique<SignalEventTask>(&done), |
| 318 &task_tracker); |
| 319 done.Wait(); | 319 done.Wait(); |
| 320 } | 320 } |
| 321 // Wait such that any notifications broadcast from one of the history threads | 321 // Wait such that any notifications broadcast from one of the history threads |
| 322 // to the UI thread are processed. | 322 // to the UI thread are processed. |
| 323 content::RunAllPendingInMessageLoop(); | 323 content::RunAllPendingInMessageLoop(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 // Checks if the favicon in |node_a| from |model_a| matches that of |node_b| | 326 // Checks if the favicon in |node_a| from |model_a| matches that of |node_b| |
| 327 // from |model_b|. Returns true if they match. | 327 // from |model_b|. Returns true if they match. |
| 328 bool FaviconsMatch(BookmarkModel* model_a, | 328 bool FaviconsMatch(BookmarkModel* model_a, |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 } // namespace | 945 } // namespace |
| 946 | 946 |
| 947 BookmarksUrlChecker::BookmarksUrlChecker(int profile, | 947 BookmarksUrlChecker::BookmarksUrlChecker(int profile, |
| 948 const GURL& url, | 948 const GURL& url, |
| 949 int expected_count) | 949 int expected_count) |
| 950 : AwaitMatchStatusChangeChecker(base::Bind(BookmarkCountsByUrlMatch, | 950 : AwaitMatchStatusChangeChecker(base::Bind(BookmarkCountsByUrlMatch, |
| 951 profile, | 951 profile, |
| 952 base::ConstRef(url), | 952 base::ConstRef(url), |
| 953 expected_count), | 953 expected_count), |
| 954 "Bookmark URL counts match.") {} | 954 "Bookmark URL counts match.") {} |
| OLD | NEW |